hachikuji commented on a change in pull request #10005: URL: https://github.com/apache/kafka/pull/10005#discussion_r569944146
########## File path: core/src/main/scala/kafka/server/metadata/LocalConfigRepository.scala ########## @@ -0,0 +1,136 @@ +/** + * 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 kafka.server.metadata + +import java.util +import java.util.Properties +import java.util.concurrent.ConcurrentHashMap +import java.util.function.BiFunction + +import org.apache.kafka.common.config.ConfigResource +import org.apache.kafka.common.config.ConfigResource.Type + +import scala.jdk.CollectionConverters._ + +/** + * A ConfigRepository that stores configurations locally. + */ +class LocalConfigRepository extends ConfigRepository { + val configMap = new ConcurrentHashMap[ConfigResource, util.HashMap[String, String]] + + /** + * Remove the topic config for the given topic name and the given key. + * + * @param topicName the name of the topic for which the config will be removed + * @param key the key identifying the topic config to remove + */ + def removeTopicConfig(topicName: String, key: String): Unit = { + setTopicConfig(topicName, key, null) + } + + /** + * Set the topic config for the given topic name and the given key to the given value. + * + * @param topicName the name of the topic for which the config will be set + * @param key the key identifying the topic config to set + * @param value the value to set for the topic config with null implying a removal + */ + def setTopicConfig(topicName: String, key: String, value: String): Unit = { + setConfig(new ConfigResource(Type.TOPIC, topicName), key, value) + } + + /** + * Remove the broker config for the given broker ID and the given key. + * + * @param brokerId the ID of the broker for which the config will be removed + * @param key the key identifying the topic config to remove + */ + def removeBrokerConfig(brokerId: Int, key: String): Unit = { Review comment: nit: I think it is better to have just one way to remove configs. I know I suggested this, but I was assuming we would not also support removal through `set`. If you think using `set` with a null value is clear enough, we can remove these. ########## File path: core/src/main/scala/kafka/cluster/Partition.scala ########## @@ -342,7 +331,7 @@ class Partition(val topicPartition: TopicPartition, // Visible for testing private[cluster] def createLog(isNew: Boolean, isFutureReplica: Boolean, offsetCheckpoints: OffsetCheckpoints): Log = { def fetchLogConfig: LogConfig = { - val props = topicConfigProvider.fetch() + val props = configRepository.topicConfig(topicPartition.topic()) Review comment: nit: we can use `configRepository.topicConfig(topic)` ########## File path: core/src/main/scala/kafka/server/KafkaServer.scala ########## @@ -348,15 +348,15 @@ class KafkaServer( /* start processing requests */ dataPlaneRequestProcessor = new KafkaApis(socketServer.dataPlaneRequestChannel, replicaManager, adminManager, groupCoordinator, transactionCoordinator, - kafkaController, forwardingManager, zkClient, config.brokerId, config, metadataCache, metrics, authorizer, quotaManagers, + kafkaController, forwardingManager, zkClient, config.brokerId, config, replicaManager.configRepository, metadataCache, metrics, authorizer, quotaManagers, Review comment: nit: Similarly here, it would be cleaner to construct the config repository separately in this class and pass it down to the components that need it including `ReplicaManager` and `KafkaApis`. ########## File path: core/src/main/scala/kafka/server/metadata/ZkConfigRepository.scala ########## @@ -0,0 +1,39 @@ +/** + * 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 kafka.server.metadata + +import java.util.Properties + +import kafka.server.ConfigType +import kafka.zk.{AdminZkClient, KafkaZkClient} +import org.apache.kafka.common.config.ConfigResource +import org.apache.kafka.common.config.ConfigResource.Type + + +object ZkConfigRepository { + def apply(zkClient: KafkaZkClient): ZkConfigRepository = + new ZkConfigRepository(new AdminZkClient(zkClient)) +} + +class ZkConfigRepository(adminZkClient: AdminZkClient) extends ConfigRepository { + override def config(configResource: ConfigResource): Properties = { + adminZkClient.fetchEntityConfig( + if (configResource.`type`() == Type.TOPIC) ConfigType.Topic else ConfigType.Broker, Review comment: Hmm... It would be better to have an explicit check for the `Broker` type. We can raise an exception for any remaining types. ########## File path: core/src/main/scala/kafka/server/metadata/LocalConfigRepository.scala ########## @@ -0,0 +1,136 @@ +/** + * 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 kafka.server.metadata + +import java.util +import java.util.Properties +import java.util.concurrent.ConcurrentHashMap +import java.util.function.BiFunction + +import org.apache.kafka.common.config.ConfigResource +import org.apache.kafka.common.config.ConfigResource.Type + +import scala.jdk.CollectionConverters._ + +/** + * A ConfigRepository that stores configurations locally. + */ +class LocalConfigRepository extends ConfigRepository { Review comment: I found the term "local" a little confusing. How about `CachedConfigRepository`? ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org