Skip to content

Commit

Permalink
perf: remove iavl cache manager
Browse files Browse the repository at this point in the history
  • Loading branch information
dudong2 committed Jul 19, 2022
1 parent 89773d3 commit b4c0c6a
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 52 deletions.
11 changes: 0 additions & 11 deletions baseapp/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,6 @@ func SetInterBlockCache(cache sdk.MultiStorePersistentCache) func(*BaseApp) {
return func(app *BaseApp) { app.setInterBlockCache(cache) }
}

// SetIAVLCacheManager provides a BaseApp option function that sets the iavl CacheManager
func SetIAVLCacheManager(size int, provider iavl.MetricsProvider) func(*BaseApp) {
return func(app *BaseApp) {
if size == 0 {
app.cms.SetIAVLCacheManager(iavl.NewCacheManagerNoCache())
} else {
app.cms.SetIAVLCacheManager(iavl.NewCacheManagerSingleton(size, provider))
}
}
}

// SetSnapshotInterval sets the snapshot interval.
func SetSnapshotInterval(interval uint64) func(*BaseApp) {
return func(app *BaseApp) { app.SetSnapshotInterval(interval) }
Expand Down
8 changes: 0 additions & 8 deletions server/mock/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,6 @@ func (ms multiStore) Restore(
panic("not implemented")
}

func (ms multiStore) SetIAVLCacheManager(cacheManager store.CacheManager) {
panic("not implemented")
}

var _ sdk.KVStore = kvStore{}

type kvStore struct {
Expand Down Expand Up @@ -204,10 +200,6 @@ func (kv kvStore) ReverseSubspaceIterator(prefix []byte) sdk.Iterator {
panic("not implemented")
}

func (kv kvStore) SetIAVLCacheManager(cacheManager store.CacheManager) {
panic("not implemented")
}

func NewCommitMultiStore() sdk.CommitMultiStore {
return multiStore{kv: make(map[sdk.StoreKey]kvStore)}
}
2 changes: 0 additions & 2 deletions server/mock/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,4 @@ func TestStore(t *testing.T) {
require.False(t, store.Has(k))
require.Panics(t, func() { store.Set([]byte(""), v) }, "setting an empty key should panic")
require.Panics(t, func() { store.Set(nil, v) }, "setting a nil key should panic")

require.Panics(t, func() { cms.SetIAVLCacheManager(nil) }, "not implemented")
}
3 changes: 1 addition & 2 deletions simapp/simd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ type appCreator struct {
func (a appCreator) newApp(logger log.Logger, db tmdb.DB, traceStore io.Writer, appOpts servertypes.AppOptions) servertypes.Application {
var cache sdk.MultiStorePersistentCache

ibCacheMetricsProvider, iavlCacheMetricsProvider :=
ibCacheMetricsProvider, _ :=
baseapp.MetricsProvider(cast.ToBool(viper.GetBool(server.FlagPrometheus)))
if cast.ToBool(appOpts.Get(server.FlagInterBlockCache)) {
cache = store.NewCommitKVStoreCacheManager(
Expand Down Expand Up @@ -286,7 +286,6 @@ func (a appCreator) newApp(logger log.Logger, db tmdb.DB, traceStore io.Writer,
baseapp.SetHaltTime(cast.ToUint64(appOpts.Get(server.FlagHaltTime))),
baseapp.SetMinRetainBlocks(cast.ToUint64(appOpts.Get(server.FlagMinRetainBlocks))),
baseapp.SetInterBlockCache(cache),
baseapp.SetIAVLCacheManager(cast.ToInt(appOpts.Get(server.FlagIAVLCacheSize)), iavlCacheMetricsProvider),
baseapp.SetTrace(cast.ToBool(appOpts.Get(server.FlagTrace))),
baseapp.SetIndexEvents(cast.ToStringSlice(appOpts.Get(server.FlagIndexEvents))),
baseapp.SetSnapshotStore(snapshotStore),
Expand Down
22 changes: 5 additions & 17 deletions store/iavl/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,16 @@ func NewCacheManagerNoCache() types.CacheManager {
// LoadStore returns an IAVL Store as a CommitKVStore. Internally, it will load the
// store's version (id) from the provided DB. An error is returned if the version
// fails to load, or if called with a positive version on an empty tree.
func LoadStore(db tmdb.DB, cacheManager types.CacheManager, id types.CommitID, lazyLoading bool, cacheSize int) (types.CommitKVStore, error) {
return LoadStoreWithInitialVersion(db, cacheManager, id, lazyLoading, 0, cacheSize)
func LoadStore(db tmdb.DB, id types.CommitID, lazyLoading bool, cacheSize int) (types.CommitKVStore, error) {
return LoadStoreWithInitialVersion(db, id, lazyLoading, 0, cacheSize)
}

// LoadStoreWithInitialVersion returns an IAVL Store as a CommitKVStore setting its initialVersion
// to the one given. Internally, it will load the store's version (id) from the
// provided DB. An error is returned if the version fails to load, or if called with a positive
// version on an empty tree.
func LoadStoreWithInitialVersion(db tmdb.DB, cacheManager types.CacheManager, id types.CommitID, lazyLoading bool, initialVersion uint64, cacheSize int) (types.CommitKVStore, error) {
if cacheManager == nil {
cacheManager = NewCacheManagerNoCache()
}
cache := cacheManager.GetCache()
tree, err := iavl.NewMutableTreeWithCacheWithOpts(db, cache, &iavl.Options{InitialVersion: initialVersion}) // TODO(dudong2): need to fix to use cacheSize(by using NewMutableTreeWithOpts)
func LoadStoreWithInitialVersion(db tmdb.DB, id types.CommitID, lazyLoading bool, initialVersion uint64, cacheSize int) (types.CommitKVStore, error) {
tree, err := iavl.NewMutableTreeWithOpts(db, cacheSize, &iavl.Options{InitialVersion: initialVersion})
if err != nil {
return nil, err
}
Expand All @@ -117,16 +113,8 @@ func LoadStoreWithInitialVersion(db tmdb.DB, cacheManager types.CacheManager, id
return nil, err
}

var metrics *Metrics
if cms, ok := cacheManager.(*CacheManagerSingleton); ok {
metrics = cms.metrics
} else {
metrics = NopMetrics()
}
return &Store{
tree: tree,
cache: cache,
metrics: metrics,
tree: tree,
}, nil
}

Expand Down
11 changes: 3 additions & 8 deletions store/rootmulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ type Store struct {
traceWriter io.Writer
traceContext types.TraceContext

interBlockCache types.MultiStorePersistentCache
iavlCacheManager types.CacheManager
interBlockCache types.MultiStorePersistentCache

listeners map[types.StoreKey][]types.WriteListener
}
Expand Down Expand Up @@ -109,10 +108,6 @@ func (rs *Store) SetLazyLoading(lazyLoading bool) {
rs.lazyLoading = lazyLoading
}

func (rs *Store) SetIAVLCacheManager(cacheManager types.CacheManager) {
rs.iavlCacheManager = cacheManager
}

// GetStoreType implements Store.
func (rs *Store) GetStoreType() types.StoreType {
return types.StoreTypeMulti
Expand Down Expand Up @@ -891,9 +886,9 @@ func (rs *Store) loadCommitStoreFromParams(key types.StoreKey, id types.CommitID
var err error

if params.initialVersion == 0 {
store, err = iavl.LoadStore(db, rs.iavlCacheManager, id, rs.lazyLoading, rs.iavlCacheSize)
store, err = iavl.LoadStore(db, id, rs.lazyLoading, rs.iavlCacheSize)
} else {
store, err = iavl.LoadStoreWithInitialVersion(db, rs.iavlCacheManager, id, rs.lazyLoading, params.initialVersion, rs.iavlCacheSize)
store, err = iavl.LoadStoreWithInitialVersion(db, id, rs.lazyLoading, params.initialVersion, rs.iavlCacheSize)
}

if err != nil {
Expand Down
4 changes: 0 additions & 4 deletions store/types/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,6 @@ type CommitMultiStore interface {
// starting a new chain at an arbitrary height.
SetInitialVersion(version int64) error

// SetIAVLCacheManager sets the CacheManager that is holding nodedb cache of IAVL tree
// If a cacheManager is not set, then IAVL tree does not use cache
SetIAVLCacheManager(cacheManager CacheManager)

// SetIAVLCacheSize sets the cache size of the IAVL tree.
SetIAVLCacheSize(size int)
}
Expand Down

0 comments on commit b4c0c6a

Please sign in to comment.