You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kafka.apache.org by ch...@apache.org on 2025/03/04 07:42:57 UTC

(kafka) branch 3.9 updated: KAFKA-18844 Stale features information in QuorumController#registerBroker (#19058)

This is an automated email from the ASF dual-hosted git repository.

chia7712 pushed a commit to branch 3.9
in repository https://gitbox.apache.org/repos/asf/kafka.git


The following commit(s) were added to refs/heads/3.9 by this push:
     new 1ec1043d519 KAFKA-18844 Stale features information in QuorumController#registerBroker (#19058)
1ec1043d519 is described below

commit 1ec1043d5197c4f807fa5cbc41d875b289443096
Author: PoAn Yang <pa...@apache.org>
AuthorDate: Tue Mar 4 15:42:51 2025 +0800

    KAFKA-18844 Stale features information in QuorumController#registerBroker (#19058)
    
    In #16848, we added `kraft.version` to finalized features and got finalized features outside controller event handling thread. This may make finalized features stale when processing `registerBroker` event. Also, some cases like `QuorumControllerTest.testBalancePartitionLeaders` become flaky cause of outdated MV. This PR moves finalized features back to controller event handling thread to avoid the error.
    
    Reviewers: Ismael Juma <ij...@apache.org>, Jun Rao <ju...@gmail.com>, Colin P. McCabe <cm...@apache.org>, Chia-Ping Tsai <ch...@gmail.com>
---
 .../main/java/org/apache/kafka/controller/QuorumController.java    | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/metadata/src/main/java/org/apache/kafka/controller/QuorumController.java b/metadata/src/main/java/org/apache/kafka/controller/QuorumController.java
index 1fe995dddd6..c2a92a43318 100644
--- a/metadata/src/main/java/org/apache/kafka/controller/QuorumController.java
+++ b/metadata/src/main/java/org/apache/kafka/controller/QuorumController.java
@@ -2251,11 +2251,12 @@ public final class QuorumController implements Controller {
         ControllerRequestContext context,
         BrokerRegistrationRequestData request
     ) {
-        // populate finalized features map with latest known kraft version for validation
-        Map<String, Short> controllerFeatures = new HashMap<>(featureControl.finalizedFeatures(Long.MAX_VALUE).featureMap());
-        controllerFeatures.put(KRaftVersion.FEATURE_NAME, raftClient.kraftVersion().featureLevel());
         return appendWriteEvent("registerBroker", context.deadlineNs(),
             () -> {
+                // Read and write data in the controller event handling thread to avoid stale information.
+                Map<String, Short> controllerFeatures = new HashMap<>(featureControl.finalizedFeatures(Long.MAX_VALUE).featureMap());
+                // Populate finalized features map with latest known kraft version for validation.
+                controllerFeatures.put(KRaftVersion.FEATURE_NAME, raftClient.kraftVersion().featureLevel());
                 ControllerResult<BrokerRegistrationReply> result = clusterControl.
                     registerBroker(request, offsetControl.nextWriteOffset(),
                         new FinalizedControllerFeatures(controllerFeatures, Long.MAX_VALUE));