Repository navigation
Mark old system log tables as readonly - #95079
alexey-milovidov merged 43 commits into
Conversation
|
Workflow [PR], commit [34e3def] Summary: ✅
AI ReviewSummaryThis PR marks rotated non-replicated Missing context / blind spots
Final VerdictStatus: ✅ Approve No new inline findings. Normal CI completion remains the only open validation dependency I saw. |
cb5fc23 to
4954f0e
Compare
When system log tables are renamed during log rotation (e.g., query_log -> query_log_0), mark them as readonly to prevent wasting CPU time on background operations. Implementation: 1. Add new 'read_only' MergeTree setting 2. Check this setting in StorageMergeTree::assertNotReadonly() 3. At startup, treat table as readonly if setting is enabled (similar to readonly disks) 4. Set read_only=1 via ALTER TABLE after renaming system log tables
9bb22ca to
88ee720
Compare
|
Should be ready for review |
…nly and avoid variable reuse
…th session-level readonly setting
…rom session-level readonly)
|
The tests have failed due to an assertion violation. The failures are related to these changes. |
…stem-logs-readonly Co-authored-by: Cursor <[email protected]> # Conflicts: # src/Storages/MergeTree/MergeTreeSettings.cpp
|
Let's add a test for the new |
…y`, move to 26.2 - Rename MergeTree setting from `table_is_readonly` to `table_readonly` - Move settings history entry from 26.1 to 26.2 - Allow ALTER MODIFY SETTING / RESET SETTING through even when the table is readonly, so the setting can be toggled back - Add stateless test for the `table_readonly` setting Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
Continued this PR: implemented the two outstanding AI-review Majors (the inline threads are now resolved) and tightened the changelog entry. Pushed AI review — AI review — background path still scanned merge candidates for read-only tables ( Changelog entry ✅ tightened to "Mark rotated non-replicated CI — the two reds are known, master-wide, and unrelated to this PR (no overlap with the system-log / MergeTree-scheduling code):
Note: @alexey-milovidov's |
A `table_readonly` table (the MergeTree setting used e.g. for rotated system log tables) must not receive new parts. The source-side gate in `MergeTreeData::alterPartition` only rejects `MOVE PARTITION ... TO TABLE` when the *source* is read-only, because the command is dispatched through the source table. When the source is writable and only the destination is read-only, the gate does not fire and `StorageMergeTree::movePartitionToTable` clones parts into the read-only destination, violating the invariant. Add a destination-side `assertNotReadonly` check in `StorageMergeTree::movePartitionToTable`, alongside the existing destination-side `UNIQUE KEY` reject, before any parts are cloned. The symmetric `REPLACE PARTITION ... FROM` command is already covered, because it is dispatched through the destination table, whose `table_readonly` is caught by the existing source-side gate. New test `04491_table_readonly_move_partition_to_table`. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Continued this PR: implemented the outstanding AI-review Major (the AI review / Cursor Bugbot —
The symmetric New test Note: @alexey-milovidov's |
…iption
Address review (AI Review Major / `clickhouse-gh` thread): the registered
`table_readonly` setting text was written for the original foreground-only
behavior ("Any attempts to insert data or modify the table will fail") and
never updated after this PR broadened the setting to suppress all on-disk
work.
The description now states that a `table_readonly` table performs no
modifications on disk at all: besides rejecting inserts/mutations/`OPTIMIZE`
and the data-mutating partition commands (including `MOVE PARTITION ... TO
TABLE` into the table), it also schedules no background merges, TTL merges
(`DELETE`/`MOVE`/recompression), recompression merges, background mutations,
or background part moves. In particular it spells out the operationally
important consequence that a table with a TTL stops reclaiming or moving
expired data while the setting is enabled, lists the read-only operations
that remain allowed (`FREEZE`/`UNFREEZE`, `FORGET PARTITION`), and notes that
the setting can be toggled back and is unsupported on `ReplicatedMergeTree`.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Continued this PR: implemented the remaining AI-review Major (the only outstanding item) and resolved its inline thread. Pushed AI review — expanded The registered
This is a documentation-only change (a Note: @alexey-milovidov's |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 107/116 (92.24%) · Uncovered code |
| and background part moves are all suppressed. As a consequence, a table with a TTL no longer reclaims or moves its expired data while this setting | ||
| is enabled. | ||
|
|
||
| The setting can always be toggled back with `ALTER TABLE ... MODIFY SETTING table_readonly = 0` (or `RESET SETTING`). It is not supported for `ReplicatedMergeTree`. |
There was a problem hiding this comment.
As a follow-up for this PR, we should note that:
- a table still can be dropped;
- a table can refresh its data parts (refresh_parts_interval);
There was a problem hiding this comment.
@groeneai, do this follow-up (documentation edit + validation).
alexey-milovidov
left a comment
There was a problem hiding this comment.
LGTM.
The new table_readonly setting is the main delivery in this PR.
Marking system tables as readonly became just a "proof" of this feature.
|
Hi @matt-metivier @alexey-milovidov — while reviewing this PR I found the following:
Could you review the test PR and add the |
| /// If true, the table is read-only (the `table_readonly` MergeTree setting): no merges of any kind run — | ||
| /// neither regular merges, nor recompression, nor TTL drop/delete merges. (Tables with a TTL are never | ||
| /// marked read-only, so no TTL work is stranded; see `SystemLog::prepareTable`.) | ||
| const bool readonly = false; |
There was a problem hiding this comment.
This breaks abstractions; it should not be a compaction part; it must be implemented at the table level, not in the merge selection algorithm.
|
Hello! Is this going to be applied to all rotated tables "left behind"? |
`SystemLog::prepareTable` now runs `ALTER TABLE ... MODIFY SETTING table_readonly = 1` on the rotated `system.*_log_N` table when it detects a schema mismatch. The setting is persisted into the rotated table's `.sql` metadata as `SETTINGS index_granularity = 8192, table_readonly = true`. `table_readonly` is a MergeTree setting that was introduced in 26.3 (`v26.3.1.896-lts`). Releases older than 26.3 do not know it, so when `MergeTreeSettingsImpl::loadFromQuery` parses the rotated metadata on those binaries it throws `UNKNOWN_SETTING` and the server refuses to start with `Cannot attach table ... from metadata file ...`. This is the cause of the `restart_with_original_version`-style failures across `test_implicit_index_upgrade`, `test_index_filename_upgrade`, `test_manipulate_statistics::test_statistics_upgrade_from_old_version`, `test_storage_s3_queue/test_migration` and `test_topk_alpha_map_compatibility` on this PR. Per maintainer direction (ClickHouse#95079 (comment)), bump the older-binary image tag in each affected compatibility test to `26.3`, which is the first release that knows `table_readonly` and can therefore re-attach a rotated system log table after downgrade.
…d cover forced merges The test inserted a "fresh" row with `d = today()` under `TTL d + INTERVAL 1 DAY`. The flaky check runs tests with a randomized `session_timezone`, so `today()` can be one day behind the server date (all CI failures had UTC-7 zones during the early UTC morning), making the fresh row already expired and dropping both parts: `TTL drop on readonly: FAIL (remaining rows: 0)`. Use a one-month TTL margin so a one-day timezone skew in either direction cannot expire the fresh part. Also set `min_age_to_force_merge_seconds = 1` and `min_age_to_force_merge_on_partition_only = 1` on the read-only table so the test covers the `getBestPartitionToOptimizeEntire` fallback, which previously bypassed `table_readonly`. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=95079&sha=be4ee0351a4bd6efab08e358c4787718db94f420&name_0=PR&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20flaky%20check%29 PR: ClickHouse#95079 Co-Authored-By: Claude Fable 5 <[email protected]>
A read-only table (the `table_readonly` MergeTree setting, used for rotated system log tables) already skips regular merges, mutations, and recompression, but it could still schedule background part moves between volumes/disks (the storage policy `move_factor` or `TTL ... TO DISK/VOLUME` rules). A rotated system log table on a multi-volume storage policy therefore kept wasting background CPU and I/O, which did not match the "no background operations on rotated log tables" contract. Guard `MergeTreeData::scheduleDataMovingJob` on `table_readonly`: it is the sole driver of the background move-selection path (the no-argument `selectPartsForMove` is called only from there), so a read-only table now never schedules a move. Explicit `ALTER TABLE ... MOVE` commands remain rejected separately by `assertNotReadonly`. Add `04341_table_readonly_background_moves`: a writable control table proves the background move pool is actively making progress while the read-only table keeps its part on the original (local) volume. Addresses the AI review feedback on ClickHouse#95079 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Most system logs in the default open-source `clickhouse-server` config have no TTL (the `<ttl>` for `query_log`, `trace_log`, etc. is commented out in `programs/server/config.xml`); only a few (`processors_profile_log`, `asynchronous_insert_log`, `blob_storage_log`, `aggregated_zookeeper_log`, `zookeeper_connection_log`) carry one. The comment in `SystemLog::prepareTable` wrongly claimed that most system logs use a default `30 DAY` TTL. Correct it so it reflects that the common case (`query_log` and friends) is frozen as readonly after rotation, and only the few TTL-configured logs stay writable. ClickHouse#95079 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…-system-logs-readonly Mark old system log tables as readonly
|
This breaks backward compatibility. Is it possible to disable this feature? |
When system log tables are renamed during log rotation (e.g.,
query_log→query_log_0), mark the rotated table as read-only to stop wasting background CPU and I/O on it.Changes
table_readonlyMergeTree setting — when set totrue, the table performs no modifications on disk and no background work: inserts, mutations,OPTIMIZE, and explicit partition commands (DROP/MOVE/ATTACH/REPLACE/FETCH PARTITION) are rejected, and no background merges (regular, recompression, or TTL), mutations, or part moves are scheduled or even scanned for. The setting can always be toggled back viaALTER ... MODIFY/RESET SETTING.StorageMergeTree::assertNotReadonlyrejects writes/mutations/OPTIMIZE;MergeTreeData::alterPartitionrejects mutating partition commands; background scheduling (scheduleDataProcessingJob/scheduleDataMovingJob,MergeTreeDataMergerMutator::selectPartsToMerge) bails out before any candidate scan.SystemLog::prepareTable— after renaming an obsolete log table, marks it withtable_readonly = 1. Replicated tables and tables carrying a TTL are intentionally skipped (a TTL-bearing table must keep reclaiming disk;table_readonlyis unsupported onReplicatedMergeTree). TheALTERis best-effort and wrapped so it can never lose in-flight log data.Closes #94628
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Mark rotated non-replicated
MergeTreesystem log tables without TTL astable_readonlyto avoid unnecessary background operations. Thetable_readonlyMergeTreesetting now also suppresses all background work on a plainMergeTreetable — regular, TTL (DELETE/MOVE/recompression) and recompression merges, background mutations, and background part moves — and rejects the mutating partition commands (ATTACH/MOVE/DROP/DROP DETACHED/FETCH/REPLACE PARTITIONandMOVE PARTITION ... TO TABLEinto the table), in addition to the inserts, mutations, andOPTIMIZEit already rejected. As a result, atable_readonlytable with a TTL no longer reclaims its expired data while the setting is enabled.Documentation entry for user-facing changes
No user-facing documentation required. This is an internal optimization that happens automatically during system log rotation.
Note
Medium Risk
Adds an automatic
ALTER TABLE ... MODIFY SETTING table_readonly=1after system log rotation, introducing additional DDL execution duringSystemLog::prepareTable()that could surface permission/setting-related failures or edge cases around non-MergeTree/absent tables.Overview
When
SystemLog::prepareTable()detects an obsolete log table and renames it (e.g.,query_log->query_log_N), it now also marks the renamed table as read-only for MergeTree-backed logs to avoid unnecessary background work.This is implemented by constructing and executing an
ALTER TABLE ... MODIFY SETTING table_readonly = 1viaInterpreterAlterQueryimmediately after the rename, with new parser/interpreter includes to support building theALTERAST.Reviewed by Cursor Bugbot for commit 89e40c5. Bugbot is set up for automated code reviews on this repo. Configure here.
Version info
26.7.1.294(included in26.7and later)