-
Notifications
You must be signed in to change notification settings - Fork 124
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
feat/btree: add BTree with scale #3536
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## development #3536 +/- ##
===============================================
+ Coverage 50.18% 50.21% +0.02%
===============================================
Files 229 230 +1
Lines 28595 28692 +97
===============================================
+ Hits 14350 14407 +57
- Misses 12721 12748 +27
- Partials 1524 1537 +13 |
cc3e5f1
to
21ff6ca
Compare
21ff6ca
to
295fe8e
Compare
295fe8e
to
144cdd2
Compare
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.
I'm concerned about adding dependency on "github.com/tidwall/btree" to scale package, I think they is a way to define scale encoding/decoding outside of the scale package.
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.
I'm curious as to where we need the btree.BTree
? We utilize btree.Map
pretty extensively in feat/grandpa
.
Have you seen #3314? |
I looked into moving Could you elaborate on your concerns? |
a30e11c
to
5a60b6f
Compare
23b27bc
to
004d7a9
Compare
7fe033a
to
2a0db41
Compare
2a0db41
to
73f923f
Compare
It's just that this is the first time (that I'm aware of) that we've added outside packages to the scale package, so that piqued my curiosity. I was more curious than concerned and now I have a better understanding. |
@kanishkatn Could you please elaborate more on this? While I see that you use the |
Here's another one: #3344. It has a custom encoding right now; I might look into changing it once I implement pebbleDB. I hope that helps! |
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, just have some questions and nits
I am going to change the primary reviewer of this PR to @timwu20. Given that Tim is the author of this package and has the most knowledge of it I would like to double-check with him before merging this in. |
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.
I think we should take a different approach to supporting the tidwall/btree
package. I propose implementing custom unmarshalling/marshalling support in pkg/scale
(#3558) first, and then creating a thin wrapper around the tidwall/btree
package that implements the Unmarshaller
and Marshaller
interfaces for the types that we need. We should make it clear that we're just doing this to support SCALE for the btree
types. This should also reduce the changes required within scale
to support the btree
types.
I've updated this to use the changes from #3617 |
2113d6c
to
5615c8a
Compare
type Map[K constraints.Ordered, V any] struct { | ||
*btree.Map[K, V] | ||
Degree int | ||
} |
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.
Why do we need to hold *btree.Map
in a struct with the Degree
? I was expecting this Map
to just be btree.Map
which reflects the same interface with the added MarshalSCALE
and UnmarshalSCALE
methods. I took a stab at what I was expecting in this branch.
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.
It is so that the user can set the degree beforehand and not worry about filtering the data after unmarshal.
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.
Let me rephrase. It gives the option for the user to set the Degree. One usecase that I see it supporting is, if there are 100 entries in the db and I care about only top 10, I can set that during the creation.
The usecase leads to lesser memory usage.
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.
But yeah, I guess I don't need to store it.
I'm not familiar with your implementation style, feels like a lot of repetitive code.
// at the time of decoding. | ||
type Tree struct { | ||
*btree.BTree | ||
Comparator func(a, b interface{}) bool |
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.
Not sure why you need this attribute given it's not used in any of the MarshalSCALE
or UnmarshalSCALE
methods.
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.
Please find the follow up questions below to get a better understanding.
Do you mean the comparator? Is the comment not descriptive enough?
Changes
Adds BTree with scale encoding and decoding apis by creating a wrapper around the tidwall's library.
Tests
go test pkg/scale
Issues
Closes #3480
Primary Reviewer
@timwu20