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

refactor: syncronize pruning manager #187

Merged

Conversation

p0mvn
Copy link
Member

@p0mvn p0mvn commented Apr 12, 2022

Description

This PR is a follow-up to: cosmos#11496 (comment)

It mitigates the risk of soundness bugs / data races by synchronizing access to all members of the pruning manager and making some operations atomic. For example, GetHeights, FlushHeights and ResetHeights was merged into one GetFlushAndResetPruningHeights.

In addition, it addresses another previously known issue: #149

  • Now, the pruning heights are flushed to disk immediately, eliminating the risk of losing data on crash and not pruning some heights

Updated unit tests to reflect all changes. Also, added a unit test to attempt pruning the same heights twice.

require.NotNil(t, manager)

manager.SetOptions(types.NewPruningOptions(types.PruningNothing))

require.Nil(t, manager.LoadPruningHeights(db.NewMemDB()))
}

func TestWithSnapshot(t *testing.T) {
Copy link
Member Author

Choose a reason for hiding this comment

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

With 2 locks, this is not possible to reproduce anymore

pruning/manager.go Outdated Show resolved Hide resolved
pruning/manager.go Outdated Show resolved Hide resolved
pruning/manager.go Outdated Show resolved Hide resolved
store/rootmulti/store.go Outdated Show resolved Hide resolved
store/rootmulti/store.go Outdated Show resolved Hide resolved
@p0mvn
Copy link
Member Author

p0mvn commented Apr 12, 2022

All comments are addressed

@p0mvn p0mvn merged this pull request into roman/upstream/snapshot-pruning-refactor Apr 13, 2022
@p0mvn p0mvn deleted the roman/upstream/no-data-races branch April 13, 2022 15:18
p0mvn added a commit that referenced this pull request Apr 13, 2022
* progress

* refactor pruning manager to have no data races; flush heights immediately when updated in memory; unit tests

* typo in TestMultiStore_PruningRestart

* fmt

* improve comments

* avoid mutex init, move comments to struct declaration, return nil with error, fix logs
p0mvn added a commit that referenced this pull request Apr 20, 2022
* progress

* refactor pruning manager to have no data races; flush heights immediately when updated in memory; unit tests

* typo in TestMultiStore_PruningRestart

* fmt

* improve comments

* avoid mutex init, move comments to struct declaration, return nil with error, fix logs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants