store/* fixes

This commit is contained in:
Jae Kwon 2017-12-04 00:56:25 -08:00
parent 1d207a2a5e
commit a47da2c8e1
4 changed files with 29 additions and 19 deletions

View File

@ -11,7 +11,7 @@ type cacheMultiStore struct {
db dbm.CacheDB
curVersion int64
lastCommitID CommitID
substores map[string]CacheWriter
substores map[string]CacheWrap
}
func newCacheMultiStoreFromRMS(rms *rootMultiStore) cacheMultiStore {
@ -19,25 +19,25 @@ func newCacheMultiStoreFromRMS(rms *rootMultiStore) cacheMultiStore {
db: rms.db.CacheDB(),
curVersion: rms.curVersion,
lastCommitID: rms.lastCommitID,
substores: make(map[string]CacheWriter, len(rms.substores)),
substores: make(map[string]CacheWrap, len(rms.substores)),
}
for name, substore := range rms.substores {
cms.substores[name] = substore.CacheWrap().(CacheWriter)
cms.substores[name] = substore.CacheWrap()
}
return cms
}
func newCacheMultiStoreFromCMS(cms cacheMultiStore) cacheMultiStore {
cms := cacheMultiStore{
cms2 := cacheMultiStore{
db: cms.db.CacheDB(),
curVersion: cms.curVersion,
lastCommitID: cms.lastCommitID,
substores: make(map[string]CacheWriter, len(cms.substores)),
substores: make(map[string]CacheWrap, len(cms.substores)),
}
for name, substore := range rs.substores {
cms.substores[name] = substore.CacheWrap().(CacheWriter)
for name, substore := range cms.substores {
cms2.substores[name] = substore.CacheWrap()
}
return cms
return cms2
}
// Implements CacheMultiStore
@ -58,22 +58,27 @@ func (cms cacheMultiStore) Write() {
}
}
// Implements CacheMultiStore
func (cms cacheMultiStore) CacheWrap() CacheWrap {
return cms.CacheMultiStore()
}
// Implements CacheMultiStore
func (cms cacheMultiStore) CacheMultiStore() CacheMultiStore {
return newCacheMultiStoreFromCMS(cms)
}
// Implements CacheMultiStore
func (cms cacheMultiStore) GetCommitter(name string) Committer {
return cms.store[name]
func (cms cacheMultiStore) GetStore(name string) interface{} {
return cms.substores[name]
}
// Implements CacheMultiStore
func (cms cacheMultiStore) GetKVStore(name string) KVStore {
return cms.store[name].(KVStore)
return cms.substores[name].(KVStore)
}
// Implements CacheMultiStore
func (cms cacheMultiStore) GetIterKVStore(name string) IterKVStore {
return cms.store[name].(IterKVStore)
return cms.substores[name].(IterKVStore)
}

View File

@ -1,3 +1,5 @@
// XXX Need to s/Committer/CommitStore/g
package store
import (

View File

@ -163,7 +163,7 @@ func (rs *rootMultiStore) Commit() CommitID {
}
// Implements CommitStore
func (rs *rootMultiStore) CacheWrap() CacheWriter {
func (rs *rootMultiStore) CacheWrap() CacheWrap {
return rs.CacheMultiStore()
}

View File

@ -32,12 +32,15 @@ type CacheWrapper interface {
NOTE: https://dave.cheney.net/2017/07/22/should-go-2-0-support-generics.
*/
CacheWrap() CacheWriter
CacheWrap() CacheWrap
}
// CacheWriter.Write syncs with the underlying store.
type CacheWriter interface {
type CacheWrap interface {
// Write syncs with the underlying store.
Write()
// CacheWrap recursively wraps again.
CacheWrap() CacheWrap
}
type CommitStore interface {
@ -60,7 +63,7 @@ type KVStore interface {
CacheKVStore() CacheKVStore
// CacheWrap() returns a CacheKVStore.
CacheWrap() CacheWriter
CacheWrap() CacheWrap
}
type CacheKVStore interface {
@ -85,7 +88,7 @@ type IterKVStore interface {
CacheIterKVStore() CacheIterKVStore
// CacheWrap() returns a CacheIterKVStore.
CacheWrap() CacheWriter
CacheWrap() CacheWrap
}
type CacheIterKVStore interface {
@ -156,7 +159,7 @@ type MultiStore interface {
CacheMultiStore() CacheMultiStore
// CacheWrap returns a CacheMultiStore.
CacheWrap() CacheWriter
CacheWrap() CacheWrap
// Convenience
GetStore(name string) interface{}