Skip to content

fix(inkless:metadata): prefer controller leader for managed replicas - #898

Open
jeqo wants to merge 3 commits into
mainfrom
jeqo/metadata-response-controller-leader
Open

jeqo wants to merge 3 commits into
mainfrom
jeqo/metadata-response-controller-leader

Conversation

@jeqo

@jeqo jeqo commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

For managed-replica diskless partitions, InklessTopicMetadataTransformer previously hashed over candidate replicas to pick the client-facing leader. Clients and tooling without an AZ saw the hash result instead of KRaft leadership, so preferred leader elections had no visible effect and leadership-skew checks reported the hash distribution.

With managed replicas, KRaft already distributes replicas across racks and balances leadership through preferred leader election. Preferring the controller leader whenever it is in the candidate replica set aligns metadata responses with KRaft leadership while keeping deterministic hash fallback when the controller leader isn't an eligible candidate.

Commits

  • fe5638d4ca fix(inkless:metadata): prefer controller leader for managed replicas
  • db32802697 test(inkless:kafkatest): pin follower rack in DeleteRecords tests
  • ef8b816be5 docs(inkless): document controller-leader preference for managed replicas

See the commit messages for the reasoning behind each step.

Operator impact

  • Clients and tooling without an AZ receive the KRaft controller leader for managed-replica and tiered diskless partitions, so preferred leader elections take effect and leadership-skew checks reflect actual leadership.
  • AZ-aware clients continue to route to same-AZ replicas; non-replica fallbacks and untiered RF=1 partitions keep hash-based selection.
  • No configuration or metric changes.

Test plan

  • InklessTopicMetadataTransformerTest: covers null AZ for Metadata and DescribeTopicPartitions (tiered and diskless-only), fallback to hash when the controller leader is offline, -1, or outside the ISR during a local-prefix switch, cross-AZ fallback with an alive controller leader, and same-AZ selection with multiple replicas in the client AZ.
  • DeleteRecordsAcrossTiersTest (consolidation_delete_records_across_tiers_test.py): pins diskless_az to a follower's rack via per-broker broker.rack overrides so both test_delete_records_follower_read_guard (pre-KIP-392 and modern consumers) and DisklessDeleteRecordsForwarder in test_delete_records_across_tiers keep exercising the follower paths. Verified locally with ducker-ak: both tests passed (2/2), with DisklessDeleteRecordsForwarder forwarding DELETE_RECORDS from the pinned follower to the leader and both consumer generations running against the pinned follower rack.

jeqo added 2 commits November 25, 2026 12:57
For managed-replica diskless partitions (RF > 1, tiered partitions at
any RF, and switched partitions with a local classic prefix),
`InklessTopicMetadataTransformer` previously selected the client-facing
leader by hashing across candidate replicas. That hash came from the
unmanaged RF=1 design, where no real replica assignment existed to
balance load across brokers.

With managed replicas, KRaft already places replicas across racks and
balances leadership through preferred leader election. Hashing masked
the controller leader from clients and tooling without an AZ, so
preferred leader elections had no visible effect and leadership-skew
checks saw the hash distribution instead of KRaft leadership.

Pass `partition.leaderId()` into `selectLeaderForManagedReplicas` for
both `Metadata` and `DescribeTopicPartitions` responses, and select it
whenever it is in the candidate replica set (same-AZ replicas or
cross-AZ alive eligible replicas). When the controller leader isn't a
candidate (such as when it is in another AZ, offline, absent, or
outside the ISR during a local-prefix switch), fall back to
`selectByHash` for deterministic routing and cache locality. Non-replica
fallbacks and the untiered RF=1 path stay unchanged.

Assisted-by: Gemini 4 Neon
`DeleteRecordsAcrossTiersTest` previously ran with no `broker.rack`
and no `diskless_az`, relying on hash-based leader selection to route
clients to a follower. Because clients without an AZ now receive the
controller leader, both the follower read guard test and
`DeleteRecords` forwarding would land on the real KRaft leader and stop
exercising the follower paths.

Assign a distinct `broker.rack` to each broker in
`DeleteRecordsAcrossTiersTest`, add optional `client_id` and
`consumer_properties` hooks in `ConsolidationVerifier`, and pin
`diskless_az` to a follower's rack for the follower read guard
consumers (old and modern) and for cross-tier `DeleteRecords`. Update
the test docstrings to match.

Assisted-by: Gemini 4 Neon

Copilot AI left a comment

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.

🟡 Changes recommended

The documentation omits the same-AZ non-replica fallback for untiered managed replicas without a local-only classic prefix, incorrectly implying that cross-AZ controller-leader routing is considered first.

1 open issue
What changed in this PR

This PR aligns client-facing metadata for managed-replica diskless partitions with KRaft leadership while preserving availability-zone routing and deterministic hash fallbacks.

Changes:

  • Prefer the controller-selected partition leader when it belongs to the eligible candidate set.
  • Add leader-selection coverage and pin DeleteRecords system tests to follower racks.
  • Update routing documentation and comments to describe the new preference.
File Description
tests/​kafkatest/​tests/​inkless/​inkless_topic_switch_test.py Clarify the leader-lookup helper’s docstring.
tests/​kafkatest/​tests/​inkless/​consolidation_delete_records_across_tiers_test.py Pin clients to follower racks to preserve follower-path coverage.
tests/​kafkatest/​services/​inkless/​consolidation_verifier.py Add client configuration options for follower routing.
storage/​inkless/​src/​test/​java/​io/​aiven/​inkless/​metadata/​InklessTopicMetadataTransformerTest.java Cover leader preference, AZ locality, and fallback cases.
storage/​inkless/​src/​main/​java/​io/​aiven/​inkless/​metadata/​InklessTopicMetadataTransformer.java Prefer the controller-selected leader within candidate replicas.
docs/​inkless/​DISKLESS_CONSOLIDATION.md Update routing and forwarding-authorization guidance.
docs/​inkless/​CLIENT-BROKER-AZ-ALIGNMENT.md Describe leader preference and hash-based fallbacks.
core/​src/​main/​scala/​kafka/​server/​DisklessDeleteRecordsForwarder.scala Update comments explaining when requests reach followers.

Review effort: Balanced

…icas

Update the AZ-alignment guide, consolidation guide, and
`DisklessDeleteRecordsForwarder` comment to reflect that
`InklessTopicMetadataTransformer` prefers the controller leader within
the chosen replica set and routes to a follower only when an AZ-aware
client stays on a same-AZ follower or the controller leader isn't an
eligible candidate.

Assisted-by: Gemini 4 Neon
@jeqo
jeqo force-pushed the jeqo/metadata-response-controller-leader branch from ef8b816 to 411dc0c Compare November 25, 2026 11:45
@jeqo
jeqo requested a balanced review from Copilot November 25, 2026 11:45

Copilot AI left a comment

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.

🟢 Approval recommended

No active review issues block approval of the metadata-routing change.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@jeqo
jeqo marked this pull request as ready for review November 25, 2026 12:31
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.

2 participants