Copy current WAL in consistent state during checkpoint #12671
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Due to a few data race issues, sometimes active WAL file gets copied in inconsistent state during checkpoint operation.
Database open from such checkpoint fails with one of these errors when
wal_recovery_mode=kAbsoluteConsistency
:Corruption: truncated record body
Corruption: error reading trailing data
This happens because size of the active WAL file is captured at a random moment:
truncated record body
error happens when WAL file size is captured right afterWritableFileWriter
flush when in-memory buffer no longer has space for new dataerror reading trailing data
happens, when WAL record gets broken down into multiple physical records(fragments), and WAL file size was captured before last fragment has been written.The fix does the following:
log::Writer
;GetLiveFilesStorageInfo
, captures current log number (if there is active WAL) and it's latest consistent offset, right after capturing manifest and options state;trim_to_size=true
+ size to the consistent offset, captured previously;GetLiveFilesStorageInfo
call (betweenmutex_.Unlock
andGetSortedWalFiles
) are ignored, since we don't know which portion of such WAL we have to copy so it would be copied in a consistent state.Fixes #12670