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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to