-
Notifications
You must be signed in to change notification settings - Fork 322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(jobsdb): update cache after transaction completes #2567
Conversation
Codecov ReportBase: 43.86% // Head: 43.86% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## release/1.2.x #2567 +/- ##
==============================================
Coverage 43.86% 43.86%
==============================================
Files 187 187
Lines 39090 39107 +17
==============================================
+ Hits 17146 17156 +10
- Misses 20860 20870 +10
+ Partials 1084 1081 -3
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
@@ -668,7 +701,7 @@ func loadConfig() { | |||
config.RegisterDurationConfigVariable(5, &addNewDSLoopSleepDuration, true, time.Second, []string{"JobsDB.addNewDSLoopSleepDuration", "JobsDB.addNewDSLoopSleepDurationInS"}...) | |||
config.RegisterDurationConfigVariable(5, &refreshDSListLoopSleepDuration, true, time.Second, []string{"JobsDB.refreshDSListLoopSleepDuration", "JobsDB.refreshDSListLoopSleepDurationInS"}...) | |||
config.RegisterDurationConfigVariable(5, &backupCheckSleepDuration, true, time.Second, []string{"JobsDB.backupCheckSleepDuration", "JobsDB.backupCheckSleepDurationIns"}...) | |||
config.RegisterDurationConfigVariable(60, &cacheExpiration, true, time.Minute, []string{"JobsDB.cacheExpiration"}...) | |||
config.RegisterDurationConfigVariable(5, &cacheExpiration, true, time.Minute, []string{"JobsDB.cacheExpiration"}...) |
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.
5 minutes by default should be more than enough and could potentially alleviate the consequences of having an incorrectly populated cache for too long.
// Commit commits the transaction and executes all listeners. | ||
func (tx *Tx) Commit() error { | ||
err := tx.Tx.Commit() | ||
if err == nil { |
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.
Any reason why we are not checking the error early and returning?
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.
In the future we might want to introduce other listeners as well, such as errorListeners
and completionListeners
. In such a case returning early wouldn't be relevant.
Now it can be done, but I preferred having one less loc instead :)
if err != nil {
return err
}
for _, successListener := range tx.successListeners {
successListener()
}
return nil
Description
By updating (invalidating) the cache entries before the transaction commits and for the period until the transaction actually commits, we are risking to have other select queries who arrive during this timeframe to populate the cache with incorrect values: until the transaction commits, changes are not visible to other queries, thus they may erroneously put "no result" entries in the cache.
The above can have as a side-effect to:
proc_error
tables)This fix introduces a
jobsdb.Tx
that wraps asql.Tx
, adding support for registering success listeners. Now, all cache entries are updated after the transaction has been successfully committed.Notion Ticket
Link
Security