Skip to content

Commit

Permalink
Delete kvstore specified in store upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
udpatil committed Aug 9, 2024
1 parent ed1e9a4 commit 4293590
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
13 changes: 13 additions & 0 deletions store/rootmulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,15 @@ func (rs *Store) loadVersion(ver int64, upgrades *types.StoreUpgrades) error {
storesKeys = append(storesKeys, key)
}
if upgrades != nil {
for _, upgrade := range upgrades.Deleted {
deletionStoreKey := types.NewKVStoreKey(upgrade)
storesKeys = append(storesKeys, deletionStoreKey)
rs.storesParams[deletionStoreKey] = storeParams{
key: deletionStoreKey,
typ: types.StoreTypeIAVL, // TODO: is this safe
}
rs.keysByName[upgrade] = deletionStoreKey
}
// deterministic iteration order for upgrades
// (as the underlying store may change and
// upgrades make store changes where the execution order may matter)
Expand Down Expand Up @@ -283,6 +292,10 @@ func (rs *Store) loadVersion(ver int64, upgrades *types.StoreUpgrades) error {
// If it was deleted, remove all data
if upgrades.IsDeleted(key.Name()) {
deleteKVStore(store.(types.KVStore))
// drop deleted KV store from stores
delete(newStores, key)
delete(rs.keysByName, key.Name())
delete(rs.storesParams, key)
} else if oldName := upgrades.RenamedFrom(key.Name()); oldName != "" {
// handle renames specially
// make an unregistered key to satify loadCommitStore params
Expand Down
13 changes: 13 additions & 0 deletions storev2/rootmulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,14 @@ func (rs *Store) LoadVersionAndUpgrade(version int64, upgrades *types.StoreUpgra
for key := range rs.storesParams {
storesKeys = append(storesKeys, key)
}

if upgrades != nil {
// load storeKeys for deletion
for _, upgrade := range upgrades.Deleted {
deletionStoreKey := types.NewKVStoreKey(upgrade)
storesKeys = append(storesKeys, deletionStoreKey)
}
}
// deterministic iteration order for upgrades
sort.Slice(storesKeys, func(i, j int) bool {
return storesKeys[i].Name() < storesKeys[j].Name()
Expand All @@ -397,11 +405,13 @@ func (rs *Store) LoadVersionAndUpgrade(version int64, upgrades *types.StoreUpgra
return nil
}

storesKeysForDeletion := make(map[types.StoreKey]struct{})
var treeUpgrades []*proto.TreeNameUpgrade
for _, key := range storesKeys {
switch {
case upgrades.IsDeleted(key.Name()):
treeUpgrades = append(treeUpgrades, &proto.TreeNameUpgrade{Name: key.Name(), Delete: true})
storesKeysForDeletion[key] = struct{}{}
case upgrades.IsAdded(key.Name()) || upgrades.RenamedFrom(key.Name()) != "":
treeUpgrades = append(treeUpgrades, &proto.TreeNameUpgrade{Name: key.Name(), RenameFrom: upgrades.RenamedFrom(key.Name())})
}
Expand All @@ -415,6 +425,9 @@ func (rs *Store) LoadVersionAndUpgrade(version int64, upgrades *types.StoreUpgra
var err error
newStores := make(map[types.StoreKey]types.CommitKVStore, len(storesKeys))
for _, key := range storesKeys {
if _, ok := storesKeysForDeletion[key]; ok {
continue
}
newStores[key], err = rs.loadCommitStoreFromParams(key, rs.storesParams[key])
if err != nil {
return err
Expand Down

0 comments on commit 4293590

Please sign in to comment.