fixes from my review
This commit is contained in:
parent
8550e79665
commit
7a9014fcaf
|
@ -13,24 +13,27 @@ import (
|
|||
|
||||
// NewIAVLLoader returns a CommitterLoader that returns
|
||||
// an IAVLCommitter
|
||||
func NewIAVLLoader(dbName string, cacheSize int, history uint64) CommitterLoader {
|
||||
func NewIAVLLoader(dbName string, cacheSize int, nHistoricalVersions uint64) CommitterLoader {
|
||||
l := iavlLoader{
|
||||
dbName: dbName,
|
||||
cacheSize: cacheSize,
|
||||
history: history,
|
||||
nHistoricalVersions: nHistoricalVersions,
|
||||
}
|
||||
return CommitterLoader(l.Load)
|
||||
}
|
||||
|
||||
var _ CacheWrappable = (*IAVLCommitter)(nil)
|
||||
var _ Committer = (*IAVLCommitter)(nil)
|
||||
|
||||
// IAVLCommitter Implements IterKVStore and Committer
|
||||
type IAVLCommitter struct {
|
||||
// we must store the last height here, as it is needed
|
||||
// for saving the versioned tree
|
||||
lastHeight uint64
|
||||
|
||||
// history is how many old versions we hold onto,
|
||||
// nHistoricalVersions is how many old versions we hold onto,
|
||||
// uses a naive "hold last X versions" algorithm
|
||||
history uint64
|
||||
nHistoricalVersions uint64
|
||||
|
||||
// this is all historical data and connection to
|
||||
// the db
|
||||
|
@ -44,11 +47,11 @@ type IAVLCommitter struct {
|
|||
// NewIAVLCommitter properly initializes a committer
|
||||
// that is ready to use as a IterKVStore
|
||||
func NewIAVLCommitter(tree *iavl.VersionedTree,
|
||||
lastHeight uint64, history uint64) *IAVLCommitter {
|
||||
lastHeight uint64, nHistoricalVersions uint64) *IAVLCommitter {
|
||||
i := &IAVLCommitter{
|
||||
tree: tree,
|
||||
lastHeight: lastHeight,
|
||||
history: history,
|
||||
nHistoricalVersions: nHistoricalVersions,
|
||||
}
|
||||
i.updateStore()
|
||||
return i
|
||||
|
@ -73,8 +76,8 @@ func (i *IAVLCommitter) Commit() CommitID {
|
|||
i.updateStore()
|
||||
|
||||
// release an old version of history
|
||||
if i.history <= i.lastHeight {
|
||||
release := i.lastHeight - i.history
|
||||
if i.nHistoricalVersions <= i.lastHeight {
|
||||
release := i.lastHeight - i.nHistoricalVersions
|
||||
i.tree.DeleteVersion(release)
|
||||
}
|
||||
|
||||
|
@ -89,9 +92,6 @@ func (i *IAVLCommitter) updateStore() {
|
|||
i.IAVLStore = IAVLStore{i.tree.Tree()}
|
||||
}
|
||||
|
||||
var _ CacheWrappable = (*IAVLCommitter)(nil)
|
||||
var _ Committer = (*IAVLCommitter)(nil)
|
||||
|
||||
// IAVLStore is the writable state (not history) and
|
||||
// implements the IterKVStore interface.
|
||||
type IAVLStore struct {
|
||||
|
@ -214,7 +214,7 @@ func (i *iavlIterator) Release() {
|
|||
type iavlLoader struct {
|
||||
dbName string
|
||||
cacheSize int
|
||||
history uint64
|
||||
nHistoricalVersion uint64
|
||||
}
|
||||
|
||||
// Load implements CommitLoader type
|
||||
|
@ -222,7 +222,7 @@ func (l iavlLoader) Load(id CommitID) (Committer, error) {
|
|||
// memory backed case, just for testing
|
||||
if l.dbName == "" {
|
||||
tree := iavl.NewVersionedTree(0, dbm.NewMemDB())
|
||||
store := NewIAVLCommitter(tree, 0, l.history)
|
||||
store := NewIAVLCommitter(tree, 0, l.nHistoricalVersions)
|
||||
return store, nil
|
||||
}
|
||||
|
||||
|
@ -248,6 +248,6 @@ func (l iavlLoader) Load(id CommitID) (Committer, error) {
|
|||
|
||||
// TODO: load the version stored in id
|
||||
store := NewIAVLCommitter(tree, tree.LatestVersion(),
|
||||
l.history)
|
||||
l.nHistoricalVersions)
|
||||
return store, nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue