-
Notifications
You must be signed in to change notification settings - Fork 132
mssmt: add new Copy method and InsertMany to optimize slightly #1467
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
Conversation
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
rootBranch := currentRoot.(*BranchNode) | |
rootBranch, ok := currentRoot.(*BranchNode) | |
if !ok { | |
return fmt.Errorf("expected currentRoot to be of type *BranchNode, got %T", currentRoot) | |
} |
Copilot uses AI. Check for mistakes.
Pull Request Test Coverage Report for Build 14483858596Details
💛 - Coveralls |
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.
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.
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.
LGTM 👍
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.
Lgtm!
pending this |
In this commit, we add a new
Copy
method that takes as an arg anothermssmt.Tree
and inserts all the keys+leaves from the target tree into the source tree. We then optimize a bit by adding anInsertMany
method that will callinsert
N 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.