2017-12-01 08:52:54 -08:00
|
|
|
package store
|
|
|
|
|
|
|
|
import dbm "github.com/tendermint/tmlibs/db"
|
|
|
|
|
|
|
|
//----------------------------------------
|
|
|
|
// cacheMultiStore
|
|
|
|
|
2017-12-03 22:55:15 -08:00
|
|
|
// cacheMultiStore holds many cache-wrapped stores.
|
2017-12-01 08:52:54 -08:00
|
|
|
// Implements MultiStore.
|
|
|
|
type cacheMultiStore struct {
|
2017-12-04 00:23:10 -08:00
|
|
|
db dbm.CacheDB
|
|
|
|
curVersion int64
|
2017-12-01 08:52:54 -08:00
|
|
|
lastCommitID CommitID
|
2017-12-03 22:55:15 -08:00
|
|
|
substores map[string]CacheWriter
|
2017-12-01 08:52:54 -08:00
|
|
|
}
|
|
|
|
|
2017-12-04 00:23:10 -08:00
|
|
|
func newCacheMultiStoreFromRMS(rms *rootMultiStore) cacheMultiStore {
|
2017-12-01 08:52:54 -08:00
|
|
|
cms := cacheMultiStore{
|
2017-12-04 00:23:10 -08:00
|
|
|
db: rms.db.CacheDB(),
|
|
|
|
curVersion: rms.curVersion,
|
|
|
|
lastCommitID: rms.lastCommitID,
|
|
|
|
substores: make(map[string]CacheWriter, len(rms.substores)),
|
|
|
|
}
|
|
|
|
for name, substore := range rms.substores {
|
|
|
|
cms.substores[name] = substore.CacheWrap().(CacheWriter)
|
|
|
|
}
|
|
|
|
return cms
|
|
|
|
}
|
|
|
|
|
|
|
|
func newCacheMultiStoreFromCMS(cms cacheMultiStore) cacheMultiStore {
|
|
|
|
cms := cacheMultiStore{
|
|
|
|
db: cms.db.CacheDB(),
|
|
|
|
curVersion: cms.curVersion,
|
|
|
|
lastCommitID: cms.lastCommitID,
|
|
|
|
substores: make(map[string]CacheWriter, len(cms.substores)),
|
2017-12-01 08:52:54 -08:00
|
|
|
}
|
|
|
|
for name, substore := range rs.substores {
|
2017-12-03 22:55:15 -08:00
|
|
|
cms.substores[name] = substore.CacheWrap().(CacheWriter)
|
2017-12-01 08:52:54 -08:00
|
|
|
}
|
|
|
|
return cms
|
|
|
|
}
|
|
|
|
|
|
|
|
// Implements CacheMultiStore
|
|
|
|
func (cms cacheMultiStore) LastCommitID() CommitID {
|
|
|
|
return cms.lastCommitID
|
|
|
|
}
|
|
|
|
|
|
|
|
// Implements CacheMultiStore
|
|
|
|
func (cms cacheMultiStore) CurrentVersion() int64 {
|
2017-12-04 00:23:10 -08:00
|
|
|
return cms.curVersion
|
2017-12-01 08:52:54 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Implements CacheMultiStore
|
|
|
|
func (cms cacheMultiStore) Write() {
|
|
|
|
cms.db.Write()
|
2017-12-04 00:23:10 -08:00
|
|
|
for _, substore := range cms.substores {
|
2017-12-03 15:01:17 -08:00
|
|
|
substore.Write()
|
2017-12-01 08:52:54 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Implements CacheMultiStore
|
2017-12-04 00:23:10 -08:00
|
|
|
func (cms cacheMultiStore) CacheMultiStore() CacheMultiStore {
|
|
|
|
return newCacheMultiStoreFromCMS(cms)
|
2017-12-01 08:52:54 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Implements CacheMultiStore
|
2017-12-04 00:23:10 -08:00
|
|
|
func (cms cacheMultiStore) GetCommitter(name string) Committer {
|
|
|
|
return cms.store[name]
|
2017-12-01 08:52:54 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Implements CacheMultiStore
|
2017-12-04 00:23:10 -08:00
|
|
|
func (cms cacheMultiStore) GetKVStore(name string) KVStore {
|
|
|
|
return cms.store[name].(KVStore)
|
2017-12-01 08:52:54 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Implements CacheMultiStore
|
2017-12-04 00:23:10 -08:00
|
|
|
func (cms cacheMultiStore) GetIterKVStore(name string) IterKVStore {
|
|
|
|
return cms.store[name].(IterKVStore)
|
2017-12-01 08:52:54 -08:00
|
|
|
}
|