Skip to content

Commit b49b341

Browse files
committed
bug-fix: delayed flush of undo files
When creating blk and rev files, these are pre-allocated for performance reasons, and then truncated down to their final size after completion. This works for blk files which are sequentially created, but since blocks are stored out of order, and since the undo data for blocks are stored sequentially (upon activation of the block), the rev file will be written to for awhile even after the blk file has been finalized. This change switches the flushing part to flush the *previous* undo file for the finalize (truncate) case, which addresses the problem, as we never write to the rev file 2 steps back.
1 parent 04f78b8 commit b49b341

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/validation.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1735,8 +1735,14 @@ void static FlushBlockFile(bool fFinalize = false)
17351735
{
17361736
LOCK(cs_LastBlockFile);
17371737

1738+
// we want to finalize flush the previous undo file, as it will have been written to
1739+
// for awhile even after we've moved onto the next blk file; if we don't do this, we
1740+
// end up with a re-opened but unflushed rev file, resulting in pre-allocated but not
1741+
// returned disk space allocation
1742+
int previous_undo_file = fFinalize && nLastBlockFile > 0 ? nLastBlockFile - 1 : nLastBlockFile;
1743+
17381744
FlatFilePos block_pos_old(nLastBlockFile, vinfoBlockFile[nLastBlockFile].nSize);
1739-
FlatFilePos undo_pos_old(nLastBlockFile, vinfoBlockFile[nLastBlockFile].nUndoSize);
1745+
FlatFilePos undo_pos_old(previous_undo_file, vinfoBlockFile[previous_undo_file].nUndoSize);
17401746

17411747
bool status = true;
17421748
status &= BlockFileSeq().Flush(block_pos_old, fFinalize);

0 commit comments

Comments
 (0)