Hopefully this is done in a database-independent manner, with minimal interference to the upcoming ultraprune.
Add -reindex, to perform in-place reindexing of blockchain data files #1870
pull jgarzik wants to merge 1 commits into bitcoin:master from jgarzik:reindex changing 3 files +75 −10-
jgarzik commented at 9:01 PM on September 26, 2012: contributor
-
BitcoinPullTester commented at 2:56 AM on September 27, 2012: none
Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/68e760d2656716cc9d538567c0735c77d8e5749e for binaries and test log.
-
in src/main.cpp:None in 68e760d265 outdated
2329 | + } 2330 | +} 2331 | + 2332 | +void ReindexBlockchainPrep() 2333 | +{ 2334 | + filesystem::path pathIdx = GetDataDir() / "blkindex.dat";
sipa commented at 2:01 PM on September 28, 2012:I really wouldn't delete bdb database files yourself. Use the dbenv methods to do so.
gavinandresen commented at 9:21 PM on October 1, 2012:I agree with sipa, dbenv seemed to get very confused when I renamed database files behind its back for my corrupt wallet.dat handling code.
sipa commented at 2:07 PM on September 28, 2012: memberSurprising how little code changes are necessary for this. Ultraprune already has a CDiskBlockPos however, which is also used inside CTxBlockPos, so maybe you can use that instead? I think you can just copy it, and remove the IMPLEMENT_SERIALIZE.
sipa commented at 10:05 PM on October 1, 2012: memberI also wonder about this: what if the current best chain happens to be known in the new/repained blockchain? There should be no need to rebuild the entire index in that case, only the block positions.
EDIT: right, you can't, as in the current database structure, transactions also contain disk positions. It's something that can be done post-ultraprune though.
jgarzik commented at 7:41 PM on October 3, 2012: contributorUpdated with the following changes:
- uses CDiskBlockPos from sipa's ultraprune branch
- calls our CDBEnv to perform database removal
sipa commented at 1:50 PM on October 7, 2012: memberHave you tested this?
$ ./bitcoind -reindex DB_ENV->dbremove: method not permitted before handle's open methodgavinandresen commented at 4:37 PM on October 7, 2012: contributorI wrote up a 4-step test plan that I've been working through.
I also have a branch (not published) to reconcile this with my corrupt wallet handling pull; @jgarzik see https://github.com/gavinandresen/bitcoin-git/commits/BDB_RECOVER
The testplan I was working through:
- Run new testnet3-in-a-box instance, let it IBD, shut it down. Remove testnet3/database/ directory. EXPECT: automatic re-index of blk0001.dat on startup.
- Same a (1), but run with -detachdb. Corrupt blkindex.dat by truncating it by a few bytes, then restart. EXPECT: automatic re-index of blk0001.dat on startup.
- Same as (2), but corrupt some bytes instead of truncating the file. EXPECT: automatic re-index.
- Compile a bitcoind against a later version of BDB (e.g. BDB 5 instead of 4). Run without -detachdb. Then startup a bitcoind compiled against the earlier BDB version. EXPECT: Something Reasonable-- not a BDB_RUNRECOVERY uncaught exception/crash.
- Same as (4), run with -detachdb. EXPECT: Same something reasonable as (4).
I haven't tested 4/5 yet, and don't know enough about BDB major version compatibility to know what is reasonable to expect.
jgarzik commented at 5:02 AM on October 9, 2012: contributorDoing the database remove in the environment definitely creates a super-large removal transactions, yet does not actually remove blkindex.dat. blk0002.dat is growing here, which should not be the case. Further debugging is needed.
gavinandresen commented at 3:20 PM on October 9, 2012: contributorInstead of:
dbenv.dbremove(NULL, strFile.c_str(), "main", DB_AUTO_COMMIT);you might trydbenv.dbremove(NULL, strFile.c_str(), NULL, DB_AUTO_COMMIT);... then re-create blkindex.dat using TxDb("cr")I think passing NULL as the third argument removes the file.
f49f263185Add -reindex, to perform in-place reindexing of blockchain data files
Caveat: a new genesis block is added to blkNNNN.dat with each run, thanks to LoadBlockIndex() creating one, when it creates a blank block index.
jgarzik commented at 3:45 AM on October 10, 2012: contributorFixed a few bugs, and rebased on top of @gavinandresen 's ::RemoveDb(). blkindex.dat is now properly removed, and reindex proceeds as expected. Things appear to be working now.
Caveat: a genesis block is newly stored to blkNNNN.dat, for each -reindex invocation. LoadBlockIndex() adds a new one to the (it thinks) newly created block file. All other blocks are properly read and processed in-place.
-reindex highlights the poor speed of BDB indexing alone... and should provide a useful apples-to-apples basis for comparing the old BDB system with ultraprune.
sipa commented at 9:58 PM on October 20, 2012: memberNeeds rebase.
BitcoinPullTester commented at 10:33 PM on October 20, 2012: noneAutomatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/f49f2631856a4a233a957ce8361ffab3b08561cc for binaries and test log.
jgarzik closed this on Oct 21, 2012jgarzik deleted the branch on Aug 24, 2014KolbyML referenced this in commit 696e328d8c on Dec 5, 2020KolbyML referenced this in commit 3c05a7bd2d on Dec 5, 2020DrahtBot locked this on Sep 8, 2021ContributorsMilestone
0.8.0
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: 2026-04-19 12:16 UTC
More mirrored repositories can be found on mirror.b10c.me