Repository navigation
Read a file moved into a FileLog directory from the beginning when it reuses a deleted file's inode - #123593
Conversation
On Linux the directory watcher reported every IN_MOVED_TO as DW_ITEM_MOVED_TO and dropped the inotify cookie. StorageFileLog treats a MOVED_TO whose inode is already tracked as a rename and keeps the old read offset. When a tracked file is deleted and a file written elsewhere on the same filesystem is moved in within one watcher batch, ext4 often gives the new file the freed inode, so the new file was read from the deleted file's offset and its first rows were silently skipped (or every read failed with "Last saved offsset ... is bigger than the file size" when the new file was shorter). The Linux watcher now pairs IN_MOVED_FROM and IN_MOVED_TO by cookie. Only a rename inside the directory delivers both halves; an unpaired IN_MOVED_TO is reported as DW_ITEM_ADDED, which resets the offset. The cookies of moves out of the directory never get paired, so they are kept in a FIFO bounded at 1024 entries that survives read() boundaries (inotify may split a pair across two reads). Eviction only turns a rename into a re-read, never into a skip. The macOS snapshot watcher already reports an arrival from elsewhere as DW_ITEM_ADDED. It still synthesized a rename when an unlinked name's inode reappeared under another name through a hard link; is_rename now ignores names that got NOTE_DELETE, matching what Linux emits for the same sequence. Behaviour change toward re-reading: a file moved out of the directory and back in within one batch is now read again from the start. 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; 1 round, 2 findings), plus my own review (2 findings).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261002-165000 |
|
Workflow [PR], commit [edf3781] Summary: ✅
AI ReviewSummaryThis PR teaches the Missing context / blind spots
Final VerdictStatus: ✅ Approve LLVM Coverage Report |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes25 object files changed (+17.76 KiB total), 0 added.
719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units8 translation units recompiled, 9 s compile time in total, 8 of them have a recent master baseline. |
618787f
…lsewhere After the merge with master (ClickHouse#123593), a file moved into the directory from elsewhere is reported as `DW_ITEM_ADDED` rather than `DW_ITEM_MOVED_TO`. The `DW_ITEM_ADDED` handler ignored names that the glob excludes, so when such a file replaced a rotated file that was read (`mv outside/replacement app.log.0`), the table kept the old name and read the new file from the old file's offset. `05316_file_log_globs` caught it in the "renamed file replaced" section. Like `DW_ITEM_MOVED_TO`, `DW_ITEM_ADDED` now drops the name when the file found there is not read. Co-Authored-By: Claude Opus 5.5 <[email protected]>
05319_file_log_rename_in_reused_inode timed out in Fast test (arm_darwin) of ClickHouse#117738: one macOS scan saw a.csv gone and b.csv, moved in from a hard link outside the directory, with the same inode, diffed them as MOVED_FROM a.csv + MOVED_TO b.csv, and StorageFileLog kept a.csv's offset, skipping rows of b.csv. ClickHouse#123593 made is_rename refuse a name in deleted_files as a rename source. Before ClickHouse#125794 every NOTE_DELETE of a watched descriptor put its name there; ClickHouse#125794 (4d75ef8) returns early while the file still has links, because kqueue reports an unlink of any name to every descriptor of the file and the scan has to find which name went away (hidden excluded aliases of 05316_file_log_globs). When the remaining link is outside the directory, nothing recorded the unlink any more. Record the inode in that branch (unlinked_inodes), and in is_rename refuse the pair when the inode's current name matches the path: the scan lists every matching name and is_rename requires one listed name per side, so such a name was not a link of the file at the last scan and the file came back, i.e. it is new here, as on Linux (an IN_MOVED_TO without its IN_MOVED_FROM is ADDED). An excluded current name can be a hidden alias and keeps ClickHouse#125794's behaviour. The set lives next to deleted_files: kept across discarded and failed passes, cleared after a committed one, the first snapshot included (its listing already reflects every unlink recorded before it, and it pairs nothing). The unlink is drained before the diff (scanFilesAndUpdateWatches drains before syncFileWatches closes descriptors), so the decision does not depend on scan timing. The test gains the same steps in one process so a macOS scan sees the unlink and the move-in together; the new content is longer than c.csv's offset, so a carried- over offset gives wrong rows (checked on Linux with a same-inode rename, which keeps the offset: only 110 is read). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #123368
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
FileLogsilently skipping the first rows of a file moved into the watched directory from elsewhere (for example a staging file renamed into place) when that file got the inode of a file just deleted from the directory. Such a file is now read from the beginning.Description
On 26.8 and 26.3, a file renamed into a
FileLogdirectory right after another file there was deleted can get that file's inode, andFileLogthen reads it from the deleted file's offset, silently skipping its first rows (or failing every read withLast saved offsset ... is bigger than the file sizewhen the new file is shorter). ext4 gives a freed inode to the next new file, so the "write to a staging file, thenmvit into place" producer pattern hits this when the delete and the rename land in one watcher batch. Found by the review bot on #123542.Cause: the Linux directory watcher reported every
IN_MOVED_TOas a rename and dropped the inotify cookie, so a file arriving from outside the directory looked like the second half of a rename inside it, andStorageFileLogkept the old offset of the matching inode.Change: the Linux watcher pairs
IN_MOVED_FROM/IN_MOVED_TOby cookie (a bounded FIFO kept acrossread()calls). An unpairedIN_MOVED_TOis reported as an added file, which is already read from offset 0. The macOS watcher already reports an arrival as added, and no longer treats an unlinked name as a rename source. A file moved out of the directory and back in within one batch is now read again from the start (duplicates instead of loss). Not covered: a file that takes a deleted file's inode while the server is stopped is still matched by inode at startup.Validation: new test
05319_file_log_rename_in_reused_inodefails on master (rows10,20are missing) and passes with the fix. Its in-directory rename arm fails if every arrival is treated as new. Reproduced with a recycled inode (no hard link) on master, 26.8.10.6 and 26.3.33.24. All FileLog stateless tests pass.Workflow [PR]
Sync PR [sync-upstream/pr/123593]
Version info
26.10.1.1438-master(included in26.10and later)