Skip to content

Conversation

achow101
Copy link
Member

Instead of having database cursors be tied to a particular DatabaseBatch object and requiring its setup and teardown be separate functions in that batch, we can have cursors be separate RAII classes. This makes it easier to create and destroy cursors as well as having cursors that have slightly different behaviors.

Additionally, since reading data from a cursor is a tri-state, this PR changes the return value of the Next function (formerly ReadAtCursor) to return an Enum rather than the current system of 2 booleans. This greatly simplifies and unifies the code that deals with cursors as now there is no confusion as to what the function returns when there are no records left to be read.

Extracted from #24914

@DrahtBot
Copy link
Contributor

DrahtBot commented Dec 12, 2022

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK furszy, theStack

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #26715 (Introduce MockableDatabase for wallet unit tests by achow101)
  • #26705 (clang-tidy: Check headers and fixes them by hebasto)
  • #26644 (wallet: bugfix, 'wallet_load_ckey' unit test fails with bdb by furszy)
  • #25722 (refactor: Use util::Result class for wallet loading by ryanofsky)
  • #25296 (Add DataStream without ser-type and ser-version and use it where possible by MarcoFalke)
  • #24914 (wallet: Load database records in a particular order by achow101)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

Copy link
Contributor

@theStack theStack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK

@achow101 achow101 force-pushed the walletdb-cursor-unstupidfy branch from 576c8fb to 115b3ab Compare December 13, 2022 23:33
Instead of having DatabaseBatch deal with opening and closing database
cursors, have a separate RAII class that deals with those.

For now, DatabaseBatch manages DatabaseCursor, but this will change
later.
@achow101 achow101 force-pushed the walletdb-cursor-unstupidfy branch from 115b3ab to bfef559 Compare December 14, 2022 17:41
Copy link
Member

@furszy furszy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review ACK bfef559 (follow-up to the reviews made to #24914)
Only few non-blocking nits.

achow101 and others added 2 commits December 16, 2022 12:35
Instead of having the DatabaseBatch manage the cursor, having the
consumer handle it directly
Next()'s result is a tri-state - failed, more to go, complete. Replace
the way that this is returned with an enum with values FAIL, MORE, and
DONE rather than with two booleans.
Copy link
Member

@furszy furszy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diff ACK 4aebd83

Copy link
Contributor

@theStack theStack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code-review ACK 4aebd83

{
sqlite3_reset(m_cursor_stmt);
m_cursor_init = false;
int res = sqlite3_finalize(m_cursor_stmt);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

L496: Why is it necessary to reset the cursor before sqlite3_finalize is called?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It probably isn't necessary, but also is not harmful.

@fanquake fanquake merged commit a62231b into bitcoin:master Jan 23, 2023
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jan 24, 2023
…ject with proper return codes

4aebd83 db: Change DatabaseCursor::Next to return status enum (Andrew Chow)
d79e8dc wallet: Have cursor users use DatabaseCursor directly (Andrew Chow)
7a198bb wallet: Introduce DatabaseCursor RAII class for managing cursor (Andrew Chow)
69efbc0 Move SafeDbt out of BerkeleyBatch (Andrew Chow)

Pull request description:

  Instead of having database cursors be tied to a particular `DatabaseBatch` object and requiring its setup and teardown be separate functions in that batch, we can have cursors be separate RAII classes. This makes it easier to create and destroy cursors as well as having cursors that have slightly different behaviors.

  Additionally, since reading data from a cursor is a tri-state, this PR changes the return value of the `Next` function (formerly `ReadAtCursor`) to return an Enum rather than the current system of 2 booleans. This greatly simplifies and unifies the code that deals with cursors as now there is no confusion as to what the function returns when there are no records left to be read.

  Extracted from bitcoin#24914

ACKs for top commit:
  furszy:
    diff ACK 4aebd83
  theStack:
    Code-review ACK 4aebd83

Tree-SHA512: 5d0be56a18de5b08c777dd5a73ba5a6ef1e696fdb07d1dca952a88ded07887b7c5c04342f9a76feb2f6fe24a45dc31f094f1f5d9500e6bdf4a44f4edb66dcaa1
@bitcoin bitcoin locked and limited conversation to collaborators Jan 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

6 participants