Skip to content

Commit

Permalink
make exception for when inter.broker.listener.name is inferred from s…
Browse files Browse the repository at this point in the history
…ecurity protocol and add test
  • Loading branch information
kevin-wu24 committed Dec 17, 2024
1 parent 207774f commit a0b1307
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
12 changes: 7 additions & 5 deletions core/src/main/scala/kafka/server/KafkaConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -911,11 +911,13 @@ class KafkaConfig private(doLog: Boolean, val props: util.Map[_, _])
effectiveAdvertisedControllerListeners.size == listeners.size,
s"The ${SocketServerConfigs.LISTENERS_CONFIG} config must only contain KRaft controller listeners from ${KRaftConfigs.CONTROLLER_LISTENER_NAMES_CONFIG} when ${KRaftConfigs.PROCESS_ROLES_CONFIG}=controller"
)
// controller.listener.names must not contain inter.broker.listener.name
require(
!controllerListenerNames.contains(interBrokerListenerName.value()),
s"${KRaftConfigs.CONTROLLER_LISTENER_NAMES_CONFIG} must not contain the '${ReplicationConfigs.INTER_BROKER_LISTENER_NAME_CONFIG}' configuration value when ${KRaftConfigs.PROCESS_ROLES_CONFIG}=controller'"
)
// controller.listener.names must not contain inter.broker.listener.name when inter.broker.listener.name is explicitly set
if (Option(getString(ReplicationConfigs.INTER_BROKER_LISTENER_NAME_CONFIG)).isDefined) {
require(
!controllerListenerNames.contains(interBrokerListenerName.value()),
s"${KRaftConfigs.CONTROLLER_LISTENER_NAMES_CONFIG} must not contain an explicitly set ${ReplicationConfigs.INTER_BROKER_LISTENER_NAME_CONFIG} configuration value when ${KRaftConfigs.PROCESS_ROLES_CONFIG}=controller'"
)
}
validateControllerQuorumVotersMustContainNodeIdForKRaftController()
validateAdvertisedControllerListenersNonEmptyForKRaftController()
validateControllerListenerNamesMustAppearInListenersForKRaftController()
Expand Down
17 changes: 17 additions & 0 deletions core/src/test/scala/unit/kafka/server/KafkaConfigTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1406,6 +1406,23 @@ class KafkaConfigTest {
KafkaConfig.fromProps(props)
}

@Test
def testControllerListenerNamesValidForKRaftControllerOnly(): Unit = {
val props = new Properties()
props.setProperty(KRaftConfigs.NODE_ID_CONFIG, "1")
props.setProperty(KRaftConfigs.PROCESS_ROLES_CONFIG, "controller")
props.setProperty(QuorumConfig.QUORUM_VOTERS_CONFIG, "1@localhost:9092")
props.setProperty(SocketServerConfigs.LISTENERS_CONFIG, "SASL_SSL://:9092,CONTROLLER://:9093")
props.setProperty(SocketServerConfigs.LISTENER_SECURITY_PROTOCOL_MAP_CONFIG, "SASL_SSL:SASL_SSL,CONTROLLER:SASL_SSL")
props.put(ReplicationConfigs.INTER_BROKER_LISTENER_NAME_CONFIG, "SASL_SSL")
props.put(KRaftConfigs.CONTROLLER_LISTENER_NAMES_CONFIG, "CONTROLLER,SASL_SSL")

val expectedExceptionContainsText =
"""controller.listener.names must not contain an explicitly set inter.broker.listener.name configuration value
|when process.roles=controller""".stripMargin.replaceAll("\n", " ")
assertBadConfigContainingMessage(props, expectedExceptionContainsText)
}

@Test
def testControllerQuorumVoterStringsToNodes(): Unit = {
assertThrows(classOf[ConfigException], () => QuorumConfig.quorumVoterStringsToNodes(Collections.singletonList("")))
Expand Down

0 comments on commit a0b1307

Please sign in to comment.