Skip to content

Commit

Permalink
attempt further fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
czarcas7ic committed Dec 21, 2023
1 parent 78bc47f commit f0de908
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 69 deletions.
5 changes: 0 additions & 5 deletions baseapp/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@ func SetIAVLDisableFastNode(disable bool) func(*BaseApp) {
return func(bapp *BaseApp) { bapp.cms.SetIAVLDisableFastNode(disable) }
}

// SetIAVLLazyLoading enables/disables lazy loading of the IAVL store.
func SetIAVLLazyLoading(lazyLoading bool) func(*BaseApp) {
return func(bapp *BaseApp) { bapp.cms.SetLazyLoading(lazyLoading) }
}

// SetInterBlockCache provides a BaseApp option function that sets the
// inter-block cache.
func SetInterBlockCache(cache sdk.MultiStorePersistentCache) func(*BaseApp) {
Expand Down
4 changes: 3 additions & 1 deletion client/pruning/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,11 @@ Supported app-db-backend types include 'goleveldb', 'rocksdb', 'pebbledb'.`,
}
cmd.Printf("pruning heights start from %v, end at %v\n", pruningHeights[0], pruningHeights[len(pruningHeights)-1])

if err = rootMultiStore.PruneStores(false, pruningHeights); err != nil {
rootMultiStore.PruneStores(pruningHeights[len(pruningHeights)-1])
if err != nil {
return err
}
fmt.Printf("successfully pruned the application root multi stores\n")

cmd.Println("successfully pruned the application root multi stores")
return nil
Expand Down
1 change: 0 additions & 1 deletion server/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,6 @@ func DefaultBaseappOptions(appOpts types.AppOptions) []func(*baseapp.BaseApp) {
mempool.SenderNonceMaxTxOpt(cast.ToInt(appOpts.Get(FlagMempoolMaxTxs))),
),
),
baseapp.SetIAVLLazyLoading(cast.ToBool(appOpts.Get(FlagIAVLLazyLoading))),
baseapp.SetChainID(chainID),
}
}
Expand Down
80 changes: 21 additions & 59 deletions store/rootmulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ type Store struct {
storesParams map[types.StoreKey]storeParams
stores map[types.StoreKey]types.CommitKVStore
keysByName map[string]types.StoreKey
lazyLoading bool
initialVersion int64
removalMap map[types.StoreKey]bool
traceWriter io.Writer
traceContext types.TraceContext
traceContextMutex sync.Mutex
interBlockCache types.MultiStorePersistentCache
listeners map[types.StoreKey][]types.WriteListener
commitHeader cmtproto.Header

initialVersion int64
removalMap map[types.StoreKey]bool
traceWriter io.Writer
traceContext types.TraceContext
traceContextMutex sync.Mutex
interBlockCache types.MultiStorePersistentCache
listeners map[types.StoreKey][]types.WriteListener
commitHeader cmtproto.Header
}

var (
Expand Down Expand Up @@ -125,11 +125,6 @@ func (rs *Store) SetIAVLDisableFastNode(disableFastNode bool) {
rs.iavlDisableFastNode = disableFastNode
}

// SetLazyLoading sets if the iavl store should be loaded lazily or not
func (rs *Store) SetLazyLoading(lazyLoading bool) {
rs.lazyLoading = lazyLoading
}

// GetStoreType implements Store.
func (rs *Store) GetStoreType() types.StoreType {
return types.StoreTypeMulti
Expand Down Expand Up @@ -600,60 +595,27 @@ func (rs *Store) handlePruning(version int64) error {
}
rs.logger.Info("prune start", "height", version)
defer rs.logger.Info("prune end", "height", version)
return rs.PruneStores(true, nil)
rs.PruneStores(version)
return nil
}

// PruneStores prunes the specific heights of the multi store.
// If clearPruningManager is true, the pruning manager will return the pruning heights,
// and they are appended to the pruningHeights to be pruned.
func (rs *Store) PruneStores(clearPruningManager bool, pruningHeights []int64) (err error) {
if clearPruningManager {
heights, err := rs.pruningManager.GetFlushAndResetPruningHeights()
if err != nil {
return err
}

if len(heights) == 0 {
rs.logger.Debug("no heights to be pruned from pruning manager")
}

pruningHeights = append(pruningHeights, heights...)
}

if len(pruningHeights) == 0 {
rs.logger.Debug("no heights need to be pruned")
return nil
}

maxHeight := int64(0)
for _, height := range pruningHeights {
if height > maxHeight {
maxHeight = height
}
}
rs.logger.Debug("pruning store", "heights", maxHeight)

func (rs *Store) PruneStores(pruningHeight int64) {
for key, store := range rs.stores {
rs.logger.Debug("pruning store", "key", key) // Also log store.name (a private variable)?

// If the store is wrapped with an inter-block cache, we must first unwrap
// it to get the underlying IAVL store.
if store.GetStoreType() != types.StoreTypeIAVL {
continue
}

store = rs.GetCommitKVStore(key)

err := store.(*iavl.Store).DeleteVersionsTo(maxHeight)
if err == nil {
continue
}
if store.GetStoreType() == types.StoreTypeIAVL {
// If the store is wrapped with an inter-block cache, we must first unwrap
// it to get the underlying IAVL store.
store = rs.GetCommitKVStore(key)

if errCause := errors.Cause(err); errCause != nil && errCause != iavltree.ErrVersionDoesNotExist {
return err
if err := store.(*iavl.Store).DeleteVersionsTo(pruningHeight); err != nil {
if errCause := errors.Cause(err); errCause != nil && errCause != iavltree.ErrVersionDoesNotExist {
panic(err)
}
}
}
}
return nil
}

// getStoreByName performs a lookup of a StoreKey given a store name typically
Expand Down
3 changes: 0 additions & 3 deletions store/types/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,6 @@ type CommitMultiStore interface {
// SetIAVLDisableFastNode enables/disables fastnode feature on iavl.
SetIAVLDisableFastNode(disable bool)

// SetIAVLLazyLoading enable/disable lazy loading on iavl.
SetLazyLoading(lazyLoading bool)

// RollbackToVersion rollback the db to specific version(height).
RollbackToVersion(version int64) error

Expand Down

0 comments on commit f0de908

Please sign in to comment.