You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kafka.apache.org by cm...@apache.org on 2024/09/13 16:18:59 UTC
(kafka) branch 3.9 updated: KAFKA-16468: verify that migrating brokers provide their inter.broker.listener (#17159)
This is an automated email from the ASF dual-hosted git repository.
cmccabe 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 7d3ba8a0eb8 KAFKA-16468: verify that migrating brokers provide their inter.broker.listener (#17159)
7d3ba8a0eb8 is described below
commit 7d3ba8a0eb85ea67f02bc0ac3af7fc20a150be8a
Author: Colin Patrick McCabe <cm...@apache.org>
AuthorDate: Fri Sep 13 09:18:24 2024 -0700
KAFKA-16468: verify that migrating brokers provide their inter.broker.listener (#17159)
When brokers undergoing ZK migration register with the controller, it should verify that they have
provided a way to contact them via their inter.broker.listener. Otherwise the migration will fail
later on with a more confusing error message.
Reviewers: David Arthur <mu...@gmail.com>
---
.../main/scala/kafka/server/ControllerServer.scala | 1 +
.../server/BrokerRegistrationRequestTest.scala | 8 ++++++
.../kafka/controller/ClusterControlManager.java | 25 +++++++++++++++++--
.../apache/kafka/controller/QuorumController.java | 13 ++++++++--
.../controller/ClusterControlManagerTest.java | 29 ++++++++++++++++++++++
5 files changed, 72 insertions(+), 4 deletions(-)
diff --git a/core/src/main/scala/kafka/server/ControllerServer.scala b/core/src/main/scala/kafka/server/ControllerServer.scala
index 0e4321cffb3..0905215f9a2 100644
--- a/core/src/main/scala/kafka/server/ControllerServer.scala
+++ b/core/src/main/scala/kafka/server/ControllerServer.scala
@@ -266,6 +266,7 @@ class ControllerServer(
setDelegationTokenExpiryTimeMs(config.delegationTokenExpiryTimeMs).
setDelegationTokenExpiryCheckIntervalMs(config.delegationTokenExpiryCheckIntervalMs).
setUncleanLeaderElectionCheckIntervalMs(config.uncleanLeaderElectionCheckIntervalMs).
+ setInterBrokerListenerName(config.interBrokerListenerName.value()).
setEligibleLeaderReplicasEnabled(config.elrEnabled)
}
controller = controllerBuilder.build()
diff --git a/core/src/test/scala/unit/kafka/server/BrokerRegistrationRequestTest.scala b/core/src/test/scala/unit/kafka/server/BrokerRegistrationRequestTest.scala
index 18625fd1a61..f3e481ebe3f 100644
--- a/core/src/test/scala/unit/kafka/server/BrokerRegistrationRequestTest.scala
+++ b/core/src/test/scala/unit/kafka/server/BrokerRegistrationRequestTest.scala
@@ -37,6 +37,7 @@ import org.junit.jupiter.api.Assertions.{assertEquals, assertThrows}
import org.junit.jupiter.api.Timeout
import org.junit.jupiter.api.extension.ExtendWith
+import java.util
import java.util.Collections
import java.util.concurrent.{CompletableFuture, TimeUnit, TimeoutException}
@@ -122,6 +123,13 @@ class BrokerRegistrationRequestTest {
.setIncarnationId(Uuid.randomUuid())
.setIsMigratingZkBroker(zkEpoch.isDefined)
.setFeatures(features)
+ .setListeners(new BrokerRegistrationRequestData.ListenerCollection(util.Arrays.asList(
+ new BrokerRegistrationRequestData.Listener().
+ setName("EXTERNAL").
+ setHost("example.com").
+ setPort(8082).
+ setSecurityProtocol(SecurityProtocol.PLAINTEXT.id))
+ .iterator()))
val resp = sendAndReceive[BrokerRegistrationRequest, BrokerRegistrationResponse](
channelManager, new BrokerRegistrationRequest.Builder(req), 30000)
diff --git a/metadata/src/main/java/org/apache/kafka/controller/ClusterControlManager.java b/metadata/src/main/java/org/apache/kafka/controller/ClusterControlManager.java
index 77ffd1036be..b0b43f05a4c 100644
--- a/metadata/src/main/java/org/apache/kafka/controller/ClusterControlManager.java
+++ b/metadata/src/main/java/org/apache/kafka/controller/ClusterControlManager.java
@@ -93,6 +93,7 @@ public class ClusterControlManager {
private FeatureControlManager featureControl = null;
private boolean zkMigrationEnabled = false;
private BrokerUncleanShutdownHandler brokerUncleanShutdownHandler = null;
+ private String interBrokerListenerName = "PLAINTEXT";
Builder setLogContext(LogContext logContext) {
this.logContext = logContext;
@@ -139,6 +140,11 @@ public class ClusterControlManager {
return this;
}
+ Builder setInterBrokerListenerName(String interBrokerListenerName) {
+ this.interBrokerListenerName = interBrokerListenerName;
+ return this;
+ }
+
ClusterControlManager build() {
if (logContext == null) {
logContext = new LogContext();
@@ -166,7 +172,8 @@ public class ClusterControlManager {
replicaPlacer,
featureControl,
zkMigrationEnabled,
- brokerUncleanShutdownHandler
+ brokerUncleanShutdownHandler,
+ interBrokerListenerName
);
}
}
@@ -260,6 +267,11 @@ public class ClusterControlManager {
private final BrokerUncleanShutdownHandler brokerUncleanShutdownHandler;
+ /**
+ * The statically configured inter-broker listener name.
+ */
+ private final String interBrokerListenerName;
+
/**
* Maps controller IDs to controller registrations.
*/
@@ -279,7 +291,8 @@ public class ClusterControlManager {
ReplicaPlacer replicaPlacer,
FeatureControlManager featureControl,
boolean zkMigrationEnabled,
- BrokerUncleanShutdownHandler brokerUncleanShutdownHandler
+ BrokerUncleanShutdownHandler brokerUncleanShutdownHandler,
+ String interBrokerListenerName
) {
this.logContext = logContext;
this.clusterId = clusterId;
@@ -296,6 +309,7 @@ public class ClusterControlManager {
this.controllerRegistrations = new TimelineHashMap<>(snapshotRegistry, 0);
this.directoryToBroker = new TimelineHashMap<>(snapshotRegistry, 0);
this.brokerUncleanShutdownHandler = brokerUncleanShutdownHandler;
+ this.interBrokerListenerName = interBrokerListenerName;
}
ReplicaPlacer replicaPlacer() {
@@ -377,6 +391,13 @@ public class ClusterControlManager {
"brokers until the metadata migration is complete.");
}
+ if (request.isMigratingZkBroker()) {
+ if (request.listeners().find(interBrokerListenerName) == null) {
+ throw new InvalidRegistrationException("Broker does not have the current inter.broker.listener " +
+ interBrokerListenerName);
+ }
+ }
+
if (featureControl.metadataVersion().isDirectoryAssignmentSupported()) {
if (request.logDirs().isEmpty()) {
throw new InvalidRegistrationException("No directories specified in request");
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 64723b86c0d..74451716277 100644
--- a/metadata/src/main/java/org/apache/kafka/controller/QuorumController.java
+++ b/metadata/src/main/java/org/apache/kafka/controller/QuorumController.java
@@ -225,6 +225,7 @@ public final class QuorumController implements Controller {
private long delegationTokenExpiryTimeMs;
private long delegationTokenExpiryCheckIntervalMs;
private long uncleanLeaderElectionCheckIntervalMs = TimeUnit.MINUTES.toMillis(5);
+ private String interBrokerListenerName = "PLAINTEXT";
public Builder(int nodeId, String clusterId) {
this.nodeId = nodeId;
@@ -380,6 +381,11 @@ public final class QuorumController implements Controller {
return this;
}
+ public Builder setInterBrokerListenerName(String interBrokerListenerName) {
+ this.interBrokerListenerName = interBrokerListenerName;
+ return this;
+ }
+
public QuorumController build() throws Exception {
if (raftClient == null) {
throw new IllegalStateException("You must set a raft client.");
@@ -437,7 +443,8 @@ public final class QuorumController implements Controller {
delegationTokenExpiryTimeMs,
delegationTokenExpiryCheckIntervalMs,
eligibleLeaderReplicasEnabled,
- uncleanLeaderElectionCheckIntervalMs
+ uncleanLeaderElectionCheckIntervalMs,
+ interBrokerListenerName
);
} catch (Exception e) {
Utils.closeQuietly(queue, "event queue");
@@ -1868,7 +1875,8 @@ public final class QuorumController implements Controller {
long delegationTokenExpiryTimeMs,
long delegationTokenExpiryCheckIntervalMs,
boolean eligibleLeaderReplicasEnabled,
- long uncleanLeaderElectionCheckIntervalMs
+ long uncleanLeaderElectionCheckIntervalMs,
+ String interBrokerListenerName
) {
this.nonFatalFaultHandler = nonFatalFaultHandler;
this.fatalFaultHandler = fatalFaultHandler;
@@ -1925,6 +1933,7 @@ public final class QuorumController implements Controller {
setFeatureControlManager(featureControl).
setZkMigrationEnabled(zkMigrationEnabled).
setBrokerUncleanShutdownHandler(this::handleUncleanBrokerShutdown).
+ setInterBrokerListenerName(interBrokerListenerName).
build();
this.producerIdControlManager = new ProducerIdControlManager.Builder().
setLogContext(logContext).
diff --git a/metadata/src/test/java/org/apache/kafka/controller/ClusterControlManagerTest.java b/metadata/src/test/java/org/apache/kafka/controller/ClusterControlManagerTest.java
index 0646d4aaa56..786891e695b 100644
--- a/metadata/src/test/java/org/apache/kafka/controller/ClusterControlManagerTest.java
+++ b/metadata/src/test/java/org/apache/kafka/controller/ClusterControlManagerTest.java
@@ -852,4 +852,33 @@ public class ClusterControlManagerTest {
clusterControl.brokerRegistrations().get(1).epoch());
}
}
+
+ @Test
+ public void testRegistrationWithIncorrectInterBrokerListenerName() {
+ ClusterControlManager clusterControl = new ClusterControlManager.Builder().
+ setClusterId("pjvUwj3ZTEeSVQmUiH3IJw").
+ setFeatureControlManager(new FeatureControlManager.Builder().build()).
+ setBrokerUncleanShutdownHandler((brokerId, records) -> { }).
+ setInterBrokerListenerName("INTERNAL").
+ setZkMigrationEnabled(true).
+ build();
+ clusterControl.activate();
+ assertEquals("Broker does not have the current inter.broker.listener INTERNAL",
+ assertThrows(InvalidRegistrationException.class,
+ () -> clusterControl.registerBroker(
+ new BrokerRegistrationRequestData().
+ setBrokerId(1).
+ setClusterId(clusterControl.clusterId()).
+ setIncarnationId(Uuid.fromString("07OOcU7MQFeSmGAFPP2Zww")).
+ setLogDirs(Arrays.asList(Uuid.fromString("Vv1gzkM2QpuE-PPrIc6XEw"))).
+ setIsMigratingZkBroker(true).
+ setListeners(new BrokerRegistrationRequestData.ListenerCollection(Collections.singleton(
+ new BrokerRegistrationRequestData.Listener().
+ setName("PLAINTEXT").
+ setHost("example.com").
+ setPort(9092).
+ setSecurityProtocol(SecurityProtocol.PLAINTEXT.id)).iterator())),
+ 111,
+ new FinalizedControllerFeatures(Collections.emptyMap(), 100L))).getMessage());
+ }
}