HomePhabricator

coins: add Sync() method to allow flush without cacheCoins drop

Description

coins: add Sync() method to allow flush without cacheCoins drop

Summary:
In certain circumstances, we may want to flush to disk without
emptying cacheCoins, which affects performance. UTXO snapshot
activation is one such case.

This method is currently unused except in unit tests, and this commit does not
change any behavior.

See also core#15265, which makes the case that under normal operation a
flush-without-erase doesn't necessarily add much benefit. I open this PR
even in light of the previous discussion because (i) flush-without-erase
almost certainly provides benefit in the case of snapshot activation (especially
on spinning disk hardware) and (ii) this diff is fairly small and gives us convenient
options for more granular cache management without changing existing policy.

Incorporates feedback from John Newbery.
Co-authored-by: Suhas Daftuar <sdaftuar@gmail.com>
Thanks to Marco Falke for help with move semantics.

This concludes backport of core#17487 and core#26999
https://github.com/bitcoin/bitcoin/pull/17487/commits/79cedc36afe2e72e42839d861734d73d545d21b8 - coins: add Sync() method to allow flush without cacheCoins drop
https://github.com/bitcoin/bitcoin/pull/17487/commits/2c3cbd6c007a588e667751024027462268626fdb - test: add use of Sync() to coins tests
https://github.com/bitcoin/bitcoin/pull/17487/commits/1d7935b45ac61791399989effc18aece8b368fbb - test: add test for coins view flush behavior using Sync()

https://github.com/bitcoin/bitcoin/pull/26999/commits/bb00357add2c44d4b2cf4341be963f6bb9bee63f - Make test/fuzz/coins_view exercise CCoinsViewCache::Sync()
https://github.com/bitcoin/bitcoin/pull/26999/commits/941feb6ca28522806c4710f85ae5673abdbdb0b9 - Avoid unclear {it = ++it;}
https://github.com/bitcoin/bitcoin/pull/26999/commits/2e16054a66b0576ec93d4032d6b74f0930a44fef - Add assertions that BatchWrite(erase=true) erases

Depends on D16161

Test Plan: ninja all check-all

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D16162

Details

Provenance
James O'Beirne <james.obeirne@gmail.com>Authored on Dec 3 2019, 18:25
PiRKCommitted on May 16 2024, 11:57
PiRKPushed on May 16 2024, 11:57
Reviewer
Restricted Project
Differential Revision
D16162: coins: add Sync() method to allow flush without cacheCoins drop
Parents
rABC44b0c160029a: test: refactor: clarify the coins simulation
Branches
Unknown
Tags
Unknown