Page MenuHomePhabricator

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

Authored by PiRK on May 15 2024, 12:05.

Details

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

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

PiRK requested review of this revision.May 15 2024, 12:05
Fabien added a subscriber: Fabien.
Fabien added inline comments.
src/coins.cpp
304 ↗(On Diff #47780)

if fOk is false, resetting the cache usage is certainly wrong.
I'm not sure how it's handled at callsite, maybe it just aborts the node, but it's worth having a look.
Accepting anyway because this is not a change in behavior.

This revision is now accepted and ready to land.May 16 2024, 08:10