You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kafka.apache.org by sa...@apache.org on 2023/08/03 08:26:06 UTC
[kafka] branch trunk updated: KAFKA-12969: Add broker level config synonyms for topic level tiered storage configs (#14114)
This is an automated email from the ASF dual-hosted git repository.
satishd pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/kafka.git
The following commit(s) were added to refs/heads/trunk by this push:
new d89b26ff443 KAFKA-12969: Add broker level config synonyms for topic level tiered storage configs (#14114)
d89b26ff443 is described below
commit d89b26ff443c8dd5d584ad0a979ac3944366cc06
Author: Kamal Chandraprakash <kc...@uber.com>
AuthorDate: Thu Aug 3 13:56:00 2023 +0530
KAFKA-12969: Add broker level config synonyms for topic level tiered storage configs (#14114)
KAFKA-12969: Add broker level config synonyms for topic level tiered storage configs.
Topic -> Broker Synonym:
local.retention.bytes -> log.local.retention.bytes
local.retention.ms -> log.local.retention.ms
We cannot add synonym for `remote.storage.enable` topic property as it depends on KIP-950
Reviewers: Divij Vaidya <di...@amazon.com>, Satish Duggana <sa...@apache.org>, Luke Chen <sh...@gmail.com>
---
.../server/ReplicaFetcherTierStateMachine.java | 2 +-
core/src/main/scala/kafka/log/UnifiedLog.scala | 2 +-
.../scala/kafka/server/DynamicBrokerConfig.scala | 34 ++++++
core/src/main/scala/kafka/server/KafkaConfig.scala | 13 ++-
.../test/scala/unit/kafka/log/LogConfigTest.scala | 39 +++++--
.../kafka/server/DynamicBrokerConfigTest.scala | 94 +++++++++++++++++
.../scala/unit/kafka/server/KafkaConfigTest.scala | 28 ++++-
.../server/config/ServerTopicConfigSynonyms.java | 4 +-
.../log/remote/storage/RemoteLogManagerConfig.java | 28 ++++-
.../kafka/storage/internals/log/LogConfig.java | 115 ++++++++++++---------
10 files changed, 292 insertions(+), 67 deletions(-)
diff --git a/core/src/main/java/kafka/server/ReplicaFetcherTierStateMachine.java b/core/src/main/java/kafka/server/ReplicaFetcherTierStateMachine.java
index 21c99d11474..3f5a1b2c69f 100644
--- a/core/src/main/java/kafka/server/ReplicaFetcherTierStateMachine.java
+++ b/core/src/main/java/kafka/server/ReplicaFetcherTierStateMachine.java
@@ -180,7 +180,7 @@ public class ReplicaFetcherTierStateMachine implements TierStateMachine {
long nextOffset;
- if (unifiedLog.remoteStorageSystemEnable() && unifiedLog.config().remoteLogConfig.remoteStorageEnable) {
+ if (unifiedLog.remoteStorageSystemEnable() && unifiedLog.config().remoteStorageEnable()) {
if (replicaMgr.remoteLogManager().isEmpty()) throw new IllegalStateException("RemoteLogManager is not yet instantiated");
RemoteLogManager rlm = replicaMgr.remoteLogManager().get();
diff --git a/core/src/main/scala/kafka/log/UnifiedLog.scala b/core/src/main/scala/kafka/log/UnifiedLog.scala
index 028f2fbbd5e..1b191844e77 100644
--- a/core/src/main/scala/kafka/log/UnifiedLog.scala
+++ b/core/src/main/scala/kafka/log/UnifiedLog.scala
@@ -168,7 +168,7 @@ class UnifiedLog(@volatile var logStartOffset: Long,
!(config.compact || Topic.isInternal(topicPartition.topic())
|| TopicBasedRemoteLogMetadataManagerConfig.REMOTE_LOG_METADATA_TOPIC_NAME.equals(topicPartition.topic())
|| Topic.CLUSTER_METADATA_TOPIC_NAME.equals(topicPartition.topic())) &&
- config.remoteLogConfig.remoteStorageEnable
+ config.remoteStorageEnable()
}
/**
diff --git a/core/src/main/scala/kafka/server/DynamicBrokerConfig.scala b/core/src/main/scala/kafka/server/DynamicBrokerConfig.scala
index 7c6d5284d71..57aaf396e85 100755
--- a/core/src/main/scala/kafka/server/DynamicBrokerConfig.scala
+++ b/core/src/main/scala/kafka/server/DynamicBrokerConfig.scala
@@ -37,6 +37,7 @@ import org.apache.kafka.common.network.{ListenerName, ListenerReconfigurable}
import org.apache.kafka.common.security.authenticator.LoginManager
import org.apache.kafka.common.utils.{ConfigUtils, Utils}
import org.apache.kafka.server.config.ServerTopicConfigSynonyms
+import org.apache.kafka.server.log.remote.storage.RemoteLogManagerConfig
import org.apache.kafka.storage.internals.log.{LogConfig, ProducerStateManagerConfig}
import scala.annotation.nowarn
@@ -675,6 +676,39 @@ class DynamicLogConfig(logManager: LogManager, server: KafkaBroker) extends Brok
// For update of topic config overrides, only config names and types are validated
// Names and types have already been validated. For consistency with topic config
// validation, no additional validation is performed.
+
+ def validateLogLocalRetentionMs(): Unit = {
+ val logRetentionMs = newConfig.logRetentionTimeMillis
+ val logLocalRetentionMs: java.lang.Long = newConfig.logLocalRetentionMs
+ if (logRetentionMs != -1L && logLocalRetentionMs != -2L) {
+ if (logLocalRetentionMs == -1L) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, logLocalRetentionMs,
+ s"Value must not be -1 as ${KafkaConfig.LogRetentionTimeMillisProp} value is set as $logRetentionMs.")
+ }
+ if (logLocalRetentionMs > logRetentionMs) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, logLocalRetentionMs,
+ s"Value must not be more than ${KafkaConfig.LogRetentionTimeMillisProp} property value: $logRetentionMs")
+ }
+ }
+ }
+
+ def validateLogLocalRetentionBytes(): Unit = {
+ val logRetentionBytes = newConfig.logRetentionBytes
+ val logLocalRetentionBytes: java.lang.Long = newConfig.logLocalRetentionBytes
+ if (logRetentionBytes > -1 && logLocalRetentionBytes != -2) {
+ if (logLocalRetentionBytes == -1) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP, logLocalRetentionBytes,
+ s"Value must not be -1 as ${KafkaConfig.LogRetentionBytesProp} value is set as $logRetentionBytes.")
+ }
+ if (logLocalRetentionBytes > logRetentionBytes) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP, logLocalRetentionBytes,
+ s"Value must not be more than ${KafkaConfig.LogRetentionBytesProp} property value: $logRetentionBytes")
+ }
+ }
+ }
+
+ validateLogLocalRetentionMs()
+ validateLogLocalRetentionBytes()
}
private def updateLogsConfig(newBrokerDefaults: Map[String, Object]): Unit = {
diff --git a/core/src/main/scala/kafka/server/KafkaConfig.scala b/core/src/main/scala/kafka/server/KafkaConfig.scala
index e6a8ffd2407..ddc206f7ed8 100755
--- a/core/src/main/scala/kafka/server/KafkaConfig.scala
+++ b/core/src/main/scala/kafka/server/KafkaConfig.scala
@@ -17,7 +17,7 @@
package kafka.server
-import java.util
+import java.{lang, util}
import java.util.concurrent.TimeUnit
import java.util.{Collections, Locale, Properties}
import kafka.cluster.EndPoint
@@ -2171,6 +2171,12 @@ class KafkaConfig private(doLog: Boolean, val props: java.util.Map[_, _], dynami
def usesTopicId: Boolean =
usesSelfManagedQuorum || interBrokerProtocolVersion.isTopicIdsSupported()
+
+ val isRemoteLogStorageSystemEnabled: lang.Boolean = getBoolean(RemoteLogManagerConfig.REMOTE_LOG_STORAGE_SYSTEM_ENABLE_PROP)
+ def logLocalRetentionBytes: java.lang.Long = getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP)
+
+ def logLocalRetentionMs: java.lang.Long = getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP)
+
validateValues()
@nowarn("cat=deprecation")
@@ -2203,6 +2209,9 @@ class KafkaConfig private(doLog: Boolean, val props: java.util.Map[_, _], dynami
require(logRollTimeJitterMillis >= 0, "log.roll.jitter.ms must be greater than or equal to 0")
require(logRetentionTimeMillis >= 1 || logRetentionTimeMillis == -1, "log.retention.ms must be unlimited (-1) or, greater than or equal to 1")
require(logDirs.nonEmpty, "At least one log directory must be defined via log.dirs or log.dir.")
+ if (isRemoteLogStorageSystemEnabled && logDirs.size > 1) {
+ throw new ConfigException(s"Multiple log directories `${logDirs.mkString(",")}` are not supported when remote log storage is enabled")
+ }
require(logCleanerDedupeBufferSize / logCleanerThreads > 1024 * 1024, "log.cleaner.dedupe.buffer.size must be at least 1MB per cleaner thread.")
require(replicaFetchWaitMaxMs <= replicaSocketTimeoutMs, "replica.socket.timeout.ms should always be at least replica.fetch.wait.max.ms" +
" to prevent unnecessary socket timeouts")
@@ -2442,6 +2451,8 @@ class KafkaConfig private(doLog: Boolean, val props: java.util.Map[_, _], dynami
logProps.put(TopicConfig.MESSAGE_TIMESTAMP_TYPE_CONFIG, logMessageTimestampType.name)
logProps.put(TopicConfig.MESSAGE_TIMESTAMP_DIFFERENCE_MAX_MS_CONFIG, logMessageTimestampDifferenceMaxMs: java.lang.Long)
logProps.put(TopicConfig.MESSAGE_DOWNCONVERSION_ENABLE_CONFIG, logMessageDownConversionEnable: java.lang.Boolean)
+ logProps.put(TopicConfig.LOCAL_LOG_RETENTION_MS_CONFIG, logLocalRetentionMs)
+ logProps.put(TopicConfig.LOCAL_LOG_RETENTION_BYTES_CONFIG, logLocalRetentionBytes)
logProps
}
diff --git a/core/src/test/scala/unit/kafka/log/LogConfigTest.scala b/core/src/test/scala/unit/kafka/log/LogConfigTest.scala
index a6c1ac88d8d..ec64ca82f69 100644
--- a/core/src/test/scala/unit/kafka/log/LogConfigTest.scala
+++ b/core/src/test/scala/unit/kafka/log/LogConfigTest.scala
@@ -27,6 +27,7 @@ import org.junit.jupiter.api.Test
import java.util.{Collections, Properties}
import org.apache.kafka.server.common.MetadataVersion.IBP_3_0_IV1
+import org.apache.kafka.server.log.remote.storage.RemoteLogManagerConfig
import org.apache.kafka.storage.internals.log.{LogConfig, ThrottledReplicaListValidator}
import scala.annotation.nowarn
@@ -57,18 +58,24 @@ class LogConfigTest {
@Test
def testKafkaConfigToProps(): Unit = {
val millisInHour = 60L * 60L * 1000L
+ val millisInDay = 24L * millisInHour
+ val bytesInGB: Long = 1024 * 1024 * 1024
val kafkaProps = TestUtils.createBrokerConfig(nodeId = 0, zkConnect = "")
kafkaProps.put(KafkaConfig.LogRollTimeHoursProp, "2")
kafkaProps.put(KafkaConfig.LogRollTimeJitterHoursProp, "2")
- kafkaProps.put(KafkaConfig.LogRetentionTimeHoursProp, "2")
+ kafkaProps.put(KafkaConfig.LogRetentionTimeHoursProp, "960") // 40 days
kafkaProps.put(KafkaConfig.LogMessageFormatVersionProp, "0.11.0")
+ kafkaProps.put(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, "2592000000") // 30 days
+ kafkaProps.put(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP, "4294967296") // 4 GB
val logProps = KafkaConfig.fromProps(kafkaProps).extractLogConfigMap
assertEquals(2 * millisInHour, logProps.get(TopicConfig.SEGMENT_MS_CONFIG))
assertEquals(2 * millisInHour, logProps.get(TopicConfig.SEGMENT_JITTER_MS_CONFIG))
- assertEquals(2 * millisInHour, logProps.get(TopicConfig.RETENTION_MS_CONFIG))
+ assertEquals(40 * millisInDay, logProps.get(TopicConfig.RETENTION_MS_CONFIG))
// The message format version should always be 3.0 if the inter-broker protocol version is 3.0 or higher
assertEquals(IBP_3_0_IV1.version, logProps.get(TopicConfig.MESSAGE_FORMAT_VERSION_CONFIG))
+ assertEquals(30 * millisInDay, logProps.get(TopicConfig.LOCAL_LOG_RETENTION_MS_CONFIG))
+ assertEquals(4 * bytesInGB, logProps.get(TopicConfig.LOCAL_LOG_RETENTION_BYTES_CONFIG))
}
@nowarn("cat=deprecation")
@@ -218,8 +225,8 @@ class LogConfigTest {
props.put(TopicConfig.RETENTION_MS_CONFIG, retentionMs.toString)
val logConfig = new LogConfig(props)
- assertEquals(retentionMs, logConfig.remoteLogConfig.localRetentionMs)
- assertEquals(retentionBytes, logConfig.remoteLogConfig.localRetentionBytes)
+ assertEquals(retentionMs, logConfig.localRetentionMs)
+ assertEquals(retentionBytes, logConfig.localRetentionBytes)
}
@Test
@@ -227,8 +234,8 @@ class LogConfigTest {
val logConfig = new LogConfig(new Properties())
// Local retention defaults are derived from retention properties which can be default or custom.
- assertEquals(LogConfig.DEFAULT_RETENTION_MS, logConfig.remoteLogConfig.localRetentionMs)
- assertEquals(LogConfig.DEFAULT_RETENTION_BYTES, logConfig.remoteLogConfig.localRetentionBytes)
+ assertEquals(LogConfig.DEFAULT_RETENTION_MS, logConfig.localRetentionMs)
+ assertEquals(LogConfig.DEFAULT_RETENTION_BYTES, logConfig.localRetentionBytes)
}
@Test
@@ -243,8 +250,8 @@ class LogConfigTest {
props.put(TopicConfig.LOCAL_LOG_RETENTION_BYTES_CONFIG, localRetentionBytes.toString)
val logConfig = new LogConfig(props)
- assertEquals(localRetentionMs, logConfig.remoteLogConfig.localRetentionMs)
- assertEquals(localRetentionBytes, logConfig.remoteLogConfig.localRetentionBytes)
+ assertEquals(localRetentionMs, logConfig.localRetentionMs)
+ assertEquals(localRetentionBytes, logConfig.localRetentionBytes)
}
@Test
@@ -275,6 +282,20 @@ class LogConfigTest {
props.put(TopicConfig.LOCAL_LOG_RETENTION_MS_CONFIG, localRetentionMs.toString)
props.put(TopicConfig.LOCAL_LOG_RETENTION_BYTES_CONFIG, localRetentionBytes.toString)
- assertThrows(classOf[ConfigException], () => new LogConfig(props));
+ assertThrows(classOf[ConfigException], () => LogConfig.validate(props))
+ }
+
+ @Test
+ def testEnableRemoteLogStorageOnCompactedTopic(): Unit = {
+ val props = new Properties()
+ props.put(TopicConfig.CLEANUP_POLICY_CONFIG, TopicConfig.CLEANUP_POLICY_DELETE)
+ props.put(TopicConfig.REMOTE_LOG_STORAGE_ENABLE_CONFIG, "true")
+ LogConfig.validate(props)
+ props.put(TopicConfig.CLEANUP_POLICY_CONFIG, TopicConfig.CLEANUP_POLICY_COMPACT)
+ assertThrows(classOf[ConfigException], () => LogConfig.validate(props))
+ props.put(TopicConfig.CLEANUP_POLICY_CONFIG, "delete, compact")
+ assertThrows(classOf[ConfigException], () => LogConfig.validate(props))
+ props.put(TopicConfig.CLEANUP_POLICY_CONFIG, "compact, delete")
+ assertThrows(classOf[ConfigException], () => LogConfig.validate(props))
}
}
diff --git a/core/src/test/scala/unit/kafka/server/DynamicBrokerConfigTest.scala b/core/src/test/scala/unit/kafka/server/DynamicBrokerConfigTest.scala
index 77715bc8230..17611b97211 100755
--- a/core/src/test/scala/unit/kafka/server/DynamicBrokerConfigTest.scala
+++ b/core/src/test/scala/unit/kafka/server/DynamicBrokerConfigTest.scala
@@ -33,6 +33,7 @@ import org.apache.kafka.common.config.{ConfigException, SslConfigs}
import org.apache.kafka.common.metrics.{JmxReporter, Metrics}
import org.apache.kafka.common.network.ListenerName
import org.apache.kafka.server.authorizer._
+import org.apache.kafka.server.log.remote.storage.RemoteLogManagerConfig
import org.apache.kafka.server.metrics.KafkaYammerMetrics
import org.apache.kafka.server.util.KafkaScheduler
import org.apache.kafka.storage.internals.log.{LogConfig, ProducerStateManagerConfig}
@@ -713,6 +714,99 @@ class DynamicBrokerConfigTest {
config.updateCurrentConfig(new KafkaConfig(props))
assertFalse(config.nonInternalValues.containsKey(KafkaConfig.MetadataLogSegmentMinBytesProp))
}
+
+ @Test
+ def testDynamicLogLocalRetentionMsConfig(): Unit = {
+ val props = TestUtils.createBrokerConfig(0, TestUtils.MockZkConnect, port = 8181)
+ props.put(KafkaConfig.LogRetentionTimeMillisProp, "2592000000")
+ val config = KafkaConfig(props)
+ val dynamicLogConfig = new DynamicLogConfig(mock(classOf[LogManager]), mock(classOf[KafkaServer]))
+ config.dynamicConfig.initialize(None)
+ config.dynamicConfig.addBrokerReconfigurable(dynamicLogConfig)
+
+ val newProps = new Properties()
+ newProps.put(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, "2160000000")
+ // update default config
+ config.dynamicConfig.validate(newProps, perBrokerConfig = false)
+ config.dynamicConfig.updateDefaultConfig(newProps)
+ assertEquals(2160000000L, config.logLocalRetentionMs)
+
+ // update per broker config
+ config.dynamicConfig.validate(newProps, perBrokerConfig = true)
+ newProps.put(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, "2150000000")
+ config.dynamicConfig.updateBrokerConfig(0, newProps)
+ assertEquals(2150000000L, config.logLocalRetentionMs)
+ }
+
+ @Test
+ def testDynamicLogLocalRetentionSizeConfig(): Unit = {
+ val props = TestUtils.createBrokerConfig(0, TestUtils.MockZkConnect, port = 8181)
+ props.put(KafkaConfig.LogRetentionBytesProp, "4294967296")
+ val config = KafkaConfig(props)
+ val dynamicLogConfig = new DynamicLogConfig(mock(classOf[LogManager]), mock(classOf[KafkaServer]))
+ config.dynamicConfig.initialize(None)
+ config.dynamicConfig.addBrokerReconfigurable(dynamicLogConfig)
+
+ val newProps = new Properties()
+ newProps.put(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP, "4294967295")
+ // update default config
+ config.dynamicConfig.validate(newProps, perBrokerConfig = false)
+ config.dynamicConfig.updateDefaultConfig(newProps)
+ assertEquals(4294967295L, config.logLocalRetentionBytes)
+
+ // update per broker config
+ config.dynamicConfig.validate(newProps, perBrokerConfig = true)
+ newProps.put(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP, "4294967294")
+ config.dynamicConfig.updateBrokerConfig(0, newProps)
+ assertEquals(4294967294L, config.logLocalRetentionBytes)
+ }
+
+ @Test
+ def testDynamicLogLocalRetentionSkipsOnInvalidConfig(): Unit = {
+ val props = TestUtils.createBrokerConfig(0, TestUtils.MockZkConnect, port = 8181)
+ props.put(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, "1000")
+ props.put(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP, "1024")
+ val config = KafkaConfig(props)
+ config.dynamicConfig.initialize(None)
+
+ // Check for invalid localRetentionMs < -2
+ verifyConfigUpdateWithInvalidConfig(config, props, Map.empty, Map(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP -> "-3"))
+ // Check for invalid localRetentionBytes < -2
+ verifyConfigUpdateWithInvalidConfig(config, props, Map.empty, Map(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP -> "-3"))
+ }
+
+ @Test
+ def testDynamicLogLocalRetentionThrowsOnIncorrectConfig(): Unit = {
+ // Check for incorrect case of logLocalRetentionMs > retentionMs
+ verifyIncorrectLogLocalRetentionProps(2000L, 1000L, 2, 100)
+ // Check for incorrect case of logLocalRetentionBytes > retentionBytes
+ verifyIncorrectLogLocalRetentionProps(500L, 1000L, 200, 100)
+ // Check for incorrect case of logLocalRetentionMs (-1 viz unlimited) > retentionMs,
+ verifyIncorrectLogLocalRetentionProps(-1, 1000L, 200, 100)
+ // Check for incorrect case of logLocalRetentionBytes(-1 viz unlimited) > retentionBytes
+ verifyIncorrectLogLocalRetentionProps(2000L, 1000L, -1, 100)
+ }
+
+ def verifyIncorrectLogLocalRetentionProps(logLocalRetentionMs: Long,
+ retentionMs: Long,
+ logLocalRetentionBytes: Long,
+ retentionBytes: Long): Unit = {
+ val props = TestUtils.createBrokerConfig(0, TestUtils.MockZkConnect, port = 8181)
+ props.put(KafkaConfig.LogRetentionTimeMillisProp, retentionMs.toString)
+ props.put(KafkaConfig.LogRetentionBytesProp, retentionBytes.toString)
+ val config = KafkaConfig(props)
+ val dynamicLogConfig = new DynamicLogConfig(mock(classOf[LogManager]), mock(classOf[KafkaServer]))
+ config.dynamicConfig.initialize(None)
+ config.dynamicConfig.addBrokerReconfigurable(dynamicLogConfig)
+
+ val newProps = new Properties()
+ newProps.put(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, logLocalRetentionMs.toString)
+ newProps.put(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP, logLocalRetentionBytes.toString)
+ // validate default config
+ assertThrows(classOf[ConfigException], () => config.dynamicConfig.validate(newProps, perBrokerConfig = false))
+ // validate per broker config
+ assertThrows(classOf[ConfigException], () => config.dynamicConfig.validate(newProps, perBrokerConfig = true))
+ }
}
class TestDynamicThreadPool() extends BrokerReconfigurable {
diff --git a/core/src/test/scala/unit/kafka/server/KafkaConfigTest.scala b/core/src/test/scala/unit/kafka/server/KafkaConfigTest.scala
index 1b969a49359..5136862192c 100755
--- a/core/src/test/scala/unit/kafka/server/KafkaConfigTest.scala
+++ b/core/src/test/scala/unit/kafka/server/KafkaConfigTest.scala
@@ -1020,6 +1020,8 @@ class KafkaConfigTest {
case RemoteLogManagerConfig.REMOTE_LOG_MANAGER_TASK_RETRY_JITTER_PROP => assertPropertyInvalid(baseProperties, name, "not_a_number", -1, 0.51)
case RemoteLogManagerConfig.REMOTE_LOG_READER_THREADS_PROP => assertPropertyInvalid(baseProperties, name, "not_a_number", 0, -1)
case RemoteLogManagerConfig.REMOTE_LOG_READER_MAX_PENDING_TASKS_PROP => assertPropertyInvalid(baseProperties, name, "not_a_number", 0, -1)
+ case RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP => assertPropertyInvalid(baseProperties, name, "not_a_number", -3)
+ case RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP => assertPropertyInvalid(baseProperties, name, "not_a_number", -3)
/** New group coordinator configs */
case KafkaConfig.NewGroupCoordinatorEnableProp => // ignore
@@ -1035,9 +1037,6 @@ class KafkaConfigTest {
case KafkaConfig.ConsumerGroupMaxSizeProp => assertPropertyInvalid(baseProperties, name, "not_a_number", 0, -1)
case KafkaConfig.ConsumerGroupAssignorsProp => // ignore string
- case TopicConfig.LOCAL_LOG_RETENTION_MS_CONFIG => assertPropertyInvalid(baseProperties, name, "not_a_number", 0, -2)
- case TopicConfig.LOCAL_LOG_RETENTION_BYTES_CONFIG => assertPropertyInvalid(baseProperties, name, "not_a_number", 0, -2)
-
case _ => assertPropertyInvalid(baseProperties, name, "not_a_number", "-1")
}
}
@@ -1053,6 +1052,7 @@ class KafkaConfigTest {
}
val props = baseProperties
+ props.put(RemoteLogManagerConfig.REMOTE_LOG_STORAGE_SYSTEM_ENABLE_PROP, "true")
val config = KafkaConfig.fromProps(props)
def assertDynamic(property: String, value: Any, accessor: () => Any): Unit = {
@@ -1114,6 +1114,10 @@ class KafkaConfigTest {
assertDynamic(kafkaConfigProp, 10014L, () => config.logRollTimeJitterMillis)
case TopicConfig.UNCLEAN_LEADER_ELECTION_ENABLE_CONFIG =>
assertDynamic(kafkaConfigProp, true, () => config.uncleanLeaderElectionEnable)
+ case TopicConfig.LOCAL_LOG_RETENTION_MS_CONFIG =>
+ assertDynamic(kafkaConfigProp, 10015L, () => config.logLocalRetentionMs)
+ case TopicConfig.LOCAL_LOG_RETENTION_BYTES_CONFIG =>
+ assertDynamic(kafkaConfigProp, 10016L, () => config.logLocalRetentionBytes)
case TopicConfig.MESSAGE_FORMAT_VERSION_CONFIG =>
// not dynamically updatable
case LogConfig.FOLLOWER_REPLICATION_THROTTLED_REPLICAS_CONFIG =>
@@ -1784,4 +1788,22 @@ class KafkaConfigTest {
props.put(KafkaConfig.ConsumerGroupHeartbeatIntervalMsProp, "25")
assertThrows(classOf[IllegalArgumentException], () => KafkaConfig.fromProps(props))
}
+
+ @Test
+ def testMultipleLogDirectoriesNotSupportedWithRemoteLogStorage(): Unit = {
+ val props = TestUtils.createBrokerConfig(0, TestUtils.MockZkConnect, port = 8181)
+ props.put(RemoteLogManagerConfig.REMOTE_LOG_STORAGE_SYSTEM_ENABLE_PROP, String.valueOf(true))
+ props.put(KafkaConfig.LogDirsProp, "/tmp/a,/tmp/b")
+
+ val caught = assertThrows(classOf[ConfigException], () => KafkaConfig.fromProps(props))
+ assertTrue(caught.getMessage.contains("Multiple log directories `/tmp/a,/tmp/b` are not supported when remote log storage is enabled"))
+ }
+
+ @Test
+ def testSingleLogDirectoryWithRemoteLogStorage(): Unit = {
+ val props = TestUtils.createBrokerConfig(0, TestUtils.MockZkConnect, port = 8181)
+ props.put(RemoteLogManagerConfig.REMOTE_LOG_STORAGE_SYSTEM_ENABLE_PROP, String.valueOf(true))
+ props.put(KafkaConfig.LogDirsProp, "/tmp/a")
+ assertDoesNotThrow(() => KafkaConfig.fromProps(props))
+ }
}
diff --git a/server-common/src/main/java/org/apache/kafka/server/config/ServerTopicConfigSynonyms.java b/server-common/src/main/java/org/apache/kafka/server/config/ServerTopicConfigSynonyms.java
index c6a8c61390d..ece3891a419 100644
--- a/server-common/src/main/java/org/apache/kafka/server/config/ServerTopicConfigSynonyms.java
+++ b/server-common/src/main/java/org/apache/kafka/server/config/ServerTopicConfigSynonyms.java
@@ -83,7 +83,9 @@ public final class ServerTopicConfigSynonyms {
sameNameWithLogPrefix(TopicConfig.MESSAGE_FORMAT_VERSION_CONFIG),
sameNameWithLogPrefix(TopicConfig.MESSAGE_TIMESTAMP_TYPE_CONFIG),
sameNameWithLogPrefix(TopicConfig.MESSAGE_TIMESTAMP_DIFFERENCE_MAX_MS_CONFIG),
- sameNameWithLogPrefix(TopicConfig.MESSAGE_DOWNCONVERSION_ENABLE_CONFIG)
+ sameNameWithLogPrefix(TopicConfig.MESSAGE_DOWNCONVERSION_ENABLE_CONFIG),
+ sameNameWithLogPrefix(TopicConfig.LOCAL_LOG_RETENTION_MS_CONFIG),
+ sameNameWithLogPrefix(TopicConfig.LOCAL_LOG_RETENTION_BYTES_CONFIG)
));
/**
diff --git a/storage/src/main/java/org/apache/kafka/server/log/remote/storage/RemoteLogManagerConfig.java b/storage/src/main/java/org/apache/kafka/server/log/remote/storage/RemoteLogManagerConfig.java
index f5700bb10b5..17a2746fdb3 100644
--- a/storage/src/main/java/org/apache/kafka/server/log/remote/storage/RemoteLogManagerConfig.java
+++ b/storage/src/main/java/org/apache/kafka/server/log/remote/storage/RemoteLogManagerConfig.java
@@ -97,7 +97,7 @@ public final class RemoteLogManagerConfig {
public static final long DEFAULT_REMOTE_LOG_MANAGER_TASK_INTERVAL_MS = 30 * 1000L;
public static final String REMOTE_LOG_MANAGER_TASK_RETRY_BACK_OFF_MS_PROP = "remote.log.manager.task.retry.backoff.ms";
- public static final String REMOTE_LOG_MANAGER_TASK_RETRY_BACK_OFF_MS_DOC = "The initial amount of wait in milli seconds before the request is retried again.";
+ public static final String REMOTE_LOG_MANAGER_TASK_RETRY_BACK_OFF_MS_DOC = "The initial amount of wait in milliseconds before the request is retried again.";
public static final long DEFAULT_REMOTE_LOG_MANAGER_TASK_RETRY_BACK_OFF_MS = 500L;
public static final String REMOTE_LOG_MANAGER_TASK_RETRY_BACK_OFF_MAX_MS_PROP = "remote.log.manager.task.retry.backoff.max.ms";
@@ -122,6 +122,18 @@ public final class RemoteLogManagerConfig {
"is full, fetch requests are served with an error.";
public static final int DEFAULT_REMOTE_LOG_READER_MAX_PENDING_TASKS = 100;
+ public static final String LOG_LOCAL_RETENTION_MS_PROP = "log.local.retention.ms";
+ public static final String LOG_LOCAL_RETENTION_MS_DOC = "The number of milliseconds to keep the local log segments before it gets eligible for deletion. " +
+ "Default value is -2, it represents `log.retention.ms` value is to be used. The effective value should always be less than or equal " +
+ "to `log.retention.ms` value.";
+ public static final Long DEFAULT_LOG_LOCAL_RETENTION_MS = -2L;
+
+ public static final String LOG_LOCAL_RETENTION_BYTES_PROP = "log.local.retention.bytes";
+ public static final String LOG_LOCAL_RETENTION_BYTES_DOC = "The maximum size of local log segments that can grow for a partition before it gets eligible for deletion. " +
+ "Default value is -2, it represents `log.retention.bytes` value to be used. The effective value should always be " +
+ "less than or equal to `log.retention.bytes` value.";
+ public static final Long DEFAULT_LOG_LOCAL_RETENTION_BYTES = -2L;
+
public static final ConfigDef CONFIG_DEF = new ConfigDef();
static {
@@ -215,7 +227,19 @@ public final class RemoteLogManagerConfig {
DEFAULT_REMOTE_LOG_READER_MAX_PENDING_TASKS,
atLeast(1),
MEDIUM,
- REMOTE_LOG_READER_MAX_PENDING_TASKS_DOC);
+ REMOTE_LOG_READER_MAX_PENDING_TASKS_DOC)
+ .defineInternal(LOG_LOCAL_RETENTION_MS_PROP,
+ LONG,
+ DEFAULT_LOG_LOCAL_RETENTION_MS,
+ atLeast(DEFAULT_LOG_LOCAL_RETENTION_MS),
+ MEDIUM,
+ LOG_LOCAL_RETENTION_MS_DOC)
+ .defineInternal(LOG_LOCAL_RETENTION_BYTES_PROP,
+ LONG,
+ DEFAULT_LOG_LOCAL_RETENTION_BYTES,
+ atLeast(DEFAULT_LOG_LOCAL_RETENTION_BYTES),
+ MEDIUM,
+ LOG_LOCAL_RETENTION_BYTES_DOC);
}
private final boolean enableRemoteStorageSystem;
diff --git a/storage/src/main/java/org/apache/kafka/storage/internals/log/LogConfig.java b/storage/src/main/java/org/apache/kafka/storage/internals/log/LogConfig.java
index 2ad084d1854..6ed1e848373 100644
--- a/storage/src/main/java/org/apache/kafka/storage/internals/log/LogConfig.java
+++ b/storage/src/main/java/org/apache/kafka/storage/internals/log/LogConfig.java
@@ -102,49 +102,14 @@ public class LogConfig extends AbstractConfig {
public static class RemoteLogConfig {
- public final boolean remoteStorageEnable;
+ private final boolean remoteStorageEnable;
+ private final long localRetentionMs;
+ private final long localRetentionBytes;
- public final long localRetentionMs;
- public final long localRetentionBytes;
-
- private RemoteLogConfig(LogConfig config, long retentionMs, long retentionSize) {
+ private RemoteLogConfig(LogConfig config) {
this.remoteStorageEnable = config.getBoolean(TopicConfig.REMOTE_LOG_STORAGE_ENABLE_CONFIG);
-
- long localLogRetentionMs = config.getLong(TopicConfig.LOCAL_LOG_RETENTION_MS_CONFIG);
-
- // -2 indicates to derive value from retentionMs property.
- if (localLogRetentionMs == -2)
- this.localRetentionMs = retentionMs;
- else {
- // Added validation here to check the effective value should not be more than RetentionMs.
- if (localLogRetentionMs == -1 && retentionMs != -1)
- throw new ConfigException(TopicConfig.LOCAL_LOG_RETENTION_MS_CONFIG, localLogRetentionMs,
- "Value must not be -1 as " + TopicConfig.RETENTION_MS_CONFIG + " value is set as " + retentionMs);
-
- if (localLogRetentionMs > retentionMs)
- throw new ConfigException(TopicConfig.LOCAL_LOG_RETENTION_MS_CONFIG, localLogRetentionMs,
- "Value must not be more than property: " + TopicConfig.RETENTION_MS_CONFIG + " value.");
-
- this.localRetentionMs = localLogRetentionMs;
- }
-
- long localLogRetentionBytes = config.getLong(TopicConfig.LOCAL_LOG_RETENTION_BYTES_CONFIG);
-
- // -2 indicates to derive value from retentionSize property.
- if (localLogRetentionBytes == -2)
- this.localRetentionBytes = retentionSize;
- else {
- // Added validation here to check the effective value should not be more than RetentionBytes.
- if (localLogRetentionBytes == -1 && retentionSize != -1)
- throw new ConfigException(TopicConfig.LOCAL_LOG_RETENTION_BYTES_CONFIG, localLogRetentionBytes,
- "Value must not be -1 as " + TopicConfig.RETENTION_BYTES_CONFIG + " value is set as " + retentionSize);
-
- if (localLogRetentionBytes > retentionSize)
- throw new ConfigException(TopicConfig.LOCAL_LOG_RETENTION_BYTES_CONFIG, localLogRetentionBytes,
- "Value must not be more than property: " + TopicConfig.RETENTION_BYTES_CONFIG + " value.");
-
- this.localRetentionBytes = localLogRetentionBytes;
- }
+ this.localRetentionMs = config.getLong(TopicConfig.LOCAL_LOG_RETENTION_MS_CONFIG);
+ this.localRetentionBytes = config.getLong(TopicConfig.LOCAL_LOG_RETENTION_BYTES_CONFIG);
}
}
@@ -205,8 +170,8 @@ public class LogConfig extends AbstractConfig {
public static final boolean DEFAULT_MESSAGE_DOWNCONVERSION_ENABLE = true;
public static final boolean DEFAULT_REMOTE_STORAGE_ENABLE = false;
- public static final int DEFAULT_LOCAL_RETENTION_BYTES = -2; // It indicates the value to be derived from RetentionBytes
- public static final int DEFAULT_LOCAL_RETENTION_MS = -2; // It indicates the value to be derived from RetentionMs
+ public static final long DEFAULT_LOCAL_RETENTION_BYTES = -2; // It indicates the value to be derived from RetentionBytes
+ public static final long DEFAULT_LOCAL_RETENTION_MS = -2; // It indicates the value to be derived from RetentionMs
public static final List<String> DEFAULT_LEADER_REPLICATION_THROTTLED_REPLICAS = Collections.emptyList();
public static final List<String> DEFAULT_FOLLOWER_REPLICATION_THROTTLED_REPLICAS = Collections.emptyList();
@@ -224,8 +189,6 @@ public class LogConfig extends AbstractConfig {
// Visible for testing
public static final Set<String> CONFIGS_WITH_NO_SERVER_DEFAULTS = Collections.unmodifiableSet(Utils.mkSet(
TopicConfig.REMOTE_LOG_STORAGE_ENABLE_CONFIG,
- TopicConfig.LOCAL_LOG_RETENTION_MS_CONFIG,
- TopicConfig.LOCAL_LOG_RETENTION_BYTES_CONFIG,
LEADER_REPLICATION_THROTTLED_REPLICAS_CONFIG,
FOLLOWER_REPLICATION_THROTTLED_REPLICAS_CONFIG
));
@@ -297,11 +260,11 @@ public class LogConfig extends AbstractConfig {
ThrottledReplicaListValidator.INSTANCE, MEDIUM, FOLLOWER_REPLICATION_THROTTLED_REPLICAS_DOC)
.define(TopicConfig.MESSAGE_DOWNCONVERSION_ENABLE_CONFIG, BOOLEAN, DEFAULT_MESSAGE_DOWNCONVERSION_ENABLE, LOW,
TopicConfig.MESSAGE_DOWNCONVERSION_ENABLE_DOC)
- .defineInternal(TopicConfig.REMOTE_LOG_STORAGE_ENABLE_CONFIG, BOOLEAN, DEFAULT_REMOTE_STORAGE_ENABLE, null,
+ .define(TopicConfig.REMOTE_LOG_STORAGE_ENABLE_CONFIG, BOOLEAN, DEFAULT_REMOTE_STORAGE_ENABLE, null,
MEDIUM, TopicConfig.REMOTE_LOG_STORAGE_ENABLE_DOC)
- .defineInternal(TopicConfig.LOCAL_LOG_RETENTION_MS_CONFIG, LONG, DEFAULT_LOCAL_RETENTION_MS, atLeast(-2), MEDIUM,
+ .define(TopicConfig.LOCAL_LOG_RETENTION_MS_CONFIG, LONG, DEFAULT_LOCAL_RETENTION_MS, atLeast(-2), MEDIUM,
TopicConfig.LOCAL_LOG_RETENTION_MS_DOC)
- .defineInternal(TopicConfig.LOCAL_LOG_RETENTION_BYTES_CONFIG, LONG, DEFAULT_LOCAL_RETENTION_BYTES, atLeast(-2), MEDIUM,
+ .define(TopicConfig.LOCAL_LOG_RETENTION_BYTES_CONFIG, LONG, DEFAULT_LOCAL_RETENTION_BYTES, atLeast(-2), MEDIUM,
TopicConfig.LOCAL_LOG_RETENTION_BYTES_DOC);
}
@@ -390,7 +353,7 @@ public class LogConfig extends AbstractConfig {
this.followerReplicationThrottledReplicas = Collections.unmodifiableList(getList(LogConfig.FOLLOWER_REPLICATION_THROTTLED_REPLICAS_CONFIG));
this.messageDownConversionEnable = getBoolean(TopicConfig.MESSAGE_DOWNCONVERSION_ENABLE_CONFIG);
- remoteLogConfig = new RemoteLogConfig(this, retentionMs, retentionSize);
+ remoteLogConfig = new RemoteLogConfig(this);
}
@SuppressWarnings("deprecation")
@@ -424,6 +387,18 @@ public class LogConfig extends AbstractConfig {
return 0;
}
+ public boolean remoteStorageEnable() {
+ return remoteLogConfig.remoteStorageEnable;
+ }
+
+ public long localRetentionMs() {
+ return remoteLogConfig.localRetentionMs == LogConfig.DEFAULT_LOCAL_RETENTION_MS ? retentionMs : remoteLogConfig.localRetentionMs;
+ }
+
+ public long localRetentionBytes() {
+ return remoteLogConfig.localRetentionBytes == LogConfig.DEFAULT_LOCAL_RETENTION_BYTES ? retentionSize : remoteLogConfig.localRetentionBytes;
+ }
+
public String overriddenConfigsAsLoggableString() {
Map<String, Object> overriddenTopicProps = new HashMap<>();
props.forEach((k, v) -> {
@@ -487,6 +462,48 @@ public class LogConfig extends AbstractConfig {
+ TopicConfig.MIN_COMPACTION_LAG_MS_CONFIG + " (" + minCompactionLag + ") > "
+ TopicConfig.MAX_COMPACTION_LAG_MS_CONFIG + " (" + maxCompactionLag + ")");
}
+
+ if (props.containsKey(TopicConfig.REMOTE_LOG_STORAGE_ENABLE_CONFIG)) {
+ boolean isRemoteStorageEnabled = (Boolean) props.get(TopicConfig.REMOTE_LOG_STORAGE_ENABLE_CONFIG);
+ String cleanupPolicy = props.get(TopicConfig.CLEANUP_POLICY_CONFIG).toString().toLowerCase(Locale.getDefault());
+ if (isRemoteStorageEnabled && cleanupPolicy.contains(TopicConfig.CLEANUP_POLICY_COMPACT)) {
+ throw new ConfigException("Remote log storage is unsupported for the compacted topics");
+ }
+ }
+
+ if (props.containsKey(TopicConfig.LOCAL_LOG_RETENTION_BYTES_CONFIG)) {
+ Long retentionBytes = (Long) props.get(TopicConfig.RETENTION_BYTES_CONFIG);
+ Long localLogRetentionBytes = (Long) props.get(TopicConfig.LOCAL_LOG_RETENTION_BYTES_CONFIG);
+ if (retentionBytes > -1 && localLogRetentionBytes != -2) {
+ if (localLogRetentionBytes == -1) {
+ String message = String.format("Value must not be -1 as %s value is set as %d.",
+ TopicConfig.RETENTION_BYTES_CONFIG, retentionBytes);
+ throw new ConfigException(TopicConfig.LOCAL_LOG_RETENTION_BYTES_CONFIG, localLogRetentionBytes, message);
+ }
+ if (localLogRetentionBytes > retentionBytes) {
+ String message = String.format("Value must not be more than %s property value: %d",
+ TopicConfig.RETENTION_BYTES_CONFIG, retentionBytes);
+ throw new ConfigException(TopicConfig.LOCAL_LOG_RETENTION_BYTES_CONFIG, localLogRetentionBytes, message);
+ }
+ }
+ }
+
+ if (props.containsKey(TopicConfig.LOCAL_LOG_RETENTION_MS_CONFIG)) {
+ Long retentionMs = (Long) props.get(TopicConfig.RETENTION_MS_CONFIG);
+ Long localLogRetentionMs = (Long) props.get(TopicConfig.LOCAL_LOG_RETENTION_MS_CONFIG);
+ if (retentionMs != -1 && localLogRetentionMs != -2) {
+ if (localLogRetentionMs == -1) {
+ String message = String.format("Value must not be -1 as %s value is set as %d.",
+ TopicConfig.RETENTION_MS_CONFIG, retentionMs);
+ throw new ConfigException(TopicConfig.LOCAL_LOG_RETENTION_MS_CONFIG, localLogRetentionMs, message);
+ }
+ if (localLogRetentionMs > retentionMs) {
+ String message = String.format("Value must not be more than %s property value: %d",
+ TopicConfig.RETENTION_MS_CONFIG, retentionMs);
+ throw new ConfigException(TopicConfig.LOCAL_LOG_RETENTION_MS_CONFIG, localLogRetentionMs, message);
+ }
+ }
+ }
}
/**