Repository navigation
Add SYSTEM RESET FILELOG to read the files of a FileLog table again or skip them - #123545
Conversation
…r skip them SYSTEM RESET FILELOG [ON CLUSTER c] [db.]table [FILE 'name' [OFFSET n | TO END]] changes where a FileLog table continues reading without recreating it: every file from the beginning, one file from the beginning or from byte n, or one file only from data appended after the command. Until now the only way to re-read or skip was to drop and recreate the table (and its views, grants and comments). StorageFileLog::resetReadPosition applies pending directory events first (as makePipe does), then writes the new offset of each affected file to its meta file and only then changes the in-memory meta and marks the file UPDATED, so the next round reopens and seeks it. It takes file_infos_mutex, so it runs between background rounds, and refuses while a direct SELECT has sources alive (running_streams > 0), because those sources use file_infos without the mutex. serialize() gets allow_lower_offset, because it otherwise refuses to store an offset smaller than the stored one (checkOffsetIsValid); the meta file is replaced through a temporary file and a rename, so a failed write leaves both the old meta file and the in-memory offset unchanged, and a crash leaves either the old or the new offset on disk. Afterwards the background thread is woken (a directory table streaming to views waits for a directory event) and the task is scheduled (a single-file table, or a table on the reschedule path, sleeps until its next poll, up to poll_directory_watch_events_backoff_max), so an idle table that streams to materialized views re-reads at once. The interpreter resolves the TableProxy stand-in of a lazily loaded table (lazy_load_tables) to its FileLog storage before the type check. New TABLE-level privilege SYSTEM RESET FILELOG (child of SYSTEM), like the engine-specific SYSTEM FLUSH OBJECT STORAGE QUEUE: rewinding or skipping offsets re-inserts or drops data, which is a different risk class than the start/stop/pause controls behind SYSTEM STREAMING ENGINES. 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; 5 rounds, 9 findings, the last round clean) plus my own review (5 rounds).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-10:20261002-133100 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-40:20261002-124200 |
|
Workflow [PR], commit [d267846] Summary: ✅
AI ReviewSummaryThis PR adds Final Verdict
LLVM Coverage ReportMeasured on commit d267846.
Changed lines: Changed C/C++ lines covered: 161/186 (86.56%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes17 object files changed (+37.92 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 units541 translation units recompiled, 3709 s compile time in total, 541 of them have a recent master baseline. |
The FileLog reset fields grew sizeof(ASTSystemQuery) from 976 to 1032 bytes, which moved every SYSTEM query AST from jemalloc's 1024-byte size class to 1280 (Parser memory check: `SYSTEM FLUSH LOGS` +256 bytes). Placing the `TO END` flag in the padding after the other bool members brings it to 1024 bytes on x86_64 and aarch64. Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov
left a comment
There was a problem hiding this comment.
Thanks! Good implementation.
The merge-queue `Style check` (`storage_casts` leg) rejects a `dynamic_cast` to a deferrable storage engine on a catalog pointer. The statement names the table, so `castStorage<StorageFileLog>(..., DeferredTable::Load)` loads a lazy `StorageTableProxy` exactly like the previous `unwrapStorageProxy` did, and the lazily loaded table arm of 05316_file_log_system_reset still passes. The duplicate `StorageProxy.h` include is dropped: master now includes it unconditionally. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
I fixed the merge-queue |
Write the new meta files of all target files to temporary paths first and only publish them (rename and update the in-memory offsets) after every write succeeded. A failed write, e.g. on a full metadata disk, now leaves the whole table at its old position instead of rewinding a subset of files. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The benchmark looked each row's group up in a constant array, `groups[number % 4096 + 1]`. About half of its CPU went to that lookup (`arrayElement` over a constant array copies row by row through a virtual `insertFrom`), not to the sampling-key code the test measures. On arm some builds run that loop about twice as slow in every server process: in the job profiles of the slow runs on ClickHouse#98708, ClickHouse#116376, ClickHouse#117754, ClickHouse#123545 and ClickHouse#123188 only that frame grew (x1.4 to x2.2) while every other frame stayed flat, so the query moved 20-27% and the confirmation restart reproduced it. The per-query tags collector numbers groups 0, 1, 2, ... with 0 reserved for the empty tag set (`ContextTimeSeriesTagsCollector.h`), so the 4096 groups the subquery creates are 1..4096 and the query can pass `number % length(groups) + 1` directly. `length(groups)` keeps the scalar subquery referenced: without it the analyzer drops the subquery, no group is registered and the function throws `Group 1 is out of bounds`. Checked on x86 with an official master build: the same keys over the 20M rows (`sum` and `groupBitXor` equal, 0 rows differ), 84 -> 52 ms, and the per-process medians of 24 processes span 79-91 ms before and 52-53 ms after. 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):
Added
SYSTEM RESET FILELOG [db.]table [FILE 'file_name' [OFFSET n | TO END]]: aFileLogtable reads all its files again from the beginning, or one file from the beginning, from a given offset, or only from data appended after the command, without recreating the table. Requires the newSYSTEM RESET FILELOGprivilege.Description
Part of "Recovery without recreating the table" in #123368: re-reading a
FileLogtable's files, or skipping a file or part of it, needed recreating the table with its views and grants.FILE: every file is read again from offset 0;FILE 'name'(as in_filename): that file from 0, from byten(at most the file size), or, withTO END, only data appended later;StorageFileLog::resetReadPositionruns underfile_infos_mutex(after a running round), applies pending directory events, writes each affected file's new offset to its meta file (temporary file + rename, before memory), marks the file for reopening and wakes or schedules the background task, so a table streaming to views re-reads at once. During a directSELECTit fails withQUERY_NOT_ALLOWED.New TABLE-level privilege
SYSTEM RESET FILELOG, likeSYSTEM FLUSH OBJECT STORAGE QUEUE: re-reading or skipping inserts or drops data, unlike the start/stop controls ofSYSTEM STREAMING ENGINES. I can reuseSYSTEM STREAMING ENGINESif you prefer.Recovering by itself once the cause is gone comes from the other #123368 PRs (#123395, #123404, #123390; per-file isolation to come). Until #123395 merges, a table already stuck with "Another select query is running" also gets
QUERY_NOT_ALLOWEDhere.Validation: the new test fails on master with
SYNTAX_ERRORand passes 50/50 with randomized settings. It covers every form, the errors, persistence acrossDETACH/ATTACH, materialized views over a directory and one file, a lazily loaded table, and both privilege checks; removing the wake-up, the schedule, the offset write or a privilege check turns it red. By hand: a reset during a running round returns once it ends.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/123545]
Version info
26.10.1.1506-master(included in26.10and later)