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:26:02 UTC
(kafka) 01/01: KAFKA-17543: Enforce that broker.id.generation.enable is disabled when migrating to KRaft
This is an automated email from the ASF dual-hosted git repository.
cmccabe pushed a commit to branch KAFKA-17543
in repository https://gitbox.apache.org/repos/asf/kafka.git
commit 0ca9b813874e27c33bbcccff9fabb53f3446c265
Author: Colin P. McCabe <cm...@apache.org>
AuthorDate: Thu Sep 12 16:11:22 2024 -0700
KAFKA-17543: Enforce that broker.id.generation.enable is disabled when migrating to KRaft
---
core/src/main/scala/kafka/server/KafkaServer.scala | 7 ++++---
core/src/test/scala/unit/kafka/server/KafkaServerTest.scala | 12 ++++++++++++
2 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/core/src/main/scala/kafka/server/KafkaServer.scala b/core/src/main/scala/kafka/server/KafkaServer.scala
index e9bc3affcc7..0729954fa2a 100755
--- a/core/src/main/scala/kafka/server/KafkaServer.scala
+++ b/core/src/main/scala/kafka/server/KafkaServer.scala
@@ -260,9 +260,6 @@ class KafkaServer(
/* generate brokerId */
config._brokerId = getOrGenerateBrokerId(initialMetaPropsEnsemble)
- // Currently, we are migrating from ZooKeeper to KRaft. If broker.id.generation.enable is set to true,
- // we must ensure that the nodeId synchronizes with the broker.id to prevent the nodeId from being -1,
- // which would result in a failure during the migration.
config._nodeId = config.brokerId
logContext = new LogContext(s"[KafkaServer id=${config.brokerId}] ")
this.logIdent = logContext.logPrefix
@@ -1135,6 +1132,10 @@ class KafkaServer(
* @return The brokerId.
*/
private def getOrGenerateBrokerId(metaPropsEnsemble: MetaPropertiesEnsemble): Int = {
+ if (config.migrationEnabled && config.brokerIdGenerationEnable) {
+ throw new RuntimeException("broker.id.generation.enable is incompatible with migration to ZK. " +
+ "Please disable it before enabling migration.")
+ }
if (config.brokerId >= 0) {
config.brokerId
} else if (metaPropsEnsemble.nodeId().isPresent) {
diff --git a/core/src/test/scala/unit/kafka/server/KafkaServerTest.scala b/core/src/test/scala/unit/kafka/server/KafkaServerTest.scala
index e8cf3ecfa5c..1b4ca5c1f4e 100755
--- a/core/src/test/scala/unit/kafka/server/KafkaServerTest.scala
+++ b/core/src/test/scala/unit/kafka/server/KafkaServerTest.scala
@@ -202,4 +202,16 @@ class KafkaServerTest extends QuorumTestHarness {
TestUtils.createServer(kafkaConfig)
}
+ @Test
+ def testGeneratedBrokerIdForbiddenDuringMigration(): Unit = {
+ val props = TestUtils.createBrokerConfig(-1, zkConnect)
+ props.put("reserved.broker.max.id", "2000")
+ props.put("zookeeper.metadata.migration.enable", "true")
+ props.put("controller.quorum.voters", "1@localhost:9092")
+ props.put("controller.listener.names", "CONTROLLER")
+ assertEquals("broker.id.generation.enable is incompatible with migration to ZK. Please disable it before enabling migration.",
+ assertThrows(classOf[RuntimeException],
+ () => TestUtils.createServer(KafkaConfig.fromProps(props))).
+ getMessage)
+ }
}