-
Notifications
You must be signed in to change notification settings - Fork 77
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
storage: add support of BadgerDB #839
Conversation
bac693d
to
db147ba
Compare
|
||
// BadgerDBOptions configuration for BadgerDB. | ||
type BadgerDBOptions struct { | ||
Dir string `yaml:"BadgerDir"` |
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.
Maybe we should use the same DataDirectoryPath
as LevelDB here?
pkg/core/storage/badgerdb_store.go
Outdated
// Batch implements the Batch interface and returns a badgerdb | ||
// compatible Batch. | ||
func (b *BadgerDBStore) Batch() Batch { | ||
return newMemoryBatch() |
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 expected to see db.NewWriteBatch()
here or some wrapper around that.
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.
Or are you not using to avoid Set
and Delete
error processing?
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.
Just didn't realized that it's possible. Fixed with wrapper around db.NewWriteBatch()
.
config/protocol.mainnet.yml
Outdated
@@ -50,6 +50,8 @@ ApplicationConfiguration: | |||
# DB: 0 | |||
# BoltDBOptions: | |||
# FilePath: "./chains/mainnet.bolt" | |||
# BadgerDbOptions: |
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.
Everywhere in code and in other options it is DB
, not Db
.
config/protocol.mainnet.yml
Outdated
@@ -50,6 +50,8 @@ ApplicationConfiguration: | |||
# DB: 0 | |||
# BoltDBOptions: | |||
# FilePath: "./chains/mainnet.bolt" | |||
# BadgerDbOptions: | |||
# BadgerDir: "./chains/mainnet" |
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.
May we change this to ./chains/mainnet.badger
like how it was done with bolt? This allows to test multiple backends simultaneously and diminish chances of unintentionally corrupting something.
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.
Bolt is a bit different in that it's a file, although I'm not sure how LevelDB would react on Badger data and vice versa, they should probably just fail to start correctly. But then again your proposal is probably a safer choice.
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.
Checked it: Badger needs a folder, not just a file. In case of ./chains/privnet.badger
it creates folder privnet.badger
and puts all data into that folder. So, which path should we use?
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's use ${NET}.badger
.
pkg/core/storage/badgerdb_store.go
Outdated
// Seek implements the Store interface. | ||
func (b *BadgerDBStore) Seek(key []byte, f func(k, v []byte)) { | ||
err := b.db.View(func(txn *badger.Txn) error { | ||
it := txn.NewIterator(badger.DefaultIteratorOptions) |
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.
IteratorOptions
has Prefix
field. Doesn't it do what we need?
https://pkg.go.dev/github.com/dgraph-io/badger?tab=doc#IteratorOptions
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 quite, so we can't get reed of it.Seek(key)
here. See https://github.com/dgraph-io/badger#prefix-scans
7f5fde3
to
1d4af7c
Compare
Codecov Report
@@ Coverage Diff @@
## master #839 +/- ##
==========================================
+ Coverage 67.13% 67.20% +0.06%
==========================================
Files 141 142 +1
Lines 13351 13422 +71
==========================================
+ Hits 8963 9020 +57
- Misses 3982 3990 +8
- Partials 406 412 +6
Continue to review full report at Codecov.
|
7cbd855
to
a60c67d
Compare
a60c67d
to
54cdfe4
Compare
closes #820