chore: sync missing features from v1.2.x to the default branch#969
chore: sync missing features from v1.2.x to the default branch#969cool-develope merged 4 commits intomasterfrom
Conversation
Co-authored-by: Marko <marbar3778@yahoo.com>
WalkthroughThe recent changes enhance the IAVL library by introducing new APIs for version management and logging, along with significant improvements in asynchronous pruning functionalities. Key updates include the addition of methods to manage committing states, optimizations for node deletion, and comprehensive tests to validate these enhancements, aiming for better performance and reliability in tree operations. Changes
Possibly related issues
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 Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
Outside diff range, codebase verification and nitpick comments (5)
prune_test.go (4)
12-12: Add a comment to describe the purpose of the test.Adding a comment at the beginning of the test function will help other developers understand the purpose of the test.
+ // TestAsyncPruning tests the async pruning functionality of the IAVL tree. func TestAsyncPruning(t *testing.T) {
13-15: Ensure proper cleanup of the database.The
defer db.Close()statement ensures that the database is closed after the test. However, it's good practice to add a comment explaining the purpose of this statement.db, err := dbm.NewGoLevelDB("test", t.TempDir()) require.NoError(t, err) + // Ensure the database is closed after the test. defer db.Close()
23-39: Consider adding comments to explain the pruning logic.Adding comments to explain the logic behind the pruning operations will improve the readability and maintainability of the test.
for i := 0; i < toVersion; i++ { for j := 0; j < keyCount; j++ { _, err := tree.Set([]byte(fmt.Sprintf("key-%d-%d", i, j)), []byte(fmt.Sprintf("value-%d-%d", i, j))) require.NoError(t, err) } tree.SetCommitting() _, v, err := tree.SaveVersion() require.NoError(t, err) tree.UnsetCommitting() + // Prune versions if the current version is a multiple of pruneInterval and greater than keepRecent. if v%pruneInterval == 0 && v > keepRecent { ti := time.Now() require.NoError(t, tree.DeleteVersionsTo(v-keepRecent)) t.Logf("Pruning %d versions took %v\n", keepRecent, time.Since(ti)) } }
58-67: Add comments to explain the reloading logic.Adding comments to explain the logic behind reloading the tree and checking the available versions will improve the readability and maintainability of the test.
// Reload the tree tree = NewMutableTree(db, 0, false, NewNopLogger()) _, err = tree.LoadVersion(int64(toVersion) - keepRecent) require.Error(t, err) + // Check the available versions after reloading the tree. versions := tree.AvailableVersions() require.Equal(t, versions[0], toVersion-int(keepRecent)+1) for _, v := range versions { _, err := tree.LoadVersion(int64(v)) require.NoError(t, err) }tree_test.go (1)
1882-1915: Consider adding comments to improve readability.Adding comments to explain the purpose of each block of code can improve readability and maintainability.
+ // Test the reference root when pruning db = dbm.NewMemDB() require.NoError(t, err) tree = NewMutableTree(db, 0, false, NewNopLogger()) _, err = tree.Set([]byte("key1"), []byte("value1")) require.NoError(t, err) _, _, err = tree.SaveVersion() require.NoError(t, err) _, _, err = tree.SaveVersion() // empty version require.NoError(t, err) require.NoError(t, tree.DeleteVersionsTo(1)) _, _, err = tree.SaveVersion() // empty version require.NoError(t, err) // Load the tree from disk tree = NewMutableTree(db, 0, false, NewNopLogger()) _, err = tree.Load() require.NoError(t, err) _, err = tree.Set([]byte("key2"), []byte("value2")) require.NoError(t, err) _, _, err = tree.SaveVersion() require.NoError(t, err) // Load the tree from disk to check if the reference root is loaded correctly tree = NewMutableTree(db, 0, false, NewNopLogger()) _, err = tree.Load() require.NoError(t, err) _, err = tree.Set([]byte("key1"), []byte("value2")) require.NoError(t, err)
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (7)
- CHANGELOG.md (1 hunks)
- migrate_test.go (2 hunks)
- mutable_tree.go (2 hunks)
- nodedb.go (12 hunks)
- options.go (2 hunks)
- prune_test.go (1 hunks)
- tree_test.go (1 hunks)
Additional comments not posted (16)
options.go (2)
87-89: LGTM! Addition ofAsyncPruningfield inOptionsstruct.The new field
AsyncPruningenhances the configuration capabilities of theOptionsstruct by allowing users to enable async pruning.
125-130: LGTM! Addition ofAsyncPruningOptionfunction.The new function
AsyncPruningOptionis well-defined and follows the pattern of other option-setting functions in the file.CHANGELOG.md (3)
9-9: LGTM! Changelog entry forDeleteVersionsFrom(int64)API.The changelog entry clearly describes the addition of the
DeleteVersionsFrom(int64)API.
9-9: LGTM! Changelog entry forGetLatestVersionAPI.The changelog entry clearly describes the addition of the
GetLatestVersionAPI.
9-9: LGTM! Changelog entry for the use of the expected interface for the IAVLLogger.The changelog entry clearly describes the use of the expected interface for the IAVL
Logger.migrate_test.go (1)
Line range hint
14-14:
Potential issue with the removal of the synchronization mechanism.The removal of the code block that waits for the pruning operation to complete may affect the reliability of the test. The test now assumes the pruning operation completes without explicit confirmation, which could introduce potential issues if the operation takes longer than expected.
mutable_tree.go (3)
696-700: LGTM!The
SetCommittingmethod is correctly implemented.
702-705: LGTM!The
UnsetCommittingmethod is correctly implemented.
1039-1039: LGTM!The refactor in the
saveNewNodesmethod simplifies the key retrieval process and improves code readability.nodedb.go (6)
253-262: LGTM!The
SetCommittingmethod is correctly implemented.
264-271: LGTM!The
UnsetCommittingmethod is correctly implemented.
273-278: LGTM!The
IsCommittingmethod is correctly implemented.
367-377: LGTM!The
deleteFromPruningmethod is correctly implemented.
379-396: LGTM!The
saveNodeFromPruningmethod is correctly implemented.
577-601: LGTM!The
startPruningmethod is correctly implemented.tree_test.go (1)
1881-1881: LGTM!The code changes are approved.
| // wait for async pruning to finish | ||
| for i := 0; i < 100; i++ { | ||
| tree.SetCommitting() | ||
| _, _, err := tree.SaveVersion() | ||
| require.NoError(t, err) | ||
| tree.UnsetCommitting() | ||
|
|
||
| firstVersion, err := tree.ndb.getFirstVersion() | ||
| require.NoError(t, err) | ||
| t.Logf("Iteration: %d First version: %d\n", i, firstVersion) | ||
| if firstVersion == int64(toVersion)-keepRecent+1 { | ||
| break | ||
| } | ||
| // simulate the consensus process | ||
| time.Sleep(500 * time.Millisecond) | ||
| } |
There was a problem hiding this comment.
Optimize the waiting logic for async pruning.
The current logic waits for async pruning to finish by iterating 100 times and sleeping for 500 milliseconds in each iteration. Consider adding a timeout mechanism to avoid potential infinite loops.
// wait for async pruning to finish
for i := 0; i < 100; i++ {
tree.SetCommitting()
_, _, err := tree.SaveVersion()
require.NoError(t, err)
tree.UnsetCommitting()
firstVersion, err := tree.ndb.getFirstVersion()
require.NoError(t, err)
t.Logf("Iteration: %d First version: %d\n", i, firstVersion)
if firstVersion == int64(toVersion)-keepRecent+1 {
break
}
// simulate the consensus process
time.Sleep(500 * time.Millisecond)
}Committable suggestion was skipped due to low confidence.
Context
#928, #925 are missing
Summary by CodeRabbit
New Features
Bug Fixes
Documentation
Tests