Skip to content

Conversation

jnewbery
Copy link
Contributor

@jnewbery jnewbery commented May 28, 2020

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.

@jnewbery jnewbery requested a review from maflcko May 28, 2020 03:01
@DrahtBot
Copy link
Contributor

DrahtBot commented May 28, 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.

@maflcko
Copy link
Member

maflcko commented May 28, 2020

Concept ⒶⒸⓀ

Copy link
Member

@fanquake fanquake left a comment

Choose a reason for hiding this comment

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

Glanced over 2495f8f and it looks like an improvement. Can you rebase now that #18792 is in, and I'll re-review.

@achow101 you might also want to take a look here?

@jnewbery
Copy link
Contributor Author

jnewbery commented Jun 4, 2020

Thanks @fanquake . I've rebased on master.

Copy link
Member

@fanquake fanquake left a 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.

@jnewbery
Copy link
Contributor Author

Rebased

Copy link
Member

@jonatack jonatack left a 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++) {
Copy link
Member

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++

Suggested change
for (auto it = env->mapFileUseCount.begin() ; it != env->mapFileUseCount.end(); it++) {
for (auto it = env->mapFileUseCount.begin() ; it != env->mapFileUseCount.end(); ++it) {

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Member

Choose a reason for hiding this comment

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

nit: self-contained

Copy link
Contributor Author

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

@jonatack
Copy link
Member

jonatack commented Jul 1, 2020

Note to reviewers: I suggest looking at the diff with space changes ignored (git show -w).

@jnewbery
Copy link
Contributor Author

jnewbery commented Jul 9, 2020

rebased

@jnewbery jnewbery force-pushed the 2020-05-refactor-periodic-flush branch from 7c10020 to e846a2a Compare July 9, 2020 06:07
Copy link
Member

@jonatack jonatack left a 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

@maflcko
Copy link
Member

maflcko commented Jul 9, 2020

ACK e846a2a 🎁

Show signature and timestamp

Signature:

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

ACK e846a2a1d9e8aa37abfa55bd4d2a0a9f55ba6c8e 🎁
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUgG+wv/SWkvdinhfmWvllvmoyHz6TKFcTwBBsvJFneg6saYLV/A21hlxGfD+iS8
xu5f03nFpFsb+bFQvRcm2FtG1McxQTnmEcnNUss0MZ53F8uNCoIG5kfM1eAfBXuw
omRgHgMAk2NMZmCUrHT2Qv4ZOKwUZ2N/4TiVvc2apXy6Zbgf0NKxqagGKs7yRXKN
arajJLM8ua6ewKQFZtPZySRvH03Ed33im0vpae/nsSmluqtJ3VnzVhoCGuxybKzT
RpbBtjD4ayMC/O8q2E93+VHao/zB/CIEpess1KEWIkyyT7w/JZ86XYiVWcEPdfkD
yHUPoPTMOhJuPe/1Vvx9sMxoSV07c/aAgodFDP/UHHaT1JIPfZwyMHWmXcx5pIZd
V9qIdH2uk2mBEp57o5HcJlA/57y4gtDd32WGo23mo/Ef1kqMKwjBs/o2YnE0/f+e
eoCn9pDih3lnbxg919suNbfCtLpVQAlqHVXMe5XafrYDLSQtXGBkfCk33CTSTEGL
8AJuiXGE
=0P36
-----END PGP SIGNATURE-----

Timestamp of file with hash d38062803983ae335282eeba787d6c83aeeabfe3699adc77650b02de45c422fc -

@maflcko
Copy link
Member

maflcko commented Jul 9, 2020

cc @achow101 any objections to this?

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.

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++) {
Copy link
Contributor

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.

@jnewbery
Copy link
Contributor Author

jnewbery commented Jul 9, 2020

I think this is ready for merge. It's a simple refactor and has 3 ACKs now.

@maflcko maflcko merged commit c4a4418 into bitcoin:master Jul 9, 2020
@maflcko
Copy link
Member

maflcko commented Jul 9, 2020

Went ahead to merge this and postponed to fix the nits in a related pull that had less ACKs (#18923)

@jnewbery jnewbery deleted the 2020-05-refactor-periodic-flush branch July 10, 2020 16:31
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Dec 7, 2020
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
@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
None yet
Development

Successfully merging this pull request may close these issues.

6 participants