-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Avoid lock: Call FlushStateToDisk(...) regardless of fCheckForPruning #11617
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
Avoid lock: Call FlushStateToDisk(...) regardless of fCheckForPruning #11617
Conversation
From what I can tell it's missing only one lock (in |
d982e13
to
60151f9
Compare
@promag Good point. Looks good now now? |
In that case reword PR and commit, like |
60151f9
to
f151609
Compare
@promag Done :-) |
f151609
to
cc0d685
Compare
@promag Had to revert to initial version. Encountered timeouts when adding locking in |
src/validation.cpp
Outdated
@@ -3232,6 +3232,7 @@ static bool AcceptBlock(const std::shared_ptr<const CBlock>& pblock, CValidation | |||
return AbortNode(state, std::string("System error: ") + e.what()); | |||
} | |||
|
|||
LOCK(cs_LastBlockFile); |
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 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.
cc0d685
to
96ff97c
Compare
@TheBlueMatt Even better! PR updated. Please re-review :-) |
utACK 96ff97c. Please reword PR again. |
src/validation.cpp
Outdated
@@ -3232,8 +3232,7 @@ static bool AcceptBlock(const std::shared_ptr<const CBlock>& pblock, CValidation | |||
return AbortNode(state, std::string("System error: ") + e.what()); | |||
} | |||
|
|||
if (fCheckForPruning) | |||
FlushStateToDisk(chainparams, state, FLUSH_STATE_NONE); // we just allocated more disk space for block files | |||
FlushStateToDisk(chainparams, state, FLUSH_STATE_NONE); // we just allocated more disk space for block files |
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.
Comment now needs updated.
utACK 96ff97cc14b483643020df2497ab06511f5d2ae8 modulo now-incorrect comment. |
96ff97c
to
932dcd4
Compare
@TheBlueMatt Comment removed :-) |
utACK 932dcd49486c6616ee5bfab9588d59fd75c4f0d4 |
This PR is a bit messy now. Regarding the original intent, I think it should do: @@ -2012,6 +2012,7 @@ void FlushStateToDisk() {
}
void PruneAndFlush() {
+ LOCK2(cs_main, cs_LastBlockFile);
CValidationState state;
fCheckForPruning = true;
const CChainParams& chainparams = Params(); An alternative is to add an argument to |
FlushStateToDisk 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" ***@***.***> wrote:
This PR is a bit messy now. Regarding the original intent, I think it
should do:
```diff
@@ -2012,6 +2012,7 @@ void FlushStateToDisk() {
}
void PruneAndFlush() {
+ LOCK2(cs_main, cs_LastBlockFile);
CValidationState state;
fCheckForPruning = true;
const CChainParams& chainparams = Params();
```
An alternative is to add an argument to `FlushStateToDisk`, like `bool
force_check_for_pruning` to avoid touching `fCheckForPruning`.
--
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub:
#11617 (comment)
|
@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. |
@TheBlueMatt With: @@ -2012,6 +2012,7 @@ void FlushStateToDisk() {
}
void PruneAndFlush() {
+ AssertLockHeld(cs_LastBlockFile);
CValidationState state;
fCheckForPruning = true;
const CChainParams& chainparams = Params(); The following fails:
Note |
PruneAndFlush() 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" ***@***.***> wrote:
@TheBlueMatt `PruneAndFlush` changes `fCheckForPruning` without the
lock.
With:
```diff
@@ -2012,6 +2012,7 @@ void FlushStateToDisk() {
}
void PruneAndFlush() {
+ AssertLockHeld(cs_LastBlockFile);
CValidationState state;
fCheckForPruning = true;
const CChainParams& chainparams = Params();
```
The following fails:
```
./test/functional/pruning.py
2017-11-07 01:02:25.034000 TestFramework (INFO): Initializing test
directory /var/folders/1v/8_69hby54nj2k3n6fywt44x80000gn/T/testgwrg340t
Assertion failed: lock cs_LastBlockFile not held in
validation.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:
#11617 (comment)
|
We have one utACK from @TheBlueMatt. Anyone else willing to review? :-) |
Testing ACK 932dcd4. |
Ready for merge? :-) |
Any chance of this getting merged or should I close? |
Any chance of getting this merged or re-reviewed? |
utACK. 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?). |
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.
18271a7
to
0000d8f
Compare
@sdaftuar Good point! Documentation added. Please re-review :-) |
Thanks, re-utACK 0000d8f |
…heckForPruning 0000d8f Document how FlushStateMode::NONE is handled (practicalswift) 2311c7c Call FlushStateToDisk(...) regardless of fCheckForPruning (practicalswift) Pull request description: 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. Tree-SHA512: 89df06256f73503a74b9e26d580ce9ed09efaef347fae1ff6a5759a2993b0db52edd2fadb65694d27e579a5aed92127753bdf41b5bb1bd516e577fcf17f17999
…heckForPruning Summary: 0000d8f Document how FlushStateMode::NONE is handled (practicalswift) 2311c7c Call FlushStateToDisk(...) regardless of fCheckForPruning (practicalswift) Pull request description: 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. Tree-SHA512: 89df06256f73503a74b9e26d580ce9ed09efaef347fae1ff6a5759a2993b0db52edd2fadb65694d27e579a5aed92127753bdf41b5bb1bd516e577fcf17f17999 Backport of Core PR11617 bitcoin/bitcoin#11617 Test Plan: make check test_runner.py Reviewers: deadalnix, Fabien, jasonbcox, O1 Bitcoin ABC, #bitcoin_abc Reviewed By: deadalnix, O1 Bitcoin ABC, #bitcoin_abc Differential Revision: https://reviews.bitcoinabc.org/D3844
…heckForPruning Summary: 0000d8f Document how FlushStateMode::NONE is handled (practicalswift) 2311c7c Call FlushStateToDisk(...) regardless of fCheckForPruning (practicalswift) Pull request description: 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. Tree-SHA512: 89df06256f73503a74b9e26d580ce9ed09efaef347fae1ff6a5759a2993b0db52edd2fadb65694d27e579a5aed92127753bdf41b5bb1bd516e577fcf17f17999 Backport of Core PR11617 bitcoin/bitcoin#11617 Test Plan: make check test_runner.py Reviewers: deadalnix, Fabien, jasonbcox, O1 Bitcoin ABC, #bitcoin_abc Reviewed By: deadalnix, O1 Bitcoin ABC, #bitcoin_abc Differential Revision: https://reviews.bitcoinabc.org/D3844
…heckForPruning Summary: 0000d8f Document how FlushStateMode::NONE is handled (practicalswift) 2311c7c Call FlushStateToDisk(...) regardless of fCheckForPruning (practicalswift) Pull request description: 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. Tree-SHA512: 89df06256f73503a74b9e26d580ce9ed09efaef347fae1ff6a5759a2993b0db52edd2fadb65694d27e579a5aed92127753bdf41b5bb1bd516e577fcf17f17999 Backport of Core PR11617 bitcoin/bitcoin#11617 Test Plan: make check test_runner.py Reviewers: deadalnix, Fabien, jasonbcox, O1 Bitcoin ABC, #bitcoin_abc Reviewed By: deadalnix, O1 Bitcoin ABC, #bitcoin_abc Differential Revision: https://reviews.bitcoinabc.org/D3844
…s of fCheckForPruning 0000d8f Document how FlushStateMode::NONE is handled (practicalswift) 2311c7c Call FlushStateToDisk(...) regardless of fCheckForPruning (practicalswift) Pull request description: 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. Tree-SHA512: 89df06256f73503a74b9e26d580ce9ed09efaef347fae1ff6a5759a2993b0db52edd2fadb65694d27e579a5aed92127753bdf41b5bb1bd516e577fcf17f17999
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. zcash: cherry picked from commit 2311c7c zcash: bitcoin/bitcoin#11617
zcash: cherry picked from commit 0000d8f zcash: bitcoin/bitcoin#11617
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. zcash: cherry picked from commit 2311c7c zcash: bitcoin/bitcoin#11617
zcash: cherry picked from commit 0000d8f zcash: bitcoin/bitcoin#11617
…s of fCheckForPruning 0000d8f Document how FlushStateMode::NONE is handled (practicalswift) 2311c7c Call FlushStateToDisk(...) regardless of fCheckForPruning (practicalswift) Pull request description: 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. Tree-SHA512: 89df06256f73503a74b9e26d580ce9ed09efaef347fae1ff6a5759a2993b0db52edd2fadb65694d27e579a5aed92127753bdf41b5bb1bd516e577fcf17f17999
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.