Reset pblocktree before deleting LevelDB file #12401

pull Sjors wants to merge 1 commits into bitcoin:master from Sjors:2018/02/reset-pblocktree changing 1 files +3 −0
  1. Sjors commented at 6:55 PM on February 9, 2018: member

    #11043 repaced:

    delete pblocktree;
    pblocktree = new CBlockTreeDB(nBlockTreeDBCache, false, fReset);
    

    With:

    pblocktree.reset(new CBlockTreeDB(nBlockTreeDBCache, false, fReset));
    

    This is problematic because new CBlockTreeDB tries to delete the existing file, which will fail with LOCK: already held by process if it's still open. That's the case for QT.

    When QT finds a problem with the index it will ask the user if they want to reindex. At that point it has already opened blocks/index. It then runs this while loop again with fReset = 1, resulting in the above error.

    This change makes that error go away, presumably because reset() without an argument closes the file.

  2. Sjors commented at 6:57 PM on February 9, 2018: member

    @laanwj if I'm correct then this regression was introduced after v0.15.1 and so we might need a new rc.

  3. Sjors cross-referenced this on Feb 9, 2018 from issue Build tx index in parallel with validation by jimpo
  4. Sjors force-pushed on Feb 9, 2018
  5. in src/init.cpp:1428 in 7bd20cf466 outdated
    1424 | @@ -1425,6 +1425,9 @@ bool AppInitMain()
    1425 |                  pcoinsTip.reset();
    1426 |                  pcoinsdbview.reset();
    1427 |                  pcoinscatcher.reset();
    1428 | +                if (fReset) {
    


    sipa commented at 7:26 PM on February 9, 2018:

    I don't think the conditional is necessary. Also, perhaps add a comment that the reset is necessary to avoid temporarily having two CBlockTreeDB objects?


    Sjors commented at 10:48 AM on February 10, 2018:

    I put the conditional there because under normal circumstances pblocktree.reset() is useless. However I don't know what it does under the hood; maybe the performance overhead is negligible.

  6. MarcoFalke added this to the milestone 0.16.0 on Feb 9, 2018
  7. jonasschnelli added the label UTXO Db and Indexes on Feb 10, 2018
  8. jonasschnelli added the label Block storage on Feb 10, 2018
  9. jonasschnelli removed the label UTXO Db and Indexes on Feb 10, 2018
  10. Sjors commented at 10:50 AM on February 10, 2018: member

    ~Should I change pcoinsTip, pcoinsdbview and pcoinscatcher in the same way?~ It's not entirely clear to me what reset() actually does.

  11. Sjors commented at 10:52 AM on February 10, 2018: member

    Also paging @practicalswift.

  12. practicalswift commented at 3:19 PM on February 10, 2018: contributor

    Thanks for the ping and thanks for finding+fixing this issue.

    utACK 7bd20cf466dfa5b2cccef00d1cd05bfbb8634f0d modulo the unnecessary conditional.

  13. Sjors force-pushed on Feb 10, 2018
  14. Sjors commented at 4:29 PM on February 10, 2018: member

    Conditional removed.

  15. MarcoFalke commented at 4:42 PM on February 10, 2018: member

    utACK 8b986dc5696db1d623465cb13d036bac722762e6

  16. MarcoFalke cross-referenced this on Feb 10, 2018 from issue QT Core wallet crash when starting with "-txindex" by user78713
  17. MarcoFalke added the label Needs backport on Feb 10, 2018
  18. practicalswift commented at 9:45 AM on February 11, 2018: contributor

    utACK 8b986dc5696db1d623465cb13d036bac722762e6

  19. laanwj commented at 10:35 AM on February 11, 2018: member

    utACK

  20. in src/init.cpp:1430 in 8b986dc569 outdated
    1424 | @@ -1425,6 +1425,7 @@ bool AppInitMain()
    1425 |                  pcoinsTip.reset();
    1426 |                  pcoinsdbview.reset();
    1427 |                  pcoinscatcher.reset();
    1428 | +                pblocktree.reset();
    


    promag commented at 10:44 AM on February 11, 2018:

    Add comment here?


    Sjors commented at 11:14 AM on February 11, 2018:

    Added comment.

  21. promag commented at 10:44 AM on February 11, 2018: member

    utACK 8b986dc.

  22. Reset pblocktree before deleting LevelDB file a8b5d20f4f
  23. Sjors force-pushed on Feb 11, 2018
  24. MarcoFalke commented at 9:44 PM on February 11, 2018: member

    utACK a8b5d20f4f171828b2bd70ab2405c42b1e452e5b

  25. laanwj merged this on Feb 12, 2018
  26. laanwj closed this on Feb 12, 2018

  27. laanwj referenced this in commit 79313d2e20 on Feb 12, 2018
  28. laanwj referenced this in commit d44cd7ed4b on Feb 12, 2018
  29. Sjors deleted the branch on Feb 12, 2018
  30. MarcoFalke removed the label Needs backport on Feb 12, 2018
  31. HashUnlimited referenced this in commit 2c8f81dc63 on Mar 16, 2018
  32. PastaPastaPasta referenced this in commit 7a795d3f01 on Mar 14, 2020
  33. PastaPastaPasta referenced this in commit 8b13a956bc on Mar 14, 2020
  34. PastaPastaPasta referenced this in commit 5e19f32b6b on Mar 15, 2020
  35. deadalnix referenced this in commit 5ba4892705 on Jun 18, 2020
  36. ftrader referenced this in commit 9b09266ea4 on Aug 17, 2020
  37. ckti referenced this in commit c32dc3e689 on Mar 28, 2021
  38. bitcoin locked this on Sep 8, 2021

github-metadata-mirror

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-05-19 06:54 UTC