Skip to content
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

wallet: Refactor BerkeleyDatabase to introduce DatabaseBatch abstract class #19325

Merged
merged 2 commits into from Jul 14, 2020

Conversation

achow101
Copy link
Member

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

@DrahtBot
Copy link
Contributor

DrahtBot commented Jun 19, 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.

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 de11059 just last two commits:

  • 6faecdf walletdb: Refactor DatabaseBatch abstract class from BerkeleyBatch (5/6)
  • de11059 walletdb: Add MakeBatch function to BerkeleyDatabase and use it (6/6)

Copy link
Member

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

I've also reviewed base branches, those could be closed and just merge this one.

@@ -161,6 +163,9 @@ class BerkeleyDatabase
/** Database pointer. This is initialized lazily and reset during flushes, so it can be null. */
std::unique_ptr<Db> m_db;

/** Make a BerkeleyBatch connected to this database */
std::unique_ptr<BerkeleyBatch> MakeBatch(const char* mode, bool flush_on_close);
Copy link
Member

@promag promag Jun 24, 2020

Choose a reason for hiding this comment

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

de11059

I was expecting std::unique_ptr<DatabaseBatch> here - I suppose a future refactor will make BerkeleyDatabase extends WalletDatabase and this method will be virtual?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes

Copy link
Member

@Sjors Sjors Jul 6, 2020

Choose a reason for hiding this comment

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

Probably wouldn't hurt to do that in this PR. (neh, doing it while adding WalletDatabase in #19334 makes sense)

@Sjors
Copy link
Member

Sjors commented Jul 6, 2020

utACK aec646b

Instead of having WalletBatch construct the BerkeleyBatch, have
BerkeleyDatabase do it and return a std::unique_ptr<BerkeleyBatch>
@Sjors
Copy link
Member

Sjors commented Jul 9, 2020

re-utACK b82f0ca

Rebased after #19320; fortunately the (modified) Read, Write, Erase, Exists function bodies are just moved in the PR: git show --color-moved=dimmed-zebra -w HEAD~1.

PR description still refers to Part of #18971

@laanwj laanwj added this to Blockers in High-priority for review Jul 9, 2020
Copy link
Contributor

@meshcollider meshcollider left a comment

Choose a reason for hiding this comment

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

LGTM, utACK b82f0ca

@maflcko
Copy link
Member

maflcko commented Jul 14, 2020

ACK b82f0ca 🌘

Show signature and timestamp

Signature:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

ACK b82f0ca4d5465b36debb6c57f335bdccf4899c49 🌘
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUgGFAwAtbreGSqXICH7l9/SP2t43FqVfnwT5lC+uUMgFTy4p8sh+XuFXUgAUmPV
cIVlpqQW7E3lWT8C5B3ZVswgLoFgU0zkXDqXwpdCwZ9PezT5VY/N3d1CIbVVALtf
CwFCbpyp5tyBgFMBC4FwV5vytzIEI7eWRcA385AB8REpjEIdiEGSpUECW3kfeOMW
w23KAobzvKS2SkqQ8/eYPjr21tkIpLpGmQiID2fgev+iUQKNviqXM9b91SwPbjas
oOdmeDCaPpx+FT84hN/r7PvbElNKuSZoNx2oK+8ueCOje8rVOOH2ZMk8mWMoYMSa
LYSRig5Xub085+K8mS4tMhR1jxP+NVZSQ0oZ9aYiGIh9fZvGZjVKhQnENUyHx54N
Wtj6DT+JwtO/GyrTYfpQBRCbWLedvJ4A5uZPxDClyzXrkXOp54VyhFETsflelpUY
pzhFLfx6hz4geRt921L/B6G0c0VvHf3L0W/uNp09pQU+2YEZRR/lUDZYPoJCYZMI
Z3gKGlpL
=8mPD
-----END PGP SIGNATURE-----

Timestamp of file with hash 86e644d67a78b1c1183ee7ddb877245bbc0cc267cb631437d4367e93677e2879 -

@maflcko maflcko removed this from Blockers in High-priority for review Jul 14, 2020
@maflcko maflcko merged commit a924f61 into bitcoin:master Jul 14, 2020
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
maflcko pushed a commit that referenced this pull request Jul 17, 2020
0cdf2a7 ci: add tsan debug symbols option (Russell Yanofsky)
9a2f126 ci: Add tsan suppression for race in DatabaseBatch (Hennadii Stepanov)

Pull request description:

  Since #19325 was merged, the corresponding change in TSan suppression file gets required.

  This PR is:
  - an analogous to #19226 and #19450, and
  - a temporary workaround for CI fail like https://cirrus-ci.com/task/5741795508224000?command=ci#L4993

ACKs for top commit:
  MarcoFalke:
    ACK 0cdf2a7

Tree-SHA512: 7832f143887c8a0df99dea03e00694621710378fbe923e3592185fcd3658546a590693b513abffc5ab96e9ef76c9c4bff3330eeee69a0c5dbe7574f34c417220
@meshcollider meshcollider moved this from PRs to Done in Sqlite wallets Jul 17, 2020
meshcollider added a commit that referenced this pull request Jul 23, 2020
d416ae5 walletdb: Introduce WalletDatabase abstract class (Andrew Chow)
2179dbc walletdb: Add BerkeleyDatabase::Open dummy function (Andrew Chow)
71d28e7 walletdb: Introduce AddRef and RemoveRef functions (Andrew Chow)
27b2766 walletdb: Move BerkeleyDatabase::Flush(true) to Close() (Andrew Chow)

Pull request description:

  A `WalletDatabase` abstract class is created from `BerkeleyDatabase` and is implemented by `BerkeleyDatabase`. First, to get to the point that this is possible, 4 functions need to be added to `BerkeleyDatabase`: `AddRef`, `RemoveRef`, `Open`, and `Close`.

  First the increment and decrement of `mapFileUseCount` is refactored into separate functions `AddRef` and `RemoveRef`.

  `Open` is introduced as a dummy function. This will raise an exception so that it always fails.

  `Close` is refactored from `Flush`. The `shutdown` argument in `Flush` is removed and instead `Flush(true)` is now the `Close` function.

  Split from #18971

  Requires #19325

ACKs for top commit:
  ryanofsky:
    Code review ACK d416ae5. Only changes since last review were rebasing after base PR #19334 merge, and adding cs_db lock in BerkeleyDatabase destructor, which should avoid races accessing env->m_databases and env->m_fileids
  fjahr:
    Code review ACK d416ae5
  meshcollider:
    Code review & test run ACK d416ae5

Tree-SHA512: 98d05ec093d7446c4488e2b0914584222a331e9a2f4d5be6af98e3f6d78fdd8e75526c12f91a8a52d4820c25bce02aa02aabe92d38bee7eb2fce07d0691b7b0d
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jul 24, 2020
d416ae5 walletdb: Introduce WalletDatabase abstract class (Andrew Chow)
2179dbc walletdb: Add BerkeleyDatabase::Open dummy function (Andrew Chow)
71d28e7 walletdb: Introduce AddRef and RemoveRef functions (Andrew Chow)
27b2766 walletdb: Move BerkeleyDatabase::Flush(true) to Close() (Andrew Chow)

Pull request description:

  A `WalletDatabase` abstract class is created from `BerkeleyDatabase` and is implemented by `BerkeleyDatabase`. First, to get to the point that this is possible, 4 functions need to be added to `BerkeleyDatabase`: `AddRef`, `RemoveRef`, `Open`, and `Close`.

  First the increment and decrement of `mapFileUseCount` is refactored into separate functions `AddRef` and `RemoveRef`.

  `Open` is introduced as a dummy function. This will raise an exception so that it always fails.

  `Close` is refactored from `Flush`. The `shutdown` argument in `Flush` is removed and instead `Flush(true)` is now the `Close` function.

  Split from bitcoin#18971

  Requires bitcoin#19325

ACKs for top commit:
  ryanofsky:
    Code review ACK d416ae5. Only changes since last review were rebasing after base PR bitcoin#19334 merge, and adding cs_db lock in BerkeleyDatabase destructor, which should avoid races accessing env->m_databases and env->m_fileids
  fjahr:
    Code review ACK d416ae5
  meshcollider:
    Code review & test run ACK d416ae5

Tree-SHA512: 98d05ec093d7446c4488e2b0914584222a331e9a2f4d5be6af98e3f6d78fdd8e75526c12f91a8a52d4820c25bce02aa02aabe92d38bee7eb2fce07d0691b7b0d
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Sep 1, 2021
Summary:
> 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.

This is a backport of [[bitcoin/bitcoin#19325 | core#19325]] [1/2]
bitcoin/bitcoin@eac9200

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D10002
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Sep 1, 2021
Summary:
Instead of having WalletBatch construct the BerkeleyBatch, have
BerkeleyDatabase do it and return a std::unique_ptr<BerkeleyBatch>

This is a backport of [[bitcoin/bitcoin#19325 | core#19325]] [2/2]
bitcoin/bitcoin@b82f0ca

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D10003
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

7 participants