-
Notifications
You must be signed in to change notification settings - Fork 86
WIP: PostgreSQL LISTEN/NOTIFY: invalidate wit cache #2172
base: master
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2172 +/- ##
==========================================
- Coverage 69.59% 69.56% -0.04%
==========================================
Files 170 171 +1
Lines 15681 15730 +49
==========================================
+ Hits 10913 10942 +29
- Misses 3774 3794 +20
Partials 994 994
Continue to review full report at Codecov.
|
gormsupport/listener_test.go
Outdated
|
||
// Send a notification from a completely different connection than the | ||
// one we established to listen to channels. | ||
s.DB.Debug().Exec("SELECT pg_notify($1, $2)", channelName, payload) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mental note for myself: I need to check for db.Error
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in b227b9f
gormsupport/listener_test.go
Outdated
|
||
// This will send a notification on the | ||
// gormsupport.ChanSpaceTemplateUpdates channel | ||
migration.PopulateCommonTypes(nil, s.DB) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mental note for myself: I need to check for err
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in b227b9f
[test] |
@kwk I think this would fix openshiftio/openshift.io#3930. |
Why don't we use a cache server like Memcached? |
@baijum I think the effort to maintain a memcached server and have it deployed is outweighed by the simplicity and tight connection we already have with postgres. Also note that we might want to use PostgreSQL's notification system for other stuff in the future, so it is not only about caching although it is the first use-case for it. One can easily think of a use case in which we use it to trigger web socket notifications to clients for example. But that's not written in stone. |
@kwk I agree there might be an inconsistent state but that wouldn't last for long. As soon as all the pods are updated we will have an empty cache in all the pods. |
@jarifibrahim in the future the templates can be changed at run-time without requiring a restart. |
|
||
// A SubscriberFunc describes the function signature that a subscriber needs to | ||
// have. The channel parameter is just an arbitrary identifier string the | ||
// identities a channel. The extra parameter is can contain optional data that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The extra parameter is can contain
@@ -140,6 +143,13 @@ func main() { | |||
os.Exit(0) | |||
} | |||
|
|||
// Ensure we delete the work item cache when we receive a notification from postgres | |||
gormsupport.SetupDatabaseListener(*config, map[string]gormsupport.SubscriberFunc{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens when SetupDatabaseListener
function return an error? The error value is not handled here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. I will have a look when this PR becomes more relevant.
PLEASE, DO NOT MERGE AS THIS MIGHT NEED APPROVAL FROM A POTENTIALLY LARGE AUDIENCE!!!
This change uses PostgreSQL's LISTEN/NOTIFY concept as an inter-process communication to signal that all core pods shall reload their work item cache after a space template was updated.
Here's the piece of code that subscribes to a channel:
This concept can be reused very easily by adding new listeners for the individual event channels.
TODO: