-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Conversation
📝 WalkthroughWalkthroughThe changes in this pull request primarily involve updating the database handling functions across several files to replace the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
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 using PR comments)
Other keywords and placeholders
Documentation and Community
|
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
🧹 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
withcoreserver.DynamicConfig
in theNewDB
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:
- Update all callers of
NewDB
to use the newcoreserver.DynamicConfig
type.- Verify that the
coreserver.DynamicConfig
type provides all the necessary configuration options that were previously available instore.DBOptions
.- 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 usecoreserver.DynamicConfig
instead ofstore.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 previousstore.DBOptions
.
📜 Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
📒 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 ofstore/v2
import are consistent with the changes made to theNewRocksDBWithOpts
function signature. This change suggests a shift towards using core server functionality.store/v2/root/reader.go (1)
57-57
: Approved: Simplified Get method implementationThe 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 theDynamicConfig
type. The removal of thestore/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
withcoreserver.DynamicConfig
in theNewPebbleDBWithOpts
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 wherestore.DBOptions
was previously used.
31-31
: LGTM: Function signature update is appropriate.The change from
opts store.DBOptions
toopts coreserver.DynamicConfig
aligns with the import modifications and potentially provides more flexibility. The function's internal logic adapts well to use the newDynamicConfig
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 usecoreserver.DynamicConfig
. The removal of thestore/v2
import and the addition of thecore/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 ofstore.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 thecoreserver.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.goLength 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.goLength 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) { |
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.
💡 Codebase verification
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
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.
This isn't necessary right? Since the interfaces are compatible.
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.
@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.
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...
!
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.
Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.
I have...
Summary by CodeRabbit
New Features
Bug Fixes
Get
method in theReader
struct for improved performance.Documentation