-
Notifications
You must be signed in to change notification settings - Fork 36.6k
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
Make nWalletDBUpdated atomic to avoid a potential race. #9227
Make nWalletDBUpdated atomic to avoid a potential race. #9227
Conversation
utACK |
If you're gonna touch this, might as well fix it - will it interact negatively with multiwallet support as written? Also, should be easy to make it only exist in walletdb.cpp, I'd think? |
Right - this should probably exist on the CWalletDB object instead of globally, otherwise multiple wallets will react on each other's changes. |
multiwallet makes the flush thread go over all the wallets and flush them all when this is updated. AFAIK extraneous flushing is mostly harmless...? |
It's would be a performance sink. Remember the thread is named badly. Our 'flushing' isn't really flushing, it is a full fledged database consolidation. Edit: so the idea of having a single flush thread visit all wallets is good, but the write tracking should be per-wallet and not global. |
This should probably also move to CScheduler to avoid having Yet Another Thread when we dont need it. |
The db flush here doesn't really flush a wallet at all, it flushes the whole database environment, so I don't believe it can be made per-wallet. |
Indeed this cannot be made per wallet, this is flushing the entire database environment. |
Right now we are flushing the DB environment (https://docs.oracle.com/cd/E17276_01/html/api_reference/C/envclose.html) with |
The wallet code is set up to flush after every (important) write immediately, that's not what the thread is for. What the flush thread does is not really flushing. The method you propose would be a less hassle solution to do flushing, but what the thread wants to do is consolidate the database files: When writing, BerkeleyDB writes to log files and merges these into the main database only incidentally. The whole circuitous exercise in the thread is to force this to happen, so that the wallet is one file. (can we please rename this thread and add a comment somewhere, everyone reading this code is confused about this, and this has been the case for years) |
Doesn't every wallet get its own database environment? I guess not. |
No-- well every database environment needs it's own database directory, cache overheads, etc. So I'm guessing that wouldn't be a great move. |
391927b
to
f820ac2
Compare
src/wallet/walletdb.h
Outdated
@@ -11,6 +11,7 @@ | |||
#include "wallet/db.h" | |||
#include "key.h" | |||
|
|||
#include <atomic> |
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.
nit: move this to the .cpp.
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.
nit picked
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.
Not it wasnt?
f820ac2
to
d63ff62
Compare
Can this get an 0.14 tag, since its a simple bugfix? |
utACK d63ff62 |
1 similar comment
utACK d63ff62 |
d63ff62 Make nWalletDBUpdated atomic to avoid a potential race. (Patrick Strateman)
… race. d63ff62 Make nWalletDBUpdated atomic to avoid a potential race. (Patrick Strateman)
… race. d63ff62 Make nWalletDBUpdated atomic to avoid a potential race. (Patrick Strateman)
… race. d63ff62 Make nWalletDBUpdated atomic to avoid a potential race. (Patrick Strateman)
…al race 5069899 Make nWalletDBUpdated atomic to avoid a potential race. (furszy) f533e37 move ThreadFlushWalletDB declaration to walletdb.h (Philip Kaufmann) Pull request description: Quick back ports, coming from dashpay#5983 and bitcoin#9227. ACKs for top commit: random-zebra: utACK 5069899 Fuzzbawls: utACK 5069899 Tree-SHA512: 81c6726619f16f53e524bb29e72966c58b069a2bfbc10b1fab89fd28569f9fc555fd0c888b049173e3bb2efa530e62c757e28a3dd11297a66ebd066f1f722fd4
zcash: cherry picked from commit d63ff62 zcash: bitcoin/bitcoin#9227
Bitcoin 0.14 locking PRs These are locking changes from upstream (bitcoin core) release 0.14, oldest to newest (when merged to the master branch). Each commit also includes a reference both to the PR and the upstream commit. - bitcoin/bitcoin#8472 - bitcoin/bitcoin#8606 - Excludes a lock move because we don't have bitcoin/bitcoin#7840 which this move was partially-reverting. - bitcoin/bitcoin#9230 - Only first commit (we don't have `LogTimestampStr` anymore). - bitcoin/bitcoin#9243 - Only the sixth commit, excluding `IsArgSet` locking (we haven't pulled that function in yet). - bitcoin/bitcoin#9626 - The cherry-picked commit does not match the upstream at all, but the resulting lock is useful. - bitcoin/bitcoin#9679 - bitcoin/bitcoin#9227 - bitcoin/bitcoin#9698 - Excludes change to `CConnman::PushMessage` in second commit (which we don't have yet). - bitcoin/bitcoin#9708 - bitcoin/bitcoin#9771
Title