HomePhabricator

Merge #12401: Reset pblocktree before deleting LevelDB file

Description

Merge #12401: Reset pblocktree before deleting LevelDB file

Summary:
a8b5d20 Reset pblocktree before deleting LevelDB file (Sjors Provoost)

Pull request description:

#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](https://github.com/bitcoin/bitcoin/blob/v0.16.0rc3/src/init.cpp#L1415) 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.

Tree-SHA512: fde8b546912f6773ac64da8476673cc270b125aa2d909212391d1a2001b35c8260a8772126b99dfd76b39faaa286feb7c43239185fe584bd4dc2bc04a64044ce

Backport of Core PR12401

Test Plan:

ninja
ninja check-all
src/bitoin-qt

Reviewers: O1 Bitcoin ABC, #bitcoin_abc, jasonbcox

Reviewed By: O1 Bitcoin ABC, #bitcoin_abc, jasonbcox

Differential Revision: https://reviews.bitcoinabc.org/D6632

Details

Provenance
Wladimir J. van der Laan <laanwj@gmail.com>Authored on Feb 12 2018, 09:11
nakihitoCommitted on Jun 18 2020, 22:38
nakihitoPushed on Jun 18 2020, 22:38
Reviewer
Restricted Owners Package
Differential Revision
D6632: Merge #12401: Reset pblocktree before deleting LevelDB file
Parents
rABC6411602e25af: Merge #15486: [addrman, net] Ensure tried collisions resolve, and allow feeler…
Branches
Unknown
Tags
Unknown