You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "unknowntpo (via GitHub)" <gi...@apache.org> on 2026/05/23 06:08:14 UTC
[PR] MINOR: Move DynamicLogConfig to server module [kafka]
unknowntpo opened a new pull request, #22353:
URL: https://github.com/apache/kafka/pull/22353
## Summary
Move `DynamicLogConfig` from `core` to the `server` module as a Java `BrokerReconfigurable`.
This also moves `extractLogConfigMap` to `AbstractKafkaConfig`, so log reconfiguration no longer depends directly on `kafka.server.KafkaConfig`.
## Testing
- `./gradlew :core:test --tests kafka.server.DynamicBrokerConfigTest`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-18948 Move DynamicLogConfig to server module [kafka]
Posted by "unknowntpo (via GitHub)" <gi...@apache.org>.
unknowntpo commented on code in PR #22353:
URL: https://github.com/apache/kafka/pull/22353#discussion_r3297028308
##########
server/src/main/java/org/apache/kafka/server/config/DynamicLogConfig.java:
##########
@@ -0,0 +1,174 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.config;
+
+import org.apache.kafka.common.config.AbstractConfig;
+import org.apache.kafka.common.config.ConfigException;
+import org.apache.kafka.config.BrokerReconfigurable;
+import org.apache.kafka.server.common.DirectoryEventHandler;
+import org.apache.kafka.server.log.remote.storage.RemoteLogManagerConfig;
+import org.apache.kafka.storage.internals.log.LogConfig;
+import org.apache.kafka.storage.internals.log.LogManager;
+import org.apache.kafka.storage.internals.log.UnifiedLog;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class DynamicLogConfig implements BrokerReconfigurable {
Review Comment:
Okay, `DynamicLogConfigTest` are added, please take a look, thanks.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-18948 Move DynamicLogConfig to server module [kafka]
Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on code in PR #22353:
URL: https://github.com/apache/kafka/pull/22353#discussion_r3305226776
##########
server/src/main/java/org/apache/kafka/server/config/DynamicLogConfig.java:
##########
@@ -0,0 +1,176 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.config;
+
+import org.apache.kafka.common.config.AbstractConfig;
+import org.apache.kafka.common.config.ConfigException;
+import org.apache.kafka.config.BrokerReconfigurable;
+import org.apache.kafka.server.common.DirectoryEventHandler;
+import org.apache.kafka.server.log.remote.storage.RemoteLogManagerConfig;
+import org.apache.kafka.storage.internals.log.LogConfig;
+import org.apache.kafka.storage.internals.log.LogManager;
+import org.apache.kafka.storage.internals.log.UnifiedLog;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class DynamicLogConfig implements BrokerReconfigurable {
+ /**
+ * The broker configurations pertaining to logs that are reconfigurable. This set contains
+ * the names you would use when setting a static or dynamic broker configuration (not topic
+ * configuration).
+ */
+ public static final Set<String> RECONFIGURABLE_CONFIGS = Stream.of(
+ ServerTopicConfigSynonyms.TOPIC_CONFIG_SYNONYMS.values(),
+ Set.of(ServerLogConfigs.CORDONED_LOG_DIRS_CONFIG))
+ .flatMap(Collection::stream)
+ .collect(Collectors.toUnmodifiableSet());
+
+ private final LogManager logManager;
+ private final DirectoryEventHandler directoryEventHandler;
+
+ public DynamicLogConfig(LogManager logManager, DirectoryEventHandler directoryEventHandler) {
+ this.logManager = logManager;
+ this.directoryEventHandler = directoryEventHandler;
+ }
+
+ @Override
+ public Set<String> reconfigurableConfigs() {
+ return RECONFIGURABLE_CONFIGS;
+ }
+
+ @Override
+ public void validateReconfiguration(AbstractConfig newConfig) {
+ AbstractKafkaConfig kafkaConfig = requireKafkaConfig(newConfig);
+ validateLogLocalRetentionMs(kafkaConfig);
+ validateLogLocalRetentionBytes(kafkaConfig);
+ validateLogRemoteCopyLagMs(kafkaConfig);
+ validateLogRemoteCopyLagBytes(kafkaConfig);
+ validateCordonedLogDirs(kafkaConfig);
+ }
+
+ private AbstractKafkaConfig requireKafkaConfig(AbstractConfig config) {
Review Comment:
Maybe we could add generics to BrokerReconfigurable? For example, BrokerReconfigurable<T extends AbstractConfig>. This would allow both the storage and server modules to access the specific config types they need
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-18948 Move DynamicLogConfig to server module [kafka]
Posted by "unknowntpo (via GitHub)" <gi...@apache.org>.
unknowntpo commented on code in PR #22353:
URL: https://github.com/apache/kafka/pull/22353#discussion_r3322018427
##########
server/src/main/java/org/apache/kafka/server/config/DynamicLogConfig.java:
##########
@@ -0,0 +1,176 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.config;
+
+import org.apache.kafka.common.config.AbstractConfig;
+import org.apache.kafka.common.config.ConfigException;
+import org.apache.kafka.config.BrokerReconfigurable;
+import org.apache.kafka.server.common.DirectoryEventHandler;
+import org.apache.kafka.server.log.remote.storage.RemoteLogManagerConfig;
+import org.apache.kafka.storage.internals.log.LogConfig;
+import org.apache.kafka.storage.internals.log.LogManager;
+import org.apache.kafka.storage.internals.log.UnifiedLog;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class DynamicLogConfig implements BrokerReconfigurable {
+ /**
+ * The broker configurations pertaining to logs that are reconfigurable. This set contains
+ * the names you would use when setting a static or dynamic broker configuration (not topic
+ * configuration).
+ */
+ public static final Set<String> RECONFIGURABLE_CONFIGS = Stream.of(
+ ServerTopicConfigSynonyms.TOPIC_CONFIG_SYNONYMS.values(),
+ Set.of(ServerLogConfigs.CORDONED_LOG_DIRS_CONFIG))
+ .flatMap(Collection::stream)
+ .collect(Collectors.toUnmodifiableSet());
+
+ private final LogManager logManager;
+ private final DirectoryEventHandler directoryEventHandler;
+
+ public DynamicLogConfig(LogManager logManager, DirectoryEventHandler directoryEventHandler) {
+ this.logManager = logManager;
+ this.directoryEventHandler = directoryEventHandler;
+ }
+
+ @Override
+ public Set<String> reconfigurableConfigs() {
+ return RECONFIGURABLE_CONFIGS;
+ }
+
+ @Override
+ public void validateReconfiguration(AbstractConfig newConfig) {
+ AbstractKafkaConfig kafkaConfig = requireKafkaConfig(newConfig);
+ validateLogLocalRetentionMs(kafkaConfig);
+ validateLogLocalRetentionBytes(kafkaConfig);
+ validateLogRemoteCopyLagMs(kafkaConfig);
+ validateLogRemoteCopyLagBytes(kafkaConfig);
+ validateCordonedLogDirs(kafkaConfig);
+ }
+
+ private AbstractKafkaConfig requireKafkaConfig(AbstractConfig config) {
Review Comment:
I raised a minor PR https://github.com/apache/kafka/pull/22409 for the generic `BrokerReconfigurable`, and add temporary commits about it to verify if it worked here. I would drop that commit after https://github.com/apache/kafka/pull/22409 is merged.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-18948 Move DynamicLogConfig to server module [kafka]
Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on PR #22353:
URL: https://github.com/apache/kafka/pull/22353#issuecomment-6107063916
@unknowntpo please fix the conflicts
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-18948 Move DynamicLogConfig to server module [kafka]
Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on code in PR #22353:
URL: https://github.com/apache/kafka/pull/22353#discussion_r3294114499
##########
server/src/main/java/org/apache/kafka/server/config/DynamicLogConfig.java:
##########
@@ -0,0 +1,174 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.config;
+
+import org.apache.kafka.common.config.AbstractConfig;
+import org.apache.kafka.common.config.ConfigException;
+import org.apache.kafka.config.BrokerReconfigurable;
+import org.apache.kafka.server.common.DirectoryEventHandler;
+import org.apache.kafka.server.log.remote.storage.RemoteLogManagerConfig;
+import org.apache.kafka.storage.internals.log.LogConfig;
+import org.apache.kafka.storage.internals.log.LogManager;
+import org.apache.kafka.storage.internals.log.UnifiedLog;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class DynamicLogConfig implements BrokerReconfigurable {
+ /**
+ * The broker configurations pertaining to logs that are reconfigurable. This set contains
+ * the names you would use when setting a static or dynamic broker configuration (not topic
+ * configuration).
+ */
+ public static final Set<String> RECONFIGURABLE_CONFIGS = Stream.of(
+ ServerTopicConfigSynonyms.TOPIC_CONFIG_SYNONYMS.values(),
+ Set.of(ServerLogConfigs.CORDONED_LOG_DIRS_CONFIG))
+ .flatMap(Collection::stream)
+ .collect(Collectors.toUnmodifiableSet());
+
+ private final LogManager logManager;
+ private final DirectoryEventHandler directoryEventHandler;
+
+ public DynamicLogConfig(LogManager logManager, DirectoryEventHandler directoryEventHandler) {
+ this.logManager = logManager;
+ this.directoryEventHandler = directoryEventHandler;
+ }
+
+ @Override
+ public Set<String> reconfigurableConfigs() {
+ return RECONFIGURABLE_CONFIGS;
+ }
+
+ @Override
+ public void validateReconfiguration(AbstractConfig newConfig) {
+ AbstractKafkaConfig kafkaConfig = requireKafkaConfig(newConfig);
+ validateLogLocalRetentionMs(kafkaConfig);
+ validateLogLocalRetentionBytes(kafkaConfig);
+ validateLogRemoteCopyLagMs(kafkaConfig);
+ validateLogRemoteCopyLagBytes(kafkaConfig);
+ validateCordonedLogDirs(kafkaConfig);
+ }
+
+ private AbstractKafkaConfig requireKafkaConfig(AbstractConfig config) {
+ if (!(config instanceof AbstractKafkaConfig kafkaConfig)) {
+ throw new IllegalArgumentException("DynamicLogConfig requires AbstractKafkaConfig, got " +
+ config.getClass().getName());
+ }
+ return kafkaConfig;
+ }
+
+ private void validateLogLocalRetentionMs(AbstractKafkaConfig config) {
+ long logRetentionMs = config.logRetentionTimeMillis();
+ long logLocalRetentionMs = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP);
+ if (logRetentionMs != -1L && logLocalRetentionMs != -2L) {
+ if (logLocalRetentionMs == -1L) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, logLocalRetentionMs,
+ "Value must not be -1 as " + ServerLogConfigs.LOG_RETENTION_TIME_MILLIS_CONFIG + " value is set as " + logRetentionMs + ".");
+ }
+ if (logLocalRetentionMs > logRetentionMs) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, logLocalRetentionMs,
+ "Value must not be more than " + ServerLogConfigs.LOG_RETENTION_TIME_MILLIS_CONFIG + " property value: " + logRetentionMs);
+ }
+ }
+ }
+
+ private void validateLogLocalRetentionBytes(AbstractKafkaConfig config) {
+ long logRetentionBytes = config.logRetentionBytes();
+ long logLocalRetentionBytes = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP);
+ if (logRetentionBytes > -1L && logLocalRetentionBytes != -2L) {
+ if (logLocalRetentionBytes == -1L) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP, logLocalRetentionBytes,
+ "Value must not be -1 as " + ServerLogConfigs.LOG_RETENTION_BYTES_CONFIG + " value is set as " + logRetentionBytes + ".");
+ }
+ if (logLocalRetentionBytes > logRetentionBytes) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP, logLocalRetentionBytes,
+ "Value must not be more than " + ServerLogConfigs.LOG_RETENTION_BYTES_CONFIG + " property value: " + logRetentionBytes);
+ }
+ }
+ }
+
+ private void validateLogRemoteCopyLagMs(AbstractKafkaConfig config) {
+ long logRetentionMs = config.logRetentionTimeMillis();
+ long logLocalRetentionMs = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP);
+ long effectiveLocalRetentionMs = logLocalRetentionMs == -2L ? logRetentionMs : logLocalRetentionMs;
+ long logRemoteCopyLagMs = config.getLong(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_MS_PROP);
+ if (logRemoteCopyLagMs > 0L && effectiveLocalRetentionMs >= 0L && logRemoteCopyLagMs > effectiveLocalRetentionMs) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_MS_PROP, logRemoteCopyLagMs,
+ "Value must not exceed " + RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP +
+ " (effective value: " + effectiveLocalRetentionMs + ")");
+ }
+ }
+
+ private void validateLogRemoteCopyLagBytes(AbstractKafkaConfig config) {
+ long logRetentionBytes = config.logRetentionBytes();
+ long logLocalRetentionBytes = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP);
+ long effectiveLocalRetentionBytes = logLocalRetentionBytes == -2L ? logRetentionBytes : logLocalRetentionBytes;
+ long logRemoteCopyLagBytes = config.getLong(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_BYTES_PROP);
+ if (logRemoteCopyLagBytes > 0L && effectiveLocalRetentionBytes >= 0L && logRemoteCopyLagBytes > effectiveLocalRetentionBytes) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_BYTES_PROP, logRemoteCopyLagBytes,
+ "Value must not exceed " + RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP +
+ " (effective value: " + effectiveLocalRetentionBytes + ")");
+ }
+ }
+
+ private void validateCordonedLogDirs(AbstractKafkaConfig config) {
+ List<String> cordonedLogDirs = config.cordonedLogDirs();
+ List<String> logDirs = config.logDirs();
+ for (String dir : cordonedLogDirs) {
+ if (!logDirs.contains(dir)) {
+ throw new ConfigException(ServerLogConfigs.CORDONED_LOG_DIRS_CONFIG, cordonedLogDirs,
+ "Invalid entry in " + ServerLogConfigs.CORDONED_LOG_DIRS_CONFIG + ": " + dir + ". " +
+ "All cordoned log dirs must be entries of " + ServerLogConfigs.LOG_DIRS_CONFIG + " or " +
+ ServerLogConfigs.LOG_DIR_CONFIG + ".");
+ }
+ }
+ }
+
+ private void updateLogsConfig(Map<String, Object> newBrokerDefaults) {
+ logManager.brokerConfigUpdated();
+ for (UnifiedLog unifiedLog : logManager.allLogs()) {
+ Map<String, Object> props = new HashMap<>(newBrokerDefaults);
+ unifiedLog.config().originals().entrySet().stream()
Review Comment:
We could call `forEach` directly
```java
unifiedLog.config().originals().forEach((k, v) -> {
if (unifiedLog.config().overriddenConfigs.contains(k)) {
props.put(k, v);
}
});
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-18948 Move DynamicLogConfig to server module [kafka]
Posted by "unknowntpo (via GitHub)" <gi...@apache.org>.
unknowntpo commented on code in PR #22353:
URL: https://github.com/apache/kafka/pull/22353#discussion_r3297029727
##########
server/src/main/java/org/apache/kafka/server/config/DynamicLogConfig.java:
##########
@@ -0,0 +1,174 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.config;
+
+import org.apache.kafka.common.config.AbstractConfig;
+import org.apache.kafka.common.config.ConfigException;
+import org.apache.kafka.config.BrokerReconfigurable;
+import org.apache.kafka.server.common.DirectoryEventHandler;
+import org.apache.kafka.server.log.remote.storage.RemoteLogManagerConfig;
+import org.apache.kafka.storage.internals.log.LogConfig;
+import org.apache.kafka.storage.internals.log.LogManager;
+import org.apache.kafka.storage.internals.log.UnifiedLog;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class DynamicLogConfig implements BrokerReconfigurable {
+ /**
+ * The broker configurations pertaining to logs that are reconfigurable. This set contains
+ * the names you would use when setting a static or dynamic broker configuration (not topic
+ * configuration).
+ */
+ public static final Set<String> RECONFIGURABLE_CONFIGS = Stream.of(
+ ServerTopicConfigSynonyms.TOPIC_CONFIG_SYNONYMS.values(),
+ Set.of(ServerLogConfigs.CORDONED_LOG_DIRS_CONFIG))
+ .flatMap(Collection::stream)
+ .collect(Collectors.toUnmodifiableSet());
+
+ private final LogManager logManager;
+ private final DirectoryEventHandler directoryEventHandler;
+
+ public DynamicLogConfig(LogManager logManager, DirectoryEventHandler directoryEventHandler) {
+ this.logManager = logManager;
+ this.directoryEventHandler = directoryEventHandler;
+ }
+
+ @Override
+ public Set<String> reconfigurableConfigs() {
+ return RECONFIGURABLE_CONFIGS;
+ }
+
+ @Override
+ public void validateReconfiguration(AbstractConfig newConfig) {
+ AbstractKafkaConfig kafkaConfig = requireKafkaConfig(newConfig);
+ validateLogLocalRetentionMs(kafkaConfig);
+ validateLogLocalRetentionBytes(kafkaConfig);
+ validateLogRemoteCopyLagMs(kafkaConfig);
+ validateLogRemoteCopyLagBytes(kafkaConfig);
+ validateCordonedLogDirs(kafkaConfig);
+ }
+
+ private AbstractKafkaConfig requireKafkaConfig(AbstractConfig config) {
+ if (!(config instanceof AbstractKafkaConfig kafkaConfig)) {
+ throw new IllegalArgumentException("DynamicLogConfig requires AbstractKafkaConfig, got " +
+ config.getClass().getName());
+ }
+ return kafkaConfig;
+ }
+
+ private void validateLogLocalRetentionMs(AbstractKafkaConfig config) {
+ long logRetentionMs = config.logRetentionTimeMillis();
+ long logLocalRetentionMs = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP);
+ if (logRetentionMs != -1L && logLocalRetentionMs != -2L) {
+ if (logLocalRetentionMs == -1L) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, logLocalRetentionMs,
+ "Value must not be -1 as " + ServerLogConfigs.LOG_RETENTION_TIME_MILLIS_CONFIG + " value is set as " + logRetentionMs + ".");
+ }
+ if (logLocalRetentionMs > logRetentionMs) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, logLocalRetentionMs,
+ "Value must not be more than " + ServerLogConfigs.LOG_RETENTION_TIME_MILLIS_CONFIG + " property value: " + logRetentionMs);
+ }
+ }
+ }
+
+ private void validateLogLocalRetentionBytes(AbstractKafkaConfig config) {
+ long logRetentionBytes = config.logRetentionBytes();
+ long logLocalRetentionBytes = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP);
+ if (logRetentionBytes > -1L && logLocalRetentionBytes != -2L) {
+ if (logLocalRetentionBytes == -1L) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP, logLocalRetentionBytes,
+ "Value must not be -1 as " + ServerLogConfigs.LOG_RETENTION_BYTES_CONFIG + " value is set as " + logRetentionBytes + ".");
+ }
+ if (logLocalRetentionBytes > logRetentionBytes) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP, logLocalRetentionBytes,
+ "Value must not be more than " + ServerLogConfigs.LOG_RETENTION_BYTES_CONFIG + " property value: " + logRetentionBytes);
+ }
+ }
+ }
+
+ private void validateLogRemoteCopyLagMs(AbstractKafkaConfig config) {
+ long logRetentionMs = config.logRetentionTimeMillis();
+ long logLocalRetentionMs = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP);
+ long effectiveLocalRetentionMs = logLocalRetentionMs == -2L ? logRetentionMs : logLocalRetentionMs;
+ long logRemoteCopyLagMs = config.getLong(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_MS_PROP);
+ if (logRemoteCopyLagMs > 0L && effectiveLocalRetentionMs >= 0L && logRemoteCopyLagMs > effectiveLocalRetentionMs) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_MS_PROP, logRemoteCopyLagMs,
+ "Value must not exceed " + RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP +
+ " (effective value: " + effectiveLocalRetentionMs + ")");
+ }
+ }
+
+ private void validateLogRemoteCopyLagBytes(AbstractKafkaConfig config) {
+ long logRetentionBytes = config.logRetentionBytes();
+ long logLocalRetentionBytes = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP);
+ long effectiveLocalRetentionBytes = logLocalRetentionBytes == -2L ? logRetentionBytes : logLocalRetentionBytes;
+ long logRemoteCopyLagBytes = config.getLong(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_BYTES_PROP);
+ if (logRemoteCopyLagBytes > 0L && effectiveLocalRetentionBytes >= 0L && logRemoteCopyLagBytes > effectiveLocalRetentionBytes) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_BYTES_PROP, logRemoteCopyLagBytes,
+ "Value must not exceed " + RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP +
+ " (effective value: " + effectiveLocalRetentionBytes + ")");
+ }
+ }
+
+ private void validateCordonedLogDirs(AbstractKafkaConfig config) {
+ List<String> cordonedLogDirs = config.cordonedLogDirs();
+ List<String> logDirs = config.logDirs();
+ for (String dir : cordonedLogDirs) {
+ if (!logDirs.contains(dir)) {
+ throw new ConfigException(ServerLogConfigs.CORDONED_LOG_DIRS_CONFIG, cordonedLogDirs,
+ "Invalid entry in " + ServerLogConfigs.CORDONED_LOG_DIRS_CONFIG + ": " + dir + ". " +
+ "All cordoned log dirs must be entries of " + ServerLogConfigs.LOG_DIRS_CONFIG + " or " +
+ ServerLogConfigs.LOG_DIR_CONFIG + ".");
+ }
+ }
+ }
+
+ private void updateLogsConfig(Map<String, Object> newBrokerDefaults) {
+ logManager.brokerConfigUpdated();
+ for (UnifiedLog unifiedLog : logManager.allLogs()) {
+ Map<String, Object> props = new HashMap<>(newBrokerDefaults);
+ unifiedLog.config().originals().entrySet().stream()
Review Comment:
Fixed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINOR: Move DynamicLogConfig to server module [kafka]
Posted by "m1a2st (via GitHub)" <gi...@apache.org>.
m1a2st commented on code in PR #22353:
URL: https://github.com/apache/kafka/pull/22353#discussion_r3292807018
##########
server/src/main/java/org/apache/kafka/server/config/DynamicLogConfig.java:
##########
@@ -0,0 +1,174 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.config;
+
+import org.apache.kafka.common.config.AbstractConfig;
+import org.apache.kafka.common.config.ConfigException;
+import org.apache.kafka.config.BrokerReconfigurable;
+import org.apache.kafka.server.common.DirectoryEventHandler;
+import org.apache.kafka.server.log.remote.storage.RemoteLogManagerConfig;
+import org.apache.kafka.storage.internals.log.LogConfig;
+import org.apache.kafka.storage.internals.log.LogManager;
+import org.apache.kafka.storage.internals.log.UnifiedLog;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class DynamicLogConfig implements BrokerReconfigurable {
Review Comment:
We should add new test for this new config class.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-18948 Move DynamicLogConfig to server module [kafka]
Posted by "unknowntpo (via GitHub)" <gi...@apache.org>.
unknowntpo commented on code in PR #22353:
URL: https://github.com/apache/kafka/pull/22353#discussion_r3297058527
##########
server/src/main/java/org/apache/kafka/server/config/DynamicLogConfig.java:
##########
@@ -0,0 +1,176 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.config;
+
+import org.apache.kafka.common.config.AbstractConfig;
+import org.apache.kafka.common.config.ConfigException;
+import org.apache.kafka.config.BrokerReconfigurable;
+import org.apache.kafka.server.common.DirectoryEventHandler;
+import org.apache.kafka.server.log.remote.storage.RemoteLogManagerConfig;
+import org.apache.kafka.storage.internals.log.LogConfig;
+import org.apache.kafka.storage.internals.log.LogManager;
+import org.apache.kafka.storage.internals.log.UnifiedLog;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class DynamicLogConfig implements BrokerReconfigurable {
+ /**
+ * The broker configurations pertaining to logs that are reconfigurable. This set contains
+ * the names you would use when setting a static or dynamic broker configuration (not topic
+ * configuration).
+ */
+ public static final Set<String> RECONFIGURABLE_CONFIGS = Stream.of(
+ ServerTopicConfigSynonyms.TOPIC_CONFIG_SYNONYMS.values(),
+ Set.of(ServerLogConfigs.CORDONED_LOG_DIRS_CONFIG))
+ .flatMap(Collection::stream)
+ .collect(Collectors.toUnmodifiableSet());
+
+ private final LogManager logManager;
+ private final DirectoryEventHandler directoryEventHandler;
+
+ public DynamicLogConfig(LogManager logManager, DirectoryEventHandler directoryEventHandler) {
+ this.logManager = logManager;
+ this.directoryEventHandler = directoryEventHandler;
+ }
+
+ @Override
+ public Set<String> reconfigurableConfigs() {
+ return RECONFIGURABLE_CONFIGS;
+ }
+
+ @Override
+ public void validateReconfiguration(AbstractConfig newConfig) {
+ AbstractKafkaConfig kafkaConfig = requireKafkaConfig(newConfig);
+ validateLogLocalRetentionMs(kafkaConfig);
+ validateLogLocalRetentionBytes(kafkaConfig);
+ validateLogRemoteCopyLagMs(kafkaConfig);
+ validateLogRemoteCopyLagBytes(kafkaConfig);
+ validateCordonedLogDirs(kafkaConfig);
+ }
+
+ private AbstractKafkaConfig requireKafkaConfig(AbstractConfig config) {
+ if (!(config instanceof AbstractKafkaConfig kafkaConfig)) {
+ throw new IllegalArgumentException("DynamicLogConfig requires AbstractKafkaConfig, got " +
+ config.getClass().getName());
+ }
+ return kafkaConfig;
+ }
+
+ private void validateLogLocalRetentionMs(AbstractKafkaConfig config) {
+ long logRetentionMs = config.logRetentionTimeMillis();
+ long logLocalRetentionMs = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP);
+ if (logRetentionMs != LogConfig.NO_RETENTION_LIMIT && logLocalRetentionMs != LogConfig.DEFAULT_LOCAL_RETENTION_MS) {
Review Comment:
I also replaced raw `-1` / `-2` retention sentinels with `LogConfig` constants. This keeps `DynamicLogConfig` aligned with `LogConfig` semantics and makes the validation easier to read without changing behavior.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-18948 Move DynamicLogConfig to server module [kafka]
Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on code in PR #22353:
URL: https://github.com/apache/kafka/pull/22353#discussion_r3500026801
##########
server/src/main/java/org/apache/kafka/server/config/DynamicLogConfig.java:
##########
@@ -0,0 +1,164 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.config;
+
+import org.apache.kafka.common.config.ConfigException;
+import org.apache.kafka.server.common.DirectoryEventHandler;
+import org.apache.kafka.server.log.remote.storage.RemoteLogManagerConfig;
+import org.apache.kafka.storage.internals.log.LogConfig;
+import org.apache.kafka.storage.internals.log.LogManager;
+import org.apache.kafka.storage.internals.log.UnifiedLog;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class DynamicLogConfig implements BrokerReconfigurable {
+ /**
+ * The broker configurations pertaining to logs that are reconfigurable. This set contains
+ * the names you would use when setting a static or dynamic broker configuration (not topic
+ * configuration).
+ */
+ public static final Set<String> RECONFIGURABLE_CONFIGS = Stream.of(
+ ServerTopicConfigSynonyms.TOPIC_CONFIG_SYNONYMS.values(),
+ Set.of(ServerLogConfigs.CORDONED_LOG_DIRS_CONFIG))
+ .flatMap(Collection::stream)
+ .collect(Collectors.toUnmodifiableSet());
+
+ private final LogManager logManager;
+ private final DirectoryEventHandler directoryEventHandler;
+
+ public DynamicLogConfig(LogManager logManager, DirectoryEventHandler directoryEventHandler) {
+ this.logManager = logManager;
+ this.directoryEventHandler = directoryEventHandler;
+ }
+
+ @Override
+ public Set<String> reconfigurableConfigs() {
+ return RECONFIGURABLE_CONFIGS;
+ }
+
+ @Override
+ public void validateReconfiguration(AbstractKafkaConfig newConfig) {
+ validateLogLocalRetentionMs(newConfig);
+ validateLogLocalRetentionBytes(newConfig);
+ validateLogRemoteCopyLagMs(newConfig);
+ validateLogRemoteCopyLagBytes(newConfig);
+ validateCordonedLogDirs(newConfig);
+ }
+
+ private void validateLogLocalRetentionMs(AbstractKafkaConfig config) {
+ long logRetentionMs = config.logRetentionTimeMillis();
+ long logLocalRetentionMs = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP);
+ if (logRetentionMs != LogConfig.NO_RETENTION_LIMIT && logLocalRetentionMs != LogConfig.DEFAULT_LOCAL_RETENTION_MS) {
+ if (logLocalRetentionMs == LogConfig.NO_RETENTION_LIMIT) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, logLocalRetentionMs,
+ "Value must not be " + LogConfig.NO_RETENTION_LIMIT + " as " + ServerLogConfigs.LOG_RETENTION_TIME_MILLIS_CONFIG + " value is set as " + logRetentionMs + ".");
+ }
+ if (logLocalRetentionMs > logRetentionMs) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, logLocalRetentionMs,
+ "Value must not be more than " + ServerLogConfigs.LOG_RETENTION_TIME_MILLIS_CONFIG + " property value: " + logRetentionMs);
+ }
+ }
+ }
+
+ private void validateLogLocalRetentionBytes(AbstractKafkaConfig config) {
+ long logRetentionBytes = config.logRetentionBytes();
+ long logLocalRetentionBytes = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP);
+ if (logRetentionBytes > LogConfig.NO_RETENTION_LIMIT && logLocalRetentionBytes != LogConfig.DEFAULT_LOCAL_RETENTION_BYTES) {
+ if (logLocalRetentionBytes == LogConfig.NO_RETENTION_LIMIT) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP, logLocalRetentionBytes,
+ "Value must not be " + LogConfig.NO_RETENTION_LIMIT + " as " + ServerLogConfigs.LOG_RETENTION_BYTES_CONFIG + " value is set as " + logRetentionBytes + ".");
+ }
+ if (logLocalRetentionBytes > logRetentionBytes) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP, logLocalRetentionBytes,
+ "Value must not be more than " + ServerLogConfigs.LOG_RETENTION_BYTES_CONFIG + " property value: " + logRetentionBytes);
+ }
+ }
+ }
+
+ private void validateLogRemoteCopyLagMs(AbstractKafkaConfig config) {
Review Comment:
ditto
##########
server/src/main/java/org/apache/kafka/server/config/DynamicLogConfig.java:
##########
@@ -0,0 +1,164 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.config;
+
+import org.apache.kafka.common.config.ConfigException;
+import org.apache.kafka.server.common.DirectoryEventHandler;
+import org.apache.kafka.server.log.remote.storage.RemoteLogManagerConfig;
+import org.apache.kafka.storage.internals.log.LogConfig;
+import org.apache.kafka.storage.internals.log.LogManager;
+import org.apache.kafka.storage.internals.log.UnifiedLog;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class DynamicLogConfig implements BrokerReconfigurable {
+ /**
+ * The broker configurations pertaining to logs that are reconfigurable. This set contains
+ * the names you would use when setting a static or dynamic broker configuration (not topic
+ * configuration).
+ */
+ public static final Set<String> RECONFIGURABLE_CONFIGS = Stream.of(
+ ServerTopicConfigSynonyms.TOPIC_CONFIG_SYNONYMS.values(),
+ Set.of(ServerLogConfigs.CORDONED_LOG_DIRS_CONFIG))
+ .flatMap(Collection::stream)
+ .collect(Collectors.toUnmodifiableSet());
+
+ private final LogManager logManager;
+ private final DirectoryEventHandler directoryEventHandler;
+
+ public DynamicLogConfig(LogManager logManager, DirectoryEventHandler directoryEventHandler) {
+ this.logManager = logManager;
+ this.directoryEventHandler = directoryEventHandler;
+ }
+
+ @Override
+ public Set<String> reconfigurableConfigs() {
+ return RECONFIGURABLE_CONFIGS;
+ }
+
+ @Override
+ public void validateReconfiguration(AbstractKafkaConfig newConfig) {
+ validateLogLocalRetentionMs(newConfig);
+ validateLogLocalRetentionBytes(newConfig);
+ validateLogRemoteCopyLagMs(newConfig);
+ validateLogRemoteCopyLagBytes(newConfig);
+ validateCordonedLogDirs(newConfig);
+ }
+
+ private void validateLogLocalRetentionMs(AbstractKafkaConfig config) {
Review Comment:
ditto
##########
server/src/main/java/org/apache/kafka/server/config/DynamicLogConfig.java:
##########
@@ -0,0 +1,164 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.config;
+
+import org.apache.kafka.common.config.ConfigException;
+import org.apache.kafka.server.common.DirectoryEventHandler;
+import org.apache.kafka.server.log.remote.storage.RemoteLogManagerConfig;
+import org.apache.kafka.storage.internals.log.LogConfig;
+import org.apache.kafka.storage.internals.log.LogManager;
+import org.apache.kafka.storage.internals.log.UnifiedLog;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class DynamicLogConfig implements BrokerReconfigurable {
+ /**
+ * The broker configurations pertaining to logs that are reconfigurable. This set contains
+ * the names you would use when setting a static or dynamic broker configuration (not topic
+ * configuration).
+ */
+ public static final Set<String> RECONFIGURABLE_CONFIGS = Stream.of(
+ ServerTopicConfigSynonyms.TOPIC_CONFIG_SYNONYMS.values(),
+ Set.of(ServerLogConfigs.CORDONED_LOG_DIRS_CONFIG))
+ .flatMap(Collection::stream)
+ .collect(Collectors.toUnmodifiableSet());
+
+ private final LogManager logManager;
+ private final DirectoryEventHandler directoryEventHandler;
+
+ public DynamicLogConfig(LogManager logManager, DirectoryEventHandler directoryEventHandler) {
+ this.logManager = logManager;
+ this.directoryEventHandler = directoryEventHandler;
+ }
+
+ @Override
+ public Set<String> reconfigurableConfigs() {
+ return RECONFIGURABLE_CONFIGS;
+ }
+
+ @Override
+ public void validateReconfiguration(AbstractKafkaConfig newConfig) {
+ validateLogLocalRetentionMs(newConfig);
+ validateLogLocalRetentionBytes(newConfig);
+ validateLogRemoteCopyLagMs(newConfig);
+ validateLogRemoteCopyLagBytes(newConfig);
+ validateCordonedLogDirs(newConfig);
+ }
+
+ private void validateLogLocalRetentionMs(AbstractKafkaConfig config) {
+ long logRetentionMs = config.logRetentionTimeMillis();
+ long logLocalRetentionMs = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP);
+ if (logRetentionMs != LogConfig.NO_RETENTION_LIMIT && logLocalRetentionMs != LogConfig.DEFAULT_LOCAL_RETENTION_MS) {
+ if (logLocalRetentionMs == LogConfig.NO_RETENTION_LIMIT) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, logLocalRetentionMs,
+ "Value must not be " + LogConfig.NO_RETENTION_LIMIT + " as " + ServerLogConfigs.LOG_RETENTION_TIME_MILLIS_CONFIG + " value is set as " + logRetentionMs + ".");
+ }
+ if (logLocalRetentionMs > logRetentionMs) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, logLocalRetentionMs,
+ "Value must not be more than " + ServerLogConfigs.LOG_RETENTION_TIME_MILLIS_CONFIG + " property value: " + logRetentionMs);
+ }
+ }
+ }
+
+ private void validateLogLocalRetentionBytes(AbstractKafkaConfig config) {
+ long logRetentionBytes = config.logRetentionBytes();
+ long logLocalRetentionBytes = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP);
+ if (logRetentionBytes > LogConfig.NO_RETENTION_LIMIT && logLocalRetentionBytes != LogConfig.DEFAULT_LOCAL_RETENTION_BYTES) {
+ if (logLocalRetentionBytes == LogConfig.NO_RETENTION_LIMIT) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP, logLocalRetentionBytes,
+ "Value must not be " + LogConfig.NO_RETENTION_LIMIT + " as " + ServerLogConfigs.LOG_RETENTION_BYTES_CONFIG + " value is set as " + logRetentionBytes + ".");
+ }
+ if (logLocalRetentionBytes > logRetentionBytes) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP, logLocalRetentionBytes,
+ "Value must not be more than " + ServerLogConfigs.LOG_RETENTION_BYTES_CONFIG + " property value: " + logRetentionBytes);
+ }
+ }
+ }
+
+ private void validateLogRemoteCopyLagMs(AbstractKafkaConfig config) {
+ long logRetentionMs = config.logRetentionTimeMillis();
+ long logLocalRetentionMs = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP);
+ long effectiveLocalRetentionMs = logLocalRetentionMs == LogConfig.DEFAULT_LOCAL_RETENTION_MS ? logRetentionMs : logLocalRetentionMs;
+ long logRemoteCopyLagMs = config.getLong(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_MS_PROP);
+ if (logRemoteCopyLagMs > 0L && effectiveLocalRetentionMs >= 0L && logRemoteCopyLagMs > effectiveLocalRetentionMs) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_MS_PROP, logRemoteCopyLagMs,
+ "Value must not exceed " + RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP +
+ " (effective value: " + effectiveLocalRetentionMs + ")");
+ }
+ }
+
+ private void validateLogRemoteCopyLagBytes(AbstractKafkaConfig config) {
+ long logRetentionBytes = config.logRetentionBytes();
+ long logLocalRetentionBytes = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP);
+ long effectiveLocalRetentionBytes = logLocalRetentionBytes == LogConfig.DEFAULT_LOCAL_RETENTION_BYTES ? logRetentionBytes : logLocalRetentionBytes;
+ long logRemoteCopyLagBytes = config.getLong(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_BYTES_PROP);
+ if (logRemoteCopyLagBytes > 0L && effectiveLocalRetentionBytes >= 0L && logRemoteCopyLagBytes > effectiveLocalRetentionBytes) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_BYTES_PROP, logRemoteCopyLagBytes,
+ "Value must not exceed " + RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP +
+ " (effective value: " + effectiveLocalRetentionBytes + ")");
+ }
+ }
+
+ private void validateCordonedLogDirs(AbstractKafkaConfig config) {
+ List<String> cordonedLogDirs = config.cordonedLogDirs();
+ List<String> logDirs = config.logDirs();
+ for (String dir : cordonedLogDirs) {
Review Comment:
ditto
##########
server/src/main/java/org/apache/kafka/server/config/DynamicLogConfig.java:
##########
@@ -0,0 +1,164 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.config;
+
+import org.apache.kafka.common.config.ConfigException;
+import org.apache.kafka.server.common.DirectoryEventHandler;
+import org.apache.kafka.server.log.remote.storage.RemoteLogManagerConfig;
+import org.apache.kafka.storage.internals.log.LogConfig;
+import org.apache.kafka.storage.internals.log.LogManager;
+import org.apache.kafka.storage.internals.log.UnifiedLog;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class DynamicLogConfig implements BrokerReconfigurable {
+ /**
+ * The broker configurations pertaining to logs that are reconfigurable. This set contains
+ * the names you would use when setting a static or dynamic broker configuration (not topic
+ * configuration).
+ */
+ public static final Set<String> RECONFIGURABLE_CONFIGS = Stream.of(
+ ServerTopicConfigSynonyms.TOPIC_CONFIG_SYNONYMS.values(),
+ Set.of(ServerLogConfigs.CORDONED_LOG_DIRS_CONFIG))
+ .flatMap(Collection::stream)
+ .collect(Collectors.toUnmodifiableSet());
+
+ private final LogManager logManager;
+ private final DirectoryEventHandler directoryEventHandler;
+
+ public DynamicLogConfig(LogManager logManager, DirectoryEventHandler directoryEventHandler) {
+ this.logManager = logManager;
+ this.directoryEventHandler = directoryEventHandler;
+ }
+
+ @Override
+ public Set<String> reconfigurableConfigs() {
+ return RECONFIGURABLE_CONFIGS;
+ }
+
+ @Override
+ public void validateReconfiguration(AbstractKafkaConfig newConfig) {
+ validateLogLocalRetentionMs(newConfig);
+ validateLogLocalRetentionBytes(newConfig);
+ validateLogRemoteCopyLagMs(newConfig);
+ validateLogRemoteCopyLagBytes(newConfig);
+ validateCordonedLogDirs(newConfig);
+ }
+
+ private void validateLogLocalRetentionMs(AbstractKafkaConfig config) {
+ long logRetentionMs = config.logRetentionTimeMillis();
+ long logLocalRetentionMs = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP);
+ if (logRetentionMs != LogConfig.NO_RETENTION_LIMIT && logLocalRetentionMs != LogConfig.DEFAULT_LOCAL_RETENTION_MS) {
+ if (logLocalRetentionMs == LogConfig.NO_RETENTION_LIMIT) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, logLocalRetentionMs,
+ "Value must not be " + LogConfig.NO_RETENTION_LIMIT + " as " + ServerLogConfigs.LOG_RETENTION_TIME_MILLIS_CONFIG + " value is set as " + logRetentionMs + ".");
+ }
+ if (logLocalRetentionMs > logRetentionMs) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, logLocalRetentionMs,
+ "Value must not be more than " + ServerLogConfigs.LOG_RETENTION_TIME_MILLIS_CONFIG + " property value: " + logRetentionMs);
+ }
+ }
+ }
+
+ private void validateLogLocalRetentionBytes(AbstractKafkaConfig config) {
+ long logRetentionBytes = config.logRetentionBytes();
+ long logLocalRetentionBytes = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP);
+ if (logRetentionBytes > LogConfig.NO_RETENTION_LIMIT && logLocalRetentionBytes != LogConfig.DEFAULT_LOCAL_RETENTION_BYTES) {
+ if (logLocalRetentionBytes == LogConfig.NO_RETENTION_LIMIT) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP, logLocalRetentionBytes,
+ "Value must not be " + LogConfig.NO_RETENTION_LIMIT + " as " + ServerLogConfigs.LOG_RETENTION_BYTES_CONFIG + " value is set as " + logRetentionBytes + ".");
+ }
+ if (logLocalRetentionBytes > logRetentionBytes) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP, logLocalRetentionBytes,
+ "Value must not be more than " + ServerLogConfigs.LOG_RETENTION_BYTES_CONFIG + " property value: " + logRetentionBytes);
+ }
+ }
+ }
+
+ private void validateLogRemoteCopyLagMs(AbstractKafkaConfig config) {
+ long logRetentionMs = config.logRetentionTimeMillis();
+ long logLocalRetentionMs = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP);
+ long effectiveLocalRetentionMs = logLocalRetentionMs == LogConfig.DEFAULT_LOCAL_RETENTION_MS ? logRetentionMs : logLocalRetentionMs;
+ long logRemoteCopyLagMs = config.getLong(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_MS_PROP);
+ if (logRemoteCopyLagMs > 0L && effectiveLocalRetentionMs >= 0L && logRemoteCopyLagMs > effectiveLocalRetentionMs) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_MS_PROP, logRemoteCopyLagMs,
+ "Value must not exceed " + RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP +
+ " (effective value: " + effectiveLocalRetentionMs + ")");
+ }
+ }
+
+ private void validateLogRemoteCopyLagBytes(AbstractKafkaConfig config) {
Review Comment:
ditto
##########
server/src/main/java/org/apache/kafka/server/config/DynamicLogConfig.java:
##########
@@ -0,0 +1,164 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.config;
+
+import org.apache.kafka.common.config.ConfigException;
+import org.apache.kafka.server.common.DirectoryEventHandler;
+import org.apache.kafka.server.log.remote.storage.RemoteLogManagerConfig;
+import org.apache.kafka.storage.internals.log.LogConfig;
+import org.apache.kafka.storage.internals.log.LogManager;
+import org.apache.kafka.storage.internals.log.UnifiedLog;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class DynamicLogConfig implements BrokerReconfigurable {
+ /**
+ * The broker configurations pertaining to logs that are reconfigurable. This set contains
+ * the names you would use when setting a static or dynamic broker configuration (not topic
+ * configuration).
+ */
+ public static final Set<String> RECONFIGURABLE_CONFIGS = Stream.of(
+ ServerTopicConfigSynonyms.TOPIC_CONFIG_SYNONYMS.values(),
+ Set.of(ServerLogConfigs.CORDONED_LOG_DIRS_CONFIG))
+ .flatMap(Collection::stream)
+ .collect(Collectors.toUnmodifiableSet());
+
+ private final LogManager logManager;
+ private final DirectoryEventHandler directoryEventHandler;
+
+ public DynamicLogConfig(LogManager logManager, DirectoryEventHandler directoryEventHandler) {
+ this.logManager = logManager;
+ this.directoryEventHandler = directoryEventHandler;
+ }
+
+ @Override
+ public Set<String> reconfigurableConfigs() {
+ return RECONFIGURABLE_CONFIGS;
+ }
+
+ @Override
+ public void validateReconfiguration(AbstractKafkaConfig newConfig) {
+ validateLogLocalRetentionMs(newConfig);
+ validateLogLocalRetentionBytes(newConfig);
+ validateLogRemoteCopyLagMs(newConfig);
+ validateLogRemoteCopyLagBytes(newConfig);
+ validateCordonedLogDirs(newConfig);
+ }
+
+ private void validateLogLocalRetentionMs(AbstractKafkaConfig config) {
+ long logRetentionMs = config.logRetentionTimeMillis();
+ long logLocalRetentionMs = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP);
+ if (logRetentionMs != LogConfig.NO_RETENTION_LIMIT && logLocalRetentionMs != LogConfig.DEFAULT_LOCAL_RETENTION_MS) {
+ if (logLocalRetentionMs == LogConfig.NO_RETENTION_LIMIT) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, logLocalRetentionMs,
+ "Value must not be " + LogConfig.NO_RETENTION_LIMIT + " as " + ServerLogConfigs.LOG_RETENTION_TIME_MILLIS_CONFIG + " value is set as " + logRetentionMs + ".");
+ }
+ if (logLocalRetentionMs > logRetentionMs) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, logLocalRetentionMs,
+ "Value must not be more than " + ServerLogConfigs.LOG_RETENTION_TIME_MILLIS_CONFIG + " property value: " + logRetentionMs);
+ }
+ }
+ }
+
+ private void validateLogLocalRetentionBytes(AbstractKafkaConfig config) {
+ long logRetentionBytes = config.logRetentionBytes();
+ long logLocalRetentionBytes = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP);
+ if (logRetentionBytes > LogConfig.NO_RETENTION_LIMIT && logLocalRetentionBytes != LogConfig.DEFAULT_LOCAL_RETENTION_BYTES) {
+ if (logLocalRetentionBytes == LogConfig.NO_RETENTION_LIMIT) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP, logLocalRetentionBytes,
+ "Value must not be " + LogConfig.NO_RETENTION_LIMIT + " as " + ServerLogConfigs.LOG_RETENTION_BYTES_CONFIG + " value is set as " + logRetentionBytes + ".");
+ }
+ if (logLocalRetentionBytes > logRetentionBytes) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP, logLocalRetentionBytes,
+ "Value must not be more than " + ServerLogConfigs.LOG_RETENTION_BYTES_CONFIG + " property value: " + logRetentionBytes);
+ }
+ }
+ }
+
+ private void validateLogRemoteCopyLagMs(AbstractKafkaConfig config) {
+ long logRetentionMs = config.logRetentionTimeMillis();
+ long logLocalRetentionMs = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP);
+ long effectiveLocalRetentionMs = logLocalRetentionMs == LogConfig.DEFAULT_LOCAL_RETENTION_MS ? logRetentionMs : logLocalRetentionMs;
+ long logRemoteCopyLagMs = config.getLong(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_MS_PROP);
+ if (logRemoteCopyLagMs > 0L && effectiveLocalRetentionMs >= 0L && logRemoteCopyLagMs > effectiveLocalRetentionMs) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_MS_PROP, logRemoteCopyLagMs,
+ "Value must not exceed " + RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP +
+ " (effective value: " + effectiveLocalRetentionMs + ")");
+ }
+ }
+
+ private void validateLogRemoteCopyLagBytes(AbstractKafkaConfig config) {
+ long logRetentionBytes = config.logRetentionBytes();
+ long logLocalRetentionBytes = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP);
+ long effectiveLocalRetentionBytes = logLocalRetentionBytes == LogConfig.DEFAULT_LOCAL_RETENTION_BYTES ? logRetentionBytes : logLocalRetentionBytes;
+ long logRemoteCopyLagBytes = config.getLong(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_BYTES_PROP);
+ if (logRemoteCopyLagBytes > 0L && effectiveLocalRetentionBytes >= 0L && logRemoteCopyLagBytes > effectiveLocalRetentionBytes) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_BYTES_PROP, logRemoteCopyLagBytes,
+ "Value must not exceed " + RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP +
+ " (effective value: " + effectiveLocalRetentionBytes + ")");
+ }
+ }
+
+ private void validateCordonedLogDirs(AbstractKafkaConfig config) {
+ List<String> cordonedLogDirs = config.cordonedLogDirs();
+ List<String> logDirs = config.logDirs();
+ for (String dir : cordonedLogDirs) {
+ if (!logDirs.contains(dir)) {
Review Comment:
Could we find all unmatched folders and then add them into the log message?
##########
server/src/test/java/org/apache/kafka/server/config/DynamicLogConfigTest.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.config;
+
+import org.apache.kafka.common.Reconfigurable;
+import org.apache.kafka.common.config.ConfigException;
+import org.apache.kafka.raft.KRaftConfigs;
+import org.apache.kafka.server.common.DirectoryEventHandler;
+import org.apache.kafka.server.log.remote.storage.RemoteLogManagerConfig;
+import org.apache.kafka.storage.internals.log.LogManager;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.Mockito.mock;
+
+public class DynamicLogConfigTest {
+
+ private final DynamicLogConfig dynamicLogConfig = new DynamicLogConfig(
+ mock(LogManager.class),
+ mock(DirectoryEventHandler.class)
+ );
+
+ @Test
+ public void testValidateLogLocalRetentionMs() {
+ assertInvalidConfig(
+ Map.of(
+ ServerLogConfigs.LOG_RETENTION_TIME_MILLIS_CONFIG, "1000",
+ RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, "-1"
+ ),
+ "Invalid value -1 for configuration " + RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP +
+ ": Value must not be -1 as " + ServerLogConfigs.LOG_RETENTION_TIME_MILLIS_CONFIG +
+ " value is set as 1000."
+ );
+
+ assertInvalidConfig(
+ Map.of(
+ ServerLogConfigs.LOG_RETENTION_TIME_MILLIS_CONFIG, "1000",
+ RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, "1001"
+ ),
+ "Invalid value 1001 for configuration " + RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP +
+ ": Value must not be more than " + ServerLogConfigs.LOG_RETENTION_TIME_MILLIS_CONFIG +
+ " property value: 1000"
+ );
+ }
+
+ @Test
+ public void testValidateLogLocalRetentionBytes() {
+ assertInvalidConfig(
+ Map.of(
+ ServerLogConfigs.LOG_RETENTION_BYTES_CONFIG, "1000",
+ RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP, "-1"
+ ),
+ "Invalid value -1 for configuration " + RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP +
+ ": Value must not be -1 as " + ServerLogConfigs.LOG_RETENTION_BYTES_CONFIG +
+ " value is set as 1000."
+ );
+
+ assertInvalidConfig(
+ Map.of(
+ ServerLogConfigs.LOG_RETENTION_BYTES_CONFIG, "1000",
+ RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP, "1001"
+ ),
+ "Invalid value 1001 for configuration " + RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP +
+ ": Value must not be more than " + ServerLogConfigs.LOG_RETENTION_BYTES_CONFIG +
+ " property value: 1000"
+ );
+ }
+
+ private void assertInvalidConfig(Map<String, Object> overrides, String expectedMessage) {
+ ConfigException exception = assertThrows(
+ ConfigException.class,
+ () -> dynamicLogConfig.validateReconfiguration(kafkaConfig(overrides))
+ );
+ assertEquals(expectedMessage, exception.getMessage());
+ }
+
+ private static AbstractKafkaConfig kafkaConfig(Map<String, Object> overrides) {
+ Map<String, Object> props = new HashMap<>();
+ props.put(KRaftConfigs.PROCESS_ROLES_CONFIG, "broker");
+ props.put(KRaftConfigs.NODE_ID_CONFIG, "1");
+ props.put(KRaftConfigs.CONTROLLER_LISTENER_NAMES_CONFIG, "CONTROLLER");
+ props.putAll(overrides);
+ return new AbstractKafkaConfig(AbstractKafkaConfig.CONFIG_DEF, props, Map.of(), false) {
+ @Override
+ public void addReconfigurable(Reconfigurable reconfigurable) {
Review Comment:
those override methods are not necessary anymore
##########
server/src/main/java/org/apache/kafka/server/config/DynamicLogConfig.java:
##########
@@ -0,0 +1,164 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.config;
+
+import org.apache.kafka.common.config.ConfigException;
+import org.apache.kafka.server.common.DirectoryEventHandler;
+import org.apache.kafka.server.log.remote.storage.RemoteLogManagerConfig;
+import org.apache.kafka.storage.internals.log.LogConfig;
+import org.apache.kafka.storage.internals.log.LogManager;
+import org.apache.kafka.storage.internals.log.UnifiedLog;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class DynamicLogConfig implements BrokerReconfigurable {
+ /**
+ * The broker configurations pertaining to logs that are reconfigurable. This set contains
+ * the names you would use when setting a static or dynamic broker configuration (not topic
+ * configuration).
+ */
+ public static final Set<String> RECONFIGURABLE_CONFIGS = Stream.of(
+ ServerTopicConfigSynonyms.TOPIC_CONFIG_SYNONYMS.values(),
+ Set.of(ServerLogConfigs.CORDONED_LOG_DIRS_CONFIG))
+ .flatMap(Collection::stream)
+ .collect(Collectors.toUnmodifiableSet());
+
+ private final LogManager logManager;
+ private final DirectoryEventHandler directoryEventHandler;
+
+ public DynamicLogConfig(LogManager logManager, DirectoryEventHandler directoryEventHandler) {
+ this.logManager = logManager;
+ this.directoryEventHandler = directoryEventHandler;
+ }
+
+ @Override
+ public Set<String> reconfigurableConfigs() {
+ return RECONFIGURABLE_CONFIGS;
+ }
+
+ @Override
+ public void validateReconfiguration(AbstractKafkaConfig newConfig) {
+ validateLogLocalRetentionMs(newConfig);
+ validateLogLocalRetentionBytes(newConfig);
+ validateLogRemoteCopyLagMs(newConfig);
+ validateLogRemoteCopyLagBytes(newConfig);
+ validateCordonedLogDirs(newConfig);
+ }
+
+ private void validateLogLocalRetentionMs(AbstractKafkaConfig config) {
+ long logRetentionMs = config.logRetentionTimeMillis();
+ long logLocalRetentionMs = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP);
+ if (logRetentionMs != LogConfig.NO_RETENTION_LIMIT && logLocalRetentionMs != LogConfig.DEFAULT_LOCAL_RETENTION_MS) {
+ if (logLocalRetentionMs == LogConfig.NO_RETENTION_LIMIT) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, logLocalRetentionMs,
+ "Value must not be " + LogConfig.NO_RETENTION_LIMIT + " as " + ServerLogConfigs.LOG_RETENTION_TIME_MILLIS_CONFIG + " value is set as " + logRetentionMs + ".");
+ }
+ if (logLocalRetentionMs > logRetentionMs) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, logLocalRetentionMs,
+ "Value must not be more than " + ServerLogConfigs.LOG_RETENTION_TIME_MILLIS_CONFIG + " property value: " + logRetentionMs);
+ }
+ }
+ }
+
+ private void validateLogLocalRetentionBytes(AbstractKafkaConfig config) {
+ long logRetentionBytes = config.logRetentionBytes();
+ long logLocalRetentionBytes = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP);
+ if (logRetentionBytes > LogConfig.NO_RETENTION_LIMIT && logLocalRetentionBytes != LogConfig.DEFAULT_LOCAL_RETENTION_BYTES) {
+ if (logLocalRetentionBytes == LogConfig.NO_RETENTION_LIMIT) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP, logLocalRetentionBytes,
+ "Value must not be " + LogConfig.NO_RETENTION_LIMIT + " as " + ServerLogConfigs.LOG_RETENTION_BYTES_CONFIG + " value is set as " + logRetentionBytes + ".");
+ }
+ if (logLocalRetentionBytes > logRetentionBytes) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP, logLocalRetentionBytes,
+ "Value must not be more than " + ServerLogConfigs.LOG_RETENTION_BYTES_CONFIG + " property value: " + logRetentionBytes);
+ }
+ }
+ }
+
+ private void validateLogRemoteCopyLagMs(AbstractKafkaConfig config) {
+ long logRetentionMs = config.logRetentionTimeMillis();
+ long logLocalRetentionMs = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP);
+ long effectiveLocalRetentionMs = logLocalRetentionMs == LogConfig.DEFAULT_LOCAL_RETENTION_MS ? logRetentionMs : logLocalRetentionMs;
+ long logRemoteCopyLagMs = config.getLong(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_MS_PROP);
+ if (logRemoteCopyLagMs > 0L && effectiveLocalRetentionMs >= 0L && logRemoteCopyLagMs > effectiveLocalRetentionMs) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_MS_PROP, logRemoteCopyLagMs,
+ "Value must not exceed " + RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP +
+ " (effective value: " + effectiveLocalRetentionMs + ")");
+ }
+ }
+
+ private void validateLogRemoteCopyLagBytes(AbstractKafkaConfig config) {
+ long logRetentionBytes = config.logRetentionBytes();
+ long logLocalRetentionBytes = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP);
+ long effectiveLocalRetentionBytes = logLocalRetentionBytes == LogConfig.DEFAULT_LOCAL_RETENTION_BYTES ? logRetentionBytes : logLocalRetentionBytes;
+ long logRemoteCopyLagBytes = config.getLong(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_BYTES_PROP);
+ if (logRemoteCopyLagBytes > 0L && effectiveLocalRetentionBytes >= 0L && logRemoteCopyLagBytes > effectiveLocalRetentionBytes) {
Review Comment:
ditto
##########
server/src/main/java/org/apache/kafka/server/config/DynamicLogConfig.java:
##########
@@ -0,0 +1,164 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.config;
+
+import org.apache.kafka.common.config.ConfigException;
+import org.apache.kafka.server.common.DirectoryEventHandler;
+import org.apache.kafka.server.log.remote.storage.RemoteLogManagerConfig;
+import org.apache.kafka.storage.internals.log.LogConfig;
+import org.apache.kafka.storage.internals.log.LogManager;
+import org.apache.kafka.storage.internals.log.UnifiedLog;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class DynamicLogConfig implements BrokerReconfigurable {
+ /**
+ * The broker configurations pertaining to logs that are reconfigurable. This set contains
+ * the names you would use when setting a static or dynamic broker configuration (not topic
+ * configuration).
+ */
+ public static final Set<String> RECONFIGURABLE_CONFIGS = Stream.of(
+ ServerTopicConfigSynonyms.TOPIC_CONFIG_SYNONYMS.values(),
+ Set.of(ServerLogConfigs.CORDONED_LOG_DIRS_CONFIG))
+ .flatMap(Collection::stream)
+ .collect(Collectors.toUnmodifiableSet());
+
+ private final LogManager logManager;
+ private final DirectoryEventHandler directoryEventHandler;
+
+ public DynamicLogConfig(LogManager logManager, DirectoryEventHandler directoryEventHandler) {
+ this.logManager = logManager;
+ this.directoryEventHandler = directoryEventHandler;
+ }
+
+ @Override
+ public Set<String> reconfigurableConfigs() {
+ return RECONFIGURABLE_CONFIGS;
+ }
+
+ @Override
+ public void validateReconfiguration(AbstractKafkaConfig newConfig) {
+ validateLogLocalRetentionMs(newConfig);
+ validateLogLocalRetentionBytes(newConfig);
+ validateLogRemoteCopyLagMs(newConfig);
+ validateLogRemoteCopyLagBytes(newConfig);
+ validateCordonedLogDirs(newConfig);
+ }
+
+ private void validateLogLocalRetentionMs(AbstractKafkaConfig config) {
+ long logRetentionMs = config.logRetentionTimeMillis();
+ long logLocalRetentionMs = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP);
+ if (logRetentionMs != LogConfig.NO_RETENTION_LIMIT && logLocalRetentionMs != LogConfig.DEFAULT_LOCAL_RETENTION_MS) {
+ if (logLocalRetentionMs == LogConfig.NO_RETENTION_LIMIT) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, logLocalRetentionMs,
+ "Value must not be " + LogConfig.NO_RETENTION_LIMIT + " as " + ServerLogConfigs.LOG_RETENTION_TIME_MILLIS_CONFIG + " value is set as " + logRetentionMs + ".");
+ }
+ if (logLocalRetentionMs > logRetentionMs) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, logLocalRetentionMs,
+ "Value must not be more than " + ServerLogConfigs.LOG_RETENTION_TIME_MILLIS_CONFIG + " property value: " + logRetentionMs);
+ }
+ }
+ }
+
+ private void validateLogLocalRetentionBytes(AbstractKafkaConfig config) {
+ long logRetentionBytes = config.logRetentionBytes();
+ long logLocalRetentionBytes = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP);
+ if (logRetentionBytes > LogConfig.NO_RETENTION_LIMIT && logLocalRetentionBytes != LogConfig.DEFAULT_LOCAL_RETENTION_BYTES) {
+ if (logLocalRetentionBytes == LogConfig.NO_RETENTION_LIMIT) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP, logLocalRetentionBytes,
+ "Value must not be " + LogConfig.NO_RETENTION_LIMIT + " as " + ServerLogConfigs.LOG_RETENTION_BYTES_CONFIG + " value is set as " + logRetentionBytes + ".");
+ }
+ if (logLocalRetentionBytes > logRetentionBytes) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP, logLocalRetentionBytes,
+ "Value must not be more than " + ServerLogConfigs.LOG_RETENTION_BYTES_CONFIG + " property value: " + logRetentionBytes);
+ }
+ }
+ }
+
+ private void validateLogRemoteCopyLagMs(AbstractKafkaConfig config) {
+ long logRetentionMs = config.logRetentionTimeMillis();
+ long logLocalRetentionMs = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP);
+ long effectiveLocalRetentionMs = logLocalRetentionMs == LogConfig.DEFAULT_LOCAL_RETENTION_MS ? logRetentionMs : logLocalRetentionMs;
+ long logRemoteCopyLagMs = config.getLong(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_MS_PROP);
+ if (logRemoteCopyLagMs > 0L && effectiveLocalRetentionMs >= 0L && logRemoteCopyLagMs > effectiveLocalRetentionMs) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_MS_PROP, logRemoteCopyLagMs,
+ "Value must not exceed " + RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP +
+ " (effective value: " + effectiveLocalRetentionMs + ")");
+ }
+ }
+
+ private void validateLogRemoteCopyLagBytes(AbstractKafkaConfig config) {
+ long logRetentionBytes = config.logRetentionBytes();
+ long logLocalRetentionBytes = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP);
+ long effectiveLocalRetentionBytes = logLocalRetentionBytes == LogConfig.DEFAULT_LOCAL_RETENTION_BYTES ? logRetentionBytes : logLocalRetentionBytes;
+ long logRemoteCopyLagBytes = config.getLong(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_BYTES_PROP);
+ if (logRemoteCopyLagBytes > 0L && effectiveLocalRetentionBytes >= 0L && logRemoteCopyLagBytes > effectiveLocalRetentionBytes) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_BYTES_PROP, logRemoteCopyLagBytes,
+ "Value must not exceed " + RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP +
+ " (effective value: " + effectiveLocalRetentionBytes + ")");
+ }
+ }
+
+ private void validateCordonedLogDirs(AbstractKafkaConfig config) {
+ List<String> cordonedLogDirs = config.cordonedLogDirs();
+ List<String> logDirs = config.logDirs();
+ for (String dir : cordonedLogDirs) {
+ if (!logDirs.contains(dir)) {
+ throw new ConfigException(ServerLogConfigs.CORDONED_LOG_DIRS_CONFIG, cordonedLogDirs,
+ "Invalid entry in " + ServerLogConfigs.CORDONED_LOG_DIRS_CONFIG + ": " + dir + ". " +
+ "All cordoned log dirs must be entries of " + ServerLogConfigs.LOG_DIRS_CONFIG + " or " +
+ ServerLogConfigs.LOG_DIR_CONFIG + ".");
+ }
+ }
+ }
+
+ private void updateLogsConfig(Map<String, Object> newBrokerDefaults) {
+ logManager.brokerConfigUpdated();
+ for (UnifiedLog unifiedLog : logManager.allLogs()) {
+ Map<String, Object> props = new HashMap<>(newBrokerDefaults);
+ unifiedLog.config().originals().forEach((key, value) -> {
+ if (unifiedLog.config().overriddenConfigs.contains(key)) {
+ props.put(key, value);
+ }
+ });
+ unifiedLog.updateConfig(new LogConfig(props, unifiedLog.config().overriddenConfigs));
+ }
+ }
+
+ @Override
+ public void reconfigure(AbstractKafkaConfig oldConfig, AbstractKafkaConfig newConfig) {
+ Map<String, Object> newBrokerDefaults = new HashMap<>(newConfig.extractLogConfigMap());
Review Comment:
Why do we copy the `newConfig.extractLogConfigMap()`?
##########
server/src/main/java/org/apache/kafka/server/config/DynamicLogConfig.java:
##########
@@ -0,0 +1,164 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.config;
+
+import org.apache.kafka.common.config.ConfigException;
+import org.apache.kafka.server.common.DirectoryEventHandler;
+import org.apache.kafka.server.log.remote.storage.RemoteLogManagerConfig;
+import org.apache.kafka.storage.internals.log.LogConfig;
+import org.apache.kafka.storage.internals.log.LogManager;
+import org.apache.kafka.storage.internals.log.UnifiedLog;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class DynamicLogConfig implements BrokerReconfigurable {
+ /**
+ * The broker configurations pertaining to logs that are reconfigurable. This set contains
+ * the names you would use when setting a static or dynamic broker configuration (not topic
+ * configuration).
+ */
+ public static final Set<String> RECONFIGURABLE_CONFIGS = Stream.of(
+ ServerTopicConfigSynonyms.TOPIC_CONFIG_SYNONYMS.values(),
+ Set.of(ServerLogConfigs.CORDONED_LOG_DIRS_CONFIG))
+ .flatMap(Collection::stream)
+ .collect(Collectors.toUnmodifiableSet());
+
+ private final LogManager logManager;
+ private final DirectoryEventHandler directoryEventHandler;
+
+ public DynamicLogConfig(LogManager logManager, DirectoryEventHandler directoryEventHandler) {
+ this.logManager = logManager;
+ this.directoryEventHandler = directoryEventHandler;
+ }
+
+ @Override
+ public Set<String> reconfigurableConfigs() {
+ return RECONFIGURABLE_CONFIGS;
+ }
+
+ @Override
+ public void validateReconfiguration(AbstractKafkaConfig newConfig) {
+ validateLogLocalRetentionMs(newConfig);
+ validateLogLocalRetentionBytes(newConfig);
+ validateLogRemoteCopyLagMs(newConfig);
+ validateLogRemoteCopyLagBytes(newConfig);
+ validateCordonedLogDirs(newConfig);
+ }
+
+ private void validateLogLocalRetentionMs(AbstractKafkaConfig config) {
+ long logRetentionMs = config.logRetentionTimeMillis();
+ long logLocalRetentionMs = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP);
+ if (logRetentionMs != LogConfig.NO_RETENTION_LIMIT && logLocalRetentionMs != LogConfig.DEFAULT_LOCAL_RETENTION_MS) {
+ if (logLocalRetentionMs == LogConfig.NO_RETENTION_LIMIT) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, logLocalRetentionMs,
+ "Value must not be " + LogConfig.NO_RETENTION_LIMIT + " as " + ServerLogConfigs.LOG_RETENTION_TIME_MILLIS_CONFIG + " value is set as " + logRetentionMs + ".");
+ }
+ if (logLocalRetentionMs > logRetentionMs) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, logLocalRetentionMs,
+ "Value must not be more than " + ServerLogConfigs.LOG_RETENTION_TIME_MILLIS_CONFIG + " property value: " + logRetentionMs);
+ }
+ }
+ }
+
+ private void validateLogLocalRetentionBytes(AbstractKafkaConfig config) {
Review Comment:
It deserves a static modifier
##########
server/src/main/java/org/apache/kafka/server/config/DynamicLogConfig.java:
##########
@@ -0,0 +1,164 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.config;
+
+import org.apache.kafka.common.config.ConfigException;
+import org.apache.kafka.server.common.DirectoryEventHandler;
+import org.apache.kafka.server.log.remote.storage.RemoteLogManagerConfig;
+import org.apache.kafka.storage.internals.log.LogConfig;
+import org.apache.kafka.storage.internals.log.LogManager;
+import org.apache.kafka.storage.internals.log.UnifiedLog;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class DynamicLogConfig implements BrokerReconfigurable {
+ /**
+ * The broker configurations pertaining to logs that are reconfigurable. This set contains
+ * the names you would use when setting a static or dynamic broker configuration (not topic
+ * configuration).
+ */
+ public static final Set<String> RECONFIGURABLE_CONFIGS = Stream.of(
+ ServerTopicConfigSynonyms.TOPIC_CONFIG_SYNONYMS.values(),
+ Set.of(ServerLogConfigs.CORDONED_LOG_DIRS_CONFIG))
+ .flatMap(Collection::stream)
+ .collect(Collectors.toUnmodifiableSet());
+
+ private final LogManager logManager;
+ private final DirectoryEventHandler directoryEventHandler;
+
+ public DynamicLogConfig(LogManager logManager, DirectoryEventHandler directoryEventHandler) {
+ this.logManager = logManager;
+ this.directoryEventHandler = directoryEventHandler;
+ }
+
+ @Override
+ public Set<String> reconfigurableConfigs() {
+ return RECONFIGURABLE_CONFIGS;
+ }
+
+ @Override
+ public void validateReconfiguration(AbstractKafkaConfig newConfig) {
+ validateLogLocalRetentionMs(newConfig);
+ validateLogLocalRetentionBytes(newConfig);
+ validateLogRemoteCopyLagMs(newConfig);
+ validateLogRemoteCopyLagBytes(newConfig);
+ validateCordonedLogDirs(newConfig);
+ }
+
+ private void validateLogLocalRetentionMs(AbstractKafkaConfig config) {
+ long logRetentionMs = config.logRetentionTimeMillis();
+ long logLocalRetentionMs = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP);
+ if (logRetentionMs != LogConfig.NO_RETENTION_LIMIT && logLocalRetentionMs != LogConfig.DEFAULT_LOCAL_RETENTION_MS) {
+ if (logLocalRetentionMs == LogConfig.NO_RETENTION_LIMIT) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, logLocalRetentionMs,
+ "Value must not be " + LogConfig.NO_RETENTION_LIMIT + " as " + ServerLogConfigs.LOG_RETENTION_TIME_MILLIS_CONFIG + " value is set as " + logRetentionMs + ".");
+ }
+ if (logLocalRetentionMs > logRetentionMs) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, logLocalRetentionMs,
+ "Value must not be more than " + ServerLogConfigs.LOG_RETENTION_TIME_MILLIS_CONFIG + " property value: " + logRetentionMs);
+ }
+ }
+ }
+
+ private void validateLogLocalRetentionBytes(AbstractKafkaConfig config) {
+ long logRetentionBytes = config.logRetentionBytes();
+ long logLocalRetentionBytes = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP);
+ if (logRetentionBytes > LogConfig.NO_RETENTION_LIMIT && logLocalRetentionBytes != LogConfig.DEFAULT_LOCAL_RETENTION_BYTES) {
+ if (logLocalRetentionBytes == LogConfig.NO_RETENTION_LIMIT) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP, logLocalRetentionBytes,
+ "Value must not be " + LogConfig.NO_RETENTION_LIMIT + " as " + ServerLogConfigs.LOG_RETENTION_BYTES_CONFIG + " value is set as " + logRetentionBytes + ".");
+ }
+ if (logLocalRetentionBytes > logRetentionBytes) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP, logLocalRetentionBytes,
+ "Value must not be more than " + ServerLogConfigs.LOG_RETENTION_BYTES_CONFIG + " property value: " + logRetentionBytes);
+ }
+ }
+ }
+
+ private void validateLogRemoteCopyLagMs(AbstractKafkaConfig config) {
+ long logRetentionMs = config.logRetentionTimeMillis();
+ long logLocalRetentionMs = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP);
+ long effectiveLocalRetentionMs = logLocalRetentionMs == LogConfig.DEFAULT_LOCAL_RETENTION_MS ? logRetentionMs : logLocalRetentionMs;
+ long logRemoteCopyLagMs = config.getLong(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_MS_PROP);
+ if (logRemoteCopyLagMs > 0L && effectiveLocalRetentionMs >= 0L && logRemoteCopyLagMs > effectiveLocalRetentionMs) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_MS_PROP, logRemoteCopyLagMs,
+ "Value must not exceed " + RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP +
+ " (effective value: " + effectiveLocalRetentionMs + ")");
+ }
+ }
+
+ private void validateLogRemoteCopyLagBytes(AbstractKafkaConfig config) {
+ long logRetentionBytes = config.logRetentionBytes();
+ long logLocalRetentionBytes = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP);
+ long effectiveLocalRetentionBytes = logLocalRetentionBytes == LogConfig.DEFAULT_LOCAL_RETENTION_BYTES ? logRetentionBytes : logLocalRetentionBytes;
+ long logRemoteCopyLagBytes = config.getLong(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_BYTES_PROP);
+ if (logRemoteCopyLagBytes > 0L && effectiveLocalRetentionBytes >= 0L && logRemoteCopyLagBytes > effectiveLocalRetentionBytes) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_BYTES_PROP, logRemoteCopyLagBytes,
+ "Value must not exceed " + RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP +
+ " (effective value: " + effectiveLocalRetentionBytes + ")");
+ }
+ }
+
+ private void validateCordonedLogDirs(AbstractKafkaConfig config) {
+ List<String> cordonedLogDirs = config.cordonedLogDirs();
+ List<String> logDirs = config.logDirs();
+ for (String dir : cordonedLogDirs) {
+ if (!logDirs.contains(dir)) {
+ throw new ConfigException(ServerLogConfigs.CORDONED_LOG_DIRS_CONFIG, cordonedLogDirs,
+ "Invalid entry in " + ServerLogConfigs.CORDONED_LOG_DIRS_CONFIG + ": " + dir + ". " +
+ "All cordoned log dirs must be entries of " + ServerLogConfigs.LOG_DIRS_CONFIG + " or " +
+ ServerLogConfigs.LOG_DIR_CONFIG + ".");
+ }
+ }
+ }
+
+ private void updateLogsConfig(Map<String, Object> newBrokerDefaults) {
+ logManager.brokerConfigUpdated();
+ for (UnifiedLog unifiedLog : logManager.allLogs()) {
+ Map<String, Object> props = new HashMap<>(newBrokerDefaults);
+ unifiedLog.config().originals().forEach((key, value) -> {
+ if (unifiedLog.config().overriddenConfigs.contains(key)) {
+ props.put(key, value);
+ }
+ });
+ unifiedLog.updateConfig(new LogConfig(props, unifiedLog.config().overriddenConfigs));
+ }
+ }
+
+ @Override
+ public void reconfigure(AbstractKafkaConfig oldConfig, AbstractKafkaConfig newConfig) {
+ Map<String, Object> newBrokerDefaults = new HashMap<>(newConfig.extractLogConfigMap());
+ logManager.reconfigureDefaultLogConfig(new LogConfig(newBrokerDefaults));
+ updateLogsConfig(newBrokerDefaults);
+
+ logManager.updateCordonedLogDirs(Set.copyOf(newConfig.cordonedLogDirs()));
+ directoryEventHandler.handleCordoned(newConfig.cordonedLogDirs().stream()
+ .flatMap(dir -> logManager.directoryId(dir).stream())
+ .collect(Collectors.toSet()));
Review Comment:
`toUnmodifiableSet`
##########
server/src/main/java/org/apache/kafka/server/config/DynamicLogConfig.java:
##########
@@ -0,0 +1,164 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.config;
+
+import org.apache.kafka.common.config.ConfigException;
+import org.apache.kafka.server.common.DirectoryEventHandler;
+import org.apache.kafka.server.log.remote.storage.RemoteLogManagerConfig;
+import org.apache.kafka.storage.internals.log.LogConfig;
+import org.apache.kafka.storage.internals.log.LogManager;
+import org.apache.kafka.storage.internals.log.UnifiedLog;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class DynamicLogConfig implements BrokerReconfigurable {
+ /**
+ * The broker configurations pertaining to logs that are reconfigurable. This set contains
+ * the names you would use when setting a static or dynamic broker configuration (not topic
+ * configuration).
+ */
+ public static final Set<String> RECONFIGURABLE_CONFIGS = Stream.of(
+ ServerTopicConfigSynonyms.TOPIC_CONFIG_SYNONYMS.values(),
+ Set.of(ServerLogConfigs.CORDONED_LOG_DIRS_CONFIG))
+ .flatMap(Collection::stream)
+ .collect(Collectors.toUnmodifiableSet());
+
+ private final LogManager logManager;
+ private final DirectoryEventHandler directoryEventHandler;
+
+ public DynamicLogConfig(LogManager logManager, DirectoryEventHandler directoryEventHandler) {
+ this.logManager = logManager;
+ this.directoryEventHandler = directoryEventHandler;
+ }
+
+ @Override
+ public Set<String> reconfigurableConfigs() {
+ return RECONFIGURABLE_CONFIGS;
+ }
+
+ @Override
+ public void validateReconfiguration(AbstractKafkaConfig newConfig) {
+ validateLogLocalRetentionMs(newConfig);
+ validateLogLocalRetentionBytes(newConfig);
+ validateLogRemoteCopyLagMs(newConfig);
+ validateLogRemoteCopyLagBytes(newConfig);
+ validateCordonedLogDirs(newConfig);
+ }
+
+ private void validateLogLocalRetentionMs(AbstractKafkaConfig config) {
+ long logRetentionMs = config.logRetentionTimeMillis();
+ long logLocalRetentionMs = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP);
+ if (logRetentionMs != LogConfig.NO_RETENTION_LIMIT && logLocalRetentionMs != LogConfig.DEFAULT_LOCAL_RETENTION_MS) {
+ if (logLocalRetentionMs == LogConfig.NO_RETENTION_LIMIT) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, logLocalRetentionMs,
+ "Value must not be " + LogConfig.NO_RETENTION_LIMIT + " as " + ServerLogConfigs.LOG_RETENTION_TIME_MILLIS_CONFIG + " value is set as " + logRetentionMs + ".");
+ }
+ if (logLocalRetentionMs > logRetentionMs) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, logLocalRetentionMs,
+ "Value must not be more than " + ServerLogConfigs.LOG_RETENTION_TIME_MILLIS_CONFIG + " property value: " + logRetentionMs);
+ }
+ }
+ }
+
+ private void validateLogLocalRetentionBytes(AbstractKafkaConfig config) {
+ long logRetentionBytes = config.logRetentionBytes();
+ long logLocalRetentionBytes = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP);
+ if (logRetentionBytes > LogConfig.NO_RETENTION_LIMIT && logLocalRetentionBytes != LogConfig.DEFAULT_LOCAL_RETENTION_BYTES) {
+ if (logLocalRetentionBytes == LogConfig.NO_RETENTION_LIMIT) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP, logLocalRetentionBytes,
+ "Value must not be " + LogConfig.NO_RETENTION_LIMIT + " as " + ServerLogConfigs.LOG_RETENTION_BYTES_CONFIG + " value is set as " + logRetentionBytes + ".");
+ }
+ if (logLocalRetentionBytes > logRetentionBytes) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP, logLocalRetentionBytes,
+ "Value must not be more than " + ServerLogConfigs.LOG_RETENTION_BYTES_CONFIG + " property value: " + logRetentionBytes);
+ }
+ }
+ }
+
+ private void validateLogRemoteCopyLagMs(AbstractKafkaConfig config) {
+ long logRetentionMs = config.logRetentionTimeMillis();
+ long logLocalRetentionMs = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP);
+ long effectiveLocalRetentionMs = logLocalRetentionMs == LogConfig.DEFAULT_LOCAL_RETENTION_MS ? logRetentionMs : logLocalRetentionMs;
+ long logRemoteCopyLagMs = config.getLong(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_MS_PROP);
+ if (logRemoteCopyLagMs > 0L && effectiveLocalRetentionMs >= 0L && logRemoteCopyLagMs > effectiveLocalRetentionMs) {
Review Comment:
`logRemoteCopyLagMs > 0L` is redundant condition
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-18948 Move DynamicLogConfig to server module [kafka]
Posted by "unknowntpo (via GitHub)" <gi...@apache.org>.
unknowntpo commented on code in PR #22353:
URL: https://github.com/apache/kafka/pull/22353#discussion_r3307835672
##########
server/src/main/java/org/apache/kafka/server/config/DynamicLogConfig.java:
##########
@@ -0,0 +1,176 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.config;
+
+import org.apache.kafka.common.config.AbstractConfig;
+import org.apache.kafka.common.config.ConfigException;
+import org.apache.kafka.config.BrokerReconfigurable;
+import org.apache.kafka.server.common.DirectoryEventHandler;
+import org.apache.kafka.server.log.remote.storage.RemoteLogManagerConfig;
+import org.apache.kafka.storage.internals.log.LogConfig;
+import org.apache.kafka.storage.internals.log.LogManager;
+import org.apache.kafka.storage.internals.log.UnifiedLog;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class DynamicLogConfig implements BrokerReconfigurable {
+ /**
+ * The broker configurations pertaining to logs that are reconfigurable. This set contains
+ * the names you would use when setting a static or dynamic broker configuration (not topic
+ * configuration).
+ */
+ public static final Set<String> RECONFIGURABLE_CONFIGS = Stream.of(
+ ServerTopicConfigSynonyms.TOPIC_CONFIG_SYNONYMS.values(),
+ Set.of(ServerLogConfigs.CORDONED_LOG_DIRS_CONFIG))
+ .flatMap(Collection::stream)
+ .collect(Collectors.toUnmodifiableSet());
+
+ private final LogManager logManager;
+ private final DirectoryEventHandler directoryEventHandler;
+
+ public DynamicLogConfig(LogManager logManager, DirectoryEventHandler directoryEventHandler) {
+ this.logManager = logManager;
+ this.directoryEventHandler = directoryEventHandler;
+ }
+
+ @Override
+ public Set<String> reconfigurableConfigs() {
+ return RECONFIGURABLE_CONFIGS;
+ }
+
+ @Override
+ public void validateReconfiguration(AbstractConfig newConfig) {
+ AbstractKafkaConfig kafkaConfig = requireKafkaConfig(newConfig);
+ validateLogLocalRetentionMs(kafkaConfig);
+ validateLogLocalRetentionBytes(kafkaConfig);
+ validateLogRemoteCopyLagMs(kafkaConfig);
+ validateLogRemoteCopyLagBytes(kafkaConfig);
+ validateCordonedLogDirs(kafkaConfig);
+ }
+
+ private AbstractKafkaConfig requireKafkaConfig(AbstractConfig config) {
Review Comment:
Good point. I don't like the cast either. A generic `BrokerReconfigurable<T extends AbstractConfig>` sounds like the right direction, but it touches the interface and all implementers, so I will keep this PR focused and
handle that in a follow-up PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-18948 Move DynamicLogConfig to server module [kafka]
Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on PR #22353:
URL: https://github.com/apache/kafka/pull/22353#issuecomment-5207179302
@unknowntpo please fix the conflicts
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-18948 Move DynamicLogConfig to server module [kafka]
Posted by "unknowntpo (via GitHub)" <gi...@apache.org>.
unknowntpo commented on PR #22353:
URL: https://github.com/apache/kafka/pull/22353#issuecomment-6329580798
Superseded by #23662, closing. Thanks @clolov and @chia7712!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-18948 Move DynamicLogConfig to server module [kafka]
Posted by "unknowntpo (via GitHub)" <gi...@apache.org>.
unknowntpo closed pull request #22353: KAFKA-18948 Move DynamicLogConfig to server module
URL: https://github.com/apache/kafka/pull/22353
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-18948 Move DynamicLogConfig to server module [kafka]
Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on code in PR #22353:
URL: https://github.com/apache/kafka/pull/22353#discussion_r3305226776
##########
server/src/main/java/org/apache/kafka/server/config/DynamicLogConfig.java:
##########
@@ -0,0 +1,176 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.config;
+
+import org.apache.kafka.common.config.AbstractConfig;
+import org.apache.kafka.common.config.ConfigException;
+import org.apache.kafka.config.BrokerReconfigurable;
+import org.apache.kafka.server.common.DirectoryEventHandler;
+import org.apache.kafka.server.log.remote.storage.RemoteLogManagerConfig;
+import org.apache.kafka.storage.internals.log.LogConfig;
+import org.apache.kafka.storage.internals.log.LogManager;
+import org.apache.kafka.storage.internals.log.UnifiedLog;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class DynamicLogConfig implements BrokerReconfigurable {
+ /**
+ * The broker configurations pertaining to logs that are reconfigurable. This set contains
+ * the names you would use when setting a static or dynamic broker configuration (not topic
+ * configuration).
+ */
+ public static final Set<String> RECONFIGURABLE_CONFIGS = Stream.of(
+ ServerTopicConfigSynonyms.TOPIC_CONFIG_SYNONYMS.values(),
+ Set.of(ServerLogConfigs.CORDONED_LOG_DIRS_CONFIG))
+ .flatMap(Collection::stream)
+ .collect(Collectors.toUnmodifiableSet());
+
+ private final LogManager logManager;
+ private final DirectoryEventHandler directoryEventHandler;
+
+ public DynamicLogConfig(LogManager logManager, DirectoryEventHandler directoryEventHandler) {
+ this.logManager = logManager;
+ this.directoryEventHandler = directoryEventHandler;
+ }
+
+ @Override
+ public Set<String> reconfigurableConfigs() {
+ return RECONFIGURABLE_CONFIGS;
+ }
+
+ @Override
+ public void validateReconfiguration(AbstractConfig newConfig) {
+ AbstractKafkaConfig kafkaConfig = requireKafkaConfig(newConfig);
+ validateLogLocalRetentionMs(kafkaConfig);
+ validateLogLocalRetentionBytes(kafkaConfig);
+ validateLogRemoteCopyLagMs(kafkaConfig);
+ validateLogRemoteCopyLagBytes(kafkaConfig);
+ validateCordonedLogDirs(kafkaConfig);
+ }
+
+ private AbstractKafkaConfig requireKafkaConfig(AbstractConfig config) {
Review Comment:
Maybe we could add generics to BrokerReconfigurable? For example, `BrokerReconfigurable<T extends AbstractConfig>`. This would allow both the storage and server modules to access the specific config types they need
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-18948 Move DynamicLogConfig to server module [kafka]
Posted by "unknowntpo (via GitHub)" <gi...@apache.org>.
unknowntpo commented on code in PR #22353:
URL: https://github.com/apache/kafka/pull/22353#discussion_r3499586023
##########
server/src/main/java/org/apache/kafka/server/config/DynamicLogConfig.java:
##########
@@ -0,0 +1,176 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.config;
+
+import org.apache.kafka.common.config.AbstractConfig;
+import org.apache.kafka.common.config.ConfigException;
+import org.apache.kafka.config.BrokerReconfigurable;
+import org.apache.kafka.server.common.DirectoryEventHandler;
+import org.apache.kafka.server.log.remote.storage.RemoteLogManagerConfig;
+import org.apache.kafka.storage.internals.log.LogConfig;
+import org.apache.kafka.storage.internals.log.LogManager;
+import org.apache.kafka.storage.internals.log.UnifiedLog;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class DynamicLogConfig implements BrokerReconfigurable {
+ /**
+ * The broker configurations pertaining to logs that are reconfigurable. This set contains
+ * the names you would use when setting a static or dynamic broker configuration (not topic
+ * configuration).
+ */
+ public static final Set<String> RECONFIGURABLE_CONFIGS = Stream.of(
+ ServerTopicConfigSynonyms.TOPIC_CONFIG_SYNONYMS.values(),
+ Set.of(ServerLogConfigs.CORDONED_LOG_DIRS_CONFIG))
+ .flatMap(Collection::stream)
+ .collect(Collectors.toUnmodifiableSet());
+
+ private final LogManager logManager;
+ private final DirectoryEventHandler directoryEventHandler;
+
+ public DynamicLogConfig(LogManager logManager, DirectoryEventHandler directoryEventHandler) {
+ this.logManager = logManager;
+ this.directoryEventHandler = directoryEventHandler;
+ }
+
+ @Override
+ public Set<String> reconfigurableConfigs() {
+ return RECONFIGURABLE_CONFIGS;
+ }
+
+ @Override
+ public void validateReconfiguration(AbstractConfig newConfig) {
+ AbstractKafkaConfig kafkaConfig = requireKafkaConfig(newConfig);
+ validateLogLocalRetentionMs(kafkaConfig);
+ validateLogLocalRetentionBytes(kafkaConfig);
+ validateLogRemoteCopyLagMs(kafkaConfig);
+ validateLogRemoteCopyLagBytes(kafkaConfig);
+ validateCordonedLogDirs(kafkaConfig);
+ }
+
+ private AbstractKafkaConfig requireKafkaConfig(AbstractConfig config) {
Review Comment:
@chia7712 fixed, PTAL.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-18948 Move DynamicLogConfig to server module [kafka]
Posted by "unknowntpo (via GitHub)" <gi...@apache.org>.
unknowntpo commented on code in PR #22353:
URL: https://github.com/apache/kafka/pull/22353#discussion_r3502998422
##########
server/src/main/java/org/apache/kafka/server/config/DynamicLogConfig.java:
##########
@@ -0,0 +1,164 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.config;
+
+import org.apache.kafka.common.config.ConfigException;
+import org.apache.kafka.server.common.DirectoryEventHandler;
+import org.apache.kafka.server.log.remote.storage.RemoteLogManagerConfig;
+import org.apache.kafka.storage.internals.log.LogConfig;
+import org.apache.kafka.storage.internals.log.LogManager;
+import org.apache.kafka.storage.internals.log.UnifiedLog;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class DynamicLogConfig implements BrokerReconfigurable {
+ /**
+ * The broker configurations pertaining to logs that are reconfigurable. This set contains
+ * the names you would use when setting a static or dynamic broker configuration (not topic
+ * configuration).
+ */
+ public static final Set<String> RECONFIGURABLE_CONFIGS = Stream.of(
+ ServerTopicConfigSynonyms.TOPIC_CONFIG_SYNONYMS.values(),
+ Set.of(ServerLogConfigs.CORDONED_LOG_DIRS_CONFIG))
+ .flatMap(Collection::stream)
+ .collect(Collectors.toUnmodifiableSet());
+
+ private final LogManager logManager;
+ private final DirectoryEventHandler directoryEventHandler;
+
+ public DynamicLogConfig(LogManager logManager, DirectoryEventHandler directoryEventHandler) {
+ this.logManager = logManager;
+ this.directoryEventHandler = directoryEventHandler;
+ }
+
+ @Override
+ public Set<String> reconfigurableConfigs() {
+ return RECONFIGURABLE_CONFIGS;
+ }
+
+ @Override
+ public void validateReconfiguration(AbstractKafkaConfig newConfig) {
+ validateLogLocalRetentionMs(newConfig);
+ validateLogLocalRetentionBytes(newConfig);
+ validateLogRemoteCopyLagMs(newConfig);
+ validateLogRemoteCopyLagBytes(newConfig);
+ validateCordonedLogDirs(newConfig);
+ }
+
+ private void validateLogLocalRetentionMs(AbstractKafkaConfig config) {
+ long logRetentionMs = config.logRetentionTimeMillis();
+ long logLocalRetentionMs = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP);
+ if (logRetentionMs != LogConfig.NO_RETENTION_LIMIT && logLocalRetentionMs != LogConfig.DEFAULT_LOCAL_RETENTION_MS) {
+ if (logLocalRetentionMs == LogConfig.NO_RETENTION_LIMIT) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, logLocalRetentionMs,
+ "Value must not be " + LogConfig.NO_RETENTION_LIMIT + " as " + ServerLogConfigs.LOG_RETENTION_TIME_MILLIS_CONFIG + " value is set as " + logRetentionMs + ".");
+ }
+ if (logLocalRetentionMs > logRetentionMs) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, logLocalRetentionMs,
+ "Value must not be more than " + ServerLogConfigs.LOG_RETENTION_TIME_MILLIS_CONFIG + " property value: " + logRetentionMs);
+ }
+ }
+ }
+
+ private void validateLogLocalRetentionBytes(AbstractKafkaConfig config) {
Review Comment:
Done in 4939a79.
##########
server/src/main/java/org/apache/kafka/server/config/DynamicLogConfig.java:
##########
@@ -0,0 +1,164 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.config;
+
+import org.apache.kafka.common.config.ConfigException;
+import org.apache.kafka.server.common.DirectoryEventHandler;
+import org.apache.kafka.server.log.remote.storage.RemoteLogManagerConfig;
+import org.apache.kafka.storage.internals.log.LogConfig;
+import org.apache.kafka.storage.internals.log.LogManager;
+import org.apache.kafka.storage.internals.log.UnifiedLog;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class DynamicLogConfig implements BrokerReconfigurable {
+ /**
+ * The broker configurations pertaining to logs that are reconfigurable. This set contains
+ * the names you would use when setting a static or dynamic broker configuration (not topic
+ * configuration).
+ */
+ public static final Set<String> RECONFIGURABLE_CONFIGS = Stream.of(
+ ServerTopicConfigSynonyms.TOPIC_CONFIG_SYNONYMS.values(),
+ Set.of(ServerLogConfigs.CORDONED_LOG_DIRS_CONFIG))
+ .flatMap(Collection::stream)
+ .collect(Collectors.toUnmodifiableSet());
+
+ private final LogManager logManager;
+ private final DirectoryEventHandler directoryEventHandler;
+
+ public DynamicLogConfig(LogManager logManager, DirectoryEventHandler directoryEventHandler) {
+ this.logManager = logManager;
+ this.directoryEventHandler = directoryEventHandler;
+ }
+
+ @Override
+ public Set<String> reconfigurableConfigs() {
+ return RECONFIGURABLE_CONFIGS;
+ }
+
+ @Override
+ public void validateReconfiguration(AbstractKafkaConfig newConfig) {
+ validateLogLocalRetentionMs(newConfig);
+ validateLogLocalRetentionBytes(newConfig);
+ validateLogRemoteCopyLagMs(newConfig);
+ validateLogRemoteCopyLagBytes(newConfig);
+ validateCordonedLogDirs(newConfig);
+ }
+
+ private void validateLogLocalRetentionMs(AbstractKafkaConfig config) {
Review Comment:
Done in 4939a79.
##########
server/src/main/java/org/apache/kafka/server/config/DynamicLogConfig.java:
##########
@@ -0,0 +1,164 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.config;
+
+import org.apache.kafka.common.config.ConfigException;
+import org.apache.kafka.server.common.DirectoryEventHandler;
+import org.apache.kafka.server.log.remote.storage.RemoteLogManagerConfig;
+import org.apache.kafka.storage.internals.log.LogConfig;
+import org.apache.kafka.storage.internals.log.LogManager;
+import org.apache.kafka.storage.internals.log.UnifiedLog;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class DynamicLogConfig implements BrokerReconfigurable {
+ /**
+ * The broker configurations pertaining to logs that are reconfigurable. This set contains
+ * the names you would use when setting a static or dynamic broker configuration (not topic
+ * configuration).
+ */
+ public static final Set<String> RECONFIGURABLE_CONFIGS = Stream.of(
+ ServerTopicConfigSynonyms.TOPIC_CONFIG_SYNONYMS.values(),
+ Set.of(ServerLogConfigs.CORDONED_LOG_DIRS_CONFIG))
+ .flatMap(Collection::stream)
+ .collect(Collectors.toUnmodifiableSet());
+
+ private final LogManager logManager;
+ private final DirectoryEventHandler directoryEventHandler;
+
+ public DynamicLogConfig(LogManager logManager, DirectoryEventHandler directoryEventHandler) {
+ this.logManager = logManager;
+ this.directoryEventHandler = directoryEventHandler;
+ }
+
+ @Override
+ public Set<String> reconfigurableConfigs() {
+ return RECONFIGURABLE_CONFIGS;
+ }
+
+ @Override
+ public void validateReconfiguration(AbstractKafkaConfig newConfig) {
+ validateLogLocalRetentionMs(newConfig);
+ validateLogLocalRetentionBytes(newConfig);
+ validateLogRemoteCopyLagMs(newConfig);
+ validateLogRemoteCopyLagBytes(newConfig);
+ validateCordonedLogDirs(newConfig);
+ }
+
+ private void validateLogLocalRetentionMs(AbstractKafkaConfig config) {
+ long logRetentionMs = config.logRetentionTimeMillis();
+ long logLocalRetentionMs = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP);
+ if (logRetentionMs != LogConfig.NO_RETENTION_LIMIT && logLocalRetentionMs != LogConfig.DEFAULT_LOCAL_RETENTION_MS) {
+ if (logLocalRetentionMs == LogConfig.NO_RETENTION_LIMIT) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, logLocalRetentionMs,
+ "Value must not be " + LogConfig.NO_RETENTION_LIMIT + " as " + ServerLogConfigs.LOG_RETENTION_TIME_MILLIS_CONFIG + " value is set as " + logRetentionMs + ".");
+ }
+ if (logLocalRetentionMs > logRetentionMs) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, logLocalRetentionMs,
+ "Value must not be more than " + ServerLogConfigs.LOG_RETENTION_TIME_MILLIS_CONFIG + " property value: " + logRetentionMs);
+ }
+ }
+ }
+
+ private void validateLogLocalRetentionBytes(AbstractKafkaConfig config) {
+ long logRetentionBytes = config.logRetentionBytes();
+ long logLocalRetentionBytes = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP);
+ if (logRetentionBytes > LogConfig.NO_RETENTION_LIMIT && logLocalRetentionBytes != LogConfig.DEFAULT_LOCAL_RETENTION_BYTES) {
+ if (logLocalRetentionBytes == LogConfig.NO_RETENTION_LIMIT) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP, logLocalRetentionBytes,
+ "Value must not be " + LogConfig.NO_RETENTION_LIMIT + " as " + ServerLogConfigs.LOG_RETENTION_BYTES_CONFIG + " value is set as " + logRetentionBytes + ".");
+ }
+ if (logLocalRetentionBytes > logRetentionBytes) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP, logLocalRetentionBytes,
+ "Value must not be more than " + ServerLogConfigs.LOG_RETENTION_BYTES_CONFIG + " property value: " + logRetentionBytes);
+ }
+ }
+ }
+
+ private void validateLogRemoteCopyLagMs(AbstractKafkaConfig config) {
Review Comment:
Done in 4939a79.
##########
server/src/main/java/org/apache/kafka/server/config/DynamicLogConfig.java:
##########
@@ -0,0 +1,164 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.config;
+
+import org.apache.kafka.common.config.ConfigException;
+import org.apache.kafka.server.common.DirectoryEventHandler;
+import org.apache.kafka.server.log.remote.storage.RemoteLogManagerConfig;
+import org.apache.kafka.storage.internals.log.LogConfig;
+import org.apache.kafka.storage.internals.log.LogManager;
+import org.apache.kafka.storage.internals.log.UnifiedLog;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class DynamicLogConfig implements BrokerReconfigurable {
+ /**
+ * The broker configurations pertaining to logs that are reconfigurable. This set contains
+ * the names you would use when setting a static or dynamic broker configuration (not topic
+ * configuration).
+ */
+ public static final Set<String> RECONFIGURABLE_CONFIGS = Stream.of(
+ ServerTopicConfigSynonyms.TOPIC_CONFIG_SYNONYMS.values(),
+ Set.of(ServerLogConfigs.CORDONED_LOG_DIRS_CONFIG))
+ .flatMap(Collection::stream)
+ .collect(Collectors.toUnmodifiableSet());
+
+ private final LogManager logManager;
+ private final DirectoryEventHandler directoryEventHandler;
+
+ public DynamicLogConfig(LogManager logManager, DirectoryEventHandler directoryEventHandler) {
+ this.logManager = logManager;
+ this.directoryEventHandler = directoryEventHandler;
+ }
+
+ @Override
+ public Set<String> reconfigurableConfigs() {
+ return RECONFIGURABLE_CONFIGS;
+ }
+
+ @Override
+ public void validateReconfiguration(AbstractKafkaConfig newConfig) {
+ validateLogLocalRetentionMs(newConfig);
+ validateLogLocalRetentionBytes(newConfig);
+ validateLogRemoteCopyLagMs(newConfig);
+ validateLogRemoteCopyLagBytes(newConfig);
+ validateCordonedLogDirs(newConfig);
+ }
+
+ private void validateLogLocalRetentionMs(AbstractKafkaConfig config) {
+ long logRetentionMs = config.logRetentionTimeMillis();
+ long logLocalRetentionMs = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP);
+ if (logRetentionMs != LogConfig.NO_RETENTION_LIMIT && logLocalRetentionMs != LogConfig.DEFAULT_LOCAL_RETENTION_MS) {
+ if (logLocalRetentionMs == LogConfig.NO_RETENTION_LIMIT) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, logLocalRetentionMs,
+ "Value must not be " + LogConfig.NO_RETENTION_LIMIT + " as " + ServerLogConfigs.LOG_RETENTION_TIME_MILLIS_CONFIG + " value is set as " + logRetentionMs + ".");
+ }
+ if (logLocalRetentionMs > logRetentionMs) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, logLocalRetentionMs,
+ "Value must not be more than " + ServerLogConfigs.LOG_RETENTION_TIME_MILLIS_CONFIG + " property value: " + logRetentionMs);
+ }
+ }
+ }
+
+ private void validateLogLocalRetentionBytes(AbstractKafkaConfig config) {
+ long logRetentionBytes = config.logRetentionBytes();
+ long logLocalRetentionBytes = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP);
+ if (logRetentionBytes > LogConfig.NO_RETENTION_LIMIT && logLocalRetentionBytes != LogConfig.DEFAULT_LOCAL_RETENTION_BYTES) {
+ if (logLocalRetentionBytes == LogConfig.NO_RETENTION_LIMIT) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP, logLocalRetentionBytes,
+ "Value must not be " + LogConfig.NO_RETENTION_LIMIT + " as " + ServerLogConfigs.LOG_RETENTION_BYTES_CONFIG + " value is set as " + logRetentionBytes + ".");
+ }
+ if (logLocalRetentionBytes > logRetentionBytes) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP, logLocalRetentionBytes,
+ "Value must not be more than " + ServerLogConfigs.LOG_RETENTION_BYTES_CONFIG + " property value: " + logRetentionBytes);
+ }
+ }
+ }
+
+ private void validateLogRemoteCopyLagMs(AbstractKafkaConfig config) {
+ long logRetentionMs = config.logRetentionTimeMillis();
+ long logLocalRetentionMs = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP);
+ long effectiveLocalRetentionMs = logLocalRetentionMs == LogConfig.DEFAULT_LOCAL_RETENTION_MS ? logRetentionMs : logLocalRetentionMs;
+ long logRemoteCopyLagMs = config.getLong(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_MS_PROP);
+ if (logRemoteCopyLagMs > 0L && effectiveLocalRetentionMs >= 0L && logRemoteCopyLagMs > effectiveLocalRetentionMs) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_MS_PROP, logRemoteCopyLagMs,
+ "Value must not exceed " + RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP +
+ " (effective value: " + effectiveLocalRetentionMs + ")");
+ }
+ }
+
+ private void validateLogRemoteCopyLagBytes(AbstractKafkaConfig config) {
Review Comment:
Done in 4939a79.
##########
server/src/main/java/org/apache/kafka/server/config/DynamicLogConfig.java:
##########
@@ -0,0 +1,164 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.config;
+
+import org.apache.kafka.common.config.ConfigException;
+import org.apache.kafka.server.common.DirectoryEventHandler;
+import org.apache.kafka.server.log.remote.storage.RemoteLogManagerConfig;
+import org.apache.kafka.storage.internals.log.LogConfig;
+import org.apache.kafka.storage.internals.log.LogManager;
+import org.apache.kafka.storage.internals.log.UnifiedLog;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class DynamicLogConfig implements BrokerReconfigurable {
+ /**
+ * The broker configurations pertaining to logs that are reconfigurable. This set contains
+ * the names you would use when setting a static or dynamic broker configuration (not topic
+ * configuration).
+ */
+ public static final Set<String> RECONFIGURABLE_CONFIGS = Stream.of(
+ ServerTopicConfigSynonyms.TOPIC_CONFIG_SYNONYMS.values(),
+ Set.of(ServerLogConfigs.CORDONED_LOG_DIRS_CONFIG))
+ .flatMap(Collection::stream)
+ .collect(Collectors.toUnmodifiableSet());
+
+ private final LogManager logManager;
+ private final DirectoryEventHandler directoryEventHandler;
+
+ public DynamicLogConfig(LogManager logManager, DirectoryEventHandler directoryEventHandler) {
+ this.logManager = logManager;
+ this.directoryEventHandler = directoryEventHandler;
+ }
+
+ @Override
+ public Set<String> reconfigurableConfigs() {
+ return RECONFIGURABLE_CONFIGS;
+ }
+
+ @Override
+ public void validateReconfiguration(AbstractKafkaConfig newConfig) {
+ validateLogLocalRetentionMs(newConfig);
+ validateLogLocalRetentionBytes(newConfig);
+ validateLogRemoteCopyLagMs(newConfig);
+ validateLogRemoteCopyLagBytes(newConfig);
+ validateCordonedLogDirs(newConfig);
+ }
+
+ private void validateLogLocalRetentionMs(AbstractKafkaConfig config) {
+ long logRetentionMs = config.logRetentionTimeMillis();
+ long logLocalRetentionMs = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP);
+ if (logRetentionMs != LogConfig.NO_RETENTION_LIMIT && logLocalRetentionMs != LogConfig.DEFAULT_LOCAL_RETENTION_MS) {
+ if (logLocalRetentionMs == LogConfig.NO_RETENTION_LIMIT) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, logLocalRetentionMs,
+ "Value must not be " + LogConfig.NO_RETENTION_LIMIT + " as " + ServerLogConfigs.LOG_RETENTION_TIME_MILLIS_CONFIG + " value is set as " + logRetentionMs + ".");
+ }
+ if (logLocalRetentionMs > logRetentionMs) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, logLocalRetentionMs,
+ "Value must not be more than " + ServerLogConfigs.LOG_RETENTION_TIME_MILLIS_CONFIG + " property value: " + logRetentionMs);
+ }
+ }
+ }
+
+ private void validateLogLocalRetentionBytes(AbstractKafkaConfig config) {
+ long logRetentionBytes = config.logRetentionBytes();
+ long logLocalRetentionBytes = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP);
+ if (logRetentionBytes > LogConfig.NO_RETENTION_LIMIT && logLocalRetentionBytes != LogConfig.DEFAULT_LOCAL_RETENTION_BYTES) {
+ if (logLocalRetentionBytes == LogConfig.NO_RETENTION_LIMIT) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP, logLocalRetentionBytes,
+ "Value must not be " + LogConfig.NO_RETENTION_LIMIT + " as " + ServerLogConfigs.LOG_RETENTION_BYTES_CONFIG + " value is set as " + logRetentionBytes + ".");
+ }
+ if (logLocalRetentionBytes > logRetentionBytes) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP, logLocalRetentionBytes,
+ "Value must not be more than " + ServerLogConfigs.LOG_RETENTION_BYTES_CONFIG + " property value: " + logRetentionBytes);
+ }
+ }
+ }
+
+ private void validateLogRemoteCopyLagMs(AbstractKafkaConfig config) {
+ long logRetentionMs = config.logRetentionTimeMillis();
+ long logLocalRetentionMs = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP);
+ long effectiveLocalRetentionMs = logLocalRetentionMs == LogConfig.DEFAULT_LOCAL_RETENTION_MS ? logRetentionMs : logLocalRetentionMs;
+ long logRemoteCopyLagMs = config.getLong(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_MS_PROP);
+ if (logRemoteCopyLagMs > 0L && effectiveLocalRetentionMs >= 0L && logRemoteCopyLagMs > effectiveLocalRetentionMs) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_MS_PROP, logRemoteCopyLagMs,
+ "Value must not exceed " + RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP +
+ " (effective value: " + effectiveLocalRetentionMs + ")");
+ }
+ }
+
+ private void validateLogRemoteCopyLagBytes(AbstractKafkaConfig config) {
+ long logRetentionBytes = config.logRetentionBytes();
+ long logLocalRetentionBytes = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP);
+ long effectiveLocalRetentionBytes = logLocalRetentionBytes == LogConfig.DEFAULT_LOCAL_RETENTION_BYTES ? logRetentionBytes : logLocalRetentionBytes;
+ long logRemoteCopyLagBytes = config.getLong(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_BYTES_PROP);
+ if (logRemoteCopyLagBytes > 0L && effectiveLocalRetentionBytes >= 0L && logRemoteCopyLagBytes > effectiveLocalRetentionBytes) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_BYTES_PROP, logRemoteCopyLagBytes,
+ "Value must not exceed " + RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP +
+ " (effective value: " + effectiveLocalRetentionBytes + ")");
+ }
+ }
+
+ private void validateCordonedLogDirs(AbstractKafkaConfig config) {
+ List<String> cordonedLogDirs = config.cordonedLogDirs();
+ List<String> logDirs = config.logDirs();
+ for (String dir : cordonedLogDirs) {
Review Comment:
Done in 2578cdd.
##########
server/src/test/java/org/apache/kafka/server/config/DynamicLogConfigTest.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.config;
+
+import org.apache.kafka.common.Reconfigurable;
+import org.apache.kafka.common.config.ConfigException;
+import org.apache.kafka.raft.KRaftConfigs;
+import org.apache.kafka.server.common.DirectoryEventHandler;
+import org.apache.kafka.server.log.remote.storage.RemoteLogManagerConfig;
+import org.apache.kafka.storage.internals.log.LogManager;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.Mockito.mock;
+
+public class DynamicLogConfigTest {
+
+ private final DynamicLogConfig dynamicLogConfig = new DynamicLogConfig(
+ mock(LogManager.class),
+ mock(DirectoryEventHandler.class)
+ );
+
+ @Test
+ public void testValidateLogLocalRetentionMs() {
+ assertInvalidConfig(
+ Map.of(
+ ServerLogConfigs.LOG_RETENTION_TIME_MILLIS_CONFIG, "1000",
+ RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, "-1"
+ ),
+ "Invalid value -1 for configuration " + RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP +
+ ": Value must not be -1 as " + ServerLogConfigs.LOG_RETENTION_TIME_MILLIS_CONFIG +
+ " value is set as 1000."
+ );
+
+ assertInvalidConfig(
+ Map.of(
+ ServerLogConfigs.LOG_RETENTION_TIME_MILLIS_CONFIG, "1000",
+ RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, "1001"
+ ),
+ "Invalid value 1001 for configuration " + RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP +
+ ": Value must not be more than " + ServerLogConfigs.LOG_RETENTION_TIME_MILLIS_CONFIG +
+ " property value: 1000"
+ );
+ }
+
+ @Test
+ public void testValidateLogLocalRetentionBytes() {
+ assertInvalidConfig(
+ Map.of(
+ ServerLogConfigs.LOG_RETENTION_BYTES_CONFIG, "1000",
+ RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP, "-1"
+ ),
+ "Invalid value -1 for configuration " + RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP +
+ ": Value must not be -1 as " + ServerLogConfigs.LOG_RETENTION_BYTES_CONFIG +
+ " value is set as 1000."
+ );
+
+ assertInvalidConfig(
+ Map.of(
+ ServerLogConfigs.LOG_RETENTION_BYTES_CONFIG, "1000",
+ RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP, "1001"
+ ),
+ "Invalid value 1001 for configuration " + RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP +
+ ": Value must not be more than " + ServerLogConfigs.LOG_RETENTION_BYTES_CONFIG +
+ " property value: 1000"
+ );
+ }
+
+ private void assertInvalidConfig(Map<String, Object> overrides, String expectedMessage) {
+ ConfigException exception = assertThrows(
+ ConfigException.class,
+ () -> dynamicLogConfig.validateReconfiguration(kafkaConfig(overrides))
+ );
+ assertEquals(expectedMessage, exception.getMessage());
+ }
+
+ private static AbstractKafkaConfig kafkaConfig(Map<String, Object> overrides) {
+ Map<String, Object> props = new HashMap<>();
+ props.put(KRaftConfigs.PROCESS_ROLES_CONFIG, "broker");
+ props.put(KRaftConfigs.NODE_ID_CONFIG, "1");
+ props.put(KRaftConfigs.CONTROLLER_LISTENER_NAMES_CONFIG, "CONTROLLER");
+ props.putAll(overrides);
+ return new AbstractKafkaConfig(AbstractKafkaConfig.CONFIG_DEF, props, Map.of(), false) {
+ @Override
+ public void addReconfigurable(Reconfigurable reconfigurable) {
Review Comment:
Removed in 5b41cb1.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-18948 Move DynamicLogConfig to server module [kafka]
Posted by "unknowntpo (via GitHub)" <gi...@apache.org>.
unknowntpo commented on code in PR #22353:
URL: https://github.com/apache/kafka/pull/22353#discussion_r3502999202
##########
server/src/main/java/org/apache/kafka/server/config/DynamicLogConfig.java:
##########
@@ -0,0 +1,164 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.config;
+
+import org.apache.kafka.common.config.ConfigException;
+import org.apache.kafka.server.common.DirectoryEventHandler;
+import org.apache.kafka.server.log.remote.storage.RemoteLogManagerConfig;
+import org.apache.kafka.storage.internals.log.LogConfig;
+import org.apache.kafka.storage.internals.log.LogManager;
+import org.apache.kafka.storage.internals.log.UnifiedLog;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class DynamicLogConfig implements BrokerReconfigurable {
+ /**
+ * The broker configurations pertaining to logs that are reconfigurable. This set contains
+ * the names you would use when setting a static or dynamic broker configuration (not topic
+ * configuration).
+ */
+ public static final Set<String> RECONFIGURABLE_CONFIGS = Stream.of(
+ ServerTopicConfigSynonyms.TOPIC_CONFIG_SYNONYMS.values(),
+ Set.of(ServerLogConfigs.CORDONED_LOG_DIRS_CONFIG))
+ .flatMap(Collection::stream)
+ .collect(Collectors.toUnmodifiableSet());
+
+ private final LogManager logManager;
+ private final DirectoryEventHandler directoryEventHandler;
+
+ public DynamicLogConfig(LogManager logManager, DirectoryEventHandler directoryEventHandler) {
+ this.logManager = logManager;
+ this.directoryEventHandler = directoryEventHandler;
+ }
+
+ @Override
+ public Set<String> reconfigurableConfigs() {
+ return RECONFIGURABLE_CONFIGS;
+ }
+
+ @Override
+ public void validateReconfiguration(AbstractKafkaConfig newConfig) {
+ validateLogLocalRetentionMs(newConfig);
+ validateLogLocalRetentionBytes(newConfig);
+ validateLogRemoteCopyLagMs(newConfig);
+ validateLogRemoteCopyLagBytes(newConfig);
+ validateCordonedLogDirs(newConfig);
+ }
+
+ private void validateLogLocalRetentionMs(AbstractKafkaConfig config) {
+ long logRetentionMs = config.logRetentionTimeMillis();
+ long logLocalRetentionMs = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP);
+ if (logRetentionMs != LogConfig.NO_RETENTION_LIMIT && logLocalRetentionMs != LogConfig.DEFAULT_LOCAL_RETENTION_MS) {
+ if (logLocalRetentionMs == LogConfig.NO_RETENTION_LIMIT) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, logLocalRetentionMs,
+ "Value must not be " + LogConfig.NO_RETENTION_LIMIT + " as " + ServerLogConfigs.LOG_RETENTION_TIME_MILLIS_CONFIG + " value is set as " + logRetentionMs + ".");
+ }
+ if (logLocalRetentionMs > logRetentionMs) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, logLocalRetentionMs,
+ "Value must not be more than " + ServerLogConfigs.LOG_RETENTION_TIME_MILLIS_CONFIG + " property value: " + logRetentionMs);
+ }
+ }
+ }
+
+ private void validateLogLocalRetentionBytes(AbstractKafkaConfig config) {
+ long logRetentionBytes = config.logRetentionBytes();
+ long logLocalRetentionBytes = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP);
+ if (logRetentionBytes > LogConfig.NO_RETENTION_LIMIT && logLocalRetentionBytes != LogConfig.DEFAULT_LOCAL_RETENTION_BYTES) {
+ if (logLocalRetentionBytes == LogConfig.NO_RETENTION_LIMIT) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP, logLocalRetentionBytes,
+ "Value must not be " + LogConfig.NO_RETENTION_LIMIT + " as " + ServerLogConfigs.LOG_RETENTION_BYTES_CONFIG + " value is set as " + logRetentionBytes + ".");
+ }
+ if (logLocalRetentionBytes > logRetentionBytes) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP, logLocalRetentionBytes,
+ "Value must not be more than " + ServerLogConfigs.LOG_RETENTION_BYTES_CONFIG + " property value: " + logRetentionBytes);
+ }
+ }
+ }
+
+ private void validateLogRemoteCopyLagMs(AbstractKafkaConfig config) {
+ long logRetentionMs = config.logRetentionTimeMillis();
+ long logLocalRetentionMs = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP);
+ long effectiveLocalRetentionMs = logLocalRetentionMs == LogConfig.DEFAULT_LOCAL_RETENTION_MS ? logRetentionMs : logLocalRetentionMs;
+ long logRemoteCopyLagMs = config.getLong(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_MS_PROP);
+ if (logRemoteCopyLagMs > 0L && effectiveLocalRetentionMs >= 0L && logRemoteCopyLagMs > effectiveLocalRetentionMs) {
Review Comment:
Done in 98cb31f.
##########
server/src/main/java/org/apache/kafka/server/config/DynamicLogConfig.java:
##########
@@ -0,0 +1,164 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.config;
+
+import org.apache.kafka.common.config.ConfigException;
+import org.apache.kafka.server.common.DirectoryEventHandler;
+import org.apache.kafka.server.log.remote.storage.RemoteLogManagerConfig;
+import org.apache.kafka.storage.internals.log.LogConfig;
+import org.apache.kafka.storage.internals.log.LogManager;
+import org.apache.kafka.storage.internals.log.UnifiedLog;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class DynamicLogConfig implements BrokerReconfigurable {
+ /**
+ * The broker configurations pertaining to logs that are reconfigurable. This set contains
+ * the names you would use when setting a static or dynamic broker configuration (not topic
+ * configuration).
+ */
+ public static final Set<String> RECONFIGURABLE_CONFIGS = Stream.of(
+ ServerTopicConfigSynonyms.TOPIC_CONFIG_SYNONYMS.values(),
+ Set.of(ServerLogConfigs.CORDONED_LOG_DIRS_CONFIG))
+ .flatMap(Collection::stream)
+ .collect(Collectors.toUnmodifiableSet());
+
+ private final LogManager logManager;
+ private final DirectoryEventHandler directoryEventHandler;
+
+ public DynamicLogConfig(LogManager logManager, DirectoryEventHandler directoryEventHandler) {
+ this.logManager = logManager;
+ this.directoryEventHandler = directoryEventHandler;
+ }
+
+ @Override
+ public Set<String> reconfigurableConfigs() {
+ return RECONFIGURABLE_CONFIGS;
+ }
+
+ @Override
+ public void validateReconfiguration(AbstractKafkaConfig newConfig) {
+ validateLogLocalRetentionMs(newConfig);
+ validateLogLocalRetentionBytes(newConfig);
+ validateLogRemoteCopyLagMs(newConfig);
+ validateLogRemoteCopyLagBytes(newConfig);
+ validateCordonedLogDirs(newConfig);
+ }
+
+ private void validateLogLocalRetentionMs(AbstractKafkaConfig config) {
+ long logRetentionMs = config.logRetentionTimeMillis();
+ long logLocalRetentionMs = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP);
+ if (logRetentionMs != LogConfig.NO_RETENTION_LIMIT && logLocalRetentionMs != LogConfig.DEFAULT_LOCAL_RETENTION_MS) {
+ if (logLocalRetentionMs == LogConfig.NO_RETENTION_LIMIT) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, logLocalRetentionMs,
+ "Value must not be " + LogConfig.NO_RETENTION_LIMIT + " as " + ServerLogConfigs.LOG_RETENTION_TIME_MILLIS_CONFIG + " value is set as " + logRetentionMs + ".");
+ }
+ if (logLocalRetentionMs > logRetentionMs) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, logLocalRetentionMs,
+ "Value must not be more than " + ServerLogConfigs.LOG_RETENTION_TIME_MILLIS_CONFIG + " property value: " + logRetentionMs);
+ }
+ }
+ }
+
+ private void validateLogLocalRetentionBytes(AbstractKafkaConfig config) {
+ long logRetentionBytes = config.logRetentionBytes();
+ long logLocalRetentionBytes = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP);
+ if (logRetentionBytes > LogConfig.NO_RETENTION_LIMIT && logLocalRetentionBytes != LogConfig.DEFAULT_LOCAL_RETENTION_BYTES) {
+ if (logLocalRetentionBytes == LogConfig.NO_RETENTION_LIMIT) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP, logLocalRetentionBytes,
+ "Value must not be " + LogConfig.NO_RETENTION_LIMIT + " as " + ServerLogConfigs.LOG_RETENTION_BYTES_CONFIG + " value is set as " + logRetentionBytes + ".");
+ }
+ if (logLocalRetentionBytes > logRetentionBytes) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP, logLocalRetentionBytes,
+ "Value must not be more than " + ServerLogConfigs.LOG_RETENTION_BYTES_CONFIG + " property value: " + logRetentionBytes);
+ }
+ }
+ }
+
+ private void validateLogRemoteCopyLagMs(AbstractKafkaConfig config) {
+ long logRetentionMs = config.logRetentionTimeMillis();
+ long logLocalRetentionMs = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP);
+ long effectiveLocalRetentionMs = logLocalRetentionMs == LogConfig.DEFAULT_LOCAL_RETENTION_MS ? logRetentionMs : logLocalRetentionMs;
+ long logRemoteCopyLagMs = config.getLong(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_MS_PROP);
+ if (logRemoteCopyLagMs > 0L && effectiveLocalRetentionMs >= 0L && logRemoteCopyLagMs > effectiveLocalRetentionMs) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_MS_PROP, logRemoteCopyLagMs,
+ "Value must not exceed " + RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP +
+ " (effective value: " + effectiveLocalRetentionMs + ")");
+ }
+ }
+
+ private void validateLogRemoteCopyLagBytes(AbstractKafkaConfig config) {
+ long logRetentionBytes = config.logRetentionBytes();
+ long logLocalRetentionBytes = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP);
+ long effectiveLocalRetentionBytes = logLocalRetentionBytes == LogConfig.DEFAULT_LOCAL_RETENTION_BYTES ? logRetentionBytes : logLocalRetentionBytes;
+ long logRemoteCopyLagBytes = config.getLong(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_BYTES_PROP);
+ if (logRemoteCopyLagBytes > 0L && effectiveLocalRetentionBytes >= 0L && logRemoteCopyLagBytes > effectiveLocalRetentionBytes) {
Review Comment:
Done in 98cb31f.
##########
server/src/main/java/org/apache/kafka/server/config/DynamicLogConfig.java:
##########
@@ -0,0 +1,164 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.config;
+
+import org.apache.kafka.common.config.ConfigException;
+import org.apache.kafka.server.common.DirectoryEventHandler;
+import org.apache.kafka.server.log.remote.storage.RemoteLogManagerConfig;
+import org.apache.kafka.storage.internals.log.LogConfig;
+import org.apache.kafka.storage.internals.log.LogManager;
+import org.apache.kafka.storage.internals.log.UnifiedLog;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class DynamicLogConfig implements BrokerReconfigurable {
+ /**
+ * The broker configurations pertaining to logs that are reconfigurable. This set contains
+ * the names you would use when setting a static or dynamic broker configuration (not topic
+ * configuration).
+ */
+ public static final Set<String> RECONFIGURABLE_CONFIGS = Stream.of(
+ ServerTopicConfigSynonyms.TOPIC_CONFIG_SYNONYMS.values(),
+ Set.of(ServerLogConfigs.CORDONED_LOG_DIRS_CONFIG))
+ .flatMap(Collection::stream)
+ .collect(Collectors.toUnmodifiableSet());
+
+ private final LogManager logManager;
+ private final DirectoryEventHandler directoryEventHandler;
+
+ public DynamicLogConfig(LogManager logManager, DirectoryEventHandler directoryEventHandler) {
+ this.logManager = logManager;
+ this.directoryEventHandler = directoryEventHandler;
+ }
+
+ @Override
+ public Set<String> reconfigurableConfigs() {
+ return RECONFIGURABLE_CONFIGS;
+ }
+
+ @Override
+ public void validateReconfiguration(AbstractKafkaConfig newConfig) {
+ validateLogLocalRetentionMs(newConfig);
+ validateLogLocalRetentionBytes(newConfig);
+ validateLogRemoteCopyLagMs(newConfig);
+ validateLogRemoteCopyLagBytes(newConfig);
+ validateCordonedLogDirs(newConfig);
+ }
+
+ private void validateLogLocalRetentionMs(AbstractKafkaConfig config) {
+ long logRetentionMs = config.logRetentionTimeMillis();
+ long logLocalRetentionMs = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP);
+ if (logRetentionMs != LogConfig.NO_RETENTION_LIMIT && logLocalRetentionMs != LogConfig.DEFAULT_LOCAL_RETENTION_MS) {
+ if (logLocalRetentionMs == LogConfig.NO_RETENTION_LIMIT) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, logLocalRetentionMs,
+ "Value must not be " + LogConfig.NO_RETENTION_LIMIT + " as " + ServerLogConfigs.LOG_RETENTION_TIME_MILLIS_CONFIG + " value is set as " + logRetentionMs + ".");
+ }
+ if (logLocalRetentionMs > logRetentionMs) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, logLocalRetentionMs,
+ "Value must not be more than " + ServerLogConfigs.LOG_RETENTION_TIME_MILLIS_CONFIG + " property value: " + logRetentionMs);
+ }
+ }
+ }
+
+ private void validateLogLocalRetentionBytes(AbstractKafkaConfig config) {
+ long logRetentionBytes = config.logRetentionBytes();
+ long logLocalRetentionBytes = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP);
+ if (logRetentionBytes > LogConfig.NO_RETENTION_LIMIT && logLocalRetentionBytes != LogConfig.DEFAULT_LOCAL_RETENTION_BYTES) {
+ if (logLocalRetentionBytes == LogConfig.NO_RETENTION_LIMIT) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP, logLocalRetentionBytes,
+ "Value must not be " + LogConfig.NO_RETENTION_LIMIT + " as " + ServerLogConfigs.LOG_RETENTION_BYTES_CONFIG + " value is set as " + logRetentionBytes + ".");
+ }
+ if (logLocalRetentionBytes > logRetentionBytes) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP, logLocalRetentionBytes,
+ "Value must not be more than " + ServerLogConfigs.LOG_RETENTION_BYTES_CONFIG + " property value: " + logRetentionBytes);
+ }
+ }
+ }
+
+ private void validateLogRemoteCopyLagMs(AbstractKafkaConfig config) {
+ long logRetentionMs = config.logRetentionTimeMillis();
+ long logLocalRetentionMs = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP);
+ long effectiveLocalRetentionMs = logLocalRetentionMs == LogConfig.DEFAULT_LOCAL_RETENTION_MS ? logRetentionMs : logLocalRetentionMs;
+ long logRemoteCopyLagMs = config.getLong(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_MS_PROP);
+ if (logRemoteCopyLagMs > 0L && effectiveLocalRetentionMs >= 0L && logRemoteCopyLagMs > effectiveLocalRetentionMs) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_MS_PROP, logRemoteCopyLagMs,
+ "Value must not exceed " + RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP +
+ " (effective value: " + effectiveLocalRetentionMs + ")");
+ }
+ }
+
+ private void validateLogRemoteCopyLagBytes(AbstractKafkaConfig config) {
+ long logRetentionBytes = config.logRetentionBytes();
+ long logLocalRetentionBytes = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP);
+ long effectiveLocalRetentionBytes = logLocalRetentionBytes == LogConfig.DEFAULT_LOCAL_RETENTION_BYTES ? logRetentionBytes : logLocalRetentionBytes;
+ long logRemoteCopyLagBytes = config.getLong(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_BYTES_PROP);
+ if (logRemoteCopyLagBytes > 0L && effectiveLocalRetentionBytes >= 0L && logRemoteCopyLagBytes > effectiveLocalRetentionBytes) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_BYTES_PROP, logRemoteCopyLagBytes,
+ "Value must not exceed " + RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP +
+ " (effective value: " + effectiveLocalRetentionBytes + ")");
+ }
+ }
+
+ private void validateCordonedLogDirs(AbstractKafkaConfig config) {
+ List<String> cordonedLogDirs = config.cordonedLogDirs();
+ List<String> logDirs = config.logDirs();
+ for (String dir : cordonedLogDirs) {
+ if (!logDirs.contains(dir)) {
+ throw new ConfigException(ServerLogConfigs.CORDONED_LOG_DIRS_CONFIG, cordonedLogDirs,
+ "Invalid entry in " + ServerLogConfigs.CORDONED_LOG_DIRS_CONFIG + ": " + dir + ". " +
+ "All cordoned log dirs must be entries of " + ServerLogConfigs.LOG_DIRS_CONFIG + " or " +
+ ServerLogConfigs.LOG_DIR_CONFIG + ".");
+ }
+ }
+ }
+
+ private void updateLogsConfig(Map<String, Object> newBrokerDefaults) {
+ logManager.brokerConfigUpdated();
+ for (UnifiedLog unifiedLog : logManager.allLogs()) {
+ Map<String, Object> props = new HashMap<>(newBrokerDefaults);
+ unifiedLog.config().originals().forEach((key, value) -> {
+ if (unifiedLog.config().overriddenConfigs.contains(key)) {
+ props.put(key, value);
+ }
+ });
+ unifiedLog.updateConfig(new LogConfig(props, unifiedLog.config().overriddenConfigs));
+ }
+ }
+
+ @Override
+ public void reconfigure(AbstractKafkaConfig oldConfig, AbstractKafkaConfig newConfig) {
+ Map<String, Object> newBrokerDefaults = new HashMap<>(newConfig.extractLogConfigMap());
Review Comment:
Sorry my bad, removed in 1e3a513.
##########
server/src/main/java/org/apache/kafka/server/config/DynamicLogConfig.java:
##########
@@ -0,0 +1,164 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.config;
+
+import org.apache.kafka.common.config.ConfigException;
+import org.apache.kafka.server.common.DirectoryEventHandler;
+import org.apache.kafka.server.log.remote.storage.RemoteLogManagerConfig;
+import org.apache.kafka.storage.internals.log.LogConfig;
+import org.apache.kafka.storage.internals.log.LogManager;
+import org.apache.kafka.storage.internals.log.UnifiedLog;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class DynamicLogConfig implements BrokerReconfigurable {
+ /**
+ * The broker configurations pertaining to logs that are reconfigurable. This set contains
+ * the names you would use when setting a static or dynamic broker configuration (not topic
+ * configuration).
+ */
+ public static final Set<String> RECONFIGURABLE_CONFIGS = Stream.of(
+ ServerTopicConfigSynonyms.TOPIC_CONFIG_SYNONYMS.values(),
+ Set.of(ServerLogConfigs.CORDONED_LOG_DIRS_CONFIG))
+ .flatMap(Collection::stream)
+ .collect(Collectors.toUnmodifiableSet());
+
+ private final LogManager logManager;
+ private final DirectoryEventHandler directoryEventHandler;
+
+ public DynamicLogConfig(LogManager logManager, DirectoryEventHandler directoryEventHandler) {
+ this.logManager = logManager;
+ this.directoryEventHandler = directoryEventHandler;
+ }
+
+ @Override
+ public Set<String> reconfigurableConfigs() {
+ return RECONFIGURABLE_CONFIGS;
+ }
+
+ @Override
+ public void validateReconfiguration(AbstractKafkaConfig newConfig) {
+ validateLogLocalRetentionMs(newConfig);
+ validateLogLocalRetentionBytes(newConfig);
+ validateLogRemoteCopyLagMs(newConfig);
+ validateLogRemoteCopyLagBytes(newConfig);
+ validateCordonedLogDirs(newConfig);
+ }
+
+ private void validateLogLocalRetentionMs(AbstractKafkaConfig config) {
+ long logRetentionMs = config.logRetentionTimeMillis();
+ long logLocalRetentionMs = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP);
+ if (logRetentionMs != LogConfig.NO_RETENTION_LIMIT && logLocalRetentionMs != LogConfig.DEFAULT_LOCAL_RETENTION_MS) {
+ if (logLocalRetentionMs == LogConfig.NO_RETENTION_LIMIT) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, logLocalRetentionMs,
+ "Value must not be " + LogConfig.NO_RETENTION_LIMIT + " as " + ServerLogConfigs.LOG_RETENTION_TIME_MILLIS_CONFIG + " value is set as " + logRetentionMs + ".");
+ }
+ if (logLocalRetentionMs > logRetentionMs) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP, logLocalRetentionMs,
+ "Value must not be more than " + ServerLogConfigs.LOG_RETENTION_TIME_MILLIS_CONFIG + " property value: " + logRetentionMs);
+ }
+ }
+ }
+
+ private void validateLogLocalRetentionBytes(AbstractKafkaConfig config) {
+ long logRetentionBytes = config.logRetentionBytes();
+ long logLocalRetentionBytes = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP);
+ if (logRetentionBytes > LogConfig.NO_RETENTION_LIMIT && logLocalRetentionBytes != LogConfig.DEFAULT_LOCAL_RETENTION_BYTES) {
+ if (logLocalRetentionBytes == LogConfig.NO_RETENTION_LIMIT) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP, logLocalRetentionBytes,
+ "Value must not be " + LogConfig.NO_RETENTION_LIMIT + " as " + ServerLogConfigs.LOG_RETENTION_BYTES_CONFIG + " value is set as " + logRetentionBytes + ".");
+ }
+ if (logLocalRetentionBytes > logRetentionBytes) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP, logLocalRetentionBytes,
+ "Value must not be more than " + ServerLogConfigs.LOG_RETENTION_BYTES_CONFIG + " property value: " + logRetentionBytes);
+ }
+ }
+ }
+
+ private void validateLogRemoteCopyLagMs(AbstractKafkaConfig config) {
+ long logRetentionMs = config.logRetentionTimeMillis();
+ long logLocalRetentionMs = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP);
+ long effectiveLocalRetentionMs = logLocalRetentionMs == LogConfig.DEFAULT_LOCAL_RETENTION_MS ? logRetentionMs : logLocalRetentionMs;
+ long logRemoteCopyLagMs = config.getLong(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_MS_PROP);
+ if (logRemoteCopyLagMs > 0L && effectiveLocalRetentionMs >= 0L && logRemoteCopyLagMs > effectiveLocalRetentionMs) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_MS_PROP, logRemoteCopyLagMs,
+ "Value must not exceed " + RemoteLogManagerConfig.LOG_LOCAL_RETENTION_MS_PROP +
+ " (effective value: " + effectiveLocalRetentionMs + ")");
+ }
+ }
+
+ private void validateLogRemoteCopyLagBytes(AbstractKafkaConfig config) {
+ long logRetentionBytes = config.logRetentionBytes();
+ long logLocalRetentionBytes = config.getLong(RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP);
+ long effectiveLocalRetentionBytes = logLocalRetentionBytes == LogConfig.DEFAULT_LOCAL_RETENTION_BYTES ? logRetentionBytes : logLocalRetentionBytes;
+ long logRemoteCopyLagBytes = config.getLong(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_BYTES_PROP);
+ if (logRemoteCopyLagBytes > 0L && effectiveLocalRetentionBytes >= 0L && logRemoteCopyLagBytes > effectiveLocalRetentionBytes) {
+ throw new ConfigException(RemoteLogManagerConfig.LOG_REMOTE_COPY_LAG_BYTES_PROP, logRemoteCopyLagBytes,
+ "Value must not exceed " + RemoteLogManagerConfig.LOG_LOCAL_RETENTION_BYTES_PROP +
+ " (effective value: " + effectiveLocalRetentionBytes + ")");
+ }
+ }
+
+ private void validateCordonedLogDirs(AbstractKafkaConfig config) {
+ List<String> cordonedLogDirs = config.cordonedLogDirs();
+ List<String> logDirs = config.logDirs();
+ for (String dir : cordonedLogDirs) {
+ if (!logDirs.contains(dir)) {
+ throw new ConfigException(ServerLogConfigs.CORDONED_LOG_DIRS_CONFIG, cordonedLogDirs,
+ "Invalid entry in " + ServerLogConfigs.CORDONED_LOG_DIRS_CONFIG + ": " + dir + ". " +
+ "All cordoned log dirs must be entries of " + ServerLogConfigs.LOG_DIRS_CONFIG + " or " +
+ ServerLogConfigs.LOG_DIR_CONFIG + ".");
+ }
+ }
+ }
+
+ private void updateLogsConfig(Map<String, Object> newBrokerDefaults) {
+ logManager.brokerConfigUpdated();
+ for (UnifiedLog unifiedLog : logManager.allLogs()) {
+ Map<String, Object> props = new HashMap<>(newBrokerDefaults);
+ unifiedLog.config().originals().forEach((key, value) -> {
+ if (unifiedLog.config().overriddenConfigs.contains(key)) {
+ props.put(key, value);
+ }
+ });
+ unifiedLog.updateConfig(new LogConfig(props, unifiedLog.config().overriddenConfigs));
+ }
+ }
+
+ @Override
+ public void reconfigure(AbstractKafkaConfig oldConfig, AbstractKafkaConfig newConfig) {
+ Map<String, Object> newBrokerDefaults = new HashMap<>(newConfig.extractLogConfigMap());
+ logManager.reconfigureDefaultLogConfig(new LogConfig(newBrokerDefaults));
+ updateLogsConfig(newBrokerDefaults);
+
+ logManager.updateCordonedLogDirs(Set.copyOf(newConfig.cordonedLogDirs()));
+ directoryEventHandler.handleCordoned(newConfig.cordonedLogDirs().stream()
+ .flatMap(dir -> logManager.directoryId(dir).stream())
+ .collect(Collectors.toSet()));
Review Comment:
Done in ba6ccdc.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org