Skip to content

Drop ClickHouse query condition cache on every replica after restore - #130

Merged
viliakov merged 2 commits into
mainfrom
clickhouse-drop-query-condition-cache
Nov 9, 2026
Merged

viliakov merged 2 commits into
mainfrom
clickhouse-drop-query-condition-cache

Conversation

@viliakov

@viliakov viliakov commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Post-restore SQL now runs SYSTEM DROP MARK CACHE and SYSTEM DROP QUERY CONDITION CACHE with ON CLUSTER default. Before this change the SQL reached only the pod behind the port-forward, and the query condition cache was never dropped. That stale cache made the traces migrator re-run V1 DDL after a restore.

Both statements are always attempted, so a replica that is down cannot stop the query condition cache from being dropped on the others. If either fails, the warning lists the statements to run by hand. Failures stay non-fatal so that workloads are still scaled back up.

ClickHouse older than 25.3 has no query condition cache and rejects that statement as a syntax error. The CLI skips the statement in that case instead of logging a misleading warning.

Reviewer check: this assumes the chart's default cluster and ZooKeeper are always present. That holds for the current and older suse-observability charts.

Validated with unit tests, lint, and live runs against a two-replica 26.8 cluster (caches emptied on both replicas) and a 24.12 server (statement skipped).

Fixes #129

🤖 Generated with Claude Code

A restored table keeps its UUID and part names, so ClickHouse 25.3+ can
answer filtered queries from a query condition cache entry recorded before
the restore. The traces migrator then sees otel_migrations as empty, re-runs
V1 DDL and crash-loops.

The service port-forward reaches only one pod, so the existing mark-cache
drop never covered the other replicas. Both drops now run ON CLUSTER
default, the cluster the chart always defines. Servers older than 25.3 have
no query condition cache and reject the statement as a syntax error; that
case alone is skipped.

Verified against a two-replica 26.8 cluster (both replicas' caches emptied)
and a clustered 24.12 server (statement skipped, restore continues).

Co-Authored-By: Claude Code <noreply@anthropic.com>

@ai-collaboration-app ai-collaboration-app Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Narrow, well-tested fix. Native-protocol *proto.Exception matching, skip scoped to the query condition cache only, and the default cluster + ZooKeeper assumption holds for the current chart (ZooKeeper isn't scaled down during a ClickHouse restore).

One change requested inline. Also worth considering: finalizeRestore (line 141) only warns on post-restore SQL failure. That's pre-existing, but these statements now decide whether traces work after restore, so the warning should say so and give the manual command (SYSTEM DROP QUERY CONDITION CACHE ON CLUSTER default). Not fatal: that would leave workloads scaled down.

Nit: the description says the skip lets older-chart restores still finish. They'd finish anyway since SQL errors only warn; the skip avoids a misleading warning.

Comment thread cmd/clickhouse/check_and_finalize.go Resolved
ON CLUSTER makes the mark cache drop fail when any replica is unreachable
(distributed DDL timeout). Returning on that first error skipped the query
condition cache drop even on healthy replicas, and because finalizeRestore
only warns, the CLI reported success while the traces initializer
crash-looped. Each statement is now attempted and the failures are joined.

The warning now says what stale caches break and lists the statements to
run by hand. A failure stays non-fatal so workloads are still scaled up.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@viliakov

viliakov commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Addressed in 64a1eb0:

  • Every post-restore statement is attempted, and the failures are combined (inline thread).
  • The finalizeRestore warning now says that stale caches can make traces migrations re-run, and lists the statements to run by hand. It stays non-fatal.
  • Description updated: the version skip avoids a misleading warning; it isn't what lets restores finish.

@ai-collaboration-app ai-collaboration-app Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, 64a1eb0 addresses everything: both drops are always attempted, the errors are joined, the timeout case is tested, and the warning names the consequence and the manual fix.

Optional nit: the manual-fix list always includes SYSTEM DROP QUERY CONDITION CACHE, which would hit a syntax error on servers older than 25.3. Fine to leave as is.

@viliakov
viliakov merged commit 5d989b5 into main Nov 9, 2026
6 checks passed
@viliakov
viliakov deleted the clickhouse-drop-query-condition-cache branch November 9, 2026 11:58
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.

ClickHouse restore: stale query condition cache makes traces migrations re-run

2 participants