Repository navigation
Count only active replicas when distributing Kafka partition locks in StorageKafka2 - #120111
Conversation
|
Hi @antaljanosbenjamin, would you mind taking a look at this one when you have a moment? It's a small improve in StorageKafka2: partition locks were distributed by counting all replicas znodes, but since those are persistent they outlive a dead replica, so a replica that lost its Keeper session would still be counted and some partitions could stop being consumed. The count now comes from the ephemeral is_active node instead. Thanks! |
|
Workflow [PR], commit [c907f34] Summary: ❌
AI ReviewSummaryThis PR changes Final Verdict✅ No new findings. LLVM Coverage ReportMeasured on commit c907f34.
Changed lines: Changed C/C++ lines covered: 32/32 (100.00%) · Uncovered code |
…ment The previous version of `test_inactive_replica_not_counted` created the dead replica znode only after `r1` had already acquired all four permanent locks. `prepareToPoll` keeps an existing assignment for `LOCKS_REFRESH_POLLS` polls, so the pre-fix code could consume the whole test workload without ever re-running `getActiveReplicasInfo`, and the test passed without exercising the broken path. Now the materialized view is attached only after the ghost replica exists, so the very first lock assignment has to decide whether to count a replica without an `is_active` node. Without the fix the node quota would be `num_partitions / 2`, so `r1` could never own the whole lock set. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…balance-consumption
…ghost replica The bot review pointed out that `getActiveReplicasInfo` now has a distinct `shard_count > 0` branch, but the new regression only exercised `shard_count == 0`. Add `test_inactive_replica_not_counted_with_shard_affinity`: a same-shard replica znode without `is_active` (plus a live replica of another shard) is created before the first lock assignment, and the live replica must still own every partition of its own shard. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…balance-consumption
The keeper client rejects `create <path> ''` with `Syntax error at position 0`; only the existence of `is_active` matters, so write a placeholder value. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…balance-consumption
|
🕵 @groeneai, the only red on this PR was |
… ones `getActiveReplicasInfo` clamped the active replica count to 1 when the `is_active` probe found no live replica at all. As pointed out in review, that count can only be zero if our own registration is gone from Keeper: `StorageKafka2::activate` creates `replicas/<name>/is_active` before the reader tasks are started and `partialShutdown` only removes it after they have been stopped, and `prepareToPoll` returns `KeeperSessionEnded` before reaching here when the session is expired. Defaulting to 1 made this replica keep claiming a full quota of partition locks while every peer left it out of its own quota, which hid the broken Keeper state instead of surfacing it. Throw `ABORTED` instead - the same "replica is not active" outcome that `StorageKafka2::assertActive` produces - so the failure is logged by the streaming task and the periodic activation check can re-register the replica. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Build profile diff (arm_release)Commit See the job log for details. |
|
🕵 @groeneai, the only red on this PR is
It looks like it is already being handled by #121163 ( |
|
Confirmed: #121163 is the right fix, and #121144 (the revert of #118423) is not needed for this red. The test is mine (#120898). Three of its expected lines pinned, through a full #121163 finished its CI green: 05227 is OK in both |
…er session The payload `StorageKafka2` stores in its `replicas/<self>/is_active` node (`active_node_identifier`) is readable from Keeper, so another client can delete the node and re-create it as its own ephemeral node with the same bytes. Both liveness checks then still took the node for our registration and the replica kept consuming while the peers counted the foreign client under its name; once the real session died later, the replica stayed counted as live and the quota bug this PR fixes came back. Ownership is now proven by the session, which cannot be replayed: `KeeperHandlingConsumer::getActiveReplicasInfo` and `StorageKafka2::isReplicaRegistrationValid` require `stat.ephemeralOwner == getClientID()` of the shared session on top of the payload, the same check `ZooKeeperLock::isLocked` uses. `activate` applies the same rule when it decides whether the node holder may remove the node, and the re-registration step no longer fast-deletes a same-payload node of a foreign live session: `StorageKafka2` remembers the session that created its latest node (`own_is_active_session_id`, kept across `partialShutdown` and the retries with backoff), so only a leftover of that session or a node of the current one is removed by payload and everything else is reported as `REPLICA_IS_ALREADY_ACTIVE`. Before the first registration of the process the payload is all there is to go by, as for every other replicated storage. New test `test_replayed_is_active_payload_triggers_reactivation` replaces our node with a node of a kazoo session carrying our own payload and requires the locks to be released while the foreign node is left in place, then the re-registration with a node of our own session once the foreign one ends. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…ion, never to the path or payload The reactivation path in `StorageKafka2::activate` validated `replicas/<self>/is_active` (payload and owner session) and then still removed it by path or by payload alone: the old `EphemeralNodeHolder` dropped by `partialShutdown` removes whatever node is at its path, and `deleteEphemeralNodeIfContentMatches` removes any node whose payload matches `active_node_identifier`. A node that another Keeper client created between the check and either removal was therefore deleted and this replica registered over it, which is exactly the split-brain the ownership checks are meant to prevent. Now the old holder is always marked as already removed in the registration-lost branch, and the node is removed there only when it is ours and only with `tryRemove(path, version)` of the version that was validated (`ZBADVERSION` leaves it in place). The leftover removal in `activate_in_keeper` is version-bound the same way, and a `ZBADVERSION` there reports `REPLICA_IS_ALREADY_ACTIVE` so the retry with backoff waits for the foreign node to disappear. Two pauseable failpoints, `kafka2_activate_pause_before_partial_shutdown` and `kafka2_activate_pause_before_is_active_removal`, sit right after the respective checks. The new integration tests pause there, plant a foreign ephemeral node with the replica's own payload, resume, and require the planted node to survive with its original owner session while the locks are released, and the replica to re-register only once the foreign session is closed. Co-Authored-By: Claude Fable 5.1 <[email protected]>
antaljanosbenjamin
left a comment
There was a problem hiding this comment.
I think this is way too complex. Count is_active should be fine, but all the rest seems too complex or I don't understand something.
Handling a non ephemeral is_active is super unnecessary. Please simplify the PR.
|
@alexey-milovidov could you please get rid of the changes that you introduced and blew up PR by completely unnecessary complexity? Fixing cases when there is not active replica and when |
…balance-consumption
…e the `releaseLocks` thread-safety comment precise Per the maintainer's review, a persistent `is_active` node is not a case worth handling: `KeeperHandlingConsumer::getActiveReplicasInfo` no longer skips markers with `ephemeralOwner == 0`, `StorageKafka2::isReplicaRegistrationValid` no longer treats them as a broken registration (the owner-session check already does not accept them as ours), and `restoreReplicaRegistration` no longer removes them. The test `test_persistent_is_active_marker_not_counted` is removed with the feature. The comment on `KeeperHandlingConsumer::releaseLocks` now states exactly which state is protected by `topic_partition_locks_mutex`, which is not, and from where the method may therefore be called. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
🕵 Thanks @antaljanosbenjamin. Two things are done in 5962fa5: the handling of a non-ephemeral On "the rest is too complex": agreed, the PR has grown far beyond the counting change. Everything beyond it was added in response to the automated review, and each layer can be dropped independently. This is the inventory, so you can say which ones to keep and I will strip the rest, tests included (cc @JingYanchao as the author):
My suggestion would be to keep 1 and 2 and drop 3, 4 and 5. Layer 2 is what makes layer 1 safe to ship; the rest guards against Keeper state edited from outside the server. I will leave the code as it is until you say which layers to remove, since stripping is quick but the choice is yours. |
…balance-consumption
The Kafka code owner asked to remove the layers added on top of the original change, which had grown to cover Keeper state edited from outside the server. This drops all of them and leaves only the fix in `KeeperHandlingConsumer::getActiveReplicasInfo`: count a replica for the partition-lock quota only when its `replicas/<name>/is_active` node exists, so a dead replica that left its persistent `replicas/<name>` znode behind no longer takes a share of the partitions. Removed: the `ReplicaNotActive` poll outcome and the reactivation of the table when its own `is_active` node is missing, the release of the partition locks on that path, the repair of the `replicas/<self>` znode and its shard number, the Keeper-session and payload ownership checks on `is_active` with the version-bound removals, the two pauseable failpoints, the `ABORTED` on direct reads, the reactivation on `KeeperSessionEnded`, and the integration tests for all of the above. The count is clamped to 1 so a transiently missing own `is_active` node cannot divide by zero in `updatePermanentLocksLocked`. The two regression tests for the counting change stay: `test_inactive_replica_not_counted` and `test_inactive_replica_not_counted_with_shard_affinity`. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
🕵 Done in 1411f18, @antaljanosbenjamin. Everything beyond the counting change is removed: the What is left is the diff against |
|
🕵 @groeneai, investigate the failure: Performance Comparison (arm_release, master_head, 3/6) - The AI Review blockers re-ask for the ownership checks and the fail-closed reactivation path; these were removed on purpose at the request of the |
|
Investigated. Not attributable to this PR, and it is covered by #121189 (mine, open). #121090 does not cover it on its own, and the reason is specific enough to be worth stating. What failed the shard. Only the dashboard arm. Why the query was published as slower. This shard judged every query against the bare floors, because the learned per-query thresholds were never fetched: All 550
What the learned bar would have been. Running That is also why the query is spread so widely: its own 99th-percentile Coverage.
So no new PR from me. #121189 is the one that clears this red, and it is still open and unreviewed. |
8ab8ab5
|
Closing the loop on the abstention I said I would add: #121189 was closed in favour of #121847, which takes the threshold-fetch timeout fix and the workflow warnings but not the abstention, so a fetch that still fails judges the shard on the bare floors, now with a warning attached. I measured what that costs before re-raising it, and it is less than when you asked. The only wired perf jobs are The |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
StorageKafka2now counts only live replicas when distributing partition locks, so a replica that lost its Keeper session no longer leaves some partitions unconsumed.Description
StorageKafka2(the Keeper-based Kafka engine) splits partition locks across replicas by dividing the partition count by the number of replicas. It counted every znode underreplicas, but those are persistent and outlive a dead replica. After a replica lost its Keeper session, its znode remained, so survivors kept dividing the quota by a count that included dead replicas, and some partitions were never locked or consumed.The count now comes from the ephemeral
is_activenode, so only live replicas are counted.Workflow [PR]
Sync PR [sync-upstream/pr/120111]
Version info
26.10.1.551-master(included in26.10and later)