Skip to content

add DDL propagation wait for SharedMergeTree migrations#86

Merged
alvarogar4 merged 7 commits intomainfrom
alvaro/num-6759-obsession-sharedmergetree-migration-race-condition
Mar 19, 2026
Merged

add DDL propagation wait for SharedMergeTree migrations#86
alvarogar4 merged 7 commits intomainfrom
alvaro/num-6759-obsession-sharedmergetree-migration-race-condition

Conversation

@alvarogar4
Copy link
Member

@alvarogar4 alvarogar4 commented Mar 18, 2026

Summary

  • On ClickHouse Cloud (SharedMergeTree), consecutive DDL statements in a migration could fail because table creation on one node hadn't propagated to the node handling the next statement (e.g., CREATE MATERIALIZED VIEW referencing a just-created table)
  • After each DDL statement, the migrate command now polls system.tables/system.columns to confirm propagation before proceeding
  • Extracted polling utilities from test-only e2e-testkit.ts into a new production module @chkit/clickhouse (ddl-propagation.ts)
  • Added E2E test that creates a table + SummingMergeTree target + materialized view in a single migration

Test plan

  • bun run typecheck passes for @chkit/clickhouse and chkit
  • bun run build passes for all packages
  • DDL race E2E test passes on ClickHouse Cloud via Doppler
  • Existing E2E tests still pass with Doppler credentials

🤖 Generated with Claude Code

@alvarogar4 alvarogar4 force-pushed the alvaro/num-6759-obsession-sharedmergetree-migration-race-condition branch from fc4d2c6 to 6217e17 Compare March 18, 2026 11:04
@alvarogar4 alvarogar4 changed the title fix(cli): add DDL propagation wait for SharedMergeTree migrations add DDL propagation wait for SharedMergeTree migrations Mar 18, 2026
On ClickHouse Cloud (SharedMergeTree), DDL statements acknowledged on
one node may not yet be visible on other nodes. This caused CREATE
MATERIALIZED VIEW to fail when it referenced a table created moments
earlier in the same migration.

After each DDL statement, the migrate command now polls system.tables
or system.columns to confirm the object has propagated before executing
the next statement.

- Extract polling utilities from e2e-testkit into production module
  packages/clickhouse/src/ddl-propagation.ts
- Export waitForDDLPropagation dispatcher from @chkit/clickhouse
- Add E2E test: table + MV in single migration on ClickHouse Cloud

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@alvarogar4 alvarogar4 force-pushed the alvaro/num-6759-obsession-sharedmergetree-migration-race-condition branch from 6217e17 to 036cc7d Compare March 18, 2026 11:16
): Promise<void> {
const { timeoutMs = DEFAULT_TIMEOUT_MS, intervalMs = DEFAULT_INTERVAL_MS } = options
const deadline = Date.now() + timeoutMs
while (Date.now() < deadline) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe directly use p-retry it has exponential backoff and all configurations easy in there. (and cleanaer syntax, imho)

Replace manual while-loop polling with p-retry for cleaner syntax
and built-in exponential backoff support.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@alvarogar4 alvarogar4 force-pushed the alvaro/num-6759-obsession-sharedmergetree-migration-race-condition branch from 0d918b4 to 7d15e6f Compare March 18, 2026 13:23
alvarogar4 and others added 5 commits March 19, 2026 13:04
…ing hoisted node_modules

The emitZod test symlinked packages/plugin-codegen/node_modules into a
temp dir, but zod may be hoisted to the workspace root depending on the
lockfile format and Bun version. Use require.resolve to find the actual
zod location and symlink only that package.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…uild

Zod v4 hoisted to root conflicts with Astro/Starlight which requires
zod v3. The codegen only emits `import { z } from 'zod'` — the devDep
is only used in tests and works fine with v3.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@alvarogar4 alvarogar4 merged commit 638f75f into main Mar 19, 2026
3 of 4 checks passed
@alvarogar4 alvarogar4 deleted the alvaro/num-6759-obsession-sharedmergetree-migration-race-condition branch March 19, 2026 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants