Repository navigation
Conversation
…fset openFilesAndSetPos opens each file by name and seeks it to the offset saved for the inode cached for that name. The cached inode changes only when the directory events are applied, and a streaming round applies them after reading. So when the file at a name was replaced (`mv` over it) or rotated (`logrotate` create mode: renamed, then created again) after the table cached it and before it applied the events, the new file was read from the old file's offset, and then once more from 0 when the events re-keyed the name: the new file arrived twice, and in a rotation the rows of the rotated file were lost, because the read advanced the old inode's offset that the rename then carried over to the rotated file. A single-file table, which has no directory events, kept reading a replaced file from the old offset forever. The check that the path still leads to the cached inode existed, but only after a failed open. Run it for every open, before and after it: - before: a name whose directory entry did not change (a single-file table, a symlink whose target was replaced) gets no event when it leads to another file, so it is re-keyed now and read from its start, unless that file is already read under another name. The macOS watcher reports a replaced symlink target as a new file, so there a directory table leaves the re-key to its events. The inode of the entry itself (lstat) is cached for this test: a regular file replaced by a symlink moved over it changes the entry and does produce an event (an unpaired IN_MOVED_TO, reported as ADDED, which resets the offset), so re-keying it here as well would read the file twice. Only a symlink entry counts as unchanged, because the inodes of the name and of its entry are read by two calls. SYSTEM RESET FILELOG re-keys such a name the same way before it sets the offset, so the offset is for the file the name leads to now. - after: the opened file is read only if the path still leads to the inode the offset is kept for. Otherwise a replaced entry waits for its pending directory events to re-key it, so the new file is read once from its start and the rotated file from its own offset; until then it costs one open and close per poll. The reader is a std::ifstream, whose descriptor is not accessible in C++23, so the identity is checked by path on both sides of the open. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Remove comments that narrate the new code in StorageFileLog.cpp; shorten two to one line. 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; 4 rounds, 10 findings) plus my own review.
Severity: ❌ blocker / Session id: cron:clickhouse-review-self-slot-58:20261005-165200 |
|
Workflow [PR], commit [bb45287] Summary: ✅
AI ReviewSummaryReviewed Findings
Final VerdictStatus: ✅ Approve No new changes requested. The previously dismissed finding is retained above for completeness. |
…e written `SYSTEM RESET FILELOG` re-keyed a name whose file was replaced without an event (a single-file table, or a symlink whose target was replaced) before writing the temporary meta files: it erased the old offset, deleted the old meta file and switched the inode. A failed write then left the table re-keyed although the command reported an error, and when the unlink of the old meta file itself failed (a read-only metadata directory), `meta_by_inode` lost the entry and the next read hit the size assertion of `file_infos`. The inode to read a name as is now computed without changing state, kept in the reset target, and applied together with the new meta files once all of them are written. The read path removes the old meta file before it changes anything in memory. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…the name The command returned success while changing nothing when the name is a symlink whose target was replaced by a file read under another name, and it set the position of the old file when the file at the name was replaced but its directory event was not applied yet (the event then reads the replacement from its start). Both now throw BAD_ARGUMENTS, as a reset of a name whose creation event is not applied yet already does. The test also checks that an offset set after a replacement in a single-file table survives DETACH and ATTACH: the immediate read rewrites the meta file from memory, so it cannot see what the reset wrote. 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 units11 translation units recompiled, 38 s compile time in total, 11 of them have a recent master baseline. Median compile-time ratio to the baselines is ×1.07 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
|
🕵 Merged master (includes #128067, which makes @groeneai, investigate the |
|
Measured on master
With slow encoder threads all 4096 rows can end up in one file, which would fail a test that expects a file above the upper threshold to be split. I will open a separate PR that makes the check exact: finish the row groups in flight before comparing (option A on #127670), unless you prefer the estimate (B).
|
|
Correction to the above: the fix is already in progress in #127864, so I won't open a second PR. It makes |
|
🕵 Merged master (clean merge;
|
|
🕵 Merged master (clean merge; |
A name that leads, with no directory event, to a file whose offset is kept for another name was skipped and never visited again. When that other name then moved on to a new file, as with symlink targets rotated by logrotate, no name read the file until the table was attached again (master reads it). The open now marks such a name to be retried, and so does a reset of all names that skips it. The rotated file's old offset is still not passed to the new name; that is the releaseInode follow-up agreed with ClickHouse#123673. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The test is new in this PR, and the Fast test fails a new test that runs longer than 15 s: it took 16.6 s there after the case for rotated symlink targets was added. The six cases use their own tables and directories, so they now run concurrently, each printing to its own file, and the output is printed in the original order. Each case drops its own tables at its end. Local debug build: 18 s -> 4.5-6.7 s (50 runs), up to 9.6 s with -j 8. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - 91da995Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
No job was dropped, and Session id: cron:our-pr-ci-monitor:20261107-023005 |
…d-file-old-offset Conflict in `StorageFileLog::openFilesAndSetPos`: master added a narrower check that skips a tracked name leading to another inode; the PR's check already covers it (and also handles untracked names), so the PR side is kept.
|
🕵 Merged master to resolve the conflict in The previous red job ( |
A name that gets no directory event for its new file (on Linux, a symlink whose target was replaced) was deferred while that file was cached under any other name. When two symlinks' targets are swapped (or rotated in a cycle), each name's new file is cached under the other name, so both were deferred forever and never read again until a reattach; SYSTEM RESET FILELOG returned success without effect, and a named reset failed. Master reads both files. Now a name is deferred only while another name still leads to the file (`isReadUnderOtherName`). If the file is cached under a name that leads elsewhere, the two names swap their files, offsets and meta files included, as `loadFiles` does by inode at a reload: the files are read on from their own offsets. `openFilesAndSetPos` does these take-overs before any re-key to a new file, which drops the offset of the file it leaves (the order the macOS watcher also keeps for renames). The reset path takes over before staging, unless a staged target keeps that file. Measured on a debug build (.scratch/maint-r5-cycle.sh): swap before the first read [100,200] (head: nothing, five reads); a three-name rotation [100,200,300]; read, detach, append, attach, swap: only the appended [104,201] (head: nothing; master [101,102,103,104,200,201] and more duplicates after a reattach); a.csv to a new file and b.csv to a.csv's old one: [202,300] (head and master read 200 and 201 again). Tests: a 05326 case with swapped symlink targets (read, then swapped back and reset), and 05326_file_log_symlink_targets_offsets for saved offsets through a swap and a rotation (no-darwin: the macOS watcher reports these as directory events). Reported by clickhouse-gh in ClickHouse#124068 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
`takeOverFile` gave the other name the file that the taking name left, but kept that name's status, so an inactive name (`NO_CHANGE`, not retried) never opened its new file. With `a.csv -> x` and `b.csv -> y`, `y` moved aside while `a.csv` is read and the targets then rotated (`x` to `y`, the old `y` to `x`), the unread file of `a.csv` was read only after a reattach: in direct SELECTs, in a materialized view, and after `SYSTEM RESET FILELOG ... FILE 'b.csv' TO END`. The other name is now retried like a name whose open failed: it is opened in the same pass when the take-over runs before the main loop, else in the next pass (`any_open_failed` keeps the background task polling). Its reader is dropped, so no stream reads a file whose offset moved to another name. A name that leads to no file is neither retried nor opened (also when it is `OPEN` after an attach): a failed open of a dangling name drops the offset of its file, so a half-completed swap (the old file of `a.csv` still under a temporary name when `a.csv` takes over) read that file again from 0 once it came back under `b.csv` (Gate B). Reported by clickhouse-gh on ClickHouse#124068 (r4576214240). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…no file `takeOverFile` did not retry a name that led to no file at take-over time, so that the failed open would not drop the offset it had just been given. Restoring a target outside the watched directory gives no event, so the name stayed `NO_CHANGE` and its file was read only after a reattach. With `a.csv -> x` and `b.csv -> y`, `x` moved aside and `y` moved to `x` before the first read, and the old `x` then moved to `y`, `100,101` stayed unread in direct SELECTs, in a materialized view and after a named `SYSTEM RESET FILELOG`; a fresh file created at `y` stayed unread too. The other name is now always retried, and a name that leads to no file follows the existing rule: what appears there later is read from its start. Keeping the offset instead is unsafe, because only the inode number identifies the file: after `mv y x` frees the inode of `x`, a new `y` often gets the same number (7 of 12 runs here, xfs), and was then read from the old file's offset, skipping its first rows. The previous code did that at the next reattach. So a file that comes back under a name that led to no file is read again from its start, as for any other such name. Master aborts in the first scenario on the `file_names.size() == meta_by_inode.size()` assertion after reading the restored file. Reported by clickhouse-gh on ClickHouse#124068 (r4576622731). Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - ff60021Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261115-083014 |
|
Fixing PR for the |
…adroom baseline `master_baseline` took the nearest commit of the run's master chain whose `Build (amd_msan)` report existed and skipped every commit without one. A master job uploads its report only in `post_run`, so a parent that is still building looked like one that never builds, and the PR was compared with an older commit. On 2026-11-14 ClickHouse#117346 (`Use clang-23`) moved the msan layout by -16.23 MiB; its own master build ran until 20:42Z, and ClickHouse#124068, ClickHouse#131668 and ClickHouse#117318, checked a few seconds earlier, were compared with the commit before it and failed with exactly master's delta. Apply the rule the performance delta gate uses for the same walk (`classify_missing_prev_master_run`, 8b06c76): when the job report is missing, read the commit's MasterCI summary and skip the commit only when MasterCI never ran there, the run has no such job, or the job is `SKIPPED`. Any other status, a report without the headroom row, or a lookup error other than 403/404 stops the walk: no baseline (the header names the commit and its status) or the existing `ERROR`. A PR success without a baseline because the walk stopped is not cached, since master's state is not a build digest input. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…es over a file A take-over makes the name it takes the file from retried. In a rotation of three files where the name in the middle was not active (e.g. after a named `SYSTEM RESET FILELOG` of the other two), that name became active only behind the single take-over pass, so the main pass of `openFilesAndSetPos` re-keyed the first name to its new file and dropped the offset of its old file before the name in the middle could take it over, and the old file was read again from the start. The pass is now repeated until it makes no take-over. Every take-over gives one more name the file it leads to, so the number of passes is bounded by the number of names. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
🕵 Merged master and addressed the open review thread (bb45287). The @groeneai, if a fix for that issue is already in progress, link it here. |
Related: #123368
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
FileLogreading a file that replaced another one under the same name (moved over it, or created again after a rotation renamed the old file, aslogrotatedoes) from the old file's offset when the replacement happened before the table noticed it: the new file was read twice and rows of the rotated file could be lost. A single-fileFileLogtable now reads a replaced file from its start.Description
On 26.8.2.7, a
FileLogdirectory table with a materialized view whose file is rotated bylogrotateor replaced bymvbefore the table applies the directory event loses the rows of the rotated file and reads the new file twice:Root cause:
openFilesAndSetPosseeks a file opened by name to the offset of the inode cached for that name, while a streaming round applies directory events only after reading; the path-to-inode check ran only after a failed open.Change: on every open, the file is read only if the path still leads to the inode its offset is kept for; a replaced name waits for its events to re-key it, so the new file is read once from its start and the rotated file from its offset. A name that gets no event when it leads to another file (a single-file table; on Linux, a symlink whose target was replaced) is re-keyed before the open and before
SYSTEM RESET FILELOGsets its offset, taking over the offset of a name that no longer leads there (swapped targets), and waits while one still does. A named reset fails when its name leads to a file it is not read as. Limit: a replacement before the directory watch is installed is read after its next event or a reload.Validation: the new test fails on master, passes 50/50. With rotation every 200 lines, master duplicated rows in 6 of 40 runs, the fix in none. All FileLog tests pass.
Workflow [PR]
Sync PR [sync-upstream/pr/124068]