cmccabe commented on code in PR #16230:
URL: https://github.com/apache/kafka/pull/16230#discussion_r1672720246


##########
server-common/src/main/java/org/apache/kafka/server/common/KRaftVersion.java:
##########
@@ -0,0 +1,81 @@
+/*
+ * 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.common;
+
+import java.util.Collections;
+import java.util.Map;
+
+public enum KRaftVersion implements FeatureVersion {
+
+    // Version 1 enables KIP-853.
+    KRAFT_VERSION_0(0, MetadataVersion.MINIMUM_KRAFT_VERSION),
+    KRAFT_VERSION_1(1, MetadataVersion.IBP_3_8_IV0);
+
+    public static final String FEATURE_NAME = "kraft.version";
+
+    private final short featureLevel;
+    private final MetadataVersion bootstrapMetadataVersion;
+
+    KRaftVersion(
+        int featureLevel,
+        MetadataVersion bootstrapMetadataVersion
+    ) {
+        this.featureLevel = (short) featureLevel;
+        this.bootstrapMetadataVersion = bootstrapMetadataVersion;
+    }
+
+    @Override
+    public short featureLevel() {
+        return featureLevel;
+    }
+
+    public static KRaftVersion fromFeatureLevel(short version) {
+        switch (version) {
+            case 0:
+                return KRAFT_VERSION_0;
+            case 1:
+                return KRAFT_VERSION_1;
+            default:
+                throw new RuntimeException("Unknown KRaft feature level: " + 
(int) version);
+        }
+    }
+
+    @Override
+    public String featureName() {
+        return FEATURE_NAME;
+    }
+
+    @Override
+    public MetadataVersion bootstrapMetadataVersion() {
+        return bootstrapMetadataVersion;
+    }
+
+    @Override
+    public Map<String, Short> dependencies() {
+        return Collections.emptyMap();
+    }
+
+    public short quorumStateVersion() {
+        switch (this) {
+            case KRAFT_VERSION_0:
+                return (short) 0;
+            case KRAFT_VERSION_1:
+                return (short) 1;
+        }
+        throw new RuntimeException("Unknown KRaft feature level: " + this);
+    }

Review Comment:
   I added `KRaftVersionTest` which includes this and other things.



-- 
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

Reply via email to