-
Notifications
You must be signed in to change notification settings - Fork 34
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: data race related to last commit info; flush pruning heights as soon as changed #154
Conversation
@@ -119,15 +124,6 @@ func (m *Manager) ShouldPruneAtHeight(height int64) bool { | |||
return m.opts.GetPruningStrategy() != types.PruningNothing && m.opts.Interval > 0 && height%int64(m.opts.Interval) == 0 | |||
} | |||
|
|||
// FlushPruningHeights flushes the pruning heights to the database for crash recovery. |
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.
Moved down and renamed to FlushAllPruningHeights
// "All" refers to regular pruning heights and snapshot heights, if any. | ||
// It serves the same function as exported FlushPruningHeights. However, it assummes that | ||
// mutex was acquired prior to calling this method. | ||
func (m *Manager) flushAllPruningHeightsUnlocked() { |
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.
This is needed because we already flush under lock in HandleHeight
|
||
rs.mx.RLock() |
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.
This might be redundant because we only write in the same goroutine above. However, there can be concurrent readers.
What do reviewers think?
// If the request's height is the latest height we've committed, then utilize | ||
// the store's lastCommitInfo as this commit info may not be flushed to disk. | ||
// Otherwise, we query for the commit info from disk. | ||
var commitInfo *types.CommitInfo | ||
|
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.
We now flush to disk as soon as rs.lastCommitInfo
is updated. Although I acknowledge that db read is more expensive, I think it's safer to make a database read and let the DB handle synchronization. Also, this change makes it more readable imo
@@ -1022,33 +1041,16 @@ func getLatestVersion(db dbm.DB) int64 { | |||
return latestVersion | |||
} | |||
|
|||
// Gets commitInfo from disk. |
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.
Moved up
closing in support of #184 |
Context
Commit(...)
and read inQuery(...)
andLastCommitID()
rs.lastCommitInfo
Left some extra comments in code
Risks