-
Notifications
You must be signed in to change notification settings - Fork 37.7k
wallet: Cleanup and separate BerkeleyDatabase and BerkeleyBatch #19335
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
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, 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. |
a2a30a5
to
d69f101
Compare
1b155cb
to
8dc24d0
Compare
8dc24d0
to
288bae7
Compare
288bae7
to
06120bf
Compare
06120bf
to
8fa346c
Compare
8fa346c
to
e73d0a1
Compare
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.
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.
Conditional code review ACK e73d0a1 if some problems below are fixed. Just reviewed last 4 commits here
- 61da2fa walletdb: track database file use as m_refcount within BerkeleyDatabase (5/8)
- 33554ed walletdb: Move Db->open to BerkeleyDatabase::Open (6/8)
- 8a98a83 walletdb: Use a global g_fileids instead of m_fileids for each env (7/8)
- e73d0a1 walletdb: Remove BerkeleyBatch friend class from BerkeleyDatabase (8/8)
e73d0a1
to
ccfd611
Compare
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.
Code review ACK ccfd611 last 5 commits
- 747ca18 Combine BerkeleyEnvironment::Verify into BerkeleyDatabase::Verify (5/9)
- 516084a walletdb: track database file use as m_refcount within BerkeleyDatabase (6/9)
- 93b5f04 walletdb: Move Db->open to BerkeleyDatabase::Open (7/9)
- 0a01ba7 No need to check for duplicate fileids in all dbenvs (8/9)
- ccfd611 walletdb: Remove BerkeleyBatch friend class from BerkeleyDatabase (9/9)
Only changes since previous review are followups from #19335 (review). This is a nice cleanup and everything here is an improvement. I do think Batch/Database refcounting interaction is too complicated though and could be made simpler later (#19335 (comment)).
ccfd611
to
df8ca1a
Compare
Instead of having BerkeleyEnvironment track the file use count, make BerkeleyDatabase do it itself.
Instead of opening the Db handle in BerkeleyBatch, make BerkeleyDatabase do that.
Since we have .walletlock in each directory, we don't need the duplicate fileid checks across all dbenvs as it shouldn't be possible anyways.
df8ca1a
to
74507ce
Compare
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.
Code review ACK 74507ce. No changes since last review other than rebase
src/wallet/bdb.cpp
Outdated
@@ -285,8 +284,7 @@ bool BerkeleyDatabase::Verify(bilingual_str& errorStr) | |||
|
|||
if (fs::exists(file_path)) | |||
{ | |||
LOCK(cs_db); |
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.
Why was this 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.
It was there to guard mapFileUseCount which we've now removed.
Code review ACK 74507ce |
…d BerkeleyBatch 74507ce walletdb: Remove BerkeleyBatch friend class from BerkeleyDatabase (Andrew Chow) 00f0041 No need to check for duplicate fileids in all dbenvs (Andrew Chow) d86efab walletdb: Move Db->open to BerkeleyDatabase::Open (Andrew Chow) 4fe4b3b walletdb: track database file use as m_refcount within BerkeleyDatabase (Andrew Chow) 65fb880 Combine BerkeleyEnvironment::Verify into BerkeleyDatabase::Verify (Andrew Chow) Pull request description: `BerkeleyBatch` and `BerkeleyDatabase` are kind of messy. The goal of this is to clean up them up so that they are logically separated. `BerkeleyBatch` currently handles the creation of the `BerkeleyDatabase`'s `Db` handle. This is instead moved into `BerkeleyDatabase` and is called by `BerkeleyBatch`. Instead of having `BerkeleyEnvironment` track each database's usage, have `BerkeleyDatabase` track this usage itself with the `m_refcount` variable that is present in `WalletDatabase`. Lastly, instead of having each `BerkeleyEnvironment` store the fileids of the databases open in it, have a global `g_fileids` to track those fileids. We were already checking fileid uniqueness globally (by checking the fileids in every environment when opening a database) so it's cleaner to do this with a global variable. All of these changes allow us to make `BerkeleyBatch` and `BerkeleyDatabase` no longer be friend classes. The diff of this PR is currently the same as in #bitcoin#18971 Requires bitcoin#19334 ACKs for top commit: laanwj: Code review ACK 74507ce ryanofsky: Code review ACK 74507ce. No changes since last review other than rebase Tree-SHA512: 845d84ee1a470e2bf5d2e2e3d7738183d8ce43ddd06a0bbd57edecf5779b2f55d70728b1b57f5daab0f078650a8d60c3e19dc30b75b36e7aa952ce268399d5f6
Summary: This is a backport of [[bitcoin/bitcoin#19335 | core#19335]] [1/5] bitcoin/bitcoin@65fb880 Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, majcosta Reviewed By: #bitcoin_abc, majcosta Differential Revision: https://reviews.bitcoinabc.org/D10034
Summary: Instead of having BerkeleyEnvironment track the file use count, make BerkeleyDatabase do it itself. This is a backport of [[bitcoin/bitcoin#19335 | core#19335]] [2/5] bitcoin/bitcoin@4fe4b3b Depends on D10034 Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, majcosta Reviewed By: #bitcoin_abc, majcosta Differential Revision: https://reviews.bitcoinabc.org/D10035
Summary: Instead of opening the Db handle in BerkeleyBatch, make BerkeleyDatabase do that. This is a backport of [[bitcoin/bitcoin#19335 | core#19335]] [3/5] bitcoin/bitcoin@d86efab Depends on D10035 Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, majcosta Reviewed By: #bitcoin_abc, majcosta Subscribers: Fabien Differential Revision: https://reviews.bitcoinabc.org/D10036
Summary: Since we have .walletlock in each directory, we don't need the duplicate fileid checks across all dbenvs as it shouldn't be possible anyways. This is a backport of [[bitcoin/bitcoin#19335 | core#19335]] [4/5] bitcoin/bitcoin@00f0041 Depends on D10036 Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, deadalnix Reviewed By: #bitcoin_abc, deadalnix Differential Revision: https://reviews.bitcoinabc.org/D10037
Summary: This is a backport of [[bitcoin/bitcoin#19335 | core#19335]] [5/5] bitcoin/bitcoin@74507ce Depends on D10037 Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, deadalnix Reviewed By: #bitcoin_abc, deadalnix Differential Revision: https://reviews.bitcoinabc.org/D10038
BerkeleyBatch
andBerkeleyDatabase
are kind of messy. The goal of this is to clean up them up so that they are logically separated.BerkeleyBatch
currently handles the creation of theBerkeleyDatabase
'sDb
handle. This is instead moved intoBerkeleyDatabase
and is called byBerkeleyBatch
.Instead of having
BerkeleyEnvironment
track each database's usage, haveBerkeleyDatabase
track this usage itself with them_refcount
variable that is present inWalletDatabase
.Lastly, instead of having each
BerkeleyEnvironment
store the fileids of the databases open in it, have a globalg_fileids
to track those fileids. We were already checking fileid uniqueness globally (by checking the fileids in every environment when opening a database) so it's cleaner to do this with a global variable.All of these changes allow us to make
BerkeleyBatch
andBerkeleyDatabase
no longer be friend classes.The diff of this PR is currently the same as in ##18971
Requires #19334