Merge PR #4997: Fix CacheMultiStoreWithVersion (inter-block cache)
This commit is contained in:
parent
d7d7a93729
commit
2d18f1e7e9
|
@ -70,6 +70,15 @@ func (cmgr *CommitKVStoreCacheManager) GetStoreCache(key types.StoreKey, store t
|
||||||
return cmgr.caches[key.Name()]
|
return cmgr.caches[key.Name()]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Unwrap returns the underlying CommitKVStore for a given StoreKey.
|
||||||
|
func (cmgr *CommitKVStoreCacheManager) Unwrap(key types.StoreKey) types.CommitKVStore {
|
||||||
|
if ckv, ok := cmgr.caches[key.Name()]; ok {
|
||||||
|
return ckv.(*CommitKVStoreCache).CommitKVStore
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Reset resets in the internal caches.
|
// Reset resets in the internal caches.
|
||||||
func (cmgr *CommitKVStoreCacheManager) Reset() {
|
func (cmgr *CommitKVStoreCacheManager) Reset() {
|
||||||
cmgr.caches = make(map[string]types.CommitKVStore)
|
cmgr.caches = make(map[string]types.CommitKVStore)
|
||||||
|
|
|
@ -25,6 +25,18 @@ func TestGetOrSetStoreCache(t *testing.T) {
|
||||||
require.Equal(t, store2, mngr.GetStoreCache(sKey, store))
|
require.Equal(t, store2, mngr.GetStoreCache(sKey, store))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUnwrap(t *testing.T) {
|
||||||
|
db := dbm.NewMemDB()
|
||||||
|
mngr := cache.NewCommitKVStoreCacheManager(cache.DefaultCommitKVStoreCacheSize)
|
||||||
|
|
||||||
|
sKey := types.NewKVStoreKey("test")
|
||||||
|
store := iavlstore.UnsafeNewStore(iavl.NewMutableTree(db, 100), 10, 10)
|
||||||
|
_ = mngr.GetStoreCache(sKey, store)
|
||||||
|
|
||||||
|
require.Equal(t, store, mngr.Unwrap(sKey))
|
||||||
|
require.Nil(t, mngr.Unwrap(types.NewKVStoreKey("test2")))
|
||||||
|
}
|
||||||
|
|
||||||
func TestStoreCache(t *testing.T) {
|
func TestStoreCache(t *testing.T) {
|
||||||
db := dbm.NewMemDB()
|
db := dbm.NewMemDB()
|
||||||
mngr := cache.NewCommitKVStoreCacheManager(cache.DefaultCommitKVStoreCacheSize)
|
mngr := cache.NewCommitKVStoreCacheManager(cache.DefaultCommitKVStoreCacheSize)
|
||||||
|
|
|
@ -321,6 +321,14 @@ func (rs *Store) CacheMultiStoreWithVersion(version int64) (types.CacheMultiStor
|
||||||
for key, store := range rs.stores {
|
for key, store := range rs.stores {
|
||||||
switch store.GetStoreType() {
|
switch store.GetStoreType() {
|
||||||
case types.StoreTypeIAVL:
|
case types.StoreTypeIAVL:
|
||||||
|
// If the store is wrapped with an inter-block cache, we must first unwrap
|
||||||
|
// it to get the underlying IAVL store.
|
||||||
|
if rs.interBlockCache != nil {
|
||||||
|
if ckvs := rs.interBlockCache.Unwrap(key); ckvs != nil {
|
||||||
|
store = ckvs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Attempt to lazy-load an already saved IAVL store version. If the
|
// Attempt to lazy-load an already saved IAVL store version. If the
|
||||||
// version does not exist or is pruned, an error should be returned.
|
// version does not exist or is pruned, an error should be returned.
|
||||||
iavlStore, err := store.(*iavl.Store).GetImmutable(version)
|
iavlStore, err := store.(*iavl.Store).GetImmutable(version)
|
||||||
|
|
|
@ -340,6 +340,9 @@ type MultiStorePersistentCache interface {
|
||||||
// cache.
|
// cache.
|
||||||
GetStoreCache(key StoreKey, store CommitKVStore) CommitKVStore
|
GetStoreCache(key StoreKey, store CommitKVStore) CommitKVStore
|
||||||
|
|
||||||
|
// Return the underlying CommitKVStore for a StoreKey.
|
||||||
|
Unwrap(key StoreKey) CommitKVStore
|
||||||
|
|
||||||
// Reset the entire set of internal caches.
|
// Reset the entire set of internal caches.
|
||||||
Reset()
|
Reset()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue