-
Notifications
You must be signed in to change notification settings - Fork 125
feat(db): add pebbledb support to 'improvements' branch #2150
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
Codecov ReportAttention: Patch coverage is
☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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 8 out of 8 changed files in this pull request and generated 1 comment.
is it possible to separate the implementations to two different packages?
this is a common practice in Go: one package for the interfaces, and one package for each implementation also this should leave storage/kv package untouched (just renamed) which is easier to review |
config/config.example.yaml
Outdated
# Type is the database type, currently only badger and pebble are supported | ||
Engine: badger |
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.
lets pls hide this from examples & docs until we test it properly with operator nodes (in the future)
for now its for exporter only and we dont want operators to play with it yet :)
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.
shouldn't we make pebble work only with exporter for now 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.
removed
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.
MO this is not fully resolved, if we really never want to see a case where someone 'accidentally' uses pebble for an operator node, we should restrict it and not just not mention it.
wdyt? @anatolie-ssv @moshe-blox @MatusKysel
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.
MO this is not fully resolved, if we really never want to see a case where someone 'accidentally' uses pebble for an operator node, we should restrict it and not just not mention it.
just as counter-argument:
- typically using "undocumented" feature is considered "at your own risk" (and it's gonna be an intentional usage because it's impossible to set pebble here instead of badger "by accident")
- does anything prevent operator from forking the code-base and removing any constraining check we might add if they really want to try it out ?
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.
Some suggestions
"github.com/ssvlabs/ssv/storage/basedb" | ||
) | ||
|
||
// TODO: reconsider prefixes? |
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.
What about this TODO, could you expand it a bit if we are gonna merge it (I can only really guess what it means) ?
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.
this TODO (and all the following comments and TODOs) are from the original PR from @y0sher and I'm afraid I don't know their context; I left them intact so we could tackle them when Yosher gets around to review this PR; @y0sher please, what did you mean by 'reconsider prefixes' here? is is safe to be removed or does it require any action?
storage/pebble/pebble.go
Outdated
batch := pdb.db.NewIndexedBatch() | ||
txn := newPebbleTxn(batch, pdb) | ||
if err := fn(txn); err != nil { | ||
return err | ||
} | ||
return batch.Commit(pebble.Sync) |
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.
This looks a bit unnecessarily hard to read to me, can't we refactor it into something like this (by rearranging some code a bit) ?
func (pdb *PebbleDB) SetMany(prefix []byte, n int, next func(int) (basedb.Obj, error)) error {
txn := pdb.NewTxn()
if err := txn.SetMany(prefix, n, next); err != nil {
return err
}
return txn.Commit()
}
I guess this applies to other methods as well.
storage/pebble/txn.go
Outdated
if err := closer.Close(); err != nil { | ||
return err | ||
} |
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 here in GetMany
we propagate error up the stack from closer.Close()
while in Get
we skip such an error ... shouldn't we handle both cases the same way (probably propagate errors) ?
storage/pebble/txn.go
Outdated
|
||
defer func() { _ = iter.Close() }() | ||
i := 0 | ||
// SeekPrefixGE starts prefix iteration mode. |
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 this comment:
- either should have more info in it (on what it's about)
- or shouldn't be here since it is an implementation detail this code doesn't care about
note, there are 2 places with this comment
return err | ||
} | ||
|
||
defer func() { _ = iter.Close() }() |
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 return an error if this failed to close (it might do more than just closed in some cases)
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 errors returned from the .Close()
method are the same as the errors returned from the iter.Error()
at the end of the function, so we're not ignoring them.
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 errors returned from the .Close() method are the same as the errors returned from the iter.Error() at the end of the function, so we're not ignoring them.
It might be better to not rely on implementation details like that (even if they "promise in a comment" that's how it works - they might change implementation and we won't even know about it)
but also it seems we could always use .Close()
(and handle error returned) every time instead of using iter.Error()
(do we ever need iter.Error()
specifically) ?
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 only reason I defer the call to Close()
is because - if a panic happens in the callback function - the defer statement will be executed regardless, but if we return Close()
instead of iter.Error()
that would lead to a leak.
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.
We could keep using defer
if we want and handle error from Close
in there ...
but I wouldn't do that - it's a bit bulky and IMO unnecessary since panic
in callback function would mean we have a bug in the code that needs to be addressed ASAP, I imagine not calling Close
in this case is of smaller importance
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 the conclusion of this article got stuck with me too much and that's why I went by the route of deferring Close
statements here.
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 defer
is a very nice thing to have/use - I don't mind it,
although here it seems to me panic
is unlikely to happen without us noticing it during testing of the code involved
@CodiumAI-Agent /review |
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.
Pull Request Overview
This PR adds support for PebbleDB alongside Badger by updating the database initialization and configuration. The changes include updating import references in tests, modifying CLI node startup to select the database engine based on configuration, and updating error wrap messages for consistency.
Reviewed Changes
Copilot reviewed 37 out of 37 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
protocol/v2/qbft/testing/storage.go | Updated storage import from kv to badger in testing. |
operator/validator/controller_test.go | Updated storage import from kv to badger in tests. |
operator/storage/storage_test.go | Updated storage import from kv to badger in tests. |
operator/fee_recipient/controller_test.go | Updated storage import from kv to badger in tests. |
network/topics/msg_validator_test.go | Updated storage import from kv to badger in tests. |
network/topics/controller_test.go | Updated storage import from kv to badger in tests. |
network/p2p/test_utils.go | Updated storage import from kv to badger in tests. |
migrations/migrations_test.go | Updated storage import from kv to badger in tests. |
message/validation/validation_test.go | Updated storage import from kv to badger in tests. |
identity/store_test.go | Updated storage import from kv to badger in tests. |
ibft/storage/store_test.go | Updated storage import from kv to badger in tests. |
exporter/api/query_handlers_test.go | Updated storage import from kv to badger in tests. |
eth/eventsyncer/event_syncer_test.go | Updated storage import from kv to badger in tests. |
eth/eventhandler/validation_test.go | Updated storage import from kv to badger in tests. |
eth/eventhandler/event_handler_test.go | Updated storage import from kv to badger in tests. |
eth/ethtest/utils_test.go | Updated storage import from kv to badger in tests. |
e2e/cmd/ssv-e2e/share_update.go | Updated storage import from kv to badger in tests. |
config/config.exporter.example.yaml | Updated config to set Engine to pebble. |
cli/operator/node_test.go | Updated storage import from kv to badger in tests. |
cli/operator/node.go | Added engine switch support for PebbleDB and BadgerDB. |
Comments suppressed due to low confidence (2)
cli/operator/node.go:145
- Consider adding tests that validate both 'pebble' and 'badger' database initializations to ensure the engine switching works as expected under different configurations.
switch cfg.DBOptions.Engine {
cli/operator/node.go:773
- [nitpick] Consider documenting the rationale for appending '-pebble' to the database path or providing a configuration option for the suffix to improve clarity and maintainability.
dbPath := cfg.DBOptions.Path + "-pebble" // opinionated approach to avoid corrupting old db location
@CodiumAI-Agent /describe |
Titlefeat(db): add pebbledb support User descriptionPut pebbledb support on top of deployed to stage exporter-2: https://grafana.ops.ssvlabsinternal.com/goto/VxWc2GJHR?orgId=1 deployed to:
PR TypeEnhancement, Tests Description
Changes walkthrough 📝
|
@CodiumAI-Agent /review |
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
@CodiumAI-Agent /improve |
PR Code Suggestions ✨Latest suggestions up to db508dd
Previous suggestionsSuggestions up to commit 452e686
|
Put pebbledb support on top of
v2.2.1-unstable.2
changesetdeployed to stage exporter-2: https://grafana.ops.ssvlabsinternal.com/goto/VxWc2GJHR?orgId=1
deployed to: