diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index af9a432102cb..c78c4a6700b1 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -170,7 +170,7 @@ func NewBaseApp( name: name, appStore: appStore{ db: db, - cms: store.NewCommitMultiStore(db), + cms: store.NewCommitMultiStoreWithLogger(db, logger), storeLoader: DefaultStoreLoader, fauxMerkleMode: false, }, diff --git a/client/pruning/main.go b/client/pruning/main.go index 655279412539..a5eac9d84360 100644 --- a/client/pruning/main.go +++ b/client/pruning/main.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "path/filepath" + "strconv" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -13,6 +14,9 @@ import ( "github.com/cosmos/cosmos-sdk/server" servertypes "github.com/cosmos/cosmos-sdk/server/types" "github.com/cosmos/cosmos-sdk/store/rootmulti" + + cfg "github.com/tendermint/tendermint/config" + tmflags "github.com/tendermint/tendermint/libs/cli/flags" "github.com/tendermint/tendermint/libs/log" dbm "github.com/tendermint/tm-db" ) @@ -81,6 +85,10 @@ Supported app-db-backend types include 'goleveldb', 'rocksdb', 'pebbledb'.`, } logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)) + logger, err = tmflags.ParseLogLevel(vp.GetString(flags.FlagLogLevel), logger, cfg.DefaultLogLevel) + if err != nil { + return err + } app := appCreator(logger, db, nil, vp) cms := app.CommitMultiStore() @@ -94,8 +102,16 @@ Supported app-db-backend types include 'goleveldb', 'rocksdb', 'pebbledb'.`, return fmt.Errorf("the database has no valid heights to prune, the latest height: %v", latestHeight) } + startHeight := 1 + + if str := vp.GetString(flags.FlagHeight); str != "" { + if startHeight, err = strconv.Atoi(str); err != nil { + return fmt.Errorf("invalid height flag %v", str) + } + } + var pruningHeights []int64 - for height := int64(1); height < latestHeight; height++ { + for height := int64(startHeight); height < latestHeight; height++ { if height < latestHeight-int64(pruningOptions.KeepRecent) { pruningHeights = append(pruningHeights, height) } @@ -121,7 +137,7 @@ Supported app-db-backend types include 'goleveldb', 'rocksdb', 'pebbledb'.`, cmd.Flags().Uint64(server.FlagPruningInterval, 10, `Height interval at which pruned heights are removed from disk (ignored if pruning is not 'custom'), this is not used by this command but kept for compatibility with the complete pruning options`) - + cmd.Flags().Uint64(server.FlagHeight, 1, `the height to begin with`) return cmd } diff --git a/store/rootmulti/store.go b/store/rootmulti/store.go index 243c6e4a7bb1..1e7561808e7a 100644 --- a/store/rootmulti/store.go +++ b/store/rootmulti/store.go @@ -605,7 +605,7 @@ func (rs *Store) PruneStores(clearPruningManager bool, pruningHeights []int64) ( return nil } - rs.logger.Debug("pruning heights", "heights", pruningHeights) + rs.logger.Debug("pruning heights", "heights", len(pruningHeights)) for key, store := range rs.stores { // If the store is wrapped with an inter-block cache, we must first unwrap @@ -614,6 +614,7 @@ func (rs *Store) PruneStores(clearPruningManager bool, pruningHeights []int64) ( continue } + rs.logger.Debug("pruning store", "store", key) store = rs.GetCommitKVStore(key) err := store.(*iavl.Store).DeleteVersions(pruningHeights...) diff --git a/store/store.go b/store/store.go index 492bd4fee1dc..53f47c6beea1 100644 --- a/store/store.go +++ b/store/store.go @@ -13,6 +13,10 @@ func NewCommitMultiStore(db dbm.DB) types.CommitMultiStore { return rootmulti.NewStore(db, log.NewNopLogger()) } +func NewCommitMultiStoreWithLogger(db dbm.DB, logger log.Logger) types.CommitMultiStore { + return rootmulti.NewStore(db, logger) +} + func NewCommitKVStoreCacheManager() types.MultiStorePersistentCache { return cache.NewCommitKVStoreCacheManager(cache.DefaultCommitKVStoreCacheSize) }