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