Skip to content

Conversation

@sipa
Copy link
Member

@sipa sipa commented Nov 4, 2015

Previously, the undo files weren't being flushed during a reindex because fKnown was set to true in FindBlockPos. That is the correct behaviour for block files as they aren't being touched, but undo files are
touched.

This changes the behaviour to always flush when switching to a new file (even for block files, though that isn't really necessary).

Intended to fix #6923.

@sipa
Copy link
Member Author

sipa commented Nov 4, 2015

@jonasschnelli @laanwj You may want to test this.

Previously, the undo weren't being flushed during a reindex because
fKnown was set to true in FindBlockPos. That is the correct behaviour
for block files as they aren't being touched, but undo files are
touched.

This changes the behaviour to always flush when switching to a new file
(even for block files, though that isn't really necessary).
@laanwj
Copy link
Member

laanwj commented Nov 5, 2015

I expect that this fixes the issue. #6923 seemed to be a case of a truncated undo file (there was a strangely-sized old undo file and a very small new one). Although I don't fully remember if it happened during -reindex. May well be the case.

Will test.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So on a reindex this means undo files still won't be truncated I suppose?

@morcos
Copy link
Contributor

morcos commented Nov 5, 2015

utACK

Would an alternative option be to at the end of the reindex loop, go through and flush all the undo files. It seems if you crash during a reindex, you don't care about the state of the undo files, its only if you were to crash after reindex before they were flushed that you would have a problem?

Such alternative option would potentially have problems in the event of new blocks being written during reindex, but thats already a problem, see #6691.

@jgarzik
Copy link
Contributor

jgarzik commented Nov 5, 2015

tested ACK

@jonasschnelli
Copy link
Contributor

Tested ACK.

@gmaxwell gmaxwell modified the milestones: 0.11.0, 0.12.0 Nov 5, 2015
@laanwj
Copy link
Member

laanwj commented Nov 5, 2015

It seems if you crash during a reindex, you don't care about the state of the undo file

I don't understand your reasoning here. The point of this PR is to avoid corruption in the undo files when there is a crash during reindex. It can then pick up where it left off next time the application is launched.

@laanwj laanwj merged commit 22e7807 into bitcoin:master Nov 5, 2015
laanwj added a commit that referenced this pull request Nov 5, 2015
22e7807 Always flush block and undo when switching to new file (Pieter Wuille)
@paveljanik
Copy link
Contributor

This change brought a new compiler warning:

main.cpp:2554:15: warning: comparison of integers of different signs: 'unsigned int' and 'int' [-Wsign-compare]
    if (nFile != nLastBlockFile) {
        ~~~~~ ^  ~~~~~~~~~~~~~~
1 warning generated.

sipa added a commit that referenced this pull request Nov 6, 2015
Previously, the undo weren't being flushed during a reindex because
fKnown was set to true in FindBlockPos. That is the correct behaviour
for block files as they aren't being touched, but undo files are
touched.

This changes the behaviour to always flush when switching to a new file
(even for block files, though that isn't really necessary).

Rebased-From: 22e7807
Github-Pull: #6948
luke-jr pushed a commit to luke-jr/bitcoin that referenced this pull request Dec 8, 2015
Previously, the undo weren't being flushed during a reindex because
fKnown was set to true in FindBlockPos. That is the correct behaviour
for block files as they aren't being touched, but undo files are
touched.

This changes the behaviour to always flush when switching to a new file
(even for block files, though that isn't really necessary).

Rebased-From: 22e7807
Github-Pull: bitcoin#6948
furszy referenced this pull request in PIVX-Project/PIVX Apr 24, 2021
ab4f184 Fixed integer comparison warning. (Eric Lombrozo)
189d8b7 Always flush block and undo when switching to new file (Pieter Wuille)

Pull request description:

  Fixing a possible blocks db corruption cause.

  > Previously, the undo weren't being flushed during a reindex because
  fKnown was set to true in FindBlockPos. That is the correct behaviour
  for block files as they aren't being touched, but undo files are
  touched.

  > This changes the behavior to always flush when switching to a new file
  (even for block files, though that isn't really necessary).

  Coming from dashpay#6948.

ACKs for top commit:
  random-zebra:
    utACK ab4f184
  Fuzzbawls:
    ACK ab4f184

Tree-SHA512: c544861e74015afab3cb7162fd49f478e455f7a7b0bfa19c9e3c74ccccd343130dab770fe5a2ad88e017889fe075da999caa89bb06dc669d41d7ba573295cbea
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UndoReadFromDisk: Checksum mismatch

7 participants