Skip to content

Conversation

@achow101
Copy link
Member

Instead of returning a Dbc (BDB cursor object) and having the caller deal with the cursor, make BerkeleyBatch handle the cursor internally.

Split from #18971

@DrahtBot
Copy link
Contributor

DrahtBot commented Jun 17, 2020

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

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.

@laanwj
Copy link
Member

laanwj commented Jun 18, 2020

This does limit flexibility a bit, though I guess one cursor at a time is enough for all our current and future use cases.

@achow101 achow101 force-pushed the bdb-internal-cursor branch from 40d31e3 to cda8654 Compare June 18, 2020 14:57
@achow101
Copy link
Member Author

This does limit flexibility a bit, though I guess one cursor at a time is enough for all our current and future use cases.

If another cursor was needed, you could use another Batch object. But we barely use cursors, so one is enough for now.

@laanwj
Copy link
Member

laanwj commented Jun 18, 2020

If another cursor was needed, you could use another Batch object. But we barely use cursors, so one is enough for now.

Ohh! I missed that it's on the batch, not on the database object.

Copy link
Contributor

@ryanofsky ryanofsky 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 cda86544ae9de430e4558b87945046d5612202ac. Nice to make cursor usage safer & more generic, even if it's a slightly less flexible than before (limited to single cursor per batch). I left minor style suggestion below, but feel free to ignore

Copy link
Contributor

@promag promag 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.

Instead of returning a Dbc (BDB cursor object) and having the caller
deal with the cursor, make BerkeleyBatch handle the cursor internally.

