-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Refactor: clean up PeriodicFlush() #19085
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
Refactor: clean up PeriodicFlush() #19085
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. |
Concept ⒶⒸⓀ |
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.
Thanks @fanquake . I've rebased on master. |
2495f8f
to
9c03104
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.
ACK 9c03104 - Thanks for the quick follow up. This is a nice simplification, and it'd seem that functions like BerkeleyDatabase::Backup
or BerkeleyEnvironment::Flush
could receive similar refactors.
There was one behaviour I noticed while reviewing (unchanged by this PR), which I've opened an issue for in #19175.
Rebased |
9c03104
to
7c10020
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.
ACK 9c03104 nice refactoring
LogPrint(BCLog::WALLETDB, "Flushing %s\n", strFile); | ||
int64_t nStart = GetTimeMillis(); | ||
// Don't flush if any databases are in use | ||
for (auto it = env->mapFileUseCount.begin() ; it != env->mapFileUseCount.end(); it++) { |
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.
nit, while retouching this code, ++i
is preferred over i++
for (auto it = env->mapFileUseCount.begin() ; it != env->mapFileUseCount.end(); it++) { | |
for (auto it = env->mapFileUseCount.begin() ; it != env->mapFileUseCount.end(); ++it) { |
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 makes no difference to the compiled code since we're not using the return value of the incrementer. I'll change to ++it
if I have to retouch this branch, but otherwise it's not worth invalidating ACKs.
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.
nit, extra space after begin
. Better, use range based loop.
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.
Yes. Even better. Will change if I have to retouch.
LogPrint(BCLog::WALLETDB, "Flushing %s\n", strFile); | ||
int64_t nStart = GetTimeMillis(); | ||
|
||
// Flush wallet file so it's self contained |
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.
nit: self-contained
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.
Will change if I need to retouch
Note to reviewers: I suggest looking at the diff with space changes ignored ( |
rebased |
7c10020
to
e846a2a
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.
re-ACK e846a2a per git range-diff f7c19e8 7c10020 e846a2a
ACK e846a2a 🎁 Show signature and timestampSignature:
Timestamp of file with hash |
cc @achow101 any objections to this? |
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.
ACK e846a2a.
LogPrint(BCLog::WALLETDB, "Flushing %s\n", strFile); | ||
int64_t nStart = GetTimeMillis(); | ||
// Don't flush if any databases are in use | ||
for (auto it = env->mapFileUseCount.begin() ; it != env->mapFileUseCount.end(); it++) { |
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.
nit, extra space after begin
. Better, use range based loop.
I think this is ready for merge. It's a simple refactor and has 3 ACKs now. |
Went ahead to merge this and postponed to fix the nits in a related pull that had less ACKs (#18923) |
Summary: ``` PeriodicFlush() is much more convoluted than it needs to be: it has triple nesting, local variables counting refs and return values, and increments the mapFileUseCount iterator unnecessarily. Removing all of that makes the function much easier to understand. ``` Backport of core [[bitcoin/bitcoin#19085 | PR19085]]. Depends on D8617. Test Plan: ninja all check-all Reviewers: #bitcoin_abc, majcosta Reviewed By: #bitcoin_abc, majcosta Differential Revision: https://reviews.bitcoinabc.org/D8618
PeriodicFlush()
is much more convoluted than it needs to be: it has triple nesting, local variables counting refs and return values, and increments themapFileUseCount
iterator unnecessarily. Removing all of that makes the function much easier to understand.