Repository navigation
fix(usage): migrate the usage schema without touching retention - #14553
Conversation
A release that adds a usage column, such as `ordinal`, only reached a deployment through `setup()`, and `setup()` also re-applies the events and daily TTL. A deployment that wraps its usage connection could not run it at all: `Connection::setup()` returned early for `Connection::fromUsage()`, so the `usage-setup` task reported the schema ready without running DDL, and the events INSERT failed on the missing column. - `Usage::migrate()` creates and upgrades the schema (tables, daily view, columns, skip indexes, projections) and leaves the TTL alone. `setup()` is `migrate()` followed by the retention TTL. Adapters inherit a `migrate()` that runs `setup()`, so third-party adapters keep working. - `Connection::setup()` applies the schema on a wrapped connection too. A wrapped connection still skips the lazy readiness health check. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`Accumulator::flush()` passed the whole buffer to one `addBatch()` call. The adapter inserts it in chunks of 1,000, so when a later chunk failed the exception left every entry buffered, and the next flush inserted the chunks that had already been written a second time. The accumulator now writes one batch per `addBatch()` call and drops each batch from the buffer as soon as it is written. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Review complete. No issues found — approved ✅. This PR evolves
No findings met the review threshold; the verified candidates were below the confidence cutoff or informational only. Reviewed commit: f837b65 |
Security rulesNo new WARNING or ERROR findings from security rules. 19 existing findings tracked in
|
🟢 Tier S · Ready to merge
This change separates ClickHouse schema migration from retention setup, exposes migration through the usage API, and lets wrapped usage connections apply their schema. It also flushes accumulator entries in 1,000-item batches and removes successful batches from the buffer immediately.
📂 Walkthrough · 10
Reviewed |
✨ 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]>
What does this PR do?
Fixes two usage bugs at their source, both found on cloud (appwrite-labs/cloud#6554): every usage events INSERT failed with
Code: 16 ... No such column ordinal, and the workaround there patched the table from the worker at runtime.Schema migration
ordinal) only reached a deployment throughUsage::setup(), which also re-applies the events and daily retention TTL. So rolling out a column meant applying a TTL nobody had reviewed.Connection::setup()returned early forConnection::fromUsage(), sousage-setupprinted "ClickHouse schemas are ready" and ran no DDL.Changes:
Usage::migrate()creates and upgrades the schema (tables, daily view, columns, skip indexes, projections) and leaves the TTL alone.setup()is nowmigrate()followed by the retention TTL. Adapters inherit amigrate()that runssetup(), so third-party adapters still work. The ClickHouse adapter overrides it.Connection::setup()now applies the schema on a wrapped connection too. A wrapped connection still skips the lazy readiness health check.Accumulator double write
Accumulator::flush()passed the whole buffer to oneaddBatch()call. The adapter inserts in chunks of 1,000, so if a later chunk failed, every entry stayed buffered and the next flush wrote the earlier chunks again. The accumulator now sends one batch peraddBatch()call and removes each batch from the buffer once it is written.Test Plan
ClickHouseSchemaTest::testMigrateAddsMissingColumnsWithoutApplyingRetention(E2E, real ClickHouse) starts from a legacy events table with no dimension columns and no TTL, using an adapter configured with a 30-day retention. Aftermigrate(), every event column (includingordinal) exists, neither the events table nor the daily table has a TTL, and an insert with anordinaltag succeeds. A followingsetup()then applies the TTL to both tables.AccumulatorTest::testRetryAfterAFailedBatchWritesEveryEntryOncebuffers 2,500 entries and fails the second batch. Only the first batch leaves the buffer, and after the retry each of the 2,500 entries has been written exactly once. Without the fix it fails: all 2,500 stay buffered and the first 1,000 are written twice.Tests\Unit\Usage\ConnectionTest::testSetupAppliesTheSchemaThroughAWrappedConnectionfails on main (the setup count is 0) and passes here.testWrappedConnectionIsReadyWithoutAHealthCheckcovers the wrapped behaviour this PR keeps.bin/monorepo check usagepasses (Pint, Rector, PHPStan), andbin/monorepo test usagepasses (unit 112 tests, E2E 273 tests on ClickHouse 25.11 and MariaDB). Pint and PHPStan pass on the server files.Related PRs and Issues
migrate()from its usage setup task in place of the worker's runtime schema repair.Checklist
🤖 Generated with Claude Code