Skip to content

Do not throw a logical error when StorageKafka2 is not active - #113913

Merged
alexey-milovidov merged 2 commits into
masterfrom
kafka2-assert-active-not-logical-error
Aug 9, 2026
Merged

alexey-milovidov merged 2 commits into
masterfrom
kafka2-assert-active-not-logical-error

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Aug 8, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Kafka tables with Keeper-stored offsets (kafka_keeper_path) now throw ABORTED instead of LOGICAL_ERROR when the table becomes inactive after a Keeper session loss (e.g. during a direct read or materialized-view streaming).

StorageKafka2::assertActive threw LOGICAL_ERROR when the table is not active. But the table legitimately becomes inactive at any moment when the Keeper session expires and partialShutdown runs, racing with direct reads (Kafka2Source::generateImpl calls getZooKeeperAndAssertActive) and with the materialized-view streaming task. So an inactive table on these paths is an expected runtime condition, not a bug — the code even carried a TODO(antaljanosbenjamin): change LOGICAL_ERROR to something sensible.

In debug and sanitizer builds a LOGICAL_ERROR aborts the server, and this surfaced in the stress test as Logical error: Table is not active (replica path: A):
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112788&sha=ba3438849a503d92dd66f6b64e89ff66c29bf6cc&name_0=PR&name_1=Stress%20test%20%28amd_debug%29

Throw ABORTED instead, consistent with the neighboring Table is detached exception in the same file.

A focused regression test, test_storage_kafka/test_keeper_session_loss_direct_read.py, forces a Keeper session loss (network partition), waits until partialShutdown has run and reactivation keeps failing, then runs a direct SELECT and asserts it fails with ABORTED instead of a logical error.

Related: #112788

`StorageKafka2::assertActive` threw `LOGICAL_ERROR` when the table is
not active, but the table legitimately becomes inactive whenever the
Keeper session expires and `partialShutdown` runs, racing with direct
reads (`Kafka2Source::generateImpl`) and materialized-view streaming.
In debug and sanitizer builds this aborts the server and shows up in
the stress test as `Logical error: Table is not active (replica path: A)`.
Throw `ABORTED` instead, resolving the old TODO.

Seen in: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112788&sha=ba3438849a503d92dd66f6b64e89ff66c29bf6cc&name_0=PR&name_1=Stress%20test%20%28amd_debug%29
Related PR: #112788

Co-Authored-By: Claude Fable 5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [325b020]

Summary: ✅


AI Review

Summary

This PR changes StorageKafka2::assertActive to throw ABORTED instead of LOGICAL_ERROR when a Keeper-backed Kafka table becomes inactive after session loss, and adds a deterministic direct-read regression for that path. I did not find a remaining code-level problem in the helper or its direct-read / MV-streaming callers, but the PR metadata currently classifies an experimental surface as a stable-release bug fix.

PR Metadata
  • Changelog category: incorrect. Keeper-stored Kafka offsets still require allow_experimental_kafka_offsets_storage_in_keeper = 1 and are documented as experimental, so Bug Fix (user-visible misbehavior in an official stable release) is not the right category here. Replace it with Improvement.
  • Changelog entry: required for Improvement, and the current text is specific, user-readable, and accurate enough as-is.
Missing context / blind spots
  • ⚠️ The only Praktika report attached when I reviewed this PR was Build profile diff; no integration-test report was available, so I validated the new regression coverage by code inspection rather than CI results.
Final Verdict

✅ No code blockers found. Change the Changelog category to Improvement, then this looks ready.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.60% 86.60% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 78.80% 78.80% +0.00%

Changed lines: Changed C/C++ lines covered: 2/2 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Aug 8, 2026
Comment thread src/Storages/Kafka/StorageKafka2.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

No arm_release build profile data for commit 325b020 - the build was skipped, reused from cache, or predates profile upload.

The test drops the Keeper connections, waits until `partialShutdown` has run and
reactivation keeps failing, then runs a direct `SELECT` and asserts it fails with
`ABORTED` (`Code: 236`) instead of a logical error that would abort the server in
debug and sanitizer builds.

Co-Authored-By: Claude Fable 5 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default and removed pr-ci labels Aug 8, 2026
Comment thread src/Storages/Kafka/StorageKafka2.cpp Resolved

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

LGTM

@alexey-milovidov alexey-milovidov self-assigned this Aug 9, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 9, 2026
Merged via the queue into master with commit 6ab5466 Aug 9, 2026
180 checks passed
@alexey-milovidov
alexey-milovidov deleted the kafka2-assert-active-not-logical-error branch August 9, 2026 19:57
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 9, 2026
@antaljanosbenjamin

Copy link
Copy Markdown
Member

@alexey-milovidov the new test is flaky. Could you please take a look at it?

pull Bot pushed a commit to sonvt1710/ClickHouse that referenced this pull request Sep 23, 2026
…e else

zkutil::ZooKeeper::deleteEphemeralNodeIfContentMatches waits for a contended
ephemeral to disappear and threw LOGICAL_ERROR on timeout. That condition is
expected runtime state rather than a broken invariant:

  * another live server may legitimately hold the node, which is the whole
    reason the content predicate exists;
  * the wait can be shorter than the holder's session. Keeper removes a dead
    session's ephemerals only at session expiry, and the timeout negotiated
    during the handshake is stored in Coordination::ZooKeeper's own args copy
    and never propagated to zkutil::ZooKeeper::args, which is the object this
    wait reads. The message already names this case and then classified it as
    a logical error anyway.

LOGICAL_ERROR calls abortOnFailedAssertion from the Exception constructor
under DEBUG_OR_SANITIZER_BUILD, i.e. before unwinding, so a caller-side catch
cannot prevent the abort and the fix has to be at the shared site. Raise
ABORTED instead. The message, the wait and the control flow are unchanged, so
the operation still fails and activation still refuses to proceed rather than
assuming ownership.

This follows ClickHouse#113913, which chose ABORTED for the sibling condition in
StorageKafka2::assertActive. That covered the direct-read path; this is the
activation path. All six call sites (StorageKafka2, the MergeTree restarting
thread, two in DatabaseReplicatedWorker and two in DDLWorker) already treat a
failed activation as retryable and none of them branches on the error code.

Verified in both directions with a TestKeeper gtest, and end-to-end against a
live server through ReplicatedMergeTreeRestartingThread, where the previous
code terminated the server and the new code reports ABORTED, retries with
backoff and leaves the replica read-only.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants