-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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): build the migration manager in the root store factory #22336
Open
cool-develope
wants to merge
37
commits into
main
Choose a base branch
from
store/factory_migration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
6362846
confgi the migration manager in root factory
cool-develope e7bd885
minor fix
cool-develope 3bb541b
add simple test
cool-develope 1e6e4f1
small fix
cool-develope cb86a77
Merge branch 'main' into store/factory_migration
cool-develope 31eb8fd
fix migration
cool-develope 79d978b
Merge branch 'main' into store/factory_migration
cool-develope eb8029c
fix db close
cool-develope 01a470e
Merge branch 'main' into store/factory_migration
cool-develope f3091f5
Merge branch 'main' into store/factory_migration
tac0turtle 19c6da3
go mod change
tac0turtle f58431a
fix diff
tac0turtle 4ef10b7
fix factory
tac0turtle b854054
Merge branch 'main' into store/factory_migration
tac0turtle ddaf4da
return error when version is not present
tac0turtle 1b93050
Merge branch 'main' into store/factory_migration
tac0turtle 03fdd2a
Merge branch 'main' into store/factory_migration
tac0turtle ae75111
fix build
tac0turtle a10a72f
minor touch up of build
tac0turtle 5f2cb83
fixes
tac0turtle 99a813a
refactor(store/v2): compatible with storev1 (#23201)
tac0turtle 2e13d91
Merge branch 'main' into store/factory_migration
tac0turtle 2b9419e
lint fixes
tac0turtle 2106a3b
fix cometbft tests
tac0turtle 010bc58
Merge branch 'main' into store/factory_migration
tac0turtle 31a4aed
fix simapp tests
tac0turtle 6ee0260
store fix
tac0turtle ba62dd5
revert make file changes
tac0turtle cb687e2
revert build file changes
tac0turtle e04b614
drop convert function
tac0turtle 759cb53
fix lint
tac0turtle 1c5b07d
Merge branch 'main' into store/factory_migration
tac0turtle 76aeebe
fix bank failing test
tac0turtle f9da53b
fix store tests
tac0turtle 4f8ca79
Merge branch 'main' into store/factory_migration
tac0turtle 9a55795
Merge branch 'main' into store/factory_migration
tac0turtle b5b2fa0
fix go mod
tac0turtle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,9 @@ import ( | |
"cosmossdk.io/store/v2/commitment/mem" | ||
"cosmossdk.io/store/v2/db" | ||
"cosmossdk.io/store/v2/internal" | ||
"cosmossdk.io/store/v2/migration" | ||
"cosmossdk.io/store/v2/pruning" | ||
"cosmossdk.io/store/v2/snapshots" | ||
"cosmossdk.io/store/v2/storage" | ||
"cosmossdk.io/store/v2/storage/pebbledb" | ||
"cosmossdk.io/store/v2/storage/rocksdb" | ||
|
@@ -139,11 +141,11 @@ func CreateRootStore(opts *FactoryOptions) (store.RootStore, error) { | |
return nil, err | ||
} | ||
|
||
newTreeFn := func(key string) (commitment.Tree, error) { | ||
newTreeFn := func(key string, scType SCType) (commitment.Tree, error) { | ||
if internal.IsMemoryStoreKey(key) { | ||
return mem.New(), nil | ||
} else { | ||
switch storeOpts.SCType { | ||
switch scType { | ||
case SCTypeIavl: | ||
return iavl.NewIavlTree(db.NewPrefixDB(opts.SCRawDB, []byte(key)), opts.Logger, storeOpts.IavlConfig), nil | ||
case SCTypeIavlV2: | ||
|
@@ -154,17 +156,31 @@ func CreateRootStore(opts *FactoryOptions) (store.RootStore, error) { | |
} | ||
} | ||
|
||
// check if we need to migrate the store | ||
isMigrating := false | ||
scType := storeOpts.SCType | ||
ssLatestVersion, err := ss.GetLatestVersion() | ||
if err != nil { | ||
return nil, err | ||
} | ||
if ssLatestVersion != latestVersion { | ||
isMigrating = true // need to migrate | ||
if scType != SCTypeIavl { | ||
scType = SCTypeIavl // only support iavl v1 for migration | ||
} | ||
} | ||
|
||
trees := make(map[string]commitment.Tree, len(opts.StoreKeys)) | ||
for _, key := range opts.StoreKeys { | ||
tree, err := newTreeFn(key) | ||
tree, err := newTreeFn(key, scType) | ||
if err != nil { | ||
return nil, err | ||
} | ||
trees[key] = tree | ||
} | ||
oldTrees := make(map[string]commitment.Tree, len(opts.StoreKeys)) | ||
for _, key := range removedStoreKeys { | ||
tree, err := newTreeFn(string(key)) | ||
tree, err := newTreeFn(string(key), scType) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
@@ -176,6 +192,31 @@ func CreateRootStore(opts *FactoryOptions) (store.RootStore, error) { | |
return nil, err | ||
} | ||
|
||
var mm *migration.Manager | ||
if isMigrating { | ||
snapshotDB, err := snapshots.NewStore(fmt.Sprintf("%s/data/snapshots/store.db", opts.RootDir)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
tac0turtle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
snapshotMgr := snapshots.NewManager(snapshotDB, snapshots.SnapshotOptions{}, sc, nil, nil, opts.Logger) | ||
var newSC *commitment.CommitStore | ||
if scType != storeOpts.SCType { | ||
newTrees := make(map[string]commitment.Tree, len(opts.StoreKeys)) | ||
for _, key := range opts.StoreKeys { | ||
tree, err := newTreeFn(key, storeOpts.SCType) | ||
if err != nil { | ||
return nil, err | ||
} | ||
newTrees[key] = tree | ||
} | ||
newSC, err = commitment.NewCommitStore(newTrees, nil, opts.SCRawDB, opts.Logger) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
mm = migration.NewManager(opts.SCRawDB, snapshotMgr, ss, newSC, opts.Logger) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider refactoring migration setup for better maintainability. The migration setup logic is complex and handles multiple concerns. Consider extracting it into a separate function for better maintainability and testing. func setupMigrationManager(opts *FactoryOptions, ss *storage.StorageStore, sc *commitment.CommitStore, scType SCType) (*migration.Manager, error) {
snapshotDB, err := snapshots.NewStore(fmt.Sprintf("%s/data/snapshots/store.db", opts.RootDir))
if err != nil {
return nil, err
}
snapshotMgr := snapshots.NewManager(snapshotDB, snapshots.SnapshotOptions{}, sc, nil, nil, opts.Logger)
var newSC *commitment.CommitStore
if scType != opts.Options.SCType {
newSC, err = createNewCommitStore(opts, scType)
if err != nil {
snapshotDB.Close() // Cleanup on error
return nil, err
}
}
return migration.NewManager(opts.SCRawDB, snapshotMgr, ss, newSC, opts.Logger), nil
} |
||
|
||
pm := pruning.NewManager(sc, ss, storeOpts.SCPruningOption, storeOpts.SSPruningOption) | ||
return New(opts.SCRawDB, opts.Logger, ss, sc, pm, nil, nil) | ||
return New(opts.SCRawDB, opts.Logger, ss, sc, pm, mm, nil) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🛠️ Refactor suggestion
Simplify
isMigrating
assignmentYou can assign the result of the condition directly to
isMigrating
to make the code more concise.Apply this diff to streamline the variable initialization:
📝 Committable suggestion