Skip to content
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

Closed
wants to merge 8 commits into from

Conversation

p0mvn
Copy link
Member

@p0mvn p0mvn commented Mar 24, 2022

Context

Left some extra comments in code

Risks

  • This change introduced performance overhead due to synchronization in exchange for safety

@p0mvn p0mvn changed the title fix: race condition related to last commit info and flush pruning heights as soon as changed fix: race condition related to last commit info; flush pruning heights as soon as changed Mar 24, 2022
@@ -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.
Copy link
Member Author

@p0mvn p0mvn Mar 24, 2022

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() {
Copy link
Member Author

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()
Copy link
Member Author

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

Copy link
Member Author

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.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved up

@p0mvn p0mvn changed the title fix: race condition related to last commit info; flush pruning heights as soon as changed fix: data race related to last commit info; flush pruning heights as soon as changed Mar 24, 2022
@p0mvn
Copy link
Member Author

p0mvn commented Apr 21, 2022

closing in support of #184

@p0mvn p0mvn closed this Apr 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant