Signed-off-by: Anthony Fieroni bvbfan@abv.bg
Don't call lsn_reset in periodic flush #18904
pull bvbfan wants to merge 1 commits into bitcoin:master from bvbfan:lsn_reset_fix changing 5 files +14 −32-
bvbfan commented at 6:48 AM on May 7, 2020: contributor
- fanquake added the label Wallet on May 7, 2020
-
bvbfan commented at 6:51 AM on May 7, 2020: contributor
lsn_reset on big wallet (actually wallet can became bigger) takes a minutes on GB file. It shuffles the priv key location but it does not make sense to be so frequently.
- bvbfan cross-referenced this on May 7, 2020 from issue On windows 10 most of the time the wallet is in the - (not responding) mode, please tell me what to do by Yoperok
- ryanofsky cross-referenced this on May 7, 2020 from issue build: Allow BDB between 4.8 and 5.3 without --with-incompatible-bdb by achow101
-
laanwj commented at 5:35 PM on May 7, 2020: member
Shuffling private key location is not the point here. Does it still concatenate the bdb logs after this, so that everything becomes one file? That's the point of the periodic flush.
-
bvbfan commented at 5:08 AM on May 8, 2020: contributor
Does it still concatenate the bdb logs after this, so that everything becomes one file?
https://docs.oracle.com/cd/E17276_01/html/api_reference/C/txncheckpoint.html
If there has been database environment activity since the last checkpoint, the DB_ENV->txn_checkpoint method flushes the underlying memory pool, writes a checkpoint record to the log, and then flushes the log.
https://docs.oracle.com/cd/E17275_01/html/api_reference/C/envlsn_reset.html
The DB_ENV->lsn_reset() method allows database files to be moved from one transactional database environment to another.
There is no need to be called on every flush.
-
achow101 commented at 6:16 AM on May 8, 2020: member
I don't think this is safe without #18907. Otherwise there could be a condition where the log files are removed and the database opened again which could cause corruption. As I understand it,
lsn_resetis required if we're going to do any log file removals. -
achow101 commented at 4:20 PM on May 8, 2020: member
During
BerkeleyEnvironment::Open, ifdbenv->openfails, it will move the transaction logs to a backup directory and retrydbenv->open. If the LSNs in the wallet file were not reset when this occurs, then there could be corruption issues due to mismatched LSNs. This situation could occur if Core has an unclean exit and if there is something that causes the environment to fail to open (e.g. a different BDB version). -
bvbfan commented at 8:44 AM on May 9, 2020: contributor
When batch is using db is open without retry or i miss something https://github.com/bitcoin/bitcoin/blob/master/src/wallet/db.cpp#L533
- DrahtBot cross-referenced this on May 14, 2020 from issue wallet: Refactor the classes in wallet/db.{cpp/h} by achow101
-
DrahtBot commented at 3:50 AM on May 14, 2020: contributor
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--174a7506f384e20aa4161008e828411d-->
Conflicts
Reviewers, this pull request conflicts with the following ones:
- #19461 (multiprocess: Add bitcoin-gui -ipcconnect option by ryanofsky)
- #19460 (multiprocess: Add bitcoin-wallet -ipcconnect option by ryanofsky)
- #10102 (Multiprocess bitcoin by ryanofsky)
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
- DrahtBot cross-referenced this on May 27, 2020 from issue wallet: Add sqlite as an alternative wallet database and use it for new descriptor wallets by achow101
- DrahtBot cross-referenced this on May 28, 2020 from issue Refactor: clean up PeriodicFlush() by jnewbery
- DrahtBot cross-referenced this on May 29, 2020 from issue wallet: Introduce and use DummyDatabase instead of dummy BerkeleyDatabase by achow101
- DrahtBot cross-referenced this on Jun 2, 2020 from issue wallettool: Add dump and createfromdump commands by achow101
- DrahtBot cross-referenced this on Jun 16, 2020 from issue wallet: Refactor BerkeleyBatch Read, Write, Erase, and Exists functions into non-template functions by achow101
- DrahtBot cross-referenced this on Jun 16, 2020 from issue wallet: move BDB specific classes to bdb.{cpp/h} by achow101
- DrahtBot added the label Needs rebase on Jun 17, 2020
- DrahtBot removed the label Needs rebase on Jun 17, 2020
- DrahtBot cross-referenced this on Jun 20, 2020 from issue wallet: Cleanup and separate BerkeleyDatabase and BerkeleyBatch by achow101
- DrahtBot added the label Needs rebase on Jul 9, 2020
- DrahtBot removed the label Needs rebase on Jul 9, 2020
-
bvbfan commented at 4:40 PM on July 9, 2020: contributor
@achow101 i do some code refactor as well. In periodic flush it isn't needed lsn_reset to be called, to close the db as well. It just needs to trigger writing of log checkpoints. Looking at docs https://docs.oracle.com/cd/E17276_01/html/api_reference/C/txncheckpoint.html https://docs.oracle.com/cd/E17275_01/html/api_reference/C/envlsn_reset.html lsn_reset is needed when we want to move db from one environment to another, it rewrites entire file, which is crucial slow when wallet file is large.
- DrahtBot cross-referenced this on Jul 9, 2020 from issue wallet: Never schedule MaybeCompactWalletDB when -flushwallet is off by maflcko
-
ryanofsky commented at 8:40 PM on July 9, 2020: contributor
In periodic flush it isn't needed lsn_reset to be called, to close the db as well. It just needs to trigger writing of log checkpoints.
If the point is to avoid data loss it makes sense to only require writing a new log checkpoint. If the point is to allow deleting the logs entirely (#2558)
maybe it does make sense to call lsn_reset.
I'm a little confused both about the behavior and the design goals. Maybe there should be an option to not delete log files.
- DrahtBot cross-referenced this on Jul 10, 2020 from issue wallet: Introduce WalletDatabase abstract class by achow101
-
bvbfan commented at 4:35 AM on July 10, 2020: contributor
If the point is to avoid data loss it makes sense to only require writing a new log checkpoint. If the point is to allow deleting the logs entirely (#2558)
maybe it does make sense to call lsn_reset.
Sure, here it's needed, as well in backup and rewrite. The problem in periodic flush is rewriting entire file (say it can be couple of GiB) for nothing, it blocks the UI, daemon as well. #18886
- DrahtBot cross-referenced this on Jul 11, 2020 from issue refactor: remove ::vpwallets and related global variables by ryanofsky
- DrahtBot cross-referenced this on Jul 14, 2020 from issue multiprocess: Add bitcoin-gui -ipcconnect option by ryanofsky
- DrahtBot cross-referenced this on Jul 14, 2020 from issue multiprocess: Add bitcoin-wallet -ipcconnect option by ryanofsky
- DrahtBot cross-referenced this on Jul 15, 2020 from issue Multiprocess bitcoin by ryanofsky
- DrahtBot added the label Needs rebase on Jul 23, 2020
- DrahtBot removed the label Needs rebase on Jul 23, 2020
- DrahtBot cross-referenced this on Jul 29, 2020 from issue Remove wallet.dat path handling from wallet.cpp, rpcwallet.cpp by ryanofsky
- DrahtBot added the label Needs rebase on Jul 29, 2020
- DrahtBot removed the label Needs rebase on Jul 29, 2020
-
achow101 commented at 9:25 PM on August 13, 2020: member
I'm still not convinced that this is safe to do. I think it would be better to ensure that after each write, the database is portable. That would remove the need for
PeriodicFlushin general which would resolve this issue. But at the same time, doing that is probably not performant.At this point, it may be better to just leave this as is and merge sqlite wallets which don't have this issue. Then provide an upgrade path from bdb to sqlite (i.e. a straight record to record conversion) so that people who are experiencing these performance issues can just upgrade to sqlite.
-
bvbfan commented at 5:38 AM on August 25, 2020: contributor
Hi, @achow101 i don't think it's needed to remove
PeriodicFlushat all, because it prevents data loss by writing txs to backup db.https://www.mit.edu/afs.new/sipb/project/subversion/docs/ref/transapp/checkpoint.html
- DrahtBot added the label Needs rebase on Sep 7, 2020
- DrahtBot removed the label Needs rebase on Sep 8, 2020
- DrahtBot cross-referenced this on Sep 20, 2020 from issue refactor: Some wallet cleanups by promag
- DrahtBot cross-referenced this on Oct 12, 2020 from issue rpc, wallet: Expose database format in getwalletinfo by promag
- DrahtBot added the label Needs rebase on Oct 19, 2020
- DrahtBot removed the label Needs rebase on Oct 20, 2020
- DrahtBot added the label Needs rebase on Dec 2, 2020
-
maflcko commented at 12:03 PM on October 22, 2021: member
Needs rebase if still relevant
-
bvbfan commented at 12:16 PM on October 22, 2021: contributor
Hi @MarcoFalke, it speed-up periodic flush since lsn_reset rewrites entire file, high unlikely to periodic action. I've using across other forks without issue, but i've not follow will bdb backend entire replaced via sqlite one or they will keep operate in cooperation? If bdb is still well used backend, so the changes is good to be pushed. Thanks.
-
maflcko commented at 12:25 PM on October 22, 2021: member
-
bvbfan commented at 12:39 PM on October 28, 2021: contributor
Rebased
- DrahtBot removed the label Needs rebase on Oct 28, 2021
- DrahtBot cross-referenced this on Mar 3, 2022 from issue Disallow more unsafe string->path conversions allowed by path append operators by ryanofsky
- DrahtBot cross-referenced this on Mar 27, 2022 from issue Add and use ForEachWallet by promag
- DrahtBot added the label Needs rebase on May 3, 2022
- DrahtBot removed the label Needs rebase on May 3, 2022
-
bvbfan commented at 2:24 PM on June 17, 2022: contributor
I think it would be better to ensure that after each write, the database is portable.
That's look very aggressive. Bigger wallets will suffer even more, that's a ton of GiB rewritten. LSN changes the key position thus entire file is regenerated.
- DrahtBot cross-referenced this on Jun 29, 2022 from issue Use steady clock for all millis bench logging by maflcko
- DrahtBot added the label Needs rebase on Sep 16, 2022
-
3011d6c18a
Don't call lsn_reset in periodic flush
Signed-off-by: Anthony Fieroni <bvbfan@abv.bg>
- DrahtBot removed the label Needs rebase on Sep 16, 2022
-
achow101 commented at 8:30 PM on October 12, 2022: member
Given that future efforts in the wallet are aimed at descriptor wallets, and legacy wallets and BDB are slated for removal in the future, we're no longer investing time into non-critical issues (i.e. money losing) for the legacy wallet and BDB.
- achow101 closed this on Oct 12, 2022
- maflcko cross-referenced this on Nov 23, 2022 from issue send BTC is very slow with huge wallet by JokerCatz
- bitcoin locked this on Oct 12, 2023