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

chore: sync missing features from v1.2.x to the default branch #969

Merged
merged 4 commits into from
Jul 26, 2024

Conversation

cool-develope
Copy link
Collaborator

@cool-develope cool-develope commented Jul 26, 2024

Context

#928, #925 are missing

Summary by CodeRabbit

  • New Features

    • Introduced APIs for deleting versions from a specified point and retrieving the latest version.
    • Added asynchronous pruning capability to enhance database performance.
    • Implemented methods to manage the committing state in the database.
  • Bug Fixes

    • Improved test reliability by simplifying the control flow related to pruning operations.
  • Documentation

    • Updated changelog to reflect new features and enhancements.
  • Tests

    • Added comprehensive tests for asynchronous pruning and version management in the mutable tree.

@cool-develope cool-develope requested a review from a team as a code owner July 26, 2024 14:17
Copy link

coderabbitai bot commented Jul 26, 2024

Walkthrough

The 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

Files Change Summary
CHANGELOG.md, mutable_tree.go, nodedb.go, options.go Introduced new APIs like DeleteVersionsFrom and GetLatestVersion, enhanced logging practices, and added methods for managing committing states in the mutable tree and node database.
migrate_test.go, prune_test.go, tree_test.go Simplified test functions for pruning and introduced comprehensive tests for asynchronous pruning, ensuring improved reliability and performance in version management.

Possibly related issues

🐰 In the garden of code, I hop with glee,
New APIs bloom, as bright as can be!
With pruning and testing, my heart's all aglow,
For IAVL's adventures are sure to grow!
Hopping through versions, we leap and we twirl,
In the world of data, watch our magic unfurl! 🌼✨


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?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a 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

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

Commits

Files that changed from the base of the PR and between 558a18c and ebd583d.

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 of AsyncPruning field in Options struct.

The new field AsyncPruning enhances the configuration capabilities of the Options struct by allowing users to enable async pruning.


125-130: LGTM! Addition of AsyncPruningOption function.

The new function AsyncPruningOption is well-defined and follows the pattern of other option-setting functions in the file.

CHANGELOG.md (3)

9-9: LGTM! Changelog entry for DeleteVersionsFrom(int64) API.

The changelog entry clearly describes the addition of the DeleteVersionsFrom(int64) API.


9-9: LGTM! Changelog entry for GetLatestVersion API.

The changelog entry clearly describes the addition of the GetLatestVersion API.


9-9: LGTM! Changelog entry for the use of the expected interface for the IAVL Logger.

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 SetCommitting method is correctly implemented.


702-705: LGTM!

The UnsetCommitting method is correctly implemented.


1039-1039: LGTM!

The refactor in the saveNewNodes method simplifies the key retrieval process and improves code readability.

nodedb.go (6)

253-262: LGTM!

The SetCommitting method is correctly implemented.


264-271: LGTM!

The UnsetCommitting method is correctly implemented.


273-278: LGTM!

The IsCommitting method is correctly implemented.


367-377: LGTM!

The deleteFromPruning method is correctly implemented.


379-396: LGTM!

The saveNodeFromPruning method is correctly implemented.


577-601: LGTM!

The startPruning method is correctly implemented.

tree_test.go (1)

1881-1881: LGTM!

The code changes are approved.

Comment on lines +41 to +56
// 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)
}
Copy link

Choose a reason for hiding this comment

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

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.

@cool-develope cool-develope merged commit d561baf into master Jul 26, 2024
8 checks passed
@cool-develope cool-develope deleted the sync/v1.2.x-features branch July 26, 2024 15:36
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.

2 participants