You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "m1a2st (via GitHub)" <gi...@apache.org> on 2024/09/18 14:21:04 UTC
[PR] KAFKA-17564: Move BrokerFeatures to server module [kafka]
m1a2st opened a new pull request, #17228:
URL: https://github.com/apache/kafka/pull/17228
Jira: https://issues.apache.org/jira/browse/KAFKA-17564
### Committer Checklist (excluded from commit message)
- [ ] Verify design and implementation
- [ ] Verify test coverage and CI build status
- [ ] Verify documentation (including upgrade notes)
--
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
Re: [PR] KAFKA-17564: Move BrokerFeatures to server module [kafka]
Posted by "m1a2st (via GitHub)" <gi...@apache.org>.
m1a2st commented on PR #17228:
URL: https://github.com/apache/kafka/pull/17228#issuecomment-2358810269
@frankvicky thanks for your comments, addressed them.
--
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
Re: [PR] KAFKA-17564: Move BrokerFeatures to server module [kafka]
Posted by "frankvicky (via GitHub)" <gi...@apache.org>.
frankvicky commented on code in PR #17228:
URL: https://github.com/apache/kafka/pull/17228#discussion_r1765205630
##########
server/src/main/java/org/apache/kafka/server/BrokerFeatures.java:
##########
@@ -0,0 +1,194 @@
+/*
+ * 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;
+
+import org.apache.kafka.common.feature.Features;
+import org.apache.kafka.common.feature.SupportedVersionRange;
+import org.apache.kafka.metadata.VersionRange;
+import org.apache.kafka.server.common.MetadataVersion;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import static java.lang.String.format;
+
+/**
+ * A class that encapsulates the latest features supported by the Broker and also provides APIs to
+ * check for incompatibilities between the features supported by the Broker and finalized features.
+ * This class is immutable in production. It provides few APIs to mutate state only for the purpose
+ * of testing.
+ */
+public class BrokerFeatures {
+
+ private volatile Features<SupportedVersionRange> supportedFeatures;
+ private static final Logger log = LoggerFactory.getLogger(BrokerFeatures.class);
+
+ private BrokerFeatures(Features<SupportedVersionRange> supportedFeatures) {
+ this.supportedFeatures = supportedFeatures;
+ }
+
+ public static BrokerFeatures createDefault(boolean unstableFeatureVersionsEnabled) {
+ return new BrokerFeatures(defaultSupportedFeatures(unstableFeatureVersionsEnabled));
+ }
+
+ public static Map<String, VersionRange> createDefaultFeatureMap(BrokerFeatures features) {
+ Map<String, SupportedVersionRange> supportedFeatures = features.supportedFeatures.features();
+ Map<String, VersionRange> result = new HashMap<>();
+ for (Map.Entry<String, SupportedVersionRange> entry : supportedFeatures.entrySet()) {
+ result.put(entry.getKey(), VersionRange.of(entry.getValue().min(), entry.getValue().max()));
+ }
+ return result;
+ }
+
+ public static Features<SupportedVersionRange> defaultSupportedFeatures(boolean unstableFeatureVersionsEnabled) {
+ Map<String, SupportedVersionRange> features = new HashMap<>();
+ features.put(MetadataVersion.FEATURE_NAME,
+ new SupportedVersionRange(
+ MetadataVersion.MINIMUM_KRAFT_VERSION.featureLevel(),
+ unstableFeatureVersionsEnabled ? MetadataVersion.latestTesting().featureLevel()
+ : MetadataVersion.latestProduction().featureLevel()));
+ org.apache.kafka.server.common.Features.PRODUCTION_FEATURES.forEach(feature -> {
Review Comment:
I think we could use static import here to avoid full qualified name.
##########
core/src/main/scala/kafka/controller/KafkaController.scala:
##########
@@ -432,7 +434,7 @@ class KafkaController(val config: KafkaConfig,
val newVersion = createFeatureZNode(
FeatureZNode(config.interBrokerProtocolVersion,
FeatureZNodeStatus.Enabled,
- brokerFeatures.defaultFinalizedFeatures
+ brokerFeatures.defaultFinalizedFeatures.map { case (k, v) => (k, v.shortValue()) }
Review Comment:
`brokerFeatures.defaultFinalizedFeatures.asScala.map { case (k, v) => (k, v.shortValue()) }`
In this way we could avoid using deprecated library and remove this import:
`import scala.collection.convert.ImplicitConversions.map AsScala`
##########
server/src/main/java/org/apache/kafka/server/BrokerFeatures.java:
##########
@@ -0,0 +1,194 @@
+/*
+ * 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;
+
+import org.apache.kafka.common.feature.Features;
+import org.apache.kafka.common.feature.SupportedVersionRange;
+import org.apache.kafka.metadata.VersionRange;
+import org.apache.kafka.server.common.MetadataVersion;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import static java.lang.String.format;
+
+/**
+ * A class that encapsulates the latest features supported by the Broker and also provides APIs to
+ * check for incompatibilities between the features supported by the Broker and finalized features.
+ * This class is immutable in production. It provides few APIs to mutate state only for the purpose
+ * of testing.
+ */
+public class BrokerFeatures {
+
+ private volatile Features<SupportedVersionRange> supportedFeatures;
+ private static final Logger log = LoggerFactory.getLogger(BrokerFeatures.class);
+
+ private BrokerFeatures(Features<SupportedVersionRange> supportedFeatures) {
+ this.supportedFeatures = supportedFeatures;
+ }
+
+ public static BrokerFeatures createDefault(boolean unstableFeatureVersionsEnabled) {
+ return new BrokerFeatures(defaultSupportedFeatures(unstableFeatureVersionsEnabled));
+ }
+
+ public static Map<String, VersionRange> createDefaultFeatureMap(BrokerFeatures features) {
+ Map<String, SupportedVersionRange> supportedFeatures = features.supportedFeatures.features();
+ Map<String, VersionRange> result = new HashMap<>();
+ for (Map.Entry<String, SupportedVersionRange> entry : supportedFeatures.entrySet()) {
+ result.put(entry.getKey(), VersionRange.of(entry.getValue().min(), entry.getValue().max()));
+ }
Review Comment:
`supportedFeatures.forEach((key, value) -> result.put(key, VersionRange.of(value.min(), value.max())))`
--
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