Repository navigation
Add schema versioning to the TimeSeries engine and a version guard to the PromQL layer - #111204
Conversation
|
Workflow [PR], commit [f9c515d] Summary: ✅
AI ReviewSummaryThis PR adds explicit Findings❌ Blockers
Tests
Final Verdict
LLVM Coverage ReportMeasured on commit f9c515d.
Changed lines: Changed C/C++ lines covered: 214/243 (88.07%) · Uncovered code |
|
Preview deployment for your docs. Learn more about Mintlify Previews.
|
|
@vitlibar this one is ready for review. I have other PRs depending on this one, so please review this first. |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 165/179 (92.18%) · Uncovered code |
…eSeries tables The test test_prometheus_protocols/test_upgrade_from_prealpha.py failed in #111697 because tables created by older versions of ClickHouse don't have the `locality_hash` column while the read and write paths assumed it exists. The original plan was to reject such tables via the TimeSeries schema versioning (PR #111204); that dependency is dropped in favor of presence-based compatibility: - `StorageTimeSeriesSelector` generates the `(locality_hash, id) IN (...)` condition only when both the samples and the tags target tables have the column, otherwise it falls back to the previous `id IN (...)` filter; - `TimeSeriesSink` and the Prometheus remote-write protocol fill the column only if the samples table has it; - `checkTargetTable` validates the column (`UInt64` type, and the `MATERIALIZED xxHash64(metric_name)` expression in the tags table) only when the column is present. Newly created `TimeSeries` tables still always get the column because `normalizeInnerTableColumns` adds it to the inner tables at CREATE time. The new test `04628_timeseries_locality_hash_compat` covers tables without the column and the mixed cases (only samples / only tags have it). Co-Authored-By: Claude Fable 5 <[email protected]>
|
Dear @vitlibar, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
|
I'll finish this PR |
de1c178 to
82643b9
Compare
Build profile diff (arm_release)Comparing Binary sizes
The official master build is compiled with Object file sizes
|
| Object file | Master | PR | Δ |
|---|---|---|---|
src/CMakeFiles/dbms.dir/Processors/QueryPlan/Optimizations/Cascades/Rules/AggregationPushdown.cpp.o |
new | 278.38 KiB | +278.38 KiB |
src/CMakeFiles/dbms.dir/Storages/TimeSeries/TimeSeriesVersion.cpp.o |
new | 33.66 KiB | +33.66 KiB |
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.
Compile time of recompiled translation units
346 translation units recompiled, 2812 s compile time in total, 343 of them have a recent master baseline.
Translation units without a recent master baseline:
src/Processors/QueryPlan/Optimizations/Cascades/Rules/AggregationPushdown.cpp: 7.6 s
|
I reworked the TimeSeries schema versioning, changes:
|
3f30c12 to
84bfd37
Compare
84bfd37 to
88a3ed4
Compare
cf66c32 to
7ea1f5e
Compare
… the PromQL layer The TimeSeries table engine and the PromQL execution layer are under active development: the set of the target tables and their structure will change. Instead of supporting every historical schema in the PromQL layer, each TimeSeries table now stores an explicit schema version, and the PromQL layer declares the minimum version it supports. - New TimeSeries engine setting `version` (default 1, pinned forever to the pre-versioning schema). `normalizeTimeSeriesDefinition` stamps `version = TimeSeriesVersion::LATEST` into the CREATE query AST at CREATE time, so the version persists in the table metadata, in the DDL log of Replicated databases, and in backups. `SECONDARY_CREATE` keeps the initiator's value; a version newer than the latest known one is always rejected, and a primary CREATE requires the latest version. The setting cannot be changed by `ALTER`. - The PromQL layer (the `prometheusQuery`, `prometheusQueryRange` and `timeSeriesSelector` table functions, the `promql` dialect, and the Prometheus HTTP query API) checks that the version of the table is within [`TimeSeriesVersion::MIN_SUPPORTED_BY_PROMQL`, `TimeSeriesVersion::LATEST`] and otherwise throws `INCOMPATIBLE_SCHEMA` with an error asking to re-create the TimeSeries table and copy the data with an INSERT-SELECT query from the old table into the new one (or to upgrade ClickHouse when the table is newer than the server). - `StorageTimeSeries` now keeps the settings from the create query in the in-memory metadata, so `ALTER TABLE ... MODIFY SETTING` no longer drops unrelated settings (including the version pin) from the stored table definition. Co-Authored-By: Claude Fable 5 <[email protected]>
Fixes found by an adversarial review of the previous commit: - RESTORE: `compareRestoredTableDef` now treats a definition stamped with the initial version and a definition without the `version` setting as the same definition, so a backup made before versioning was introduced can be restored into a re-created (stamped) table and vice versa. - ON CLUSTER: hosts executing a distributed DDL entry run with mode `CREATE` (only Replicated databases use `SECONDARY_CREATE`), so the strict "new tables must have the latest version" check now exempts replays detected via `is_ddl_or_on_cluster_internal`, mirroring `already_normalized_on_initiator` in `InterpreterCreateQuery`. Without this a rolling upgrade would break `CREATE ... ON CLUSTER` after a version bump. - Fail close on writes and alters: `INSERT`, the Prometheus remote-write protocol, and `ALTER` now reject a table whose version is newer than the latest version known to the server - an older server must not modify data which only a newer server understands. Reads were already rejected. - `ALTER ... RESET SETTING` which removes the last override is now persisted: the rebuilt SETTINGS clause pins the `version` setting to stay non-empty, because `applyMetadataChangesToCreateQuery` does not replace the stored clause with an empty list and the reset would silently revert on restart. - Duplicate entries in a stored SETTINGS clause are collapsed (last one wins) when copied into the metadata, so ALTER no longer resolves settings to a stale duplicate. - `version = 0` is now rejected at CREATE and at replays of prepared queries, and the CREATE-time rejection explains the case when the version was copied by the `AS other_table` clause (where "omit the setting" is not actionable). - The Prometheus HTTP query API reports the version-guard rejection as HTTP 500 with `errorType` "internal" instead of 400 "bad_data", so clients don't attribute it to the PromQL expression. Co-Authored-By: Claude Fable 5 <[email protected]>
7ea1f5e to
f9c515d
Compare
| /// With an old DDL entry format the query is shipped un-normalized, so hosts running different releases | ||
| /// of ClickHouse would pin different latest versions. Pin the initiator's one here, like the UUIDs above. | ||
| /// A query with an AS clause is left alone: the hosts take the settings, including the version, from the other table. | ||
| if (create.is_time_series_table && create.as_table.empty() && !hasExplicitTimeSeriesSettingVersion(create)) |
There was a problem hiding this comment.
version is not the only TimeSeries default that later gets frozen into metadata. normalizeTimeSeriesDefinition also pins recent_samples_ttl_seconds when it is omitted, but this helper only runs when version itself is missing. With distributed_ddl_entry_format_version < NORMALIZE_CREATE_ON_INITIATOR_VERSION, a mixed-version CREATE ... ON CLUSTER that specifies version but omits recent_samples_ttl_seconds will still let each worker freeze its own default TTL, so the same DDL can produce different RECENT SAMPLES retention and layout across hosts.
Please either fully normalize TimeSeries CREATE queries on the initiator for the old entry format, or pin recent_samples_ttl_seconds here alongside version.
PromQL Compliance ReportBaseline: S3 master
Note: score is unchanged vs baseline. |
The
TimeSeriestable engine and the PromQL execution layer are under active development: the set of the target tables and their structure will change. Instead of supporting every historical schema in the PromQL layer, eachTimeSeriestable now stores an explicit schema version in the newversionengine setting, stamped into the CREATE query when the table is created and persisted in the table metadata. The PromQL layer declares the minimum version it supports (TimeSeriesVersion::MIN_SUPPORTED_BY_PROMQL); queries over older tables are rejected with an error asking to re-create theTimeSeriestable and copy the data with anINSERT-SELECTquery from the old table into the new one. Tables newer than the server (possible after a downgrade) can still be attached and dropped, but reads, writes (INSERT, Prometheus remote write) andALTERare rejected with an error asking to upgrade ClickHouse.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
TimeSeriestables now store an explicit schema version in theversionengine setting. The PromQL execution layer supports only a declared range of versions and rejects queries over tables outside that range with an instructive error.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/111204]
Version info
26.9.1.788(included in26.9and later)