This prepares BerkeleyBatch to work with other database systems as Dbc
objects are BDB specific.
@achow101 achow101 force-pushed the bdb-internal-cursor branch from cda8654 to ca24edf Compare June 22, 2020 19:43
bool BerkeleyBatch::ReadAtCursor(CDataStream& ssKey, CDataStream& ssValue, bool& complete)
{
complete = false;
if (m_cursor == nullptr) return false;
Copy link
Contributor

Choose a reason for hiding this comment

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

assert(m_cursor)? There was no check for pcursor.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think an assert is necessary.

Copy link
Contributor

Choose a reason for hiding this comment

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

If it's something that can't happen then an assertion is fine. Also, it means that StartCursor must be called before.

Copy link
Member Author

Choose a reason for hiding this comment

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

If I have to push again.



BerkeleyBatch::BerkeleyBatch(BerkeleyDatabase& database, const char* pszMode, bool fFlushOnCloseIn) : pdb(nullptr), activeTxn(nullptr)
BerkeleyBatch::BerkeleyBatch(BerkeleyDatabase& database, const char* pszMode, bool fFlushOnCloseIn) : pdb(nullptr), activeTxn(nullptr), m_cursor(nullptr)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit, move these to header.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm pretty sure that won't compile.

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean 04998ef.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah. Maybe if I have to push again.

Copy link
Contributor

@ryanofsky ryanofsky 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 ca24edf. Changes since last review: StartCursor rename, moving CloseCursor calls near returns

Copy link
Contributor

@promag promag 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 ca24edf.

bool BerkeleyBatch::ReadAtCursor(CDataStream& ssKey, CDataStream& ssValue, bool& complete)
{
complete = false;
if (m_cursor == nullptr) return false;
Copy link
Contributor

Choose a reason for hiding this comment

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

If it's something that can't happen then an assertion is fine. Also, it means that StartCursor must be called before.

@laanwj laanwj merged commit 2629174 into bitcoin:master Jul 1, 2020
maflcko pushed a commit that referenced this pull request Jul 14, 2020
…Batch abstract class

b82f0ca walletdb: Add MakeBatch function to BerkeleyDatabase and use it (Andrew Chow)
eac9200 walletdb: Refactor DatabaseBatch abstract class from BerkeleyBatch (Andrew Chow)

Pull request description:

  In order to support alternative database systems, we need to have a generic `Batch` class. This PR adds a `DatabaseBatch` abstract class which is implemented by `BerkeleyBatch`. `DatabaseBatch` is now the class that is used by `WalletBatch` to interact with the database. To be able to get the correct type of `DatabaseBatch`, `BerkeleyDatabase` now has a `MakeBatch` function which returns a newly constructed `std::unique_ptr<DatabaseBatch>`. For `BerkeleyDatabase`, that will be `std::unique_ptr<BerkeleyBatch>`.

  The `Read`, `Write`, `Erase`, and `Exists` template functions are moved from `BerkeleyBatch`.

  Part of #18971

  Requires #19308 and #19324

ACKs for top commit:
  Sjors:
    re-utACK b82f0ca
  MarcoFalke:
    ACK b82f0ca 🌘
  meshcollider:
    LGTM, utACK b82f0ca

Tree-SHA512: 6d2d41631c0983391dbecd702e881c6775b155c90b275df97f7157e42608ed251744f9d7ce5173d02a6c5cc38d90b611880fac7fa635d3d8c4d590681f56ac6a
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jul 14, 2020
…atabaseBatch abstract class

b82f0ca walletdb: Add MakeBatch function to BerkeleyDatabase and use it (Andrew Chow)
eac9200 walletdb: Refactor DatabaseBatch abstract class from BerkeleyBatch (Andrew Chow)

Pull request description:

  In order to support alternative database systems, we need to have a generic `Batch` class. This PR adds a `DatabaseBatch` abstract class which is implemented by `BerkeleyBatch`. `DatabaseBatch` is now the class that is used by `WalletBatch` to interact with the database. To be able to get the correct type of `DatabaseBatch`, `BerkeleyDatabase` now has a `MakeBatch` function which returns a newly constructed `std::unique_ptr<DatabaseBatch>`. For `BerkeleyDatabase`, that will be `std::unique_ptr<BerkeleyBatch>`.

  The `Read`, `Write`, `Erase`, and `Exists` template functions are moved from `BerkeleyBatch`.

  Part of bitcoin#18971

  Requires bitcoin#19308 and bitcoin#19324

ACKs for top commit:
  Sjors:
    re-utACK b82f0ca
  MarcoFalke:
    ACK b82f0ca 🌘
  meshcollider:
    LGTM, utACK b82f0ca

Tree-SHA512: 6d2d41631c0983391dbecd702e881c6775b155c90b275df97f7157e42608ed251744f9d7ce5173d02a6c5cc38d90b611880fac7fa635d3d8c4d590681f56ac6a
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Aug 30, 2021
Summary:
Instead of returning a Dbc (BDB cursor object) and having the caller
deal with the cursor, make BerkeleyBatch handle the cursor internally.

This prepares BerkeleyBatch to work with other database systems as Dbc
objects are BDB specific.

This is a backport of [[bitcoin/bitcoin#19308 | core#19308]]

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Subscribers: majcosta

Differential Revision: https://reviews.bitcoinabc.org/D9969
kwvg added a commit to kwvg/dash that referenced this pull request Mar 6, 2022
malbit added a commit to malbit/raptoreum that referenced this pull request Aug 7, 2022
refs: [bitcoin#19290](bitcoin/bitcoin#19290) - Move BDB specific things into bdb.{cpp/h}
refs: [bitcoin#19292](bitcoin/bitcoin#19292) - refactor Read, Write, Erase, and Exists into non-template functions
refs: [bitcoin#19308](bitcoin/bitcoin#19308) - BerkeleyBatch Handle cursor internally
refs: [bitcoin#19324](bitcoin/bitcoin#19324) - Move BerkeleyBatch static functions to BerkeleyDatabase
refs: [bitcoin#19320](bitcoin/bitcoin#19320) - Replace CDataStream& with CDataStream&& where appropriate
refs: [bitcoin#19325](bitcoin/bitcoin#19325) - Refactor BerkeleyDatabase to introduce DatabaseBatch abstract class
refs: [bitcoin#19334](bitcoin/bitcoin#19334) - Introduce WalletDatabase abstract class
refs: [bitcoin#19102](bitcoin/bitcoin#19102) - Introduce and use DummyDatabase instead of dummy BerkeleyDatabase
refs: [bitcoin#19085](bitcoin/bitcoin#19085) - clean-up PeriodicFlush()
refs: [bitcoin#18923](bitcoin/bitcoin#18923) - Never schedule MaybeCompactWalletDB when -flushwallet is off
refs: [bitcoin#19335](bitcoin/bitcoin#19335) - Cleanup and separate BerkeleyDatabase and BerkeleyBatch
drop salvage wallet from UI
remove BDB version from Information Tab
refs: [bitcoin#19671](bitcoin/bitcoin#19671) - Remove -zapwallettxes
refs: [bitcoin#19261](bitcoin/bitcoin#19261) - Drop ::HasWallets()
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants