dajac commented on code in PR #15685:
URL: https://github.com/apache/kafka/pull/15685#discussion_r1618450649
##########
server-common/src/main/java/org/apache/kafka/server/common/Features.java:
##########
@@ -16,72 +16,135 @@
*/
package org.apache.kafka.server.common;
-import java.util.Collections;
-import java.util.HashMap;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
import java.util.Map;
-import java.util.Objects;
+import java.util.stream.Collectors;
-import static org.apache.kafka.server.common.MetadataVersion.FEATURE_NAME;
+/**
+ * This is enum for the various features implemented for Kafka clusters.
+ * KIP-584: Versioning Scheme for Features introduced the idea of various
features, but only added one feature -- MetadataVersion.
+ * KIP-1022: Formatting and Updating Features allowed for more features to be
added. In order to set and update features,
+ * they need to be specified via the StorageTool or FeatureCommand tools.
+ * <br>
+ * Having a unified enum for the features that will use a shared type in the
API used to set and update them
+ * makes it easier to process these features.
+ */
+public enum Features {
+
+ /**
+ * Features defined. If a feature is included in this list, and marked to
be used in production they will also be specified when
+ * formatting a cluster via the StorageTool. MetadataVersion is handled
separately, so it is not included here.
+ *
+ * See {@link TestFeatureVersion} as an example. See {@link
FeatureVersion} when implementing a new feature.
+ */
+ TEST_VERSION("test.feature.version", TestFeatureVersion.values());
+
+ public static final Features[] FEATURES;
+ public static final List<Features> PRODUCTION_FEATURES;
-public final class Features {
- private final MetadataVersion version;
- private final Map<String, Short> finalizedFeatures;
- private final long finalizedFeaturesEpoch;
+ public static final List<String> PRODUCTION_FEATURE_NAMES;
+ private final String name;
+ private final FeatureVersion[] featureVersions;
- public static Features fromKRaftVersion(MetadataVersion version) {
- return new Features(version, Collections.emptyMap(), -1, true);
+ Features(String name,
+ FeatureVersion[] featureVersions) {
+ this.name = name;
+ this.featureVersions = featureVersions;
}
- public Features(
- MetadataVersion version,
- Map<String, Short> finalizedFeatures,
- long finalizedFeaturesEpoch,
- boolean kraftMode
- ) {
- this.version = version;
- this.finalizedFeatures = new HashMap<>(finalizedFeatures);
- this.finalizedFeaturesEpoch = finalizedFeaturesEpoch;
- // In KRaft mode, we always include the metadata version in the
features map.
- // In ZK mode, we never include it.
- if (kraftMode) {
- this.finalizedFeatures.put(FEATURE_NAME, version.featureLevel());
- } else {
- this.finalizedFeatures.remove(FEATURE_NAME);
- }
+ static {
+ Features[] enumValues = Features.values();
+ FEATURES = Arrays.copyOf(enumValues, enumValues.length);
+
+ PRODUCTION_FEATURES = Arrays.stream(FEATURES).filter(feature ->
+ feature.name !=
TEST_VERSION.featureName()).collect(Collectors.toList());
Review Comment:
There is a small bug here. We should use equals, I think.
--
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]