Symptom
After a Helm upgrade that bumps the ClickHouse server image version, the chart-managed ClickHouse pod restarts mid-upgrade. On restart, ClickHouse fails to attach one or more core tables (runs, runs_tags, runs_token_counts, runs_lite, runs_topk_hourly_agg), logging something like:
Code: 231. DB::Exception: Suspiciously many (<N> parts, <size> in total) broken parts to remove while maximum allowed broken parts count is 100 ... Cannot attach table `default`.<table>
This is followed by load-job failures (ASYNC_LOAD_WAIT_FAILED, Code 722/695) on tables that depend on the one that failed to attach. Since runs is the core trace table, this takes down both trace ingestion and trace querying cluster-wide, and the LangSmith UI shows "Service temporarily unavailable".
If the upgrade was run with helm upgrade --atomic and a short --timeout, the upgrade can also time out and fail to roll back cleanly if ClickHouse doesn't come back up in time.
Cause
The chart-managed ClickHouse StatefulSet defaults to a 30-second terminationGracePeriodSeconds. ClickHouse also runs inserts in async mode by default (async_insert=1, wait_for_async_insert=0): a write is acknowledged to the client before it's durably flushed to disk as a part, which improves throughput.
If the ClickHouse pod is restarted (for example when a new image is rolled out, or when an atomic Helm upgrade times out and triggers a rollback) before it can flush its async-insert buffers within the grace period, in-flight parts are left on disk with invalid checksums. On the next startup, ClickHouse's checksum validation flags these as broken parts. ClickHouse normally removes broken parts automatically, but as a safety mechanism it refuses to attach a table once its broken-part count exceeds max_suspicious_broken_parts (default 100), to avoid silently discarding data. Once that threshold is exceeded on any of the affected tables, the whole table fails to attach.
A short --timeout combined with --atomic on helm upgrade compounds this: if the upgrade doesn't complete in time, Helm triggers a rollback, which can restart ClickHouse again mid-recovery and time out again.
Downgrading the ClickHouse server version is not a safe recovery path once the new version has attached its tables and started writing in the new format: an older ClickHouse version is not guaranteed to read data written by a newer one. Downgrading is only safe if the new version never actually attached its tables, meaning it never wrote any data in the new format.
Resolution
To get ClickHouse running and traces flowing again, raise max_suspicious_broken_parts above the broken-parts count reported in the logs. Mount a ConfigMap into ClickHouse's config.d directory using the chart's clickhouse.statefulSet.volumes / clickhouse.statefulSet.volumeMounts values:
apiVersion: v1
kind: ConfigMap
metadata:
name: clickhouse-broken-parts
data:
broken_parts.xml: |
<clickhouse>
<merge_tree>
<max_suspicious_broken_parts>500</max_suspicious_broken_parts>
</merge_tree>
</clickhouse>
mounted to /etc/clickhouse-server/config.d/broken_parts.xml. Pick a value comfortably above the broken-parts count across all affected tables, since the count can differ per table.
Once the tables attach, broken parts are moved to detached/, not deleted. Inspect what was set aside with:
SELECT table, count(), sum(bytes_on_disk)
FROM system.detached_parts
GROUP BY table;
Don't downgrade ClickHouse back to the prior version as a recovery step once the new version has attached tables and started writing. Downgrading is only safe if the new version never attached.
The max_suspicious_broken_parts override is temporary: remove it once the environment is stable on the new ClickHouse version, so the safety threshold returns to its default.
Preventing recurrence on version-changing ClickHouse upgrades
Raise the ClickHouse StatefulSet's terminationGracePeriodSeconds (default 30s) to a higher value, for example 120s, via clickhouse.statefulSet.terminationGracePeriodSeconds, and keep it raised permanently. The default is too short for ClickHouse to flush async inserts cleanly on restart.
Avoid --atomic with a short --timeout on a helm upgrade that changes the ClickHouse server version. A timed-out atomic upgrade triggers a rollback that can itself restart ClickHouse mid-upgrade. Use a long --timeout instead.
For upgrades that change the ClickHouse server version specifically (not every routine chart upgrade), treat it as a one-way operation:
Pause ingestion before the upgrade by scaling the ingest-queue deployment to 0 replicas.
Snapshot the ClickHouse PVC/volume before starting.
Run the upgrade in a maintenance window.
Traces queued during the pause are retried from the queue for a bounded retry window (on the order of a couple of hours) after the first failure. Runs whose inserts were already acknowledged by ClickHouse before it went down are not retried, since the queue already considers them delivered.
Routine chart upgrades that don't change the ClickHouse version don't need the pause/snapshot/maintenance-window steps. The raised grace period should stay permanent; the raised max_suspicious_broken_parts override and the pause/snapshot steps are only needed around a ClickHouse-version-changing upgrade.