-
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
feat: ADR 040: Implement in-memory DB backend #9952
Conversation
a80c49d
to
f189a95
Compare
9bdcfa2
to
15501e8
Compare
3867290
to
1358c4f
Compare
1358c4f
to
c8cd01d
Compare
redundant since dbWriter uses a clone
3638b40
to
e17792b
Compare
Now that the interface has been merged, this is good to review. This contains MemDB, unit tests, and supporting utilities, which logically fit together but make a large PR, so let me know if it would be better to break the code down further. |
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.
Changes mainly LGTM, great work. Left some small remarks 👍
func (db *MemDB) Versions() (dbm.VersionSet, error) { | ||
db.mtx.RLock() | ||
defer db.mtx.RUnlock() | ||
return db.vmgr, nil |
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.
do we not want to return a copy of the map?
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 seems we already have a Copy
method too.
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 opted to make this copy-on-write. Versions
is called whenever version history is queried, and if the history becomes large, it could be expensive. So a vmgr
is just copied over whenever versions are saved/deleted, and the caller can safely keep the old reference.
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.
vmgr
is a pointer, so we don't make any object copy here
return &vmIterator{ch: ch} | ||
} | ||
|
||
// Count implements VersionSet. |
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.
If this type implements an interface, we don't need to add godocs for the sake of adding godocs 👍
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.
Fine with me, I was just following the existing practice
db/memdb/iterator.go
Outdated
|
||
// Error implements Iterator. | ||
func (i *memDBIterator) Error() error { | ||
return nil // famous last words |
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.
lol, any reason not to track an error? Or can one never happen?
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.
Yeah, there's no error case for this iterator - it's only invalidated when it reaches its end.
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.
ACK. Let's remove // famous last words
then
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.
haha sure, that was from the tm-db code.
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
Codecov Report
@@ Coverage Diff @@
## master #9952 +/- ##
==========================================
+ Coverage 63.56% 63.80% +0.24%
==========================================
Files 572 566 -6
Lines 53584 53363 -221
==========================================
- Hits 34058 34047 -11
+ Misses 17583 17397 -186
+ Partials 1943 1919 -24
|
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.
@robert-zaremba want to review this so we can merge?
Let's give @robert-zaremba a day to review. Is that okay? |
haha, more than one day is fine as well. It was mainly a ping, not a "needs to be done now" |
@roysc once the PR is updated to master the bot will merge it |
Visit https://dashboard.github.orijtech.com?back=0&pr=9952&remote=false&repo=cosmos%2Fcosmos-sdk to see benchmark details. |
Surprisingly the code from this change is failing tests locally $ go test
# github.com/cosmos/cosmos-sdk/db/memdb [github.com/cosmos/cosmos-sdk/db/memdb.test]
./db.go:44:23: incompatible type: cannot use (*MemDB)(nil) (value of type *MemDB) as db.DBConnection value
./db_test.go:32:9: incompatible type: cannot use NewDB() (value of type *MemDB) as db.DBConnection value
FAIL github.com/cosmos/cosmos-sdk/db/memdb [build failed] |
Description
Implements an in-memory backend for the DB interface introduced by #9573 and specified by ADR-040. This expands on the btree-based
MemDB
fromtm-db
by using copy-on-write clones to implement versioning.Resolves: vulcanize#2
Will move out of draft once #9573 is merged and rebased on.
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
to the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...
!
in the type prefix if API or client breaking change