rootMultiStore holds lastCommitID
This commit is contained in:
parent
8db15fe3ef
commit
0917fc3de7
|
@ -16,7 +16,7 @@ type cacheMultiStore struct {
|
||||||
|
|
||||||
func newCacheMultiStore(rs *rootMultiStore) cacheMultiStore {
|
func newCacheMultiStore(rs *rootMultiStore) cacheMultiStore {
|
||||||
cms := cacheMultiStore{
|
cms := cacheMultiStore{
|
||||||
db: dbm.CacheDB(),
|
db: rs.db.CacheDB(),
|
||||||
version: rs.curVersion,
|
version: rs.curVersion,
|
||||||
lastCommitID: rs.lastCommitID,
|
lastCommitID: rs.lastCommitID,
|
||||||
substores: make(map[string]CacheWriter, len(rs.substores)),
|
substores: make(map[string]CacheWriter, len(rs.substores)),
|
||||||
|
|
|
@ -21,7 +21,7 @@ const (
|
||||||
type rootMultiStore struct {
|
type rootMultiStore struct {
|
||||||
db dbm.DB
|
db dbm.DB
|
||||||
curVersion int64
|
curVersion int64
|
||||||
lastHash []byte
|
lastCommitID CommitID
|
||||||
storeLoaders map[string]CommitStoreLoader
|
storeLoaders map[string]CommitStoreLoader
|
||||||
substores map[string]CommitStore
|
substores map[string]CommitStore
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,6 @@ func NewMultiStore(db dbm.DB) *rootMultiStore {
|
||||||
return &rootMultiStore{
|
return &rootMultiStore{
|
||||||
db: db,
|
db: db,
|
||||||
curVersion: 0,
|
curVersion: 0,
|
||||||
lastHash: nil,
|
|
||||||
storeLoaders: make(map[string]CommitStoreLoader),
|
storeLoaders: make(map[string]CommitStoreLoader),
|
||||||
substores: make(map[string]CommitStore),
|
substores: make(map[string]CommitStore),
|
||||||
}
|
}
|
||||||
|
@ -64,7 +63,7 @@ func (rs *rootMultiStore) LoadVersion(ver int64) error {
|
||||||
return fmt.Errorf("Failed to load rootMultiStore: %v", err)
|
return fmt.Errorf("Failed to load rootMultiStore: %v", err)
|
||||||
}
|
}
|
||||||
rs.curVersion = 1
|
rs.curVersion = 1
|
||||||
rs.lastHash = nil
|
rs.lastCommitID = CommitID{}
|
||||||
rs.substores[name] = store
|
rs.substores[name] = store
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -98,7 +97,7 @@ func (rs *rootMultiStore) LoadVersion(ver int64) error {
|
||||||
|
|
||||||
// Success.
|
// Success.
|
||||||
rs.curVersion = ver + 1
|
rs.curVersion = ver + 1
|
||||||
rs.lastHash = state.LastHash
|
rs.lastCommitID = state.CommitID()
|
||||||
rs.substores = newSubstores
|
rs.substores = newSubstores
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -106,7 +105,6 @@ func (rs *rootMultiStore) LoadVersion(ver int64) error {
|
||||||
// Commits each substore and gets commitState.
|
// Commits each substore and gets commitState.
|
||||||
func (rs *rootMultiStore) doCommit() commitState {
|
func (rs *rootMultiStore) doCommit() commitState {
|
||||||
version := rs.curVersion
|
version := rs.curVersion
|
||||||
lastHash := rs.LastHash
|
|
||||||
substores := make([]substore, len(rs.substores))
|
substores := make([]substore, len(rs.substores))
|
||||||
|
|
||||||
for name, store := range rs.substores {
|
for name, store := range rs.substores {
|
||||||
|
@ -127,7 +125,6 @@ func (rs *rootMultiStore) doCommit() commitState {
|
||||||
|
|
||||||
return commitState{
|
return commitState{
|
||||||
Version: version,
|
Version: version,
|
||||||
LastHash: lastHash,
|
|
||||||
Substores: substores,
|
Substores: substores,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -157,11 +154,12 @@ func (rs *rootMultiStore) Commit() CommitID {
|
||||||
|
|
||||||
batch.Write()
|
batch.Write()
|
||||||
rs.version += 1
|
rs.version += 1
|
||||||
|
commitID := CommitID{
|
||||||
return CommitID{
|
|
||||||
Version: version,
|
Version: version,
|
||||||
Hash: state.Hash(),
|
Hash: state.Hash(),
|
||||||
}
|
}
|
||||||
|
rs.lastCommitID = commitID
|
||||||
|
return commitID
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements CommitStore
|
// Implements CommitStore
|
||||||
|
@ -171,16 +169,7 @@ func (rs *rootMultiStore) CacheWrap() CacheWriter {
|
||||||
|
|
||||||
// Get the last committed CommitID
|
// Get the last committed CommitID
|
||||||
func (rs *rootMultiStore) LastCommitID() CommitID {
|
func (rs *rootMultiStore) LastCommitID() CommitID {
|
||||||
|
return rs.lastCommitID
|
||||||
// If we haven't committed yet, return a zero CommitID
|
|
||||||
if rs.curVersion == 0 {
|
|
||||||
return CommitID{}
|
|
||||||
}
|
|
||||||
|
|
||||||
return CommitID{
|
|
||||||
Version: rs.curVersion - 1,
|
|
||||||
Hash: rs.LastHash,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements MultiStore
|
// Implements MultiStore
|
||||||
|
@ -212,9 +201,6 @@ type commitState struct {
|
||||||
// Version
|
// Version
|
||||||
Version int64
|
Version int64
|
||||||
|
|
||||||
// Last hash (memoization)
|
|
||||||
LastHash []byte
|
|
||||||
|
|
||||||
// Substore info for
|
// Substore info for
|
||||||
Substores []substore
|
Substores []substore
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue