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 3300cc8 commit 9fb9154
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 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [#507](https://github.com/crypto-org-chain/cosmos-sdk/pull/507) mempool respect gas wanted returned by ante handler
* [#744](https://github.com/crypto-org-chain/cosmos-sdk/pull/744) Pass raw transactions to tx executor so it can do pre-estimations.
* [#884](https://github.com/crypto-org-chain/cosmos-sdk/pull/884) Avoid decoding tx for in PrepareProposal if it's NopMempool.
* [#]() Prune cmd wait for async pruning to finish.

## [Unreleased]

Expand Down
8 changes: 6 additions & 2 deletions client/pruning/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,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 @@ -389,6 +389,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 {

Check failure on line 393 in store/iavl/store.go

View workflow job for this annotation

GitHub Actions / dependency-review

undefined: io

Check failure on line 393 in store/iavl/store.go

View workflow job for this annotation

GitHub Actions / dependency-review

undefined: io
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 @@ -1188,6 +1188,16 @@ func (rs *Store) flushMetadata(db dbm.DB, version int64, cInfo *types.CommitInfo
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())
}
}

Check warning

Code scanning / CodeQL

Iteration over map Warning

Iteration over map may be a possible source of non-determinism
return errors.Join(errs...)
}

type storeParams struct {
key types.StoreKey
db dbm.DB
Expand Down

0 comments on commit 9fb9154

Please sign in to comment.