forked from cosmos/iavl
-
Notifications
You must be signed in to change notification settings - Fork 1
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
Memtree #11
Merged
Merged
Memtree #11
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This makes it possible to persist leaf node values separately from the tree nodes themselves. As leaf nodes are loaded their values are read from the external store, when they're persisted to disk the values are omitted. The external value store needs to be updated separately when a key is set or deleted in the MutableTree.
Previously there was a single mutex that had to be acquired by a reader/writer before they could access either the node cache or the underlying DB. These changes introduce a second mutex to synchronize access to the node cache, while the original mutex is now only used to synchronize write access to the underlying DB. Multiple readers may now access the underlying DB concurrently, this should work with GoLevelDB at least since it supports concurrent readers.
The multi-mutex NodeDB is now called NodeDB2, both the new implementation and the old one implement the new NodeDB interface. MutableTree & ImmutableTree have been modified to only interact with the NodeDB interface, so they can be used with either of the two NodeDB implementations.
Add MutableTree.SaveVersionToDB to extract a single IAVL tree version
upgrade tendermint iavl
revert back to master iavl
Flushing Memtree
Revert "Flushing Memtree"
mattkanwisher
added a commit
that referenced
this pull request
Jul 2, 2019
* Memtree (#11) Storing intermidiary IAVL versions in memory and not to disk Motivation: Both Cosmos and Loom Network save an IAVL version per block, then go back and delete these versions. So you have constant churn on the IAVL and underlying Leveldb database. When realistically what you want is to only store every X Blocks. At Berlin Tendermint Conference, Zaki and I surmised a plan where new versions are in memory, while still pointing back to nodes on disk to prevent needing to load entire IAVL into main memory. Loom IAVL tree is around 256gb so this is not feasible otherwise. Usage OLD Code would be like ```go hash, version, err := s.tree.SaveVersion() ``` New Caller code would look like ```go oldVersion := s.Version() var version int64 var hash []byte //Every X versions we should persist to disk if s.flushInterval == 0 || ((oldVersion+1)%s.flushInterval == 0) { if s.flushInterval != 0 { log.Error(fmt.Sprintf("Flushing mem to disk at version %d\n", oldVersion+1)) hash, version, err = s.tree.FlushMemVersionDisk() } else { hash, version, err = s.tree.SaveVersion() } } else { hash, version, err = s.tree.SaveVersionMem() } ``` FlushMemVersionDisk: Flushes the current memory version to disk SaveVersionMem: Saves the current tree to memory instead of disk and gives you back an apphash This is an opt in feature, you have to call new apis to get it. We also have a PR that demonstrates its usage https://github.com/loomnetwork/loomchain/pull/1232/files We are now commiting every 1000 blocks, so we store 1000x less. Also we have signficant improves in IO at least double from not having to Prune old versions of the IAVL Tree * Add version saving to in memory, and ability to flush to disk periodically
enlight
pushed a commit
that referenced
this pull request
Aug 26, 2019
Storing intermediary IAVL versions in memory and not to disk Motivation: Both Cosmos and Loom Network save an IAVL version per block, then go back and delete these versions. So you have constant churn on the IAVL and underlying Leveldb database. When realistically what you want is to only store every X Blocks. At Berlin Tendermint Conference, Zaki and I surmised a plan where new versions are in memory, while still pointing back to nodes on disk to prevent needing to load entire IAVL into main memory. Loom IAVL tree is around 256gb so this is not feasible otherwise. Usage OLD Code would be like ```go hash, version, err := s.tree.SaveVersion() ``` New Caller code would look like ```go oldVersion := s.Version() var version int64 var hash []byte //Every X versions we should persist to disk if s.flushInterval == 0 || ((oldVersion+1)%s.flushInterval == 0) { if s.flushInterval != 0 { log.Error(fmt.Sprintf("Flushing mem to disk at version %d\n", oldVersion+1)) hash, version, err = s.tree.FlushMemVersionDisk() } else { hash, version, err = s.tree.SaveVersion() } } else { hash, version, err = s.tree.SaveVersionMem() } ``` FlushMemVersionDisk: Flushes the current memory version to disk SaveVersionMem: Saves the current tree to memory instead of disk and gives you back an apphash. This is an opt in feature, you have to call new apis to get it. We also have a PR that demonstrates its usage https://github.com/loomnetwork/loomchain/pull/1232/files We are now committing every 1000 blocks, so we store 1000x less. Also we have significant improves in IO at least double from not having to Prune old versions of the IAVL Tree
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.