Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(store/v2): replace dboptions by dynamic config #22185

Merged
merged 2 commits into from
Oct 10, 2024

Conversation

julienrbrt
Copy link
Member

@julienrbrt julienrbrt commented Oct 9, 2024

Description

Nit found during store api review


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, you can find examples of the prefixes below:
  • 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.

Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.

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 pruning strategy with configurable options for database management.
    • Added methods for creating and managing pruning options.
  • Bug Fixes

    • Streamlined the Get method in the Reader struct for improved performance.
  • Documentation

    • Updated method signatures to reflect changes in configuration handling across database initialization functions.

Copy link
Contributor

coderabbitai bot commented Oct 9, 2024

📝 Walkthrough

Walkthrough

The changes in this pull request primarily involve updating the database handling functions across several files to replace the store.DBOptions type with coreserver.DynamicConfig. This adjustment alters the way configuration options are passed during database instantiation. Additionally, new constants and a struct related to pruning strategies are introduced, while some import statements are modified or removed. The overall functionality of the database methods remains unchanged.

Changes

File Change Summary
store/v2/db/db.go Updated NewDB method signature to use coreserver.DynamicConfig instead of store.DBOptions. Added import for coreserver.
store/v2/db/goleveldb.go Updated NewGoLevelDB method signature to use coreserver.DynamicConfig. Added import for coreserver, removed store/v2.
store/v2/db/pebbledb.go Updated NewPebbleDBWithOpts method signature to use coreserver.DynamicConfig. Added import for coreserver, removed store/v2.
store/v2/db/rocksdb_noflag.go Updated NewRocksDBWithOpts method signature to use coreserver.DynamicConfig. Added import for coreserver, removed store/v2.
store/v2/options.go Introduced PruningStrategy type with constants, PruningOption struct, and related methods. Removed DBOptions interface.
store/v2/root/reader.go Simplified Get method in Reader struct by removing intermediate variable.

Possibly related PRs

Suggested labels

C:Store, C:server/v2

Suggested reviewers

  • kocubinski
  • hieuvubk
  • tac0turtle

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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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

@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 and nitpick comments (2)
store/v2/db/db.go (1)

Line range hint 1-31: Summary: Minor refactor with potential wider impact.

The changes in this file are minimal but significant. The replacement of store.DBOptions with coreserver.DynamicConfig in the NewDB function signature represents a shift in how configuration is handled. While the changes here are correct and follow good practices, it's crucial to ensure that this modification is consistently applied throughout the codebase.

Consider the following:

  1. Update all callers of NewDB to use the new coreserver.DynamicConfig type.
  2. Verify that the coreserver.DynamicConfig type provides all the necessary configuration options that were previously available in store.DBOptions.
  3. Update any relevant documentation or comments that might reference the old DBOptions type.

These changes align well with the PR objective of replacing dboptions with dynamic config, but careful testing and verification are necessary to ensure no functionality is broken.

store/v2/db/rocksdb_noflag.go (1)

22-24: LGTM: Function signature updated correctly.

The NewRocksDBWithOpts function signature has been updated to use coreserver.DynamicConfig instead of store.DBOptions. This change is consistent with the import modifications and likely reflects a broader refactoring effort.

Consider adding a comment explaining the purpose of coreserver.DynamicConfig in this context, especially if it differs significantly from the previous store.DBOptions.

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 4aeb053 and 4cefb72.

📒 Files selected for processing (6)
  • store/v2/db/db.go (2 hunks)
  • store/v2/db/goleveldb.go (2 hunks)
  • store/v2/db/pebbledb.go (2 hunks)
  • store/v2/db/rocksdb_noflag.go (2 hunks)
  • store/v2/options.go (0 hunks)
  • store/v2/root/reader.go (1 hunks)
💤 Files with no reviewable changes (1)
  • store/v2/options.go
🧰 Additional context used
📓 Path-based instructions (5)
store/v2/db/db.go (1)

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

store/v2/db/goleveldb.go (1)

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

store/v2/db/pebbledb.go (1)

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

store/v2/db/rocksdb_noflag.go (1)

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

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

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

🔇 Additional comments (8)
store/v2/db/db.go (1)

6-6: LGTM: Import statement follows best practices.

The new import statement for coreserver is correctly placed and uses an appropriate alias. This adheres to the Uber Golang style guide.

store/v2/db/rocksdb_noflag.go (1)

7-7: LGTM: Import changes align with function signature update.

The addition of coreserver "cosmossdk.io/core/server" import and the removal of store/v2 import are consistent with the changes made to the NewRocksDBWithOpts function signature. This change suggests a shift towards using core server functionality.

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

57-57: Approved: Simplified Get method implementation

The change improves code readability by directly returning the result of GetStateStorage().Get(). This simplification aligns well with the Uber Golang style guide's preference for clear and concise code. It also slightly improves performance by eliminating an unnecessary intermediate variable.

store/v2/db/pebbledb.go (3)

13-13: LGTM: Import changes are appropriate.

The addition of coreserver "cosmossdk.io/core/server" import is necessary for using the DynamicConfig type. The removal of the store/v2 import (not visible in the provided code) suggests it's no longer needed after the changes.


Line range hint 1-324: Summary: Refactoring to use DynamicConfig looks good.

The changes in this file are focused and minimal, primarily updating the configuration handling approach. The replacement of store.DBOptions with coreserver.DynamicConfig in the NewPebbleDBWithOpts function signature suggests a move towards a more flexible configuration system.

