Skip to content

Commit

Permalink
Problem: prune cmd don't wait for async pruning to finish
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang committed Nov 26, 2024
1 parent 14d98d2 commit 653bf17
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i

* (sims) [#21906](https://github.com/cosmos/cosmos-sdk/pull/21906) Skip sims test when running dry on validators
* (cli) [#21919](https://github.com/cosmos/cosmos-sdk/pull/21919) Query address-by-acc-num by account_id instead of id.
* (store) [#]() Prune cmd wait for async pruning to finish.

### API Breaking Changes

Expand Down
8 changes: 6 additions & 2 deletions client/pruning/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,12 @@ Supported app-db-backend types include 'goleveldb', 'rocksdb', 'pebbledb'.`,
pruningHeight := latestHeight - int64(pruningOptions.KeepRecent)
cmd.Printf("pruning heights up to %v\n", pruningHeight)

err = rootMultiStore.PruneStores(pruningHeight)
if err != nil {
if err := rootMultiStore.PruneStores(pruningHeight); err != nil {
return err
}

// close will wait for async pruning process to finish
if err := rootMultiStore.Close(); err != nil {
return err
}

Expand Down
7 changes: 7 additions & 0 deletions store/iavl/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,13 @@ func (st *Store) TraverseStateChanges(startVersion, endVersion int64, fn func(ve
return st.tree.TraverseStateChanges(startVersion, endVersion, fn)
}

func (st *Store) Close() error {
if closer, ok := st.tree.(io.Closer); ok {
return closer.Close()
}
return nil
}

// Takes a MutableTree, a key, and a flag for creating existence or absence proof and returns the
// appropriate merkle.Proof. Since this must be called after querying for the value, this function should never error
// Thus, it will panic on error rather than returning it
Expand Down
10 changes: 10 additions & 0 deletions store/rootmulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,16 @@ func (rs *Store) flushMetadata(db corestore.KVStoreWithBatch, version int64, cIn
rs.logger.Debug("flushing metadata finished", "height", version)
}

func (rs *Store) Close() error {
errs := make([]error, 0, len(rs.stores))
for _, store := range rs.stores {
if closer, ok := store.(io.Closer); ok {
errs = append(errs, closer.Close())
}
}
return errors.Join(errs...)
}

type storeParams struct {
key types.StoreKey
db corestore.KVStoreWithBatch
Expand Down

0 comments on commit 653bf17

Please sign in to comment.