Skip to content

Fix short SequentialFile reads that could drop WAL/MANIFEST data#1334

Open
uadhran wants to merge 2 commits into
google:mainfrom
uadhran:fix/sequential-file-short-reads
Open

Fix short SequentialFile reads that could drop WAL/MANIFEST data#1334
uadhran wants to merge 2 commits into
google:mainfrom
uadhran:fix/sequential-file-short-reads

Conversation

@uadhran

@uadhran uadhran commented Jun 11, 2026

Copy link
Copy Markdown

Summary

Fixes a data-loss risk when SequentialFile::Read() returns a successful short read before EOF (e.g. POSIX read() interrupted by a signal after partially filling the buffer). log::Reader previously treated any short read as EOF, which could silently drop MANIFEST or WAL data during DB::Open().

Changes

  • util/env_posix.cc: PosixSequentialFile::Read loops until n bytes are read or EOF.
  • util/env_windows.cc: Same retry loop for WindowsSequentialFile::Read.
  • db/log_reader.cc: ReadPhysicalRecord accumulates partial block reads before treating EOF.
  • include/leveldb/env.h: Document that implementations should only return short reads at EOF.
  • db/log_test.cc: Add PartialReadSourceTest regression test; update StringSource mock to match real EOF semantics.

Testing

Built and ran on Linux (CMake Release):

./leveldb_tests --gtest_filter="*PartialRead*"          # 1/1 passed
./leveldb_tests --gtest_filter="LogTest.*:PartialReadSourceTest.*"  # 39/39 passed
./env_posix_test                                       # 7/7 passed
./leveldb_tests                                        # 210 passed, 2 skipped

Did not run Windows or macOS CI matrix locally.

Related: #1285

PosixSequentialFile and WindowsSequentialFile now retry reads until the
requested byte count is satisfied or EOF is reached. log::Reader also
accumulates partial block reads so custom Env implementations are safe.

Adds PartialReadSourceTest to verify multi-block log recovery when reads
return fewer bytes than requested before EOF.

Related: google#1285
@google-cla

google-cla Bot commented Jun 11, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@uadhran
uadhran marked this pull request as ready for review June 11, 2026 08:55
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