store/* fixes
This commit is contained in:
parent
1d207a2a5e
commit
a47da2c8e1
|
@ -11,7 +11,7 @@ type cacheMultiStore struct {
|
||||||
db dbm.CacheDB
|
db dbm.CacheDB
|
||||||
curVersion int64
|
curVersion int64
|
||||||
lastCommitID CommitID
|
lastCommitID CommitID
|
||||||
substores map[string]CacheWriter
|
substores map[string]CacheWrap
|
||||||
}
|
}
|
||||||
|
|
||||||
func newCacheMultiStoreFromRMS(rms *rootMultiStore) cacheMultiStore {
|
func newCacheMultiStoreFromRMS(rms *rootMultiStore) cacheMultiStore {
|
||||||
|
@ -19,25 +19,25 @@ func newCacheMultiStoreFromRMS(rms *rootMultiStore) cacheMultiStore {
|
||||||
db: rms.db.CacheDB(),
|
db: rms.db.CacheDB(),
|
||||||
curVersion: rms.curVersion,
|
curVersion: rms.curVersion,
|
||||||
lastCommitID: rms.lastCommitID,
|
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 {
|
for name, substore := range rms.substores {
|
||||||
cms.substores[name] = substore.CacheWrap().(CacheWriter)
|
cms.substores[name] = substore.CacheWrap()
|
||||||
}
|
}
|
||||||
return cms
|
return cms
|
||||||
}
|
}
|
||||||
|
|
||||||
func newCacheMultiStoreFromCMS(cms cacheMultiStore) cacheMultiStore {
|
func newCacheMultiStoreFromCMS(cms cacheMultiStore) cacheMultiStore {
|
||||||
cms := cacheMultiStore{
|
cms2 := cacheMultiStore{
|
||||||
db: cms.db.CacheDB(),
|
db: cms.db.CacheDB(),
|
||||||
curVersion: cms.curVersion,
|
curVersion: cms.curVersion,
|
||||||
lastCommitID: cms.lastCommitID,
|
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 {
|
for name, substore := range cms.substores {
|
||||||
cms.substores[name] = substore.CacheWrap().(CacheWriter)
|
cms2.substores[name] = substore.CacheWrap()
|
||||||
}
|
}
|
||||||
return cms
|
return cms2
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements CacheMultiStore
|
// Implements CacheMultiStore
|
||||||
|
@ -58,22 +58,27 @@ func (cms cacheMultiStore) Write() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Implements CacheMultiStore
|
||||||
|
func (cms cacheMultiStore) CacheWrap() CacheWrap {
|
||||||
|
return cms.CacheMultiStore()
|
||||||
|
}
|
||||||
|
|
||||||
// Implements CacheMultiStore
|
// Implements CacheMultiStore
|
||||||
func (cms cacheMultiStore) CacheMultiStore() CacheMultiStore {
|
func (cms cacheMultiStore) CacheMultiStore() CacheMultiStore {
|
||||||
return newCacheMultiStoreFromCMS(cms)
|
return newCacheMultiStoreFromCMS(cms)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements CacheMultiStore
|
// Implements CacheMultiStore
|
||||||
func (cms cacheMultiStore) GetCommitter(name string) Committer {
|
func (cms cacheMultiStore) GetStore(name string) interface{} {
|
||||||
return cms.store[name]
|
return cms.substores[name]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements CacheMultiStore
|
// Implements CacheMultiStore
|
||||||
func (cms cacheMultiStore) GetKVStore(name string) KVStore {
|
func (cms cacheMultiStore) GetKVStore(name string) KVStore {
|
||||||
return cms.store[name].(KVStore)
|
return cms.substores[name].(KVStore)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements CacheMultiStore
|
// Implements CacheMultiStore
|
||||||
func (cms cacheMultiStore) GetIterKVStore(name string) IterKVStore {
|
func (cms cacheMultiStore) GetIterKVStore(name string) IterKVStore {
|
||||||
return cms.store[name].(IterKVStore)
|
return cms.substores[name].(IterKVStore)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
// XXX Need to s/Committer/CommitStore/g
|
||||||
|
|
||||||
package store
|
package store
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
@ -163,7 +163,7 @@ func (rs *rootMultiStore) Commit() CommitID {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements CommitStore
|
// Implements CommitStore
|
||||||
func (rs *rootMultiStore) CacheWrap() CacheWriter {
|
func (rs *rootMultiStore) CacheWrap() CacheWrap {
|
||||||
return rs.CacheMultiStore()
|
return rs.CacheMultiStore()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,12 +32,15 @@ type CacheWrapper interface {
|
||||||
|
|
||||||
NOTE: https://dave.cheney.net/2017/07/22/should-go-2-0-support-generics.
|
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 CacheWrap interface {
|
||||||
type CacheWriter interface {
|
// Write syncs with the underlying store.
|
||||||
Write()
|
Write()
|
||||||
|
|
||||||
|
// CacheWrap recursively wraps again.
|
||||||
|
CacheWrap() CacheWrap
|
||||||
}
|
}
|
||||||
|
|
||||||
type CommitStore interface {
|
type CommitStore interface {
|
||||||
|
@ -60,7 +63,7 @@ type KVStore interface {
|
||||||
CacheKVStore() CacheKVStore
|
CacheKVStore() CacheKVStore
|
||||||
|
|
||||||
// CacheWrap() returns a CacheKVStore.
|
// CacheWrap() returns a CacheKVStore.
|
||||||
CacheWrap() CacheWriter
|
CacheWrap() CacheWrap
|
||||||
}
|
}
|
||||||
|
|
||||||
type CacheKVStore interface {
|
type CacheKVStore interface {
|
||||||
|
@ -85,7 +88,7 @@ type IterKVStore interface {
|
||||||
CacheIterKVStore() CacheIterKVStore
|
CacheIterKVStore() CacheIterKVStore
|
||||||
|
|
||||||
// CacheWrap() returns a CacheIterKVStore.
|
// CacheWrap() returns a CacheIterKVStore.
|
||||||
CacheWrap() CacheWriter
|
CacheWrap() CacheWrap
|
||||||
}
|
}
|
||||||
|
|
||||||
type CacheIterKVStore interface {
|
type CacheIterKVStore interface {
|
||||||
|
@ -156,7 +159,7 @@ type MultiStore interface {
|
||||||
CacheMultiStore() CacheMultiStore
|
CacheMultiStore() CacheMultiStore
|
||||||
|
|
||||||
// CacheWrap returns a CacheMultiStore.
|
// CacheWrap returns a CacheMultiStore.
|
||||||
CacheWrap() CacheWriter
|
CacheWrap() CacheWrap
|
||||||
|
|
||||||
// Convenience
|
// Convenience
|
||||||
GetStore(name string) interface{}
|
GetStore(name string) interface{}
|
||||||
|
|
Loading…
Reference in New Issue