Skip to content

Commit

Permalink
fix(store): use stdout logger instead of nop (#14)
Browse files Browse the repository at this point in the history
* fix(store): use stdout logger instead of nop

* feat(store/rootmulti): attach baseapp logger as rootmulti logger
feat(client/pruning): support log level
feat(client/pruning): height flag for specifying the height to begin with

* fix: test

* fix(store): add NewCommitMultiStoreWithLogger

* revert lint
  • Loading branch information
inon-man authored Sep 18, 2023
1 parent 11d6b35 commit d903043
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
20 changes: 18 additions & 2 deletions client/pruning/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"path/filepath"
"strconv"

"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand All @@ -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"
)
Expand Down Expand Up @@ -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()

Expand All @@ -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)
}
Expand All @@ -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
}

Expand Down
3 changes: 2 additions & 1 deletion store/rootmulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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...)
Expand Down
4 changes: 4 additions & 0 deletions store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit d903043

Please sign in to comment.