Skip to content

Commit ea5b5fe

Browse files
KAFKA-19432 Add an ERROR log message if broker.heartbeat.interval.ms is too large (apache#20046)
* Log error message if `broker.heartbeat.interval.ms * 2` is large than `broker.session.timeout.ms`. * Add test case `testLogBrokerHeartbeatIntervalMsShouldBeLowerThanHalfOfBrokerSessionTimeoutMs`. Reviewers: Chia-Ping Tsai <chia7712@gmail.com>
1 parent a9bce06 commit ea5b5fe

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

core/src/main/scala/kafka/server/KafkaConfig.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,13 @@ class KafkaConfig private(doLog: Boolean, val props: util.Map[_, _])
513513
require(replicaFetchWaitMaxMs <= replicaLagTimeMaxMs, "replica.fetch.wait.max.ms should always be less than or equal to replica.lag.time.max.ms" +
514514
" to prevent frequent changes in ISR")
515515

516+
if (brokerHeartbeatIntervalMs * 2 > brokerSessionTimeoutMs) {
517+
error(s"${KRaftConfigs.BROKER_HEARTBEAT_INTERVAL_MS_CONFIG} ($brokerHeartbeatIntervalMs ms) must be less than or equal to half of the ${KRaftConfigs.BROKER_SESSION_TIMEOUT_MS_CONFIG} ($brokerSessionTimeoutMs ms). " +
518+
s"The ${KRaftConfigs.BROKER_SESSION_TIMEOUT_MS_CONFIG} is configured on controller. The ${KRaftConfigs.BROKER_HEARTBEAT_INTERVAL_MS_CONFIG} is configured on broker. " +
519+
s"If a broker doesn't send heartbeat request within ${KRaftConfigs.BROKER_SESSION_TIMEOUT_MS_CONFIG}, it loses broker lease. " +
520+
s"Please increase ${KRaftConfigs.BROKER_SESSION_TIMEOUT_MS_CONFIG} or decrease ${KRaftConfigs.BROKER_HEARTBEAT_INTERVAL_MS_CONFIG}.")
521+
}
522+
516523
val advertisedBrokerListenerNames = effectiveAdvertisedBrokerListeners.map(l => ListenerName.normalised(l.listener)).toSet
517524

518525
// validate KRaft-related configs

core/src/test/scala/unit/kafka/server/KafkaConfigTest.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import org.apache.kafka.common.network.ListenerName
2929
import org.apache.kafka.common.record.{CompressionType, Records}
3030
import org.apache.kafka.common.security.auth.SecurityProtocol
3131
import org.apache.kafka.common.config.internals.BrokerSecurityConfigs
32+
import org.apache.kafka.common.utils.LogCaptureAppender
3233
import org.apache.kafka.coordinator.group.ConsumerGroupMigrationPolicy
3334
import org.apache.kafka.coordinator.group.Group.GroupType
3435
import org.apache.kafka.coordinator.group.GroupCoordinatorConfig
@@ -40,11 +41,13 @@ import org.apache.kafka.server.config.{DelegationTokenManagerConfigs, KRaftConfi
4041
import org.apache.kafka.server.log.remote.storage.RemoteLogManagerConfig
4142
import org.apache.kafka.server.metrics.MetricConfigs
4243
import org.apache.kafka.storage.internals.log.CleanerConfig
44+
import org.apache.logging.log4j.Level
4345
import org.junit.jupiter.api.Assertions._
4446
import org.junit.jupiter.api.Test
4547
import org.junit.jupiter.api.function.Executable
4648

4749
import scala.jdk.CollectionConverters._
50+
import scala.util.Using
4851

4952
class KafkaConfigTest {
5053

@@ -1899,4 +1902,19 @@ class KafkaConfigTest {
18991902
val message = assertThrows(classOf[IllegalArgumentException], () => KafkaConfig.fromProps(props)).getMessage
19001903
assertEquals("requirement failed: controller.listener.names must contain at least one value appearing in the 'listeners' configuration when running the KRaft controller role", message)
19011904
}
1905+
1906+
@Test
1907+
def testLogBrokerHeartbeatIntervalMsShouldBeLowerThanHalfOfBrokerSessionTimeoutMs(): Unit = {
1908+
val props = createDefaultConfig()
1909+
Using.resource(LogCaptureAppender.createAndRegister) { appender =>
1910+
appender.setClassLogger(KafkaConfig.getClass, Level.ERROR)
1911+
props.setProperty(KRaftConfigs.BROKER_HEARTBEAT_INTERVAL_MS_CONFIG, "4500")
1912+
props.setProperty(KRaftConfigs.BROKER_SESSION_TIMEOUT_MS_CONFIG, "8999")
1913+
KafkaConfig.fromProps(props)
1914+
assertTrue(appender.getMessages.contains("broker.heartbeat.interval.ms (4500 ms) must be less than or equal to half of the broker.session.timeout.ms (8999 ms). " +
1915+
"The broker.session.timeout.ms is configured on controller. The broker.heartbeat.interval.ms is configured on broker. " +
1916+
"If a broker doesn't send heartbeat request within broker.session.timeout.ms, it loses broker lease. " +
1917+
"Please increase broker.session.timeout.ms or decrease broker.heartbeat.interval.ms."))
1918+
}
1919+
}
19021920
}

0 commit comments

Comments
 (0)