-
Notifications
You must be signed in to change notification settings - Fork 51
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!: Iterator Key()
and Value()
no longer return a copy
#168
Conversation
- returns the key itself, not a copy. - updated docs to reflect the change
- returns the key itself, not a copy. - updated docs to reflect the change
- returns the key itself, not a copy. - updated docs to reflect the change.
To reflect the changes, the tests now copy the iterator's key for further use
Unfortunately, I don't think we can avoid the copy in rocksdb In short, my understanding is that we need the copy of the key/value in order to free its memory allocated in the C library, thus avoiding possible memory leaks. |
- returns the value itself, not a copy - updated tests to reflect the change - updated docs to reflect the change
We can't avoid the copy in the func (item *Item) Value(fn func(val []byte) error) error
func (item *Item) ValueCopy(dst []byte) ([]byte, error) Note:
In both cases, the library returns as a copy of the original value; as far as I can tell, it offers no possibility of accessing the original value directly. |
- returns the value itself, not a copy - updated docs to reflect the change
Given the discussion above, addressing #168 makes the library behave inconsistently depending on the underlying database used. Namely, some databases require callers to make copies of key and value, while others do not. Consequently, users cannot switch between databases without first checking the behavior of their |
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 so far 👍
@@ -279,19 +279,22 @@ func (i *badgerDBIterator) Valid() bool { | |||
return true | |||
} | |||
|
|||
// Key implements Iterator. |
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.
// Key implements Iterator. |
I'd remove these comments.
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 would leave them, because I think they give readers some additional context about the functions.
Granted, in the context of this repo it's clear what the functions refer to.
Still, I would argue it doesn't hurt to leave extra-info in.
That's debatable because, in the |
I see your point.
therefore, users of the library know that they must create a copy, thus these changes shouldn't break anything. |
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.
👍
Key()
and Value()
no longer return a copy
Could you add a changelog entry? btw we're using https://github.com/informalsystems/unclog |
…s. (#3541) Related to cometbft/cometbft-db#168. #### Changes We recently updated cometbft-db `Iterator` type `Key()` and `Value()` APIs to return their values directly instead of a copy. Therefore, this PR ensures that code in cometbft that modifies or stores references to the return value of those APIs creates a copy before continuing. --- #### PR checklist ~- [ ] Tests written/updated~ - [x] Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog) - [x] Updated relevant documentation (`docs/` or `spec/`) and code comments - [x] Title follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec
…s. (#3541) Related to cometbft/cometbft-db#168. #### Changes We recently updated cometbft-db `Iterator` type `Key()` and `Value()` APIs to return their values directly instead of a copy. Therefore, this PR ensures that code in cometbft that modifies or stores references to the return value of those APIs creates a copy before continuing. --- #### PR checklist ~- [ ] Tests written/updated~ - [x] Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog) - [x] Updated relevant documentation (`docs/` or `spec/`) and code comments - [x] Title follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec (cherry picked from commit 3be35f0)
…s. (backport #3541) (#3598) Related to cometbft/cometbft-db#168. #### Changes We recently updated cometbft-db `Iterator` type `Key()` and `Value()` APIs to return their values directly instead of a copy. Therefore, this PR ensures that code in cometbft that modifies or stores references to the return value of those APIs creates a copy before continuing. --- #### PR checklist ~- [ ] Tests written/updated~ - [x] Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog) - [x] Updated relevant documentation (`docs/` or `spec/`) and code comments - [x] Title follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec <hr>This is an automatic backport of pull request #3541 done by [Mergify](https://mergify.com). Co-authored-by: Alessandro Sforzin <alessandro@informal.systems>
* Revert "remove deprecated boltdb and cleveldb (#155)" This reverts commit badc0b8. We decided to reinstate boltDB and clevelDB and mark them as deprecated until a future version of CometBFT in which we'll drop cometbft-db and support only 1 backend DB. * updated cleveldb Iterator API docs to conform to the changes made in #168 * updated go.mod * updated boltDB Iterator APIs to conform to the changes made in #168 * added changelog entry * Formatting Co-authored-by: Daniel <daniel.cason@informal.systems> * formatting to please the linter * added additional context in the docs of backend types constants --------- Co-authored-by: Daniel <daniel.cason@informal.systems>
Context
Closes #156.
Changes
The:
Iterator.Key()
API implementations of levelDB, badgerDB, and pebbleDB no longer return a copy of the key.Iterator.Value()
API implementations of levelDB and pebbleDB no longer return a copy of the value.Rather, as the updated docs reflect, the caller is responsible for creating a copy of the slice if they want to modify it.
See my further comments about rocksdb and badgerdb below.