Skip to content

[server] Unify LeaderAndIsr access between CoordinatorContext and ZooKeeper #5108

Description

@swuferhong

Search before asking

  • I searched in the issues and found nothing similar.

Motivation

Description

CoordinatorContext maintains an in-memory copy of LeaderAndIsr, while ZooKeeper stores the durable coordinator state. Currently, coordinator code does not have a consistent rule for deciding which source should be used.

Some paths read LeaderAndIsr from ZooKeeper even when the same snapshot is already available in CoordinatorContext or has just been read by the caller. This adds synchronous ZooKeeper round trips on the coordinator event thread.

There is also a consistency risk in write paths. For example, updateBucketEpochAndSendRequest() currently updates CoordinatorContext before writing the new LeaderAndIsr to ZooKeeper. If the ZooKeeper write fails or has an uncertain outcome, the in-memory state may diverge from the durable state.

This was identified while reviewing the rebalance recovery changes in #3860:

#3860 (comment)

The task should define and apply a consistent access policy for LeaderAndIsr:

  • Use the current CoordinatorContext snapshot for normal coordinator processing when it is known to be current.
  • Avoid repeated ZooKeeper reads when the caller already has the required LeaderAndIsr.
  • Publish a new LeaderAndIsr to CoordinatorContext only after the corresponding ZooKeeper write is confirmed.
  • If a ZooKeeper write has an uncertain outcome, reload the durable state and reconcile CoordinatorContext before continuing.
  • Reload LeaderAndIsr from ZooKeeper during coordinator recovery or when the in-memory state cannot be trusted.
  • Prefer centralizing these rules so individual call sites do not need to decide independently between ZooKeeper and CoordinatorContext.

Regression tests should cover:

  • A confirmed ZooKeeper write updates both ZooKeeper and CoordinatorContext.
  • A failed write does not leave CoordinatorContext ahead of ZooKeeper.
  • An uncertain write outcome is reconciled from ZooKeeper.
  • Recovery rebuilds the in-memory state from the durable state.
  • Existing coordinator paths do not introduce redundant synchronous ZooKeeper reads.

This task should focus on the consistency contract and shared access pattern. The rebalance-specific removal of redundant reads remains part of #3860.

Solution

No response

Anything else?

No response

Willingness to contribute

  • I'm willing to submit a PR!

Activity

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions