Skip to content

Shard unavailable during reconciliation #1704

Closed

Description

@cw9

Description

We encountered an incident of losing all replicas in a shard during a roll, which led to query failures (or partial data returned when skip_unavailable_shards was enabled). Here's a detailed breakdown of the events:

  1. A deployment updated the ClickHouse Operator (CHOP) with a config change.
  2. CHOP began rolling the CHI: chi-foo-1.
  3. It successfully rolled chi-foo-1-0-0-0 and moved on to chi-foo-1-0-1-0.
  4. chi-foo-1-0-1-0 was brought down as part of the roll.
  5. A Kubernetes node drain event occurred, causing CHOP to be rescheduled to a new node.
  6. CHOP re-evaluated the CHI and decided to restart the roll.
  7. It began rolling chi-foo-1-0-0-0 again, even though chi-foo-1-0-1-0 was still down.
  8. As a result, both replicas were temporarily unavailable.
  9. During this window, ClickHouse queries either failed or returned partial results due to both replicas being down.
  10. Once chi-foo-1-0-0-0 came back online, queries recovered.
  11. CHOP then brought up chi-foo-1-0-1-0.

Expected Behavior

  • CHOP should ensure at least one replica remains available during a CHI roll, even if it is rescheduled or interrupted.
  • CHOP should try to bring the cluster back to a steady state before proceeding with the rollout of a new configuration—specifically, it should bring up all missing replicas from the previous state before continuing to roll out the new version.

Environment

  • CHOP version: 0.24.2
  • ClickHouse version: 25.3

Questions

We would appreciate guidance on how this situation could be handled more gracefully by CHOP. Specifically:

  • Is there a recommended mechanism to ensure the cluster reaches a steady state before continuing with a rollout?
  • Could CHOP implement safeguards to prevent simultaneous downtime of all replicas, particularly in scenarios involving operator rescheduling or external interruptions like node drains?
  • Are there any existing patterns or features we could leverage to enforce this behavior today?

We’re potentially interested in contributing a fix or enhancement for this issue. If the maintainers agree that improving this behavior makes sense, we’d be happy to discuss possible approaches or take on an implementation with some guidance.

Activity

  1. added
    research required
    planned
    on Feb 19, 2026
  2. sunsingerus commented on Feb 19, 2026

    @sunsingerus
    Collaborator

    Thank you for the detailed incident report — this is a real and well-understood gap in the operator's rolling reconciliation logic. We've confirmed the root cause in the code.

    What is happening

    There are two separate gaps that combine to produce this incident:

    Gap 1 — No steady-state recovery on operator restart

    When the operator restarts, it uses generation equality to decide whether to reconcile:

    • If the CHI spec has not changed (generation is the same) and the operator restarted within ~1 minute → isCleanRestart() returns true → reconciliation is skipped entirely
    • If the CHI spec has not changed and the restart is after ~1 minute → isGenerationTheSame() returns true → reconciliation is also skipped

    In both cases the operator considers the cluster to already be in the desired state, even if a host is actually stuck mid-roll and still down. There is no "are all hosts actually healthy?" health check on startup.

    Gap 2 — No pre-exclusion shard health check

    shouldExcludeHost() (worker-wait-exclude-include-restart.go) only decides whether the current host needs to be rolled — it never checks whether other replicas in the same shard are currently healthy. So when reconciliation restarts from host-0-0 while host-0-1 is still down, nothing prevents excluding host-0-0 and causing simultaneous downtime of all replicas.

    Failure paths

    Depending on timing after the operator reschedule, one of three outcomes occurs:

    Scenario Outcome
    Restarts within 1 min, generation unchanged isCleanRestart() → skip → host-0-1 stays down
    Restarts after 1 min, generation unchanged isGenerationTheSame() → skip → host-0-1 stays down
    Operator triggers full re-reconcile Re-rolls from host-0-0 while host-0-1 still down → both replicas down

    Planned fixes

    We plan to address this with two complementary changes:

    1. Steady-state health check on startup: On operator restart, before deciding to skip reconciliation, verify that all hosts in the CHI are actually running and healthy. If any host is down or in a degraded state, trigger a targeted recovery reconcile rather than skipping.

    2. Pre-exclusion shard quorum check: Before excluding a host for rolling, verify that all other replicas in the same shard are currently up and ready. If another replica is already down, block the exclusion until the shard reaches a healthy state.

    If you'd like to contribute

    We welcome contributions on this. The two key files to modify are:

    • pkg/controller/chi/worker-status-helpers.go — isCleanRestart() / isGenerationTheSame() — add a post-restart health sweep
    • pkg/controller/chi/worker-wait-exclude-include-restart.go — shouldExcludeHost() — add shard quorum check before excluding

    Please open a draft PR and we can discuss the approach before full implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugplannedresearch required

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions