Skip to content

Do not reuse logs that end with an incomplete record#1336

Open
uadhran wants to merge 1 commit into
google:mainfrom
uadhran:fix/reuse-logs-incomplete-record
Open

Do not reuse logs that end with an incomplete record#1336
uadhran wants to merge 1 commit into
google:mainfrom
uadhran:fix/reuse-logs-incomplete-record

Conversation

@uadhran

@uadhran uadhran commented Jun 11, 2026

Copy link
Copy Markdown

Summary

Fixes a corruption risk when reuse_logs is enabled and a WAL or MANIFEST ends with an incomplete record (writer crashed mid-record). Previously log::Reader silently discarded the partial tail, then reuse appended new data — turning a safe discard into likely corruption.

Changes

  • db/log_reader.h / db/log_reader.cc: Add HasIncompleteTrailingRecord(); set when EOF discards truncated header, partial payload, or incomplete fragmented record.
  • db/db_impl.cc: Skip WAL reuse in RecoverLogFile when the flag is set.
  • db/version_set.cc: Skip MANIFEST reuse in Recover when the flag is set.
  • db/log_test.cc: Unit tests for complete vs incomplete EOF.
  • db/recovery_test.cc: Integration test that truncated WAL is not reused (reuse_logs).

Testing

Linux (CMake Release):

./leveldb_tests --gtest_filter="LogTest.Incomplete*:LogTest.Complete*:RecoveryTest.LogNot*:RecoveryTest.LogFileReuse:RecoveryTest.ManifestReused"  # 5/5 passed
./leveldb_tests  # 212 passed, 2 skipped
./env_posix_test  # not re-run (unchanged POSIX env paths)

Did not run Windows/macOS builds locally; relies on CI.

Related: #1287

Add Reader::HasIncompleteTrailingRecord to report when EOF discards a
partial tail record. Skip WAL and MANIFEST reuse when this flag is set,
preventing append from turning a safely discarded fragment into corruption.

Related: google#1287
@uadhran
uadhran marked this pull request as ready for review June 11, 2026 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant