ijuma commented on code in PR #13049: URL: https://github.com/apache/kafka/pull/13049#discussion_r1058623369
########## 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 { Review Comment: Removed `define` overrides since we now rely on the statically defined `ServerTopicConfigSynonyms` to retrieve the server config default/synonym. -- 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-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org