-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-13935 Fix static usages of IBP in KRaft mode #12250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
e2e3ce3
dcac78c
f404e21
d62d722
49f34d0
b903301
d9f398f
e9fc686
9833a65
df839a3
24006b6
eeaeb61
eaf680d
015349f
f79528f
0145d53
aea22cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ import kafka.log.UnifiedLog | |
| import org.apache.kafka.common.{KafkaException, Uuid} | ||
| import org.apache.kafka.common.utils.Utils | ||
| import org.apache.kafka.controller.BootstrapMetadata | ||
| import org.apache.kafka.server.common.MetadataVersion | ||
| import org.apache.kafka.test.TestUtils | ||
| import org.junit.jupiter.api.Assertions._ | ||
| import org.junit.jupiter.api.Test | ||
|
|
@@ -71,12 +72,13 @@ class KafkaRaftServerTest { | |
|
|
||
| private def invokeLoadMetaProperties( | ||
| metaProperties: MetaProperties, | ||
| configProperties: Properties | ||
| configProperties: Properties, | ||
| metadataVersion: Option[MetadataVersion] = Some(MetadataVersion.latest()) | ||
| ): (MetaProperties, BootstrapMetadata, collection.Seq[String]) = { | ||
| val tempLogDir = TestUtils.tempDirectory() | ||
| try { | ||
| writeMetaProperties(tempLogDir, metaProperties) | ||
|
|
||
| metadataVersion.foreach(mv => writeBootstrapMetadata(tempLogDir, mv)) | ||
| configProperties.put(KafkaConfig.LogDirProp, tempLogDir.getAbsolutePath) | ||
| val config = KafkaConfig.fromProps(configProperties) | ||
| KafkaRaftServer.initializeLogDirs(config) | ||
|
|
@@ -94,6 +96,11 @@ class KafkaRaftServerTest { | |
| checkpoint.write(metaProperties.toProperties) | ||
| } | ||
|
|
||
| private def writeBootstrapMetadata(logDir: File, metadataVersion: MetadataVersion): Unit = { | ||
| val bootstrapMetadata = BootstrapMetadata.create(metadataVersion) | ||
| BootstrapMetadata.write(bootstrapMetadata, logDir.toPath) | ||
| } | ||
|
|
||
| @Test | ||
| def testStartupFailsIfMetaPropertiesMissingInSomeLogDir(): Unit = { | ||
| val clusterId = clusterIdBase64 | ||
|
|
@@ -147,6 +154,7 @@ class KafkaRaftServerTest { | |
| // One log dir is online and has properly formatted `meta.properties` | ||
| val validDir = TestUtils.tempDirectory() | ||
| writeMetaProperties(validDir, MetaProperties(clusterId, nodeId)) | ||
| writeBootstrapMetadata(validDir, MetadataVersion.latest()) | ||
|
|
||
| // Use a regular file as an invalid log dir to trigger an IO error | ||
| val invalidDir = TestUtils.tempFile("blah") | ||
|
|
@@ -215,4 +223,47 @@ class KafkaRaftServerTest { | |
| () => KafkaRaftServer.initializeLogDirs(config)) | ||
| } | ||
|
|
||
| @Test | ||
| def testKRaftUpdateWithIBP(): Unit = { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we have a test case with an invalid IBP version?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we have an invalid IBP here, KafkaConfig will throw a ConfigException right away. Basically, if we're in KRaft mode and IBP is user-defined as something less than 3.0 (or, 3.0-IV1 really), we won't even try to start up. I'll see if I can add a test that initializes the controller with a bad metadata version.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A test case for |
||
| val clusterId = clusterIdBase64 | ||
| val nodeId = 0 | ||
| val metaProperties = MetaProperties(clusterId, nodeId) | ||
|
|
||
| val configProperties = new Properties | ||
| configProperties.put(KafkaConfig.ProcessRolesProp, "broker,controller") | ||
| configProperties.put(KafkaConfig.NodeIdProp, nodeId.toString) | ||
| configProperties.put(KafkaConfig.ListenersProp, "PLAINTEXT://127.0.0.1:9092,SSL://127.0.0.1:9093") | ||
| configProperties.put(KafkaConfig.QuorumVotersProp, s"$nodeId@localhost:9093") | ||
| configProperties.put(KafkaConfig.ControllerListenerNamesProp, "SSL") | ||
| configProperties.put(KafkaConfig.InterBrokerProtocolVersionProp, "3.2") | ||
|
|
||
| val (loadedMetaProperties, bootstrapMetadata, offlineDirs) = | ||
| invokeLoadMetaProperties(metaProperties, configProperties, None) | ||
|
|
||
| assertEquals(metaProperties, loadedMetaProperties) | ||
| assertEquals(Seq.empty, offlineDirs) | ||
| assertEquals(bootstrapMetadata.metadataVersion(), MetadataVersion.IBP_3_2_IV0) | ||
| } | ||
|
|
||
| @Test | ||
| def testKRaftUpdateWithoutIBP(): Unit = { | ||
| val clusterId = clusterIdBase64 | ||
| val nodeId = 0 | ||
| val metaProperties = MetaProperties(clusterId, nodeId) | ||
|
|
||
| val logDir = TestUtils.tempDirectory() | ||
| writeMetaProperties(logDir, metaProperties) | ||
|
|
||
| val configProperties = new Properties | ||
| configProperties.put(KafkaConfig.ProcessRolesProp, "broker,controller") | ||
| configProperties.put(KafkaConfig.NodeIdProp, nodeId.toString) | ||
| configProperties.put(KafkaConfig.ListenersProp, "PLAINTEXT://127.0.0.1:9092,SSL://127.0.0.1:9093") | ||
| configProperties.put(KafkaConfig.QuorumVotersProp, s"$nodeId@localhost:9093") | ||
| configProperties.put(KafkaConfig.ControllerListenerNamesProp, "SSL") | ||
| configProperties.put(KafkaConfig.LogDirProp, logDir.getAbsolutePath) | ||
|
|
||
| val config = KafkaConfig.fromProps(configProperties) | ||
| assertEquals("Cannot upgrade from KRaft version prior to 3.3 without first setting inter.broker.protocol.version on each broker.", | ||
| assertThrows(classOf[KafkaException], () => KafkaRaftServer.initializeLogDirs(config)).getMessage) | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.