Skip to content

[server] Do not send unpersisted LeaderAndIsr after ISR removal fails - #5481

Open
mcgrj wants to merge 2 commits into
apache:mainfrom
mcgrj:server-unpersisted-leaderandisr
Open

mcgrj wants to merge 2 commits into
apache:mainfrom
mcgrj:server-unpersisted-leaderandisr

Conversation

@mcgrj

@mcgrj mcgrj commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Generative AI disclosure: Yes. Prepared with Grok Bot.

Generated-by: Grok Bot following the guidelines

Purpose

Linked issue: close #5478

When a fenced coordinator takes a replica out of the ISR, ReplicaStateMachine#doRemoveReplicaFromIsr fails to write the new LeaderAndIsr to ZooKeeper but still returns it, so it is sent to the tablet servers. They then hold an epoch that ZooKeeper never stored and reject the next coordinator's NotifyLeaderAndIsr as stale.

Brief change log

  • doRemoveReplicaFromIsr returns an empty map when batchUpdateLeaderAndIsr fails, so only persisted state is sent. TableBucketStateMachine already aborts the same way on a fenced write.
  • CoordinatorEventProcessor#updateBucketEpochAndSendRequest stops before sending when its write throws, so it is left as is. Its cache ordering is covered by [server] Unify LeaderAndIsr access between CoordinatorContext and ZooKeeper #5108.

Tests

  • ReplicaStateMachineTest#testFencedIsrRemovalIsNotSentToTabletServers fences the coordinator, takes a replica offline, and checks that ZooKeeper and the coordinator cache keep the original LeaderAndIsr and that no NotifyLeaderAndIsr is sent. It fails without the change.

API and Format

None.

Documentation

None.

mcgrj added 2 commits December 3, 2026 08:21
When a replica goes offline, ReplicaStateMachine removes it from the ISR
in ZooKeeper and notifies the remaining replicas. If the ZooKeeper batch
update fails, for example with BadVersion because a newer coordinator has
fenced this one, the error was logged and the unsaved LeaderAndIsr was
still sent to the tablet servers. The tablet servers then held a bucket
epoch that ZooKeeper never stored, so the next coordinator's
NotifyLeaderAndIsr was rejected as stale and the replica marked offline.

Return no adjusted LeaderAndIsr when the update fails, as the leader
election paths in TableBucketStateMachine already do.

Generated-by: Grok Bot
Generated-by: Grok Bot
LOG.error("Fail to batch update bucket LeaderAndIsr.", e);
}
return adjustedLeaderAndIsr;
return Collections.emptyMap();

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.

Returning an empty map makes sense when the ZooKeeper transaction fails without committing any updates. How do we recover if only some batches commit?

batchUpdateLeaderAndIsr uses a separate ZooKeeper transaction for each batch of up to 1,024 buckets. If the first batch commits and the second fails, returning an empty map here means the coordinator neither updates its cache nor notifies the TabletServers about the buckets that were already committed. What reconciles those buckets after the failure? Could we add a test that commits the first batch, fails the second, and verifies the recovery path? The new test only covers a single bucket.

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.

[server] Coordinator sends tablet servers a LeaderAndIsr it failed to write to ZooKeeper

2 participants