ahuang98 commented on code in PR #21053:
URL: https://github.com/apache/kafka/pull/21053#discussion_r2591071179
##########
metadata/src/main/java/org/apache/kafka/image/ConfigurationsDelta.java:
##########
@@ -21,17 +21,48 @@
import org.apache.kafka.common.config.ConfigResource.Type;
import org.apache.kafka.common.metadata.ConfigRecord;
import org.apache.kafka.common.metadata.RemoveTopicRecord;
+import org.apache.kafka.metadata.KafkaConfigSchema;
import org.apache.kafka.server.common.MetadataVersion;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Set;
+import java.util.function.Supplier;
/**
* Represents changes to the configurations in the metadata image.
*/
public final class ConfigurationsDelta {
+ /**
+ * Supplier for KafkaConfigSchema to get valid config names whitelist by
resource type.
+ */
+ private static volatile Supplier<KafkaConfigSchema> configSchemaSupplier =
null;
+
+ /**
+ * Set the supplier for KafkaConfigSchema. This should be called during
initialization.
+ */
+ public static void setConfigSchemaSupplier(Supplier<KafkaConfigSchema>
supplier) {
+ configSchemaSupplier = supplier;
+ }
+
+ /**
+ * Get the set of valid configuration names for a given resource type.
+ * Returns empty set if configSchema is not initialized.
+ */
+ static Set<String> getValidConfigNames(Type resourceType) {
+ Supplier<KafkaConfigSchema> supplier = configSchemaSupplier;
+ if (supplier == null) {
+ return Set.of();
+ }
+ KafkaConfigSchema configSchema = supplier.get();
+ if (configSchema == null) {
+ return Set.of();
+ }
+ return configSchema.validConfigNames(resourceType);
Review Comment:
what about something like
```
return Optional.ofNullable(configSchemaSupplier)
.map(Supplier::get)
.map(schema -> schema.validConfigNames(resourceType))
.orElse(Set.of());
```
##########
metadata/src/main/java/org/apache/kafka/image/ConfigurationsDelta.java:
##########
@@ -21,17 +21,48 @@
import org.apache.kafka.common.config.ConfigResource.Type;
import org.apache.kafka.common.metadata.ConfigRecord;
import org.apache.kafka.common.metadata.RemoveTopicRecord;
+import org.apache.kafka.metadata.KafkaConfigSchema;
import org.apache.kafka.server.common.MetadataVersion;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Set;
+import java.util.function.Supplier;
/**
* Represents changes to the configurations in the metadata image.
*/
public final class ConfigurationsDelta {
+ /**
+ * Supplier for KafkaConfigSchema to get valid config names whitelist by
resource type.
+ */
+ private static volatile Supplier<KafkaConfigSchema> configSchemaSupplier =
null;
+
+ /**
+ * Set the supplier for KafkaConfigSchema. This should be called during
initialization.
+ */
+ public static void setConfigSchemaSupplier(Supplier<KafkaConfigSchema>
supplier) {
+ configSchemaSupplier = supplier;
+ }
+
+ /**
+ * Get the set of valid configuration names for a given resource type.
+ * Returns empty set if configSchema is not initialized.
+ */
+ static Set<String> getValidConfigNames(Type resourceType) {
Review Comment:
can we have this method handle `UNKNOWN` type to simplify logic elsewhere?
--
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]