You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by GitBox <gi...@apache.org> on 2023/01/03 18:11:44 UTC

[GitHub] [kafka] ijuma commented on a diff in pull request #13049: KAFKA-14478: Move LogConfig/CleanerConfig and related to storage module

ijuma commented on code in PR #13049:
URL: https://github.com/apache/kafka/pull/13049#discussion_r1060835881


##########
storage/src/main/java/org/apache/kafka/server/log/internals/LogConfig.java:
##########
@@ -0,0 +1,504 @@
+/*
+ * 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.log.internals;
+
+import static java.util.Arrays.asList;
+import static org.apache.kafka.common.config.ConfigDef.Range.between;
+import static org.apache.kafka.common.config.ConfigDef.Type.BOOLEAN;
+import static org.apache.kafka.common.config.ConfigDef.Type.DOUBLE;
+import static org.apache.kafka.common.config.ConfigDef.Type.LIST;
+import static org.apache.kafka.common.config.ConfigDef.Type.LONG;
+import static org.apache.kafka.common.config.ConfigDef.Type.STRING;
+import static org.apache.kafka.server.common.MetadataVersion.IBP_3_0_IV1;
+import static org.apache.kafka.common.config.ConfigDef.Importance.LOW;
+import static org.apache.kafka.common.config.ConfigDef.Importance.MEDIUM;
+import static org.apache.kafka.common.config.ConfigDef.Range.atLeast;
+import static org.apache.kafka.common.config.ConfigDef.Type.INT;
+import static org.apache.kafka.common.config.ConfigDef.ValidString.in;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Properties;
+import java.util.Set;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.stream.Collectors;
+import org.apache.kafka.common.config.AbstractConfig;
+import org.apache.kafka.common.config.ConfigDef;
+import org.apache.kafka.common.config.ConfigDef.ConfigKey;
+import org.apache.kafka.common.config.ConfigDef.Type;
+import org.apache.kafka.common.config.ConfigDef.ValidList;
+import org.apache.kafka.common.config.ConfigException;
+import org.apache.kafka.common.config.TopicConfig;
+import org.apache.kafka.common.errors.InvalidConfigurationException;
+import org.apache.kafka.common.record.LegacyRecord;
+import org.apache.kafka.common.record.RecordVersion;
+import org.apache.kafka.common.record.Records;
+import org.apache.kafka.common.record.TimestampType;
+import org.apache.kafka.common.utils.ConfigUtils;
+import org.apache.kafka.common.utils.Utils;
+import org.apache.kafka.server.common.MetadataVersion;
+import org.apache.kafka.server.common.MetadataVersionValidator;
+import org.apache.kafka.server.config.ServerTopicConfigSynonyms;
+import org.apache.kafka.server.record.BrokerCompressionType;
+
+public class LogConfig extends AbstractConfig {
+
+    public static class MessageFormatVersion {
+        private final String messageFormatVersionString;
+        private final String interBrokerProtocolVersionString;
+        private final MetadataVersion messageFormatVersion;
+        private final MetadataVersion interBrokerProtocolVersion;
+
+        public MessageFormatVersion(String messageFormatVersionString, String interBrokerProtocolVersionString) {
+            this.messageFormatVersionString = messageFormatVersionString;
+            this.interBrokerProtocolVersionString = interBrokerProtocolVersionString;
+            this.messageFormatVersion = MetadataVersion.fromVersionString(messageFormatVersionString);
+            this.interBrokerProtocolVersion = MetadataVersion.fromVersionString(interBrokerProtocolVersionString);
+        }
+
+        public MetadataVersion messageFormatVersion() {
+            return messageFormatVersion;
+        }
+
+        public MetadataVersion interBrokerProtocolVersion() {
+            return interBrokerProtocolVersion;
+        }
+
+        public boolean shouldIgnore() {
+            return shouldIgnoreMessageFormatVersion(interBrokerProtocolVersion);
+        }
+
+        public boolean shouldWarn() {
+            return interBrokerProtocolVersion.isAtLeast(IBP_3_0_IV1)
+                && messageFormatVersion.highestSupportedRecordVersion().precedes(RecordVersion.V2);
+        }
+
+        @SuppressWarnings("deprecation")
+        public String topicWarningMessage(String topicName) {
+            return "Topic configuration " + TopicConfig.MESSAGE_FORMAT_VERSION_CONFIG + " with value `"
+                + messageFormatVersionString + "` is ignored for `" + topicName + "` because the "
+                + "inter-broker protocol version `" + interBrokerProtocolVersionString + "` is greater or "
+                + "equal than 3.0. This configuration is deprecated and it will be removed in Apache Kafka 4.0.";
+        }
+    }
+
+    public static class RemoteLogConfig {
+
+        public final boolean remoteStorageEnable;
+
+        public final long localRetentionMs;
+        public final long localRetentionBytes;
+
+        private RemoteLogConfig(LogConfig config, long retentionMs, long retentionSize) {
+            this.remoteStorageEnable = config.getBoolean(TopicConfig.REMOTE_LOG_STORAGE_ENABLE_CONFIG);
+
+            long localLogRetentionMs = config.getLong(TopicConfig.LOCAL_LOG_RETENTION_MS_CONFIG);
+
+            // -2 indicates to derive value from retentionMs property.
+            if (localLogRetentionMs == -2)
+                this.localRetentionMs = retentionMs;
+            else {
+                // Added validation here to check the effective value should not be more than RetentionMs.
+                if (localLogRetentionMs == -1 && retentionMs != -1)
+                    throw new ConfigException(TopicConfig.LOCAL_LOG_RETENTION_MS_CONFIG, localLogRetentionMs,
+                        "Value must not be -1 as " + TopicConfig.RETENTION_MS_CONFIG + " value is set as " + retentionMs);
+
+                if (localLogRetentionMs > retentionMs)
+                    throw new ConfigException(TopicConfig.LOCAL_LOG_RETENTION_MS_CONFIG, localLogRetentionMs,
+                        "Value must not be more than property: " + TopicConfig.RETENTION_MS_CONFIG + " value.");
+
+                this.localRetentionMs = localLogRetentionMs;
+            }
+
+            long localLogRetentionBytes = config.getLong(TopicConfig.LOCAL_LOG_RETENTION_BYTES_CONFIG);
+
+            // -2 indicates to derive value from retentionSize property.
+            if (localLogRetentionBytes == -2)
+                this.localRetentionBytes = retentionSize;
+            else {
+                // Added validation here to check the effective value should not be more than RetentionBytes.
+                if (localLogRetentionBytes == -1 && retentionSize != -1)
+                    throw new ConfigException(TopicConfig.LOCAL_LOG_RETENTION_BYTES_CONFIG, localLogRetentionBytes,
+                        "Value must not be -1 as " + TopicConfig.RETENTION_BYTES_CONFIG + " value is set as " + retentionSize);
+
+                if (localLogRetentionBytes > retentionSize)
+                    throw new ConfigException(TopicConfig.LOCAL_LOG_RETENTION_BYTES_CONFIG, localLogRetentionBytes,
+                        "Value must not be more than property: " + TopicConfig.RETENTION_BYTES_CONFIG + " value.");
+
+                this.localRetentionBytes = localLogRetentionBytes;
+            }
+        }
+    }
+
+    // Visible for testing
+    public static class LogConfigDef extends ConfigDef {
+        public LogConfigDef() {
+            this(new ConfigDef());
+        }
+
+        public LogConfigDef(ConfigDef base) {
+            super(base);
+        }
+
+        @Override
+        public List<String> headers() {
+            return asList("Name", "Description", "Type", "Default", "Valid Values", SERVER_DEFAULT_HEADER_NAME, "Importance");
+        }
+
+        // Visible for testing
+        @Override
+        public String getConfigValue(ConfigKey key, String headerName) {
+            if (headerName.equals(SERVER_DEFAULT_HEADER_NAME))
+                return ServerTopicConfigSynonyms.TOPIC_CONFIG_SYNONYMS.get(key.name);
+            else
+                return super.getConfigValue(key, headerName);
+        }
+
+        public Optional<String> serverConfigName(String configName) {
+            return Optional.ofNullable(ServerTopicConfigSynonyms.TOPIC_CONFIG_SYNONYMS.get(configName));
+        }
+    }
+
+    // Visible for testing
+    public static final String SERVER_DEFAULT_HEADER_NAME = "Server Default Property";
+
+    public static final int DEFAULT_MAX_MESSAGE_BYTES = 1024 * 1024 + Records.LOG_OVERHEAD;
+    public static final int DEFAULT_SEGMENT_BYTES = 1024 * 1024 * 1024;
+    public static final long DEFAULT_SEGMENT_MS = 24 * 7 * 60 * 60 * 1000L;
+    public static final long DEFAULT_SEGMENT_JITTER_MS = 0;
+    public static final long DEFAULT_RETENTION_MS = 24 * 7 * 60 * 60 * 1000L;
+    public static final long DEFAULT_RETENTION_BYTES = -1L;
+    public static final int DEFAULT_SEGMENT_INDEX_BYTES = 10 * 1024 * 1024;
+    public static final int DEFAULT_INDEX_INTERVAL_BYTES = 4096;
+    public static final long DEFAULT_FILE_DELETE_DELAY_MS = 60000L;
+    public static final String DEFAULT_CLEANUP_POLICY = TopicConfig.CLEANUP_POLICY_DELETE;
+    public static final long DEFAULT_FLUSH_MESSAGES_INTERVAL = Long.MAX_VALUE;
+    public static final long DEFAULT_FLUSH_MS = Long.MAX_VALUE;
+    public static final long DEFAULT_DELETE_RETENTION_MS = 24 * 60 * 60 * 1000L;
+    public static final long DEFAULT_MIN_COMPACTION_LAG_MS = 0;
+    public static final long DEFAULT_MAX_COMPACTION_LAG_MS = Long.MAX_VALUE;
+    public static final double DEFAULT_MIN_CLEANABLE_DIRTY_RATIO = 0.5;
+    public static final boolean DEFAULT_UNCLEAN_LEADER_ELECTION_ENABLE = false;
+    public static final int DEFAULT_MIN_IN_SYNC_REPLICAS = 1;
+    public static final String DEFAULT_COMPRESSION_TYPE = BrokerCompressionType.PRODUCER.name;
+    public static final boolean DEFAULT_PREALLOCATE = false;
+    public static final String DEFAULT_MESSAGE_TIMESTAMP_TYPE = "CreateTime";
+    public static final long DEFAULT_MESSAGE_TIMESTAMP_DIFFERENCE_MAX_MS = Long.MAX_VALUE;
+    public static final boolean DEFAULT_MESSAGE_DOWNCONVERSION_ENABLE = true;
+
+    public static final boolean DEFAULT_REMOTE_STORAGE_ENABLE = false;
+    public static final int DEFAULT_LOCAL_RETENTION_BYTES = -2; // It indicates the value to be derived from RetentionBytes
+    public static final int DEFAULT_LOCAL_RETENTION_MS = -2; // It indicates the value to be derived from RetentionMs
+    public static final List<String> DEFAULT_LEADER_REPLICATION_THROTTLED_REPLICAS = Collections.emptyList();
+    public static final List<String> DEFAULT_FOLLOWER_REPLICATION_THROTTLED_REPLICAS = Collections.emptyList();
+
+    /* See `TopicConfig.MESSAGE_FORMAT_VERSION_CONFIG` for details */
+    @Deprecated
+    public static final String DEFAULT_MESSAGE_FORMAT_VERSION = IBP_3_0_IV1.version();
+
+    // Leave these out of TopicConfig for now as they are replication quota configs
+    public static final String LEADER_REPLICATION_THROTTLED_REPLICAS_CONFIG = "leader.replication.throttled.replicas";
+    public static final String FOLLOWER_REPLICATION_THROTTLED_REPLICAS_CONFIG = "follower.replication.throttled.replicas";
+
+    @SuppressWarnings("deprecation")
+    private static final String MESSAGE_FORMAT_VERSION_CONFIG = TopicConfig.MESSAGE_FORMAT_VERSION_CONFIG;
+
+    // Visible for testing
+    public static final Set<String> CONFIGS_WITH_NO_SERVER_DEFAULTS = Collections.unmodifiableSet(Utils.mkSet(
+        TopicConfig.REMOTE_LOG_STORAGE_ENABLE_CONFIG,
+        TopicConfig.LOCAL_LOG_RETENTION_MS_CONFIG,
+        TopicConfig.LOCAL_LOG_RETENTION_BYTES_CONFIG,
+        LEADER_REPLICATION_THROTTLED_REPLICAS_CONFIG,
+        FOLLOWER_REPLICATION_THROTTLED_REPLICAS_CONFIG
+    ));
+
+    public static final String LEADER_REPLICATION_THROTTLED_REPLICAS_DOC = "A list of replicas for which log replication should be throttled on " +
+        "the leader side. The list should describe a set of replicas in the form " +
+        "[PartitionId]:[BrokerId],[PartitionId]:[BrokerId]:... or alternatively the wildcard '*' can be used to throttle " +
+        "all replicas for this topic.";
+    public static final String FOLLOWER_REPLICATION_THROTTLED_REPLICAS_DOC = "A list of replicas for which log replication should be throttled on " +
+        "the follower side. The list should describe a set of " + "replicas in the form " +
+        "[PartitionId]:[BrokerId],[PartitionId]:[BrokerId]:... or alternatively the wildcard '*' can be used to throttle " +
+        "all replicas for this topic.";
+
+    @SuppressWarnings("deprecation")
+    private static final String MESSAGE_FORMAT_VERSION_DOC = TopicConfig.MESSAGE_FORMAT_VERSION_DOC;

Review Comment:
   We do, there's no way to suppress deprecations within the static block (I made this change to get the code to compile).



-- 
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