-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Restart application issue #5579
Changes from all commits
a540b0e
253ad5c
f1e5ba9
923f1e5
a35591b
0ae90d8
d612e56
63bd983
9e4b434
fbd1a52
42fc8ef
aa81b5d
67d5087
c9c0fd1
f041162
d52da2c
f52fa5e
5fab6cd
c811093
4fa7fe7
e8676ab
d8186a6
b210d0e
5b00d1a
5102a90
6e67a1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
package iavl | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"sync" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/tendermint/iavl" | ||
abci "github.com/tendermint/tendermint/abci/types" | ||
"github.com/tendermint/tendermint/crypto/merkle" | ||
|
@@ -29,18 +31,38 @@ var ( | |
|
||
// Store Implements types.KVStore and CommitKVStore. | ||
type Store struct { | ||
tree Tree | ||
tree Tree | ||
pruning types.PruningOptions | ||
} | ||
|
||
// LoadStore returns an IAVL Store as a CommitKVStore. Internally it will load the | ||
// LoadStore returns an IAVL Store as a CommitKVStore. Internally, it will load the | ||
// store's version (id) from the provided DB. An error is returned if the version | ||
// fails to load. | ||
func LoadStore(db dbm.DB, id types.CommitID, pruning types.PruningOptions, lazyLoading bool) (types.CommitKVStore, error) { | ||
if !pruning.IsValid() { | ||
fedekunze marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return nil, fmt.Errorf("pruning options are invalid: %v", pruning) | ||
} | ||
|
||
var keepRecent int64 | ||
|
||
// Determine the value of keepRecent based on the following: | ||
// | ||
// If KeepEvery = 1, keepRecent should be 0 since there is no need to keep | ||
// latest version in a in-memory cache. | ||
// | ||
// If KeepEvery > 1, keepRecent should be 1 so that state changes in between | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Huh, that's what 1 does? |
||
// flushed states can be saved in the in-memory latest tree. | ||
if pruning.KeepEvery == 1 { | ||
keepRecent = 0 | ||
} else { | ||
keepRecent = 1 | ||
} | ||
|
||
tree, err := iavl.NewMutableTreeWithOpts( | ||
db, | ||
dbm.NewMemDB(), | ||
defaultIAVLCacheSize, | ||
iavl.PruningOptions(pruning.KeepEvery(), pruning.KeepRecent()), | ||
iavl.PruningOptions(pruning.KeepEvery, keepRecent), | ||
) | ||
if err != nil { | ||
return nil, err | ||
|
@@ -56,15 +78,23 @@ func LoadStore(db dbm.DB, id types.CommitID, pruning types.PruningOptions, lazyL | |
return nil, err | ||
} | ||
|
||
return &Store{tree: tree}, nil | ||
return &Store{ | ||
tree: tree, | ||
pruning: pruning, | ||
}, nil | ||
} | ||
|
||
// UnsafeNewStore returns a reference to a new IAVL Store with a given mutable | ||
// IAVL tree reference. | ||
// IAVL tree reference. It should only be used for testing purposes. | ||
// | ||
// CONTRACT: The IAVL tree should be fully loaded. | ||
func UnsafeNewStore(tree *iavl.MutableTree) *Store { | ||
return &Store{tree: tree} | ||
// CONTRACT: PruningOptions passed in as argument must be the same as pruning options | ||
// passed into iavl.MutableTree | ||
func UnsafeNewStore(tree *iavl.MutableTree, po types.PruningOptions) *Store { | ||
alexanderbez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return &Store{ | ||
tree: tree, | ||
pruning: po, | ||
} | ||
} | ||
|
||
// GetImmutable returns a reference to a new store backed by an immutable IAVL | ||
|
@@ -82,18 +112,36 @@ func (st *Store) GetImmutable(version int64) (*Store, error) { | |
return nil, err | ||
} | ||
|
||
return &Store{tree: &immutableTree{iTree}}, nil | ||
return &Store{ | ||
tree: &immutableTree{iTree}, | ||
pruning: st.pruning, | ||
}, nil | ||
} | ||
|
||
// Implements Committer. | ||
// Commit commits the current store state and returns a CommitID with the new | ||
// version and hash. | ||
func (st *Store) Commit() types.CommitID { | ||
// Save a new version. | ||
hash, version, err := st.tree.SaveVersion() | ||
if err != nil { | ||
// TODO: Do we want to extend Commit to allow returning errors? | ||
panic(err) | ||
} | ||
|
||
// If the version we saved got flushed to disk, check if previous flushed | ||
// version should be deleted. | ||
if st.pruning.FlushVersion(version) { | ||
previous := version - st.pruning.KeepEvery | ||
|
||
// Previous flushed version should only be pruned if the previous version is | ||
// not a snapshot version OR if snapshotting is disabled (SnapshotEvery == 0). | ||
if previous != 0 && !st.pruning.SnapshotVersion(previous) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe |
||
err := st.tree.DeleteVersion(previous) | ||
if errCause := errors.Cause(err); errCause != nil && errCause != iavl.ErrVersionDoesNotExist { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about
https://github.com/cosmos/cosmos-sdk/blob/master/types/errors/errors.go#L175 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ++ |
||
panic(err) | ||
} | ||
} | ||
} | ||
|
||
return types.CommitID{ | ||
Version: version, | ||
Hash: hash, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for automatically inferring, and less confusion in configs