Avoid lock: Call FlushStateToDisk(…) regardless of fCheckForPruning #11617
pull practicalswift wants to merge 2 commits into bitcoin:master from practicalswift:cs_LastBlockFile-fCheckForPruning changing 1 files +4 −2-
practicalswift commented at 10:27 am on November 6, 2017: contributorFlushStateToDisk(…) won’t do anything besides check if we need to prune if FLUSH_STATE_NONE is given. We avoid reading the variable fCheckForPruning which is guarded by the mutex cs_LastBlockFile.
-
fanquake added the label Validation on Nov 6, 2017
-
practicalswift renamed this:
Add missing cs_LastBlockFile lock in AcceptBlock
validation: Add missing cs_LastBlockFile lock in AcceptBlock
on Nov 6, 2017 -
promag commented at 2:52 pm on November 6, 2017: memberFrom what I can tell it’s missing only one lock (in
PruneAndFlush
) maybe fix it here too? -
practicalswift force-pushed on Nov 6, 2017
-
practicalswift commented at 3:28 pm on November 6, 2017: contributor@promag Good point. Looks good now now?
-
promag commented at 3:31 pm on November 6, 2017: memberIn that case reword PR and commit, like
Add missing cs_LastBlockFile locks
-
practicalswift renamed this:
validation: Add missing cs_LastBlockFile lock in AcceptBlock
validation: Add missing cs_LastBlockFile locks
on Nov 6, 2017 -
practicalswift force-pushed on Nov 6, 2017
-
practicalswift commented at 3:44 pm on November 6, 2017: contributor@promag Done :-)
-
practicalswift force-pushed on Nov 6, 2017
-
practicalswift commented at 4:23 pm on November 6, 2017: contributor@promag Had to revert to initial version. Encountered timeouts when adding locking in
PruneAndFlush
as suggested and haven’t investigated deeper yet. What is your suggested patch? :-) -
in src/validation.cpp:3235 in cc0d685674 outdated
3231@@ -3232,6 +3232,7 @@ static bool AcceptBlock(const std::shared_ptr<const CBlock>& pblock, CValidation 3232 return AbortNode(state, std::string("System error: ") + e.what()); 3233 } 3234 3235+ LOCK(cs_LastBlockFile);
TheBlueMatt commented at 8:25 pm on November 6, 2017:It seems like we could just always call FlushStateToDisk instead? It wont do anything besides check if we need to prune if FLUSH_STATE_NONE is given.practicalswift force-pushed on Nov 6, 2017practicalswift commented at 8:33 pm on November 6, 2017: contributor@TheBlueMatt Even better! PR updated. Please re-review :-)promag commented at 8:44 pm on November 6, 2017: memberutACK 96ff97c. Please reword PR again.practicalswift renamed this:
validation: Add missing cs_LastBlockFile locks
Call FlushStateToDisk(...) regardless of fCheckForPruning
on Nov 6, 2017in src/validation.cpp:3235 in 96ff97cc14 outdated
3231@@ -3232,8 +3232,7 @@ static bool AcceptBlock(const std::shared_ptr<const CBlock>& pblock, CValidation 3232 return AbortNode(state, std::string("System error: ") + e.what()); 3233 } 3234 3235- if (fCheckForPruning) 3236- FlushStateToDisk(chainparams, state, FLUSH_STATE_NONE); // we just allocated more disk space for block files 3237+ FlushStateToDisk(chainparams, state, FLUSH_STATE_NONE); // we just allocated more disk space for block files
TheBlueMatt commented at 9:51 pm on November 6, 2017:Comment now needs updated.TheBlueMatt commented at 9:56 pm on November 6, 2017: memberutACK 96ff97cc14b483643020df2497ab06511f5d2ae8 modulo now-incorrect comment.practicalswift force-pushed on Nov 6, 2017practicalswift commented at 10:16 pm on November 6, 2017: contributor@TheBlueMatt Comment removed :-)TheBlueMatt commented at 11:46 pm on November 6, 2017: memberutACK 932dcd49486c6616ee5bfab9588d59fd75c4f0d4promag commented at 0:54 am on November 7, 2017: memberThis PR is a bit messy now. Regarding the original intent, I think it should do:
0@@ -2012,6 +2012,7 @@ void FlushStateToDisk() { 1 } 2 3 void PruneAndFlush() { 4+ LOCK2(cs_main, cs_LastBlockFile); 5 CValidationState state; 6 fCheckForPruning = true; 7 const CChainParams& chainparams = Params();
An alternative is to add an argument to
FlushStateToDisk
, likebool force_check_for_pruning
to avoid touchingfCheckForPruning
.TheBlueMatt commented at 0:58 am on November 7, 2017: memberFlushStateToDisk already checks fCheckForPruning and doesn’t do anything if it’s not set and NONE is passed as the second argument. Despite the complication in FlushStateToDisk, I do not believe this PR has any effect except resolving the (probably not actually a) missing lock bug.
On November 6, 2017 7:55:04 PM EST, “João Barbosa” notifications@github.com wrote:
This PR is a bit messy now. Regarding the original intent, I think it should do:
0@@ -2012,6 +2012,7 @@ void FlushStateToDisk() { 1} 2 3void PruneAndFlush() { 4+ LOCK2(cs_main, cs_LastBlockFile); 5 CValidationState state; 6 fCheckForPruning = true; 7 const CChainParams& chainparams = Params();
An alternative is to add an argument to
FlushStateToDisk
, likebool force_check_for_pruning
to avoid touchingfCheckForPruning
.– You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub: https://github.com/bitcoin/bitcoin/pull/11617#issuecomment-342339354
promag commented at 1:00 am on November 7, 2017: member@TheBlueMatt IMO the best approach to avoid long/recursive/shared locks is to create a snapshot of the chain and use that downstream. The only lock required is when the chain snapshot is created. A slight more advanced solution is copy-on-write, which compared to shared lock, doesn’t make the writer wait for readers to finish.promag commented at 1:04 am on November 7, 2017: member@TheBlueMatt
PruneAndFlush
changesfCheckForPruning
without the lock.With:
0@@ -2012,6 +2012,7 @@ void FlushStateToDisk() { 1 } 2 3 void PruneAndFlush() { 4+ AssertLockHeld(cs_LastBlockFile); 5 CValidationState state; 6 fCheckForPruning = true; 7 const CChainParams& chainparams = Params();
The following fails:
0./test/functional/pruning.py 12017-11-07 01:02:25.034000 TestFramework (INFO): Initializing test directory /var/folders/1v/8_69hby54nj2k3n6fywt44x80000gn/T/testgwrg340t 2Assertion failed: lock cs_LastBlockFile not held in validation.cpp:2015; locks held:
Note
./configure CPPFLAGS=-DDEBUG_LOCKORDER
.TheBlueMatt commented at 1:58 am on November 7, 2017: memberPruneAndFlush() would change behavior in an otherwise-simple lock-fix PR, please, no.
The other part of my context is #10279, in which I want to more clearly separate out the disk operations from validation logic - thus, I’m strongly averse to adding a disk-management lock in validation functions directly.
On November 6, 2017 8:04:20 PM EST, “João Barbosa” notifications@github.com wrote:
@TheBlueMatt
PruneAndFlush
changesfCheckForPruning
without the lock.With:
0@@ -2012,6 +2012,7 @@ void FlushStateToDisk() { 1} 2 3void PruneAndFlush() { 4+ AssertLockHeld(cs_LastBlockFile); 5 CValidationState state; 6 fCheckForPruning = true; 7 const CChainParams& chainparams = Params();
The following fails:
0./test/functional/pruning.py 12017-11-07 01:02:25.034000 TestFramework (INFO): Initializing test 2directory /var/folders/1v/8_69hby54nj2k3n6fywt44x80000gn/T/testgwrg340t 3Assertion failed: lock cs_LastBlockFile not held in 4validation.cpp:2015; locks held:
Note
./configure CPPFLAGS=-DDEBUG_LOCKORDER
.– You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub: https://github.com/bitcoin/bitcoin/pull/11617#issuecomment-342341040
practicalswift commented at 10:11 am on November 8, 2017: contributorWe have one utACK from @TheBlueMatt. Anyone else willing to review? :-)promag commented at 1:26 pm on November 8, 2017: memberTesting
fCheckForPruning
is not needed inAcceptBlock
(which BTW assertscs_main
is held) since the check is done inFlushStateToDisk
.ACK 932dcd4.
practicalswift commented at 7:11 pm on November 21, 2017: contributorReady for merge? :-)practicalswift commented at 10:48 am on January 28, 2018: contributorAny chance of this getting merged or should I close?practicalswift force-pushed on Jan 29, 2018practicalswift commented at 3:13 pm on January 29, 2018: contributorRebased! Please re-review :-)practicalswift commented at 3:00 pm on March 14, 2018: contributorThis trivial fix is blocking my other locking annotations work since I have to re-include this fix in all other PR:s to get correct locking. Having this merged into master would help the locking annotations effort :-)
Ping @MarcoFalke, @TheBlueMatt and @laanwj :-)
TheBlueMatt commented at 4:10 pm on March 15, 2018: memberutACK 48c8610a9c42df6de5dead0f98dc6ced214345bapracticalswift force-pushed on Mar 29, 2018practicalswift commented at 2:11 pm on March 29, 2018: contributorRebased! Please re-review :-)practicalswift renamed this:
Call FlushStateToDisk(...) regardless of fCheckForPruning
Avoid (previously missing) lock: Call FlushStateToDisk(...) regardless of fCheckForPruning
on Apr 9, 2018practicalswift renamed this:
Avoid (previously missing) lock: Call FlushStateToDisk(...) regardless of fCheckForPruning
Avoid lock: Call FlushStateToDisk(...) regardless of fCheckForPruning
on Apr 9, 2018practicalswift commented at 11:02 pm on April 9, 2018: contributorAny chance of getting this merged or re-reviewed?sdaftuar commented at 6:14 pm on April 10, 2018: memberutACK. I’d prefer if we also added clearer documentation that FlushStateMode::NONE behaves in the way that we’re relying on here (perhaps an extra comment in FlushStateToDisk?).Call FlushStateToDisk(...) regardless of fCheckForPruning
FlushStateToDisk(...) won't do anything besides check if we need to prune if FLUSH_STATE_NONE is given. We avoid reading the variable fCheckForPruning which is guarded by the mutex cs_LastBlockFile.
Document how FlushStateMode::NONE is handled 0000d8f727practicalswift force-pushed on Apr 11, 2018practicalswift commented at 10:47 am on April 11, 2018: contributor@sdaftuar Good point! Documentation added. Please re-review :-)sdaftuar commented at 12:56 pm on April 11, 2018: memberlaanwj merged this on Apr 11, 2018laanwj closed this on Apr 11, 2018
laanwj referenced this in commit 1b5723ee57 on Apr 11, 2018jasonbcox referenced this in commit 61b72926bc on Aug 16, 2019jonspock referenced this in commit d20295dd59 on Nov 4, 2019proteanx referenced this in commit 356a11e6ac on Nov 4, 2019PastaPastaPasta referenced this in commit da0e1360b2 on Nov 1, 2020LarryRuane referenced this in commit c930122e34 on Mar 22, 2021LarryRuane referenced this in commit a3890c9c9c on Mar 22, 2021practicalswift deleted the branch on Apr 10, 2021LarryRuane referenced this in commit 4e5622cc30 on Apr 26, 2021LarryRuane referenced this in commit b9b6303974 on Apr 26, 2021LarryRuane referenced this in commit 892e5ec8dd on May 27, 2021LarryRuane referenced this in commit a78deb8ac8 on May 27, 2021str4d referenced this in commit f1d48e6023 on Sep 23, 2021str4d referenced this in commit 261dbe731d on Sep 23, 2021gades referenced this in commit 7299e642e3 on Mar 28, 2022str4d referenced this in commit 0410057c07 on May 14, 2022str4d referenced this in commit a7101db8d3 on May 14, 2022DrahtBot locked this on Aug 16, 2022
This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-12-18 18:12 UTC
More mirrored repositories can be found on mirror.b10c.me