Repository navigation
Read a FileLog file again from the beginning after it is truncated in place - #123390
Conversation
… place
logrotate with copytruncate truncates the file in place: the inode stays,
the size drops. FileLog keeps one offset per inode, so the saved offset
survived and openFilesAndSetPos threw CANNOT_READ_ALL_DATA ("Last saved
offsset ... is bigger than the file size"). That function runs once per
round for all files of the table before any source is built, so one
truncated file failed every round of the whole table until the file grew
back to its old size, and then the bytes before the old offset were
skipped.
Now a file smaller than its saved offset is read again from offset 0. The
on-disk offset file is removed before the reset, because serialize ->
checkOffsetIsValid raises LOGICAL_ERROR when the stored offset is larger
than the new one (as the DW_ITEM_ADDED path already handles). Removing
first keeps the old offset in memory if the removal throws, so the next
round retries.
A file truncated and regrown to at least its old size between two reads is
not detectable by size and is still read from the old offset.
The arms of 02023 and 02025 that asserted the removed exception are
deleted; 05316 covers the new behavior after ATTACH and live.
Related: ClickHouse#123368
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 0 findings) plus my own cold review (1 nit).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261002-014800 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-40:20261002-011100 |
|
Workflow [PR], commit [d99b059] Summary: ✅
AI ReviewSummaryThis PR teaches Final Verdict
LLVM Coverage ReportMeasured on commit d99b059.
Changed lines: Changed C/C++ lines covered: 14/14 (100.00%) · Uncovered code |
The reset to offset 0 happens only when the file is still shorter than its saved offset at the next read. A file truncated and regrown to at least that offset before then is read from the old offset, so the docs now say so. The live arm of 05316 truncated app.log once, right after ATTACH. The directory watcher installs its inotify watch asynchronously, so an overwrite that lands first produces no event and the polling reads time out. The overwrite is now repeated on every attempt; the content is the same each time. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 11 s compile time in total, 7 of them have a recent master baseline. |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
FileLognow reads a file again from the beginning if, at the next read, it is shorter than the offset already read from it (for example afterlogrotatewithcopytruncate), instead of failing every read of the table withCANNOT_READ_ALL_DATAuntil the file grows back to its old size.Description
Related: #123368 (the
copytruncaterotation item).copytruncatekeeps the inode and drops the size, so FileLog keeps the saved offset of that inode, andStorageFileLog::openFilesAndSetPosthrewLast saved offsset for File app.log is bigger than the file size. That check runs for all files before any source is built, so every round failed: the materialized view stopped reading every file of the table, and a directSELECTfailed. Once the file grew back to its old size, reading resumed at the old offset, skipping the lines written after the truncation. The same applied to the first read afterATTACHor a restart.Now a file smaller than its saved offset is read again from offset 0: its offset file is removed first (else
serializeraisesLOGICAL_ERRORon the smaller offset, as theDW_ITEM_ADDEDpath already handles), the offset is reset, and anInformationline is logged. A file truncated and regrown to at least its old size between two reads cannot be detected by size and is still read from the old offset. The rotated copyapp.log.1, if left in the watched directory, is a new inode and is read as a new file; that belongs to the issue's file selection item.02023and02025asserted the old exception; those arms are removed in favor of the new test (afterATTACHand live).Validation: the new test fails on master (
(6 > 5),(6 > 2), the untouched file not read) and passes with the fix; the issue's materialized view setup loses no row; dropping the offset-file removal fails the test with thatLOGICAL_ERROR; all FileLog tests and 50/50 randomized runs pass.copytruncatewas never supported (the exception was deliberate and asserted by tests since 2021), hence Improvement.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/123390]
Version info
26.10.1.1326-master(included in26.10and later)