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

feat(store/v2): pruning manager #20430

Merged
merged 12 commits into from
May 29, 2024
Merged

feat(store/v2): pruning manager #20430

merged 12 commits into from
May 29, 2024

Conversation

cool-develope
Copy link
Contributor

@cool-develope cool-develope commented May 20, 2024

Description

Closes: #20429


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...

  • included the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

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...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

  • New Features

    • Introduced a new interface to pause pruning during commits.
    • Added a PruningManager for managing state storage and commitment pruning based on chain height.
  • Refactor

    • Removed pruneOpts parameter from various initialization functions.
    • Updated function signatures and logic to align with new pruning management.
  • Tests

    • Added and updated test cases for new pruning functionality.
    • Modified test initializations to reflect changes in function signatures.

@cool-develope cool-develope requested a review from a team as a code owner May 20, 2024 21:34
@cool-develope cool-develope marked this pull request as draft May 20, 2024 21:34
Copy link
Contributor

coderabbitai bot commented May 20, 2024

Warning

Rate Limit Exceeded

@cool-develope has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 43 minutes and 27 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between 8bf3749 and 63f6363.

Walkthrough

The changes introduce a new Pruning Manager to handle pruning operations for state storage and commitment stores, allowing for deferred pruning and pausing. The IavlTree and CommitStore structs are updated to implement the PausablePruner interface. Additionally, several test suites and initialization functions are refactored to accommodate the new pruning manager and remove obsolete pruning options.

Changes

File(s) Change Summary
store/v2/commitment/iavl/tree.go Added PausablePruner interface implementation to IavlTree with PausePruning method.
store/v2/commitment/iavl/tree_test.go, store/v2/commitment/store_test_suite.go Modified NewStore function signature to remove pruneOpts parameter and added asynchronous pruning checks.
store/v2/commitment/store.go Refactored NewCommitStore function to remove pruneOpts and added Prune and PausePruning methods.
store/v2/migration/manager.go, store/v2/migration/manager_test.go Changed WriteBatch to WriteChangeset and adjusted initialization parameters for stores.
store/v2/pruning/README.md, store/v2/pruning/manager.go, store/v2/pruning/manager_test.go Introduced PruningManager for managing pruning operations based on chain height and added test cases.
store/v2/root/factory.go, store/v2/root/store.go, store/v2/root/store_test.go, store/v2/root/migrate_test.go Added pruningManager field to Store struct and updated initialization and commit logic to use it.
store/v2/storage/.../db_test.go, store/v2/storage/storage_bench_test.go Removed nil argument from NewStorageStore function calls.
store/v2/storage/store.go Removed pruneOptions field from StorageStore and related logic from ApplyChangeset method.

Sequence Diagram(s) (Beta)

sequenceDiagram
    participant User
    participant PruningManager
    participant CommitStore
    participant IavlTree

    User->>CommitStore: Commit()
    CommitStore->>PruningManager: Signal Commit
    PruningManager->>IavlTree: PausePruning()
    IavlTree->>PruningManager: Pruning Paused
    PruningManager-->>CommitStore: Commit Signal Processed
    CommitStore-->>User: Commit Complete
Loading

Assessment against linked issues

Objective Addressed Explanation
Implement the separated Pruning Manager for pruning removed stores and deferred pruning (#20429)
Refactor initialization and commit logic to use the new Pruning Manager (#20429)
Remove obsolete pruneOpts parameter and related logic from store initialization and methods (#20429)
Update test cases to reflect changes in pruning management and store initialization (#20429)

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 full the 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 Configration 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
Contributor

@cool-develope your pull request is missing a changelog!

Copy link
Contributor

@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: 3

Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 1f06f5b and 46563b1.
Files ignored due to path filters (2)
  • store/v2/go.mod is excluded by !**/*.mod
  • store/v2/go.sum is excluded by !**/*.sum
Files selected for processing (15)
  • store/v2/commitment/iavl/tree.go (2 hunks)
  • store/v2/commitment/iavl/tree_test.go (1 hunks)
  • store/v2/commitment/store.go (5 hunks)
  • store/v2/commitment/store_test_suite.go (4 hunks)
  • store/v2/migration/manager_test.go (3 hunks)
  • store/v2/pruning/manager.go (1 hunks)
  • store/v2/root/factory.go (4 hunks)
  • store/v2/root/migrate_test.go (4 hunks)
  • store/v2/root/store.go (6 hunks)
  • store/v2/root/store_test.go (2 hunks)
  • store/v2/storage/pebbledb/db_test.go (1 hunks)
  • store/v2/storage/rocksdb/db_test.go (1 hunks)
  • store/v2/storage/sqlite/db_test.go (1 hunks)
  • store/v2/storage/store.go (2 hunks)
  • store/v2/store.go (2 hunks)
Additional Context Used
Path-based Instructions (15)
store/v2/storage/pebbledb/db_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/v2/pruning/manager.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

store/v2/storage/rocksdb/db_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/v2/root/factory.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

store/v2/commitment/iavl/tree_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/v2/commitment/iavl/tree.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

store/v2/storage/store.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

store/v2/store.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

store/v2/migration/manager_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/v2/storage/sqlite/db_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/v2/commitment/store_test_suite.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

store/v2/root/migrate_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/v2/root/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/v2/commitment/store.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

store/v2/root/store.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

Additional comments not posted (19)
store/v2/pruning/manager.go (1)

1-67: LGTM! Ensure the Manager struct and its methods are integrated correctly with other components.

store/v2/root/factory.go (1)

Line range hint 15-106: LGTM! Ensure the CreateRootStore function integrates correctly with other components.

Verification successful

The CreateRootStore function is correctly integrated in runtime/v2/builder.go to initialize the root store and set up the application manager. The context and usage align with the intended functionality.

  • runtime/v2/builder.go: Correctly initializes a.app.db using CreateRootStore.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the integration of `CreateRootStore` function with other components.

# Test: Search for the usage of `CreateRootStore` function. Expect: Correct integration points.
rg --type go $'CreateRootStore'

Length of output: 307



Script:

#!/bin/bash
# Description: Inspect the usage of `CreateRootStore` in `runtime/v2/builder.go`.

# Extract the lines around the usage of `CreateRootStore` to understand its context.
rg --type go -A 10 -B 10 $'CreateRootStore' runtime/v2/builder.go

Length of output: 634

store/v2/commitment/iavl/tree_test.go (1)

17-24: LGTM! Ensure the NewCommitStore integrates correctly with the new pruning manager.

Verification successful

To ensure the NewCommitStore integrates correctly with the new pruning manager, we need to review its implementation in store/v2/commitment/store.go and check for references to the pruning manager.


The NewCommitStore function implementation does not directly reference the pruning manager. However, there are references to the pruning manager in store/v2/root/store.go. We need to review these references to understand if the pruning manager is integrated with NewCommitStore indirectly through other components.


The NewCommitStore function does not directly reference the pruning manager. However, the pruning manager is integrated within the store/v2/root/store.go file, where it handles signaling commits. This suggests that the pruning manager's integration is managed at a higher level in the codebase, ensuring that the NewCommitStore function operates correctly within this context.

  • store/v2/root/store.go: Contains references to the pruning manager, indicating its role in signaling commits.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the integration of `NewCommitStore` with the new pruning manager.

# Test: Search for the function usage. Expect: Only occurances of the new signature.
rg --type go $'NewCommitStore'

Length of output: 1095



Script:

#!/bin/bash
# Description: Review the implementation of `NewCommitStore` and check for references to the pruning manager.

# Extract the implementation of `NewCommitStore` function.
ast-grep --lang go --pattern $'func NewCommitStore(trees map[string]Tree, db corestore.KVStoreWithBatch, logger log.Logger) (*CommitStore, error) {
  $$$
}' 

# Search for references to the pruning manager in the codebase.
rg --type go 'pruning manager'

Length of output: 1132



Script:

#!/bin/bash
# Description: Review the references to the pruning manager in `store/v2/root/store.go`.

# Extract lines around the references to the pruning manager for context.
rg --type go --context 5 'pruning manager' store/v2/root/store.go

Length of output: 1378

store/v2/commitment/iavl/tree.go (1)

Line range hint 11-111: LGTM! Ensure the PausePruning method and the interface implementation are integrated correctly with other components.

Verification successful

The PausePruning method is correctly integrated with other components in the codebase. The method is referenced and utilized in store/v2/store.go, store/v2/commitment/store.go, and store/v2/pruning/manager.go, ensuring that the pruning process can be paused or resumed as needed.

  • store/v2/store.go: Defines the PausablePruner interface, which includes the PausePruning method.
  • store/v2/commitment/store.go: Implements the PausePruning method in the CommitStore struct, iterating over multiTrees and invoking PausePruning on each tree that implements PausablePruner.
  • store/v2/pruning/manager.go: Uses the PausePruning method in the SignalCommit function to manage concurrent writes during pruning.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the integration of `PausePruning` method with other components.

# Test: Search for the usage of `PausePruning` method. Expect: Correct integration points.
rg --type go $'PausePruning'

Length of output: 678



Script:

#!/bin/bash
# Description: Inspect the usage and context of `PausePruning` in the identified files.

# Display lines around the usage of `PausePruning` in store/v2/store.go
rg --type go --context 5 'PausePruning' store/v2/store.go

# Display lines around the usage of `PausePruning` in store/v2/commitment/store.go
rg --type go --context 5 'PausePruning' store/v2/commitment/store.go

# Display lines around the usage of `PausePruning` in store/v2/pruning/manager.go
rg --type go --context 5 'PausePruning' store/v2/pruning/manager.go

Length of output: 1376

store/v2/storage/store.go (2)

20-20: Implementation of store.Pruner interface in StorageStore looks good.


30-33: Updated NewStorageStore function signature simplifies initialization and aligns with the PR's objectives.

store/v2/store.go (1)

82-96: Introduction of Pruner and PausablePruner interfaces enhances control over the pruning process and supports dynamic management of state consistency.

store/v2/migration/manager_test.go (2)

31-31: Changes in the initialization of CommitStore reflect the updated constructor and align with the PR's objectives to simplify store setup in tests.

Also applies to: 50-50


41-41: Initialization of StorageStore in test setup correctly reflects the changes to its constructor in the main implementation.

store/v2/storage/sqlite/db_test.go (1)

22-22: Updated NewDB function in test suite correctly uses the new StorageStore constructor, maintaining consistency with main codebase changes.

store/v2/commitment/store_test_suite.go (2)

28-28: Updated NewStore function in test suite reflects the main codebase changes, ensuring consistency and simplification in test setup.

Also applies to: 33-33, 67-67, 132-132


152-154: Pruning logic in test case correctly implements and tests the intended functionality using PruneOptions.

store/v2/root/migrate_test.go (1)

17-17: Changes in test setup and migration logic in MigrateStoreTestSuite correctly integrate new components and reflect updates to store constructors, ensuring comprehensive testing of migration functionality.

Also applies to: 45-45, 66-66, 72-72, 79-79, 82-82

store/v2/root/store_test.go (2)

16-16: Ensure the new import cosmossdk.io/store/v2/pruning is utilized appropriately in the tests.

Verification successful

The pruning package is imported and used in the test suite, specifically with the pruning.NewManager function. This indicates that the new import is indeed utilized in the tests.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the usage of the `pruning` package in the test suite.

# Test: Search for the usage of the `pruning` package. Expect: At least one usage.
rg --type go $'pruning' store/v2/root/store_test.go

Length of output: 127


48-48: Initialization of StorageStore should be accompanied by tests that verify its interaction with the new pruning manager.

store/v2/commitment/store.go (2)

31-31: The CommitStore now implements store.PausablePruner. Ensure that the implementation of the interface methods (Prune and PausePruning) is correct and adheres to the expected behavior.

Verification successful

The CommitStore correctly implements the Prune and PausePruning methods as required by the store.PausablePruner interface. The methods adhere to the expected behavior, ensuring proper functionality.

  • Prune method: Iterates through versions, deletes metadata, and prunes trees.
  • PausePruning method: Pauses pruning for each tree that supports the PausablePruner interface.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correct implementation of `store.PausablePruner` methods in `CommitStore`.

# Test: Search for the implementation of `Prune` and `PausePruning`. Expect: Correct implementation according to interface definition.
rg --type go $'func \(c \*CommitStore\) (Prune|PausePruning)' store/v2/commitment/store.go

Length of output: 199



Script:

#!/bin/bash
# Extract the full implementation of the `Prune` and `PausePruning` methods from `CommitStore`.

# Extract the `Prune` method implementation.
rg --type go --context 10 $'func (c *CommitStore) Prune(version uint64) (ferr error) {' store/v2/commitment/store.go

# Extract the `PausePruning` method implementation.
rg --type go --context 10 $'func (c *CommitStore) PausePruning(pause bool) {' store/v2/commitment/store.go

Length of output: 565



Script:

#!/bin/bash
# Extract the full implementation of the `Prune` and `PausePruning` methods from `CommitStore`.

# Extract the `Prune` method implementation.
rg --type go --context 10 'func \(c \*CommitStore\) Prune\(version uint64\) \(ferr error\) \{' store/v2/commitment/store.go

# Extract the `PausePruning` method implementation.
rg --type go --context 10 'func \(c \*CommitStore\) PausePruning\(pause bool\) \{' store/v2/commitment/store.go

Length of output: 1292


286-286: Review the implementation of Prune and PausePruning methods to ensure they handle errors appropriately and perform the expected operations on the trees.

Also applies to: 312-319

Verification successful

The implementations of the Prune and PausePruning methods have been reviewed. Both methods handle errors appropriately:

  • The Prune method checks for errors when deleting keys and writing the batch, returning the error if encountered. It also accumulates errors from pruning individual trees.
  • The PausePruning method checks if each tree supports pausing pruning and calls the PausePruning method on those that do.

No issues were found in the error handling of these methods.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify error handling in `Prune` and `PausePruning`.

# Test: Search for error handling patterns in `Prune` and `PausePruning`. Expect: Proper error handling.
rg --type go $'if err != nil' store/v2/commitment/store.go

Length of output: 377



Script:

#!/bin/bash
# Description: Locate and extract the implementations of `Prune` and `PausePruning` methods in `store/v2/commitment/store.go`.

# Search for the `Prune` method implementation.
ast-grep --lang go --pattern $'func (s *$_) Prune($_) $_ {
  $$$
}' store/v2/commitment/store.go

# Search for the `PausePruning` method implementation.
ast-grep --lang go --pattern $'func (s *$_) PausePruning($_) $_ {
  $$$
}' store/v2/commitment/store.go

Length of output: 202



Script:

#!/bin/bash
# Description: Search for the method names `Prune` and `PausePruning` in `store/v2/commitment/store.go`.

# Search for the `Prune` method.
rg 'Prune' store/v2/commitment/store.go

# Search for the `PausePruning` method.
rg 'PausePruning' store/v2/commitment/store.go

Length of output: 516



Script:

#!/bin/bash
# Description: Extract the lines of code for the `Prune` and `PausePruning` methods from `store/v2/commitment/store.go`.

# Extract lines for the `Prune` method.
sed -n '288,311p' store/v2/commitment/store.go

# Extract lines for the `PausePruning` method.
sed -n '312,319p' store/v2/commitment/store.go

Length of output: 785

store/v2/root/store.go (2)

281-285: Review the signaling to the pruningManager during the commit process to ensure it correctly handles the start and end of a commit.

Also applies to: 314-318

Verification successful

The signaling to the pruningManager during the commit process correctly handles both the start and end of a commit. The first call to SignalCommit with true signals the start of a commit, and the second call with false signals the end of a commit.

  • Lines 281-285: Signal the start of a commit.
  • Lines 314-318: Signal the end of a commit.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the signaling process to `pruningManager` during commits.

# Test: Search for the signaling logic in the commit process. Expect: Correct signaling.
rg --type go $'SignalCommit' store/v2/root/store.go

Length of output: 191



Script:

#!/bin/bash
# Extract surrounding lines of SignalCommit calls to understand the context
rg --type go -A 5 -B 5 'SignalCommit' store/v2/root/store.go

Length of output: 852


47-49: The Store struct now includes a pruningManager. Ensure that the initialization in the New function correctly sets up the pruningManager and that it is utilized appropriately in the rest of the class methods.

Also applies to: 69-78

Verification successful

The pruningManager is correctly initialized in the New function of the Store class and is used in the SignalCommit method. The SignalCommit method in the pruning.Manager is implemented to handle the start and end of a commit process, pausing and resuming pruning as necessary.

  • The pruningManager is initialized in the New function:

    return &Store{
        logger:           logger.With("module", "root_store"),
        initialVersion:   1,
        stateStorage:     ss,
        stateCommitment:  sc,
        pruningManager:   pm,
        migrationManager: mm,
        telemetry:        m,
        isMigrating:      mm != nil,
    }, nil
  • The SignalCommit method is implemented as follows:

    func (m *Manager) SignalCommit(start bool, version uint64) error {
        if scPausablePruner, ok := m.scPruner.(store.PausablePruner); ok {
            scPausablePruner.PausePruning(start)
        }
        if ssPausablePruner, ok := m.ssPruner.(store.PausablePruner); ok {
            ssPausablePruner.PausePruning(start)
        }
    
        if !start {
            return m.Prune(version)
        }
    
        return nil
    }

The initialization and usage of pruningManager appear to be correctly implemented.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correct setup and utilization of `pruningManager` in the `Store` class.

# Test: Search for the usage of `pruningManager` in the `Store` class methods. Expect: Correct setup and utilization.
rg --type go $'pruningManager' store/v2/root/store.go

Length of output: 344



Script:

#!/bin/bash
# Description: Verify the initialization of `pruningManager` in the `New` function and the implementation of `SignalCommit`.

# Test: Search for the initialization of `pruningManager` in the `New` function.
rg --type go 'New' store/v2/root/store.go

# Test: Search for the implementation of `SignalCommit` method in the `pruning.Manager`.
rg --type go 'SignalCommit' 

Length of output: 576



Script:

#!/bin/bash
# Description: Extract the full implementation of the `New` function and the `SignalCommit` method.

# Extract the full implementation of the `New` function.
rg --type go -A 20 'func New(' store/v2/root/store.go

# Extract the full implementation of the `SignalCommit` method.
rg --type go -A 20 'func (m *Manager) SignalCommit(' store/v2/pruning/manager.go

Length of output: 320



Script:

#!/bin/bash
# Description: Extract the full implementation of the `New` function and the `SignalCommit` method.

# Extract the full implementation of the `New` function.
rg --type go -A 20 'func New\(' store/v2/root/store.go

# Extract the full implementation of the `SignalCommit` method.
rg --type go -A 20 'func \(m \*Manager\) SignalCommit\(' store/v2/pruning/manager.go

Length of output: 1004

Comment on lines +56 to +57
pm := pruning.NewManager(sc, ss, nil, nil)
rs, err := New(noopLog, ss, sc, pm, nil, nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

The search results indicate that while pruning.NewManager is instantiated in the test file, there is no evidence that it is being used in conjunction with RootStore. This suggests that the integration of pruning.Manager with RootStore is not being tested.

  • Ensure that tests verify the correct behavior of RootStore with the pruning manager integrated.
Analysis chain

The creation of RootStore now includes a pruning.Manager. Ensure that the tests verify the correct behavior of RootStore with the pruning manager integrated.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correct behavior of `RootStore` with the pruning manager.

# Test: Search for tests that involve `RootStore` and `pruning.Manager`. Expect: At least one test.
rg --type go $'RootStore.*pruning.Manager' store/v2/root/store_test.go

Length of output: 71



Script:

#!/bin/bash
# Description: Verify the correct behavior of `RootStore` with the pruning manager.

# Step 1: Search for `RootStore` instantiation in the test file.
rg --type go 'RootStore' store/v2/root/store_test.go

# Step 2: Search for `pruning.Manager` instantiation in the test file.
rg --type go 'pruning.Manager' store/v2/root/store_test.go

Length of output: 792



Script:

#!/bin/bash
# Description: Verify the correct behavior of `RootStore` with the pruning manager.

# Step 1: Search for the instantiation of `RootStore` in the test file.
rg --type go 'New(noopLog, ss, sc, pm, nil, nil)' store/v2/root/store_test.go

# Step 2: Check if `pruning.Manager` is passed as a parameter to `RootStore`.
rg --type go 'pruning.NewManager' store/v2/root/store_test.go

Length of output: 185

@@ -20,7 +20,7 @@ func TestStorageTestSuite(t *testing.T) {
db.SetSync(false)
}

return storage.NewStorageStore(db, nil, log.NewNopLogger()), err
return storage.NewStorageStore(db, log.NewNopLogger()), err
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

The recent commits and PRs do not mention the new pruning manager, indicating that it might not be integrated yet. To ensure proper integration, the NewStorageStore function should be updated to include the new pruning manager if it is part of the intended changes.

  • File: store/v2/storage/store.go
  • Function: NewStorageStore
Analysis chain

LGTM! Ensure the NewStorageStore integrates correctly with the new pruning manager.


The search results indicate multiple instances of NewStorageStore with different signatures. To verify the integration with the new pruning manager, we need to inspect the definition of NewStorageStore and ensure it includes the new pruning manager.


The definition of NewStorageStore does not include the new pruning manager. This suggests that the integration might be missing or handled elsewhere. To confirm, we need to check for any recent changes or PRs that might include the new pruning manager integration.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the integration of `NewStorageStore` with the new pruning manager.

# Test: Search for the function usage. Expect: Only occurances of the new signature.
rg --type go $'NewStorageStore'

Length of output: 1189



Script:

#!/bin/bash
# Description: Verify the definition of `NewStorageStore` to check for integration with the new pruning manager.

# Test: Retrieve the definition of `NewStorageStore` function.
ast-grep --lang go --pattern $'func NewStorageStore($_, $_) *$_ {
  $$$
}'

Length of output: 390



Script:

#!/bin/bash
# Description: Check for recent changes or PRs related to the new pruning manager integration.

# Test: List recent commits and PRs to find references to the new pruning manager.
git log -n 10 --oneline
gh pr list --state merged --limit 10

Length of output: 1444

@@ -21,7 +21,7 @@ func TestStorageTestSuite(t *testing.T) {
s := &storage.StorageTestSuite{
NewDB: func(dir string) (store.VersionedDatabase, error) {
db, err := New(dir)
return storage.NewStorageStore(db, nil, log.NewNopLogger()), err
return storage.NewStorageStore(db, log.NewNopLogger()), err
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

The NewStorageStore function does not currently initialize the pruning manager. This is evident from the implementation found in store/v2/storage/store.go, which only initializes the logger and db fields of the StorageStore struct.

  • store/v2/storage/store.go:func NewStorageStore(db Database, logger log.Logger) *StorageStore {

To ensure proper integration with the new pruning manager, the NewStorageStore function should be updated to initialize the pruning manager as well.

Analysis chain

LGTM! Ensure the NewStorageStore integrates correctly with the new pruning manager.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the integration of `NewStorageStore` with the new pruning manager.

# Test: Search for the function usage. Expect: Only occurances of the new signature.
rg --type go $'NewStorageStore'

Length of output: 1189



Script:

#!/bin/bash
# Description: Verify the integration of `NewStorageStore` with the new pruning manager.

# Test: Search for references to the pruning manager within the `NewStorageStore` function and its usage.
rg --type go 'pruningManager' --context 5

Length of output: 9794



Script:

#!/bin/bash
# Description: Verify the initialization of the pruning manager within the `NewStorageStore` function.

# Test: Search for the implementation of the `NewStorageStore` function.
rg --type go 'func NewStorageStore' --context 10

Length of output: 1172

store/v2/commitment/store.go Dismissed Show dismissed Hide dismissed
@cool-develope cool-develope marked this pull request as ready for review May 21, 2024 19:48
Copy link
Contributor

@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: 0

Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 46563b1 and ae7a468.
Files selected for processing (17)
  • store/v2/commitment/iavl/tree.go (3 hunks)
  • store/v2/commitment/iavl/tree_test.go (2 hunks)
  • store/v2/commitment/store.go (5 hunks)
  • store/v2/commitment/store_test_suite.go (5 hunks)
  • store/v2/database.go (2 hunks)
  • store/v2/migration/manager.go (1 hunks)
  • store/v2/migration/manager_test.go (4 hunks)
  • store/v2/pruning/manager_test.go (1 hunks)
  • store/v2/root/factory.go (5 hunks)
  • store/v2/root/migrate_test.go (4 hunks)
  • store/v2/root/store.go (7 hunks)
  • store/v2/root/store_test.go (3 hunks)
  • store/v2/storage/pebbledb/db_test.go (1 hunks)
  • store/v2/storage/rocksdb/db_test.go (1 hunks)
  • store/v2/storage/sqlite/db_test.go (1 hunks)
  • store/v2/storage/storage_bench_test.go (1 hunks)
  • store/v2/storage/storage_test_suite.go (1 hunks)
Files skipped from review as they are similar to previous changes (12)
  • store/v2/commitment/iavl/tree.go
  • store/v2/commitment/iavl/tree_test.go
  • store/v2/commitment/store.go
  • store/v2/commitment/store_test_suite.go
  • store/v2/migration/manager_test.go
  • store/v2/root/factory.go
  • store/v2/root/migrate_test.go
  • store/v2/root/store.go
  • store/v2/root/store_test.go
  • store/v2/storage/pebbledb/db_test.go
  • store/v2/storage/rocksdb/db_test.go
  • store/v2/storage/sqlite/db_test.go
Additional Context Used
Path-based Instructions (5)
store/v2/database.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

store/v2/storage/storage_bench_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/v2/pruning/manager_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/v2/migration/manager.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

store/v2/storage/storage_test_suite.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

Additional comments not posted (5)
store/v2/database.go (1)

30-31: The addition of the WriteChangeset method in the Committer interface aligns well with the PR's objectives to enhance commitment management.

store/v2/storage/storage_bench_test.go (1)

30-30: The use of log.NewNopLogger() in the instantiation of StorageStore for benchmark tests is a good practice, as it prevents logging overhead from affecting performance measurements.

Also applies to: 38-38, 42-42

store/v2/pruning/manager_test.go (1)

1-173: The PruningManagerTestSuite is comprehensive and well-structured, effectively testing various scenarios including error handling and state verification post-pruning. This ensures the reliability and robustness of the pruning functionality.

store/v2/migration/manager.go (1)

236-236: The updates in the Sync method to handle changesets committed during the migration process are crucial for maintaining data consistency. This is a key enhancement in the migration functionality.

store/v2/storage/storage_test_suite.go (1)

25-25: The addition of the NewDB field to the StorageTestSuite struct enhances the flexibility and reusability of the test suite by allowing dynamic instantiation of storage backends. This is a valuable improvement for testing different configurations.

@kocubinski kocubinski self-assigned this May 23, 2024
store/v2/root/store.go Outdated Show resolved Hide resolved
Copy link
Member

@kocubinski kocubinski left a comment

Choose a reason for hiding this comment

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

Generally LGTM, suggested some updates to comments for code clarity.

Copy link
Member

@tac0turtle tac0turtle left a comment

Choose a reason for hiding this comment

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

utACK, can we add a few docs on the pruning manager and a small diagram using plantuml on how its meant to be used

@@ -0,0 +1,69 @@
package pruning
Copy link
Member

Choose a reason for hiding this comment

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

can you add a small readme/doc.go on the design with a small diagram on how this is meant to be used

Copy link
Contributor

@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: 2

Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between ae7a468 and 8bf3749.
Files ignored due to path filters (2)
  • store/v2/go.mod is excluded by !**/*.mod
  • store/v2/go.sum is excluded by !**/*.sum
Files selected for processing (18)
  • store/v2/commitment/iavl/tree.go (3 hunks)
  • store/v2/commitment/iavl/tree_test.go (2 hunks)
  • store/v2/commitment/store.go (5 hunks)
  • store/v2/commitment/store_test_suite.go (5 hunks)
  • store/v2/migration/manager.go (1 hunks)
  • store/v2/migration/manager_test.go (4 hunks)
  • store/v2/pruning/README.md (1 hunks)
  • store/v2/pruning/manager.go (1 hunks)
  • store/v2/pruning/manager_test.go (1 hunks)
  • store/v2/root/factory.go (5 hunks)
  • store/v2/root/migrate_test.go (4 hunks)
  • store/v2/root/store.go (7 hunks)
  • store/v2/root/store_test.go (3 hunks)
  • store/v2/storage/pebbledb/db_test.go (1 hunks)
  • store/v2/storage/rocksdb/db_test.go (1 hunks)
  • store/v2/storage/sqlite/db_test.go (1 hunks)
  • store/v2/storage/storage_bench_test.go (1 hunks)
  • store/v2/storage/store.go (2 hunks)
Files skipped from review as they are similar to previous changes (14)
  • store/v2/commitment/iavl/tree.go
  • store/v2/commitment/iavl/tree_test.go
  • store/v2/commitment/store_test_suite.go
  • store/v2/migration/manager.go
  • store/v2/migration/manager_test.go
  • store/v2/pruning/manager.go
  • store/v2/pruning/manager_test.go
  • store/v2/root/store.go
  • store/v2/root/store_test.go
  • store/v2/storage/pebbledb/db_test.go
  • store/v2/storage/rocksdb/db_test.go
  • store/v2/storage/sqlite/db_test.go
  • store/v2/storage/storage_bench_test.go
  • store/v2/storage/store.go
Additional Context Used
LanguageTool (1)
store/v2/pruning/README.md (1)

Near line 17: Possible missing comma found.
Context: ...rinterface defines thePausePruning` method which is used to pause the pruning proc...
Rule ID: AI_HYDRA_LEO_MISSING_COMMA

Markdownlint (1)
store/v2/pruning/README.md (1)

52: null
Files should end with a single newline character

Path-based Instructions (4)
store/v2/pruning/README.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

store/v2/root/factory.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

store/v2/root/migrate_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/v2/commitment/store.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

Additional comments not posted (10)
store/v2/pruning/README.md (2)

1-14: The introduction and description of the PruningManager and PruneOptions are clear and well-documented.


23-52: The Pruning Flow diagram provides a clear visual representation of the process. Good use of the mermaid diagram to illustrate complex interactions.

store/v2/root/factory.go (3)

Line range hint 1-43: The imports and type definitions are appropriate and well-organized.


Line range hint 53-106: The CreateRootStore function is well-implemented with clear error handling and initialization logic for different storage types. Good use of helper function ensureDir for directory management.


Line range hint 1-106: The overall structure and formatting of the file conform to the Uber Golang style guide.

store/v2/root/migrate_test.go (3)

Line range hint 1-18: The imports and initial setup for the MigrateStoreTestSuite are appropriate and well-organized, providing a solid foundation for the tests.


Line range hint 46-83: The test functions in the MigrateStoreTestSuite are well-implemented, covering a variety of scenarios and properly handling errors. Good use of assertions to ensure state correctness.


Line range hint 1-83: The overall structure and formatting of the test file are well-maintained and follow best practices for test code.

store/v2/commitment/store.go (2)

Line range hint 31-319: The method implementations in CommitStore, including PausePruning and Prune, correctly adhere to their respective interfaces. The implementation details are consistent with the expected behavior described in the PR.


Line range hint 1-320: The overall structure and formatting of the file conform to the Uber Golang style guide.

store/v2/pruning/README.md Outdated Show resolved Hide resolved
store/v2/pruning/README.md Outdated Show resolved Hide resolved
@cool-develope cool-develope added this pull request to the merge queue May 29, 2024
Merged via the queue into main with commit b8c8482 May 29, 2024
64 of 65 checks passed
@cool-develope cool-develope deleted the store/pruning_manager branch May 29, 2024 13:59
alpe added a commit that referenced this pull request May 31, 2024
* main: (120 commits)
  chore: update protoc-gen-swagger to protoc-gen-openapiv2 (#20448)
  ci: Add GitHub Action for go mod tidy and mocks (#20501)
  chore: Address linter issues (#20486)
  fix: wrap errors in auto CLI service registration (#20493)
  chore: fix comment (#20498)
  chore: fix the note box syntax error (#20499)
  feat(server/v2): introduce cometbft v2 (#20483)
  refactor(x/upgrade): migrate to appmodule.VersionMap (#20485)
  docs: code guidelines changes (#20482)
  feat(cosmovisor): load cosmovisor configuration from toml file (#19995)
  perf(math): Significantly speedup Dec quo truncate and quo Roundup (#20034)
  fix: Bump CometBFT versions (#20481)
  refactor(core): remove redundant ExecMode (#20322)
  feat(store/v2): pruning manager (#20430)
  chore: force reload sonar cloud  (#20480)
  refactor(x/accounts): reuse calculated sum in `func safeAdd` (#20458)
  refactor: remove `defer` in loop (#20223)
  ci: remove livness test (#20474)
  build(deps): Bump bufbuild/buf-setup-action from 1.32.1 to 1.32.2 (#20477)
  chore: migrate a few diagrams to mermaid (#20473)
  ...
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.

Implement the separated Pruning Manager for pruning removed stores and defered pruning
4 participants