Repository navigation
fix(usage): converge drifted usage columns and give new tables their TTL - #14561
Conversation
migrate() only added missing columns. A table created by an older release kept the old shape: `protocol`, `timeZone` and `weatherCode` stayed Nullable(String) after they became LowCardinality, and `accept`, `acceptLanguage` and `queryKeys` stayed without CODEC(ZSTD(3)). Columns that migrate() did add came without their codec, unlike a freshly created table. Cloud carried a bespoke task with its own ALTERs to close that gap. migrate() now reads each table's columns from system.columns. It adds the missing ones with their full definition and modifies the ones whose type or codec differs. A converged table gets no ALTER. Columns are converged before ensureIndexes() adds their skip index, because ClickHouse refuses to change the type of an indexed column. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Review complete. 🟠 1 high 💬 Inline comments (1)
🧹 Nitpicks (1) — 🟢 1 low
The change extends
Reviewed commit: 6b555e4 |
🟢 Tier S · Ready to merge
This PR makes ClickHouse usage migrations converge legacy event and gauge dimension column types and codecs, temporarily rebuilding skip indexes that cover columns being modified. Newly created event and daily tables receive the configured retention TTL, while existing tables keep their policy until Latest changes: The newest commit replaces regex-based index-expression matching with a small identifier scanner, preserving covering-index detection without using regular expressions.
📂 Walkthrough · 5
Reviewed the commits since |
Security rulesNo new WARNING or ERROR findings from security rules. 19 existing findings tracked in
|
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
Two gaps in migrate(): - ClickHouse refuses to change a column that a skip index covers (code 524, ALTER_OF_COLUMN_IS_FORBIDDEN). A table that #14553's migrate() had already indexed, such as `protocol` with `index-protocol`, aborted the convergence. migrate() now drops the indexes covering a drifted column, modifies the column, then adds the same indexes back and materializes them for existing parts. A run interrupted midway resumes on the next run. - migrate() created a missing events or daily table without the retention TTL, so a table it created grew without bound. A table migrate() creates now carries the configured TTL in its CREATE TABLE. An existing table's TTL is still never altered; only setup() changes it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The findings that requested changes are resolved. See the summary comment for what is still open.
There was a problem hiding this comment.
This PR adds schema-convergence DDL to the usage ClickHouse adapter (type/codec MODIFY COLUMN plus pending ADD COLUMN in one ALTER) with a new e2e convergence test, but the convergence ALTER can fail on legacy tables whose columns are covered by skip indexes.
Key findings
- 🟠 MODIFY COLUMN convergence fails when skip index covers column — ClickHouse.php:1441
The repository does not add regex. getSkipIndexesCovering() now splits each index expression from system.data_skipping_indices into identifiers with strspn/strcspn and compares them with the drifted columns. Co-Authored-By: Claude Opus 5.5 <[email protected]>
What does this PR do?
This closes the gaps
Usage::migrate()(#14553) left, so cloud can drop its bespoketask-patch-add-usage-events-attributes. That task opens its own ClickHouse connection and runs these ALTERs by hand.Column shapes. A table created by an older release kept its old column shapes:
protocol,timeZoneandweatherCodestayedNullable(String)after they becameLowCardinality(Nullable(String)).accept,acceptLanguageandqueryKeysstayed withoutCODEC(ZSTD(3)).migrate()added came without their codec.migrate()(and sosetup()) now reads each events and gauges table's columns fromsystem.columns. It adds missing columns with their full definition and runsMODIFY COLUMNon columns whose type or codec differs. A column the library gives no codec keeps its own. Once a table has converged,migrate()sends no ALTER.Indexed columns. ClickHouse refuses to change a column that a skip index covers (code 524,
ALTER_OF_COLUMN_IS_FORBIDDEN). That is the real state of a table #14553'smigrate()has already indexed, e.g.protocolwithindex-protocol. For each drifted column,migrate():system.data_skipping_indicesand drops the indexes covering it (DROP INDEX IF EXISTS);MODIFY COLUMN;ADD INDEX IF NOT EXISTS);MATERIALIZE INDEXso existing parts are indexed again.A run interrupted midway resumes on the next run: the column is still drifted, and
ensureIndexes()restores the library's indexes.Retention on new tables.
migrate()created a missing events or daily table without the TTL, so it grew without bound. A tablemigrate()creates now carries the configured retention TTL in itsCREATE TABLE. An existing table's TTL is still never altered bymigrate(); onlysetup()changes it. Gauges never get a TTL.Operational note: a type change schedules a ClickHouse mutation that rewrites that column, and so does materializing a restored index. Both run asynchronously. A codec change only applies to parts written or merged afterwards.
Test Plan
All E2E tests run against real ClickHouse 25.11. Each new test fails on main.
testMigrateConvergesColumnsThatPredateTheirTypeAndCodecstarts from the legacy shape with the indexes present:protocolasNullable(String)withindex-protocol(set(0)), andacceptwithout its codec but withindex-accept(bloom_filter). Aftermigrate(), both columns have converged, both indexes exist, and a furthermigrate()adds no entry tosystem.mutations. Without the fix it fails with code 524.testMigrateCreatesNewTablesWithTheRetention: with a 30-day retention,migrate()on an empty namespace creates the events and daily tables withTTL toDateTime(time) + toIntervalDay(30), and the gauges table without a TTL.testMigrateAddsMissingColumnsWithoutApplyingRetention: an existing events table with no TTL still has none aftermigrate(), while the daily table thatmigrate()creates gets the TTL.bin/monorepo check usagepasses (Pint, Rector, PHPStan).bin/monorepo test usagepasses: 112 unit and 275 E2E tests.Related PRs and Issues
PatchAddUsageEventsAttributesonce this merges.Checklist
🤖 Generated with Claude Code