mssmt: add new Copy method and InsertMany to optimize slightly #1467
Merged
Roasbeef merged 2 commits intolightninglabs:mainfrom Apr 22, 2025
Merged
mssmt: add new Copy method and InsertMany to optimize slightly #1467Roasbeef merged 2 commits intolightninglabs:mainfrom
Roasbeef merged 2 commits intolightninglabs:mainfrom
Conversation
There was a problem hiding this comment.
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
mssmt/tree.go:450
- The type assertion to *BranchNode may panic if the underlying type is not as expected. Consider checking the type before casting to ensure safe failure handling.
rootBranch := currentRoot.(*BranchNode)
| if err != nil { | ||
| return err | ||
| } | ||
| rootBranch := currentRoot.(*BranchNode) |
There was a problem hiding this comment.
The direct type assertion of currentRoot to *BranchNode can lead to a runtime panic if the type is not correct. It is recommended to perform a type check to handle unexpected types gracefully.
Suggested change
| rootBranch := currentRoot.(*BranchNode) | |
| rootBranch, ok := currentRoot.(*BranchNode) | |
| if !ok { | |
| return fmt.Errorf("expected currentRoot to be of type *BranchNode, got %T", currentRoot) | |
| } |
Pull Request Test Coverage Report for Build 14483858596Details
💛 - Coveralls |
ffranr
reviewed
Apr 15, 2025
Collaborator
ffranr
left a comment
There was a problem hiding this comment.
Looks good to me!
Some of the comments are missing punctuation, but no big deal.
This commit introduces a new `Copy` method to both the `FullTree` and `CompactedTree` implementations of the MS-SMT. This method allows copying all key-value pairs from a source tree to a target tree, assuming the target tree is initially empty. The `Copy` method is implemented differently for each tree type: - For `FullTree`, the method recursively traverses the tree, collecting all non-empty leaf nodes along with their keys. It then inserts these leaves into the target tree. - For `CompactedTree`, the method similarly traverses the tree, collecting all non-empty compacted leaf nodes along with their keys. It then inserts these leaves into the target tree. A new test case, `TestTreeCopy`, is added to verify the correctness of the `Copy` method for both tree types, including copying between different tree types (FullTree to CompactedTree and vice versa). The test case generates a set of random leaves, inserts them into a source tree, copies the source tree to a target tree, and then verifies that the target tree contains the same leaves as the source tree.
This commit introduces the InsertMany method to both the FullTree and CompactedTree implementations of the MS-SMT. This method allows for the insertion of multiple leaf nodes in a single database transaction, improving efficiency when adding multiple leaves at once. The InsertMany method is added to the Tree interface and implemented in both FullTree and CompactedTree. The implementation includes sum overflow checks before each insertion and updates the root within the transaction for consistency. A new test case, TestInsertMany, is added to verify the functionality of the InsertMany method in both FullTree and CompactedTree. The test inserts a random set of leaves using InsertMany and verifies the resulting root and retrieved leaves. The Copy method in both FullTree and CompactedTree is updated to use InsertMany for efficiency when copying leaves to the target tree.
Member
|
pending this |
This file contains hidden or 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
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.
In this commit, we add a new
Copymethod that takes as an arg anothermssmt.Treeand inserts all the keys+leaves from the target tree into the source tree. We then optimize a bit by adding anInsertManymethod that will callinsertN times in the sameTreeStoreUpdateTx. This doesn't yet implement any fancy optimizations to ensure the root is only updated once as #1347 does.This was spun off a work unit related to #1464.