-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
feat(store/v1): async pruning iavl #20321
base: main
Are you sure you want to change the base?
Conversation
Important Review skippedReview was skipped due to path filters Files ignored due to path filters (4)
You can disable this status message by setting the WalkthroughThe recent changes introduce new methods for managing pruning behavior during commit operations in the Cosmos SDK. Specifically, they add functionality to pause and resume pruning, ensuring that commits are not disrupted. These updates involve adding new methods to existing interfaces and implementing these methods in relevant store files. Additionally, the Changes
Sequence Diagram(s) (Beta)sequenceDiagram
participant User
participant Store
participant Committer
participant PausablePruner
User->>Store: Call SetCommitting(true)
Store->>+Committer: SetCommitting(true)
Committer-->>Store: Acknowledge
Store->>+PausablePruner: PausePruning(true)
PausablePruner-->>Store: Acknowledge
Note right of Store: Commit operations proceed<br>with pruning paused.
User->>Store: Call SetCommitting(false)
Store->>+Committer: SetCommitting(false)
Committer-->>Store: Acknowledge
Store->>+PausablePruner: PausePruning(false)
PausablePruner-->>Store: Acknowledge
Note right of Store: Pruning resumes after<br>commit operations.
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
@cool-develope your pull request is missing a changelog! |
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.
Actionable comments posted: 0
Review Details
Configuration used: .coderabbit.yml
Review profile: CHILL
Files ignored due to path filters (2)
store/go.mod
is excluded by!**/*.mod
store/go.sum
is excluded by!**/*.sum
Files selected for processing (8)
- store/iavl/store.go (2 hunks)
- store/iavl/tree.go (2 hunks)
- store/mem/store.go (1 hunks)
- store/rootmulti/dbadapter.go (1 hunks)
- store/rootmulti/store.go (2 hunks)
- store/rootmulti/store_test.go (4 hunks)
- store/transient/store.go (1 hunks)
- store/types/store.go (1 hunks)
Files skipped from review due to trivial changes (1)
- store/rootmulti/store_test.go
Additional Context Used
Path-based Instructions (7)
store/transient/store.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.store/rootmulti/dbadapter.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.store/mem/store.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.store/iavl/tree.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.store/iavl/store.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.store/types/store.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.store/rootmulti/store.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
Additional comments not posted (9)
store/transient/store.go (1)
34-34
: The implementation ofSetCommitting
as a no-op is appropriate for a transient store, where data does not persist beyond a session.store/rootmulti/dbadapter.go (1)
43-43
: The implementation ofSetCommitting
as a no-op is appropriate forcommitDBStoreAdapter
, aligning with its characteristics of not computing any commit hash and not loading older state.store/mem/store.go (1)
53-53
: The implementation ofSetCommitting
as a no-op is appropriate for a memory store, where pruning operations are not required.store/iavl/tree.go (2)
59-59
: The implementation ofSetCommitting
to raise an exception on an immutable IAVL tree is appropriate, ensuring the tree's integrity by preventing state changes.
63-63
: The implementation ofUnsetCommitting
to raise an exception on an immutable IAVL tree is appropriate, ensuring the tree's integrity by preventing state changes.store/iavl/store.go (2)
55-55
: The update toLoadStoreWithInitialVersion
to includeiavl.AsyncPruningOption(true)
is correctly implemented, aligning with the PR's objectives to enhance pruning efficiency by enabling asynchronous operations.
153-153
: The implementation ofSetCommitting
to delegate state changes based on theisCommit
flag is appropriate, allowing the IAVL store to manage its committing status effectively.store/types/store.go (1)
30-30
: The addition ofSetCommitting
to theCommitter
interface is appropriate, enabling different store types to implement their own pruning logic during commit phases, aligning with the PR's objectives.store/rootmulti/store.go (1)
461-466
: Ensure that all stores implementSetCommitting
method to avoid runtime panics.Verification successful
The verification process has confirmed that all store types within the codebase implement the
SetCommitting
method. This includes theStore
types instore/rootmulti
,store/mem
,store/iavl
, andstore/transient
. Therefore, the concern about potential runtime panics due to missing implementations of this method is unfounded.
store/rootmulti/store.go
:SetCommitting
implementedstore/mem/store.go
:SetCommitting
implementedstore/iavl/store.go
:SetCommitting
implementedstore/transient/store.go
:SetCommitting
implementedScripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that all stores implement the `SetCommitting` method. # Test: Search for stores that might not implement `SetCommitting`. Expect: No results. rg --type go $'func \\\\(.*Store\\\\) SetCommitting\\\\('Length of output: 173
Script:
#!/bin/bash # Description: Verify that all stores implement the `SetCommitting` method. # Test: Search for stores that might not implement `SetCommitting`. Expect: No results. rg --type go 'func \(.*Store\) SetCommitting\('Length of output: 319
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.
LGTM, just the question around breaking the interface, can we cast to iavl tree and avoid the breakage
SetCommitting() | ||
UnsetCommitting() | ||
SaveVersion() ([]byte, int64, error) |
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.
do we need to break this interface?
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.
yes, this is the interface of MutableTree
, not allow to modify it
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.
Actionable comments posted: 0
Review Details
Configuration used: .coderabbit.yml
Review profile: CHILL
Files ignored due to path filters (6)
simapp/go.mod
is excluded by!**/*.mod
simapp/go.sum
is excluded by!**/*.sum
store/go.mod
is excluded by!**/*.mod
store/go.sum
is excluded by!**/*.sum
tests/go.mod
is excluded by!**/*.mod
tests/go.sum
is excluded by!**/*.sum
Files selected for processing (3)
- simapp/gomod2nix.toml (7 hunks)
- store/rootmulti/store.go (2 hunks)
- store/types/store.go (1 hunks)
Files skipped from review as they are similar to previous changes (2)
- store/rootmulti/store.go
- store/types/store.go
Additional comments not posted (10)
simapp/gomod2nix.toml (10)
5-6
: Ensure the updated version and hash forbuf.build/gen/go/cometbft/cometbft/protocolbuffers/go
are correct and consistent with the source.
8-9
: Ensure the updated version and hash forbuf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go
are correct and consistent with the source.
135-136
: Ensure the updated version and hash forgithub.com/cosmos/iavl
are correct and consistent with the source.
276-277
: Ensure the updated version and hash forgithub.com/hashicorp/go-hclog
are correct and consistent with the source.
390-391
: Ensure the updated version and hash forgithub.com/pelletier/go-toml/v2
are correct and consistent with the source.
402-403
: Ensure the updated version and hash forgithub.com/prometheus/client_golang
are correct and consistent with the source.
514-515
: Ensure the updated version and hash forgolang.org/x/crypto
are correct and consistent with the source.
517-518
: Ensure the updated version and hash forgolang.org/x/exp
are correct and consistent with the source.
523-524
: Ensure the updated version and hash forgolang.org/x/net
are correct and consistent with the source.
532-533
: Ensure the updated version and hash forgolang.org/x/sys
are correct and consistent with the source.
@tac0turtle , need new tag? |
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.
Actionable comments posted: 0
Review Details
Configuration used: .coderabbit.yml
Review profile: CHILL
Files selected for processing (3)
- store/iavl/store.go (2 hunks)
- store/rootmulti/store.go (5 hunks)
- store/types/store.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- store/rootmulti/store.go
Additional Context Used
Path-based Instructions (2)
store/iavl/store.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.store/types/store.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
Additional comments not posted (3)
store/iavl/store.go (2)
55-55
: Async pruning option added.
150-157
: PausePruning method added.store/types/store.go (1)
32-36
: The newPausablePruner
interface looks good and is well-documented.
@kocubinski appreciate update 🙏 |
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.
Actionable comments posted: 0
Review Details
Configuration used: .coderabbit.yml
Review profile: CHILL
Files ignored due to path filters (6)
simapp/go.mod
is excluded by!**/*.mod
simapp/go.sum
is excluded by!**/*.sum
store/go.mod
is excluded by!**/*.mod
store/go.sum
is excluded by!**/*.sum
tests/go.mod
is excluded by!**/*.mod
tests/go.sum
is excluded by!**/*.sum
Files selected for processing (1)
- simapp/gomod2nix.toml (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- simapp/gomod2nix.toml
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 start. The integration makes sense but I think IAVL needs some better protection to not block when UnsetCommitting
is not used correct
if pause { | ||
st.tree.SetCommitting() | ||
} else { | ||
st.tree.UnsetCommitting() |
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.
I looked into the iavl impl and this method is not safe to be called (multiple times) without a SetCommitting
before. This is risky for a public method as people may use it without deeper knowledge. PausePruning(false)
does not look like a 💣
IMHO it makes sense to fix UnsetCommitting.
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.
I was also thinking if we need to provide better locking so that no other process accidentally unlocks? Do you think such a scenario exists? In this case, control must be within the iavl and you can have a tree.DoWithCommitPaused{func(){...})
that is guarded
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.
I believe those should be handled within iavl
, cosmos/iavl#953
I added some comments for this PR.
store/rootmulti/store_test.go
Outdated
// Ensure async pruning is done | ||
time.Sleep(500 * time.Millisecond) | ||
ms.Commit() | ||
|
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.
Tests are passing without PausePruning
set. How can you ensure the expected behaviour?
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.
PausePruning
is handled within Commit
, the extra commit is for batch flushing.
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.
It is not straight forward but you can ensure the pauses calls with some decorator:
var _ types.PausablePruner = &pauseableCommitKVStoreStub{}
type pauseableCommitKVStoreStub struct {
types.CommitKVStore
pauseCalled []bool
}
func (p *pauseableCommitKVStoreStub) PausePruning(b bool) {
p.pauseCalled = append(p.pauseCalled, b)
}
func TestPausePruningOnCommit(t *testing.T) {
store := NewStore(dbm.NewMemDB(), log.NewNopLogger(), metrics.NewNoOpMetrics())
store.SetPruning(pruningtypes.NewCustomPruningOptions(2, 11))
store.MountStoreWithDB(testStoreKey1, types.StoreTypeIAVL, nil)
require.NoError(t, store.LoadLatestVersion())
myStub := &pauseableCommitKVStoreStub{CommitKVStore: store.stores[testStoreKey1]}
store.stores[testStoreKey1] = myStub
// when
store.Commit()
// then
assert.Equal(t, []bool{true, false}, myStub.pauseCalled)
}
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.
Actionable comments posted: 4
Review Details
Configuration used: .coderabbit.yml
Review profile: CHILL
Files selected for processing (3)
- store/rootmulti/store.go (5 hunks)
- store/rootmulti/store_test.go (4 hunks)
- store/types/store.go (1 hunks)
Additional Context Used
Path-based Instructions (3)
store/types/store.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.store/rootmulti/store_test.go (2)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
Pattern
**/*_test.go
: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"store/rootmulti/store.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
Additional comments not posted (2)
store/types/store.go (1)
32-38
: The addition of thePausablePruner
interface is well-implemented and clearly documented.store/rootmulti/store_test.go (1)
583-596
: The test case for pruning the same heights twice is correctly implemented to ensure idempotency and stability of the pruning process.
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.
Thanks for the updates and further infos! 🛥️
If you can add the type check to the iavl.Store
, this would be great.
I have added some more test examples and nits. Feel free to adopt but no blockers
store/rootmulti/store_test.go
Outdated
@@ -617,6 +624,10 @@ func TestMultiStore_PruningRestart(t *testing.T) { | |||
actualHeightToPrune = ms.pruningManager.GetPruningHeight(ms.LatestVersion()) | |||
require.Equal(t, int64(8), actualHeightToPrune) | |||
|
|||
// Ensure async pruning is done | |||
time.Sleep(500 * time.Millisecond) | |||
ms.Commit() |
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.
nit: do you need this extra commit? It is passing without
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.
yes, to flush the batch data which includes pruning info
store/rootmulti/store_test.go
Outdated
// Ensure async pruning is done | ||
time.Sleep(500 * time.Millisecond) | ||
ms.Commit() | ||
|
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.
It is not straight forward but you can ensure the pauses calls with some decorator:
var _ types.PausablePruner = &pauseableCommitKVStoreStub{}
type pauseableCommitKVStoreStub struct {
types.CommitKVStore
pauseCalled []bool
}
func (p *pauseableCommitKVStoreStub) PausePruning(b bool) {
p.pauseCalled = append(p.pauseCalled, b)
}
func TestPausePruningOnCommit(t *testing.T) {
store := NewStore(dbm.NewMemDB(), log.NewNopLogger(), metrics.NewNoOpMetrics())
store.SetPruning(pruningtypes.NewCustomPruningOptions(2, 11))
store.MountStoreWithDB(testStoreKey1, types.StoreTypeIAVL, nil)
require.NoError(t, store.LoadLatestVersion())
myStub := &pauseableCommitKVStoreStub{CommitKVStore: store.stores[testStoreKey1]}
store.stores[testStoreKey1] = myStub
// when
store.Commit()
// then
assert.Equal(t, []bool{true, false}, myStub.pauseCalled)
}
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.
Actionable comments posted: 1
Review Details
Configuration used: .coderabbit.yml
Review profile: CHILL
Files selected for processing (3)
- store/iavl/store.go (3 hunks)
- store/rootmulti/store.go (5 hunks)
- store/rootmulti/store_test.go (4 hunks)
Files skipped from review as they are similar to previous changes (2)
- store/rootmulti/store.go
- store/rootmulti/store_test.go
Additional Context Used
Path-based Instructions (1)
store/iavl/store.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
Additional comments not posted (2)
store/iavl/store.go (2)
34-34
: Interface implementation confirmed.The
Store
struct is correctly asserted to implement thetypes.PausablePruner
interface, ensuring type safety.
151-158
: Review the implementation ofPausePruning
.This method toggles the committing state of the tree, which is crucial for the new asynchronous pruning feature. Ensure that the locking mechanism is robust enough to handle concurrent accesses as suggested in previous comments.
@@ -52,7 +53,7 @@ func LoadStore(db dbm.DB, logger log.Logger, key types.StoreKey, id types.Commit | |||
// provided DB. An error is returned if the version fails to load, or if called with a positive | |||
// version on an empty tree. | |||
func LoadStoreWithInitialVersion(db dbm.DB, logger log.Logger, key types.StoreKey, id types.CommitID, initialVersion uint64, cacheSize int, disableFastNode bool, metrics metrics.StoreMetrics) (types.CommitKVStore, error) { | |||
tree := iavl.NewMutableTree(wrapper.NewDBWrapper(db), cacheSize, disableFastNode, logger, iavl.InitialVersionOption(initialVersion)) | |||
tree := iavl.NewMutableTree(wrapper.NewDBWrapper(db), cacheSize, disableFastNode, logger, iavl.InitialVersionOption(initialVersion), iavl.AsyncPruningOption(true)) |
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.
Tip
Codebase Verification
Ensure consistent handling of the new pruning options.
The new pruning option iavl.AsyncPruningOption
is only applied in one instance of iavl.NewMutableTree
in store/iavl/store.go
. Other instances of iavl.NewMutableTree
do not include this option, which may lead to inconsistent behavior.
store/v2/commitment/iavl/tree.go
store/prefix/store_test.go
store/iavl/store_test.go
store/cache/cache_test.go
Please review these instances to ensure the new pruning option is correctly and consistently applied.
Analysis chain
Ensure proper handling of new pruning options.
Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify that the new pruning options are correctly handled throughout the system.
# Test: Search for usage of `iavl.AsyncPruningOption` to ensure it's correctly implemented.
rg --type go $'iavl.AsyncPruningOption'
Length of output: 223
Script:
#!/bin/bash
# Description: Verify that the new pruning options are correctly handled throughout the system.
# Test: Search for all instances of `iavl.NewMutableTree` to ensure the new pruning option is consistently applied.
rg --type go 'iavl.NewMutableTree'
Length of output: 2000
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.
Actionable comments posted: 0
Review Details
Configuration used: .coderabbit.yml
Review profile: CHILL
Files ignored due to path filters (6)
simapp/go.mod
is excluded by!**/*.mod
simapp/go.sum
is excluded by!**/*.sum
store/go.mod
is excluded by!**/*.mod
store/go.sum
is excluded by!**/*.sum
tests/go.mod
is excluded by!**/*.mod
tests/go.sum
is excluded by!**/*.sum
Files selected for processing (4)
- simapp/gomod2nix.toml (1 hunks)
- store/iavl/store.go (3 hunks)
- store/rootmulti/store.go (2 hunks)
- store/rootmulti/store_test.go (4 hunks)
Files skipped from review due to trivial changes (1)
- simapp/gomod2nix.toml
Files skipped from review as they are similar to previous changes (3)
- store/iavl/store.go
- store/rootmulti/store.go
- store/rootmulti/store_test.go
Description
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
in the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...
Summary by CodeRabbit
New Features
Bug Fixes
Refactor