These modifications appear to be part of a larger refactoring effort and are implemented consistently. The changes don't introduce any apparent issues and maintain the overall functionality of the PebbleDB implementation.

However, it's important to ensure that these changes are reflected appropriately throughout the codebase, particularly in areas where NewPebbleDBWithOpts is called or where store.DBOptions was previously used.


31-31: LGTM: Function signature update is appropriate.

The change from opts store.DBOptions to opts coreserver.DynamicConfig aligns with the import modifications and potentially provides more flexibility. The function's internal logic adapts well to use the new DynamicConfig type.

Please verify that all calls to NewPebbleDBWithOpts across the codebase have been updated to use the new signature. Run the following script to check for any remaining uses of the old signature:

✅ Verification successful

Verified: No remaining calls to NewPebbleDBWithOpts with the old signature were found.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for calls to NewPebbleDBWithOpts with the old signature
rg --type go 'NewPebbleDBWithOpts\s*\([^)]*store\.DBOptions[^)]*\)'

Length of output: 69


Script:

#!/bin/bash
# Search for all calls to NewPebbleDBWithOpts function
rg --type go 'NewPebbleDBWithOpts\s*\('

Length of output: 236

store/v2/db/goleveldb.go (2)

17-19: LGTM: Import statements updated appropriately.

The changes in the import statements align with the refactoring of the NewGoLevelDB function to use coreserver.DynamicConfig. The removal of the store/v2 import and the addition of the core/server import reflect the shift in dependencies.


31-31: LGTM: Function signature updated, verify implementation.

The function signature has been appropriately updated to use coreserver.DynamicConfig instead of store.DBOptions. This change aligns with the updated import statements and reflects a shift in how configuration options are handled.

Please ensure that the function implementation correctly uses the new coreserver.DynamicConfig type. Run the following script to verify the usage:

✅ Verification successful

Verified: Function implementation correctly uses coreserver.DynamicConfig.

The NewGoLevelDB function signature has been updated appropriately, and the implementation correctly utilizes the coreserver.DynamicConfig type to retrieve and apply configuration settings.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of NewGoLevelDB function

# Test: Check if the function correctly uses coreserver.DynamicConfig
rg --type go -A 10 'func NewGoLevelDB\(' store/v2/db/goleveldb.go

Length of output: 416


Script:

#!/bin/bash
# Description: Verify the coreserver.DynamicConfig definition

# Test 1: Check if coreserver.DynamicConfig has a Get method
ast-grep --lang go --pattern $'type DynamicConfig interface {
  Get($_)
  $$$
}'

# Description: Verify that "maxopenfiles" is a valid key in DynamicConfig
rg --type go 'const\s+MaxOpenFiles\s*='

# Description: Check usage of OpenFilesCacheCapacity in GoLevelDB
rg --type go 'OpenFilesCacheCapacity' store/v2/db/goleveldb.go

Length of output: 404

@@ -18,7 +18,7 @@ const (
DBFileSuffix string = ".db"
)

func NewDB(dbType DBType, name, dataDir string, opts store.DBOptions) (corestore.KVStoreWithBatch, error) {
func NewDB(dbType DBType, name, dataDir string, opts coreserver.DynamicConfig) (corestore.KVStoreWithBatch, error) {
Copy link
Contributor

@coderabbitai coderabbitai bot Oct 9, 2024

Choose a reason for hiding this comment

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

💡 Codebase verification

⚠️ Action Required: Update NewDB Function Callers

Several instances of the NewDB function are still using the old signature with missing arguments. Please update the following files to include the opts coreserver.DynamicConfig parameter:

  • store/v2/root/builder.go
  • store/v2/storage/storage_test_suite.go
  • simsx/runner.go
  • server/v2/store/commands.go
  • server/util.go
  • client/snapshot/restore.go
  • client/pruning/main.go

Ensure all callers pass the required coreserver.DynamicConfig argument to prevent potential runtime errors.

🔗 Analysis chain

LGTM: Function signature updated correctly.

The NewDB function signature has been updated to use coreserver.DynamicConfig instead of store.DBOptions. This change is consistent with the new import and maintains good naming conventions.

To ensure this change doesn't break existing code, please verify all callers of this function. Run the following script to find all occurrences of NewDB in the codebase:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all occurrences of NewDB function calls
# Expected result: All calls should use coreserver.DynamicConfig as the last argument

rg --type go 'NewDB\s*\(' -A 3

Length of output: 6663

Copy link
Member

Choose a reason for hiding this comment

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

This isn't necessary right? Since the interfaces are compatible.

Copy link
Contributor

Choose a reason for hiding this comment

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

@kocubinski, thank you for the clarification. If the interfaces are compatible, then updating the callers may indeed be unnecessary.


✏️ Learnings added
Learnt from: kocubinski
PR: cosmos/cosmos-sdk#22185
File: store/v2/db/db.go:21-21
Timestamp: 2024-10-09T18:15:02.775Z
Learning: The interfaces `store.DBOptions` and `coreserver.DynamicConfig` are compatible, so when modifying the `NewDB` function signature, existing callers do not need to be updated.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

@julienrbrt julienrbrt added this pull request to the merge queue Oct 10, 2024
Merged via the queue into main with commit 3a03804 Oct 10, 2024
80 of 82 checks passed
@julienrbrt julienrbrt deleted the julien/dboptions branch October 10, 2024 10:29
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.

5 participants