junrao commented on a change in pull request #10070:
URL: https://github.com/apache/kafka/pull/10070#discussion_r578851481



##########
File path: 
metadata/src/main/java/org/apache/kafka/controller/FeatureControlManager.java
##########
@@ -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 org.apache.kafka.controller;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map.Entry;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import org.apache.kafka.common.metadata.FeatureLevelRecord;
+import org.apache.kafka.common.protocol.Errors;
+import org.apache.kafka.common.requests.ApiError;
+import org.apache.kafka.metadata.ApiMessageAndVersion;
+import org.apache.kafka.metadata.FeatureMap;
+import org.apache.kafka.metadata.FeatureMapAndEpoch;
+import org.apache.kafka.metadata.VersionRange;
+import org.apache.kafka.timeline.SnapshotRegistry;
+import org.apache.kafka.timeline.TimelineHashMap;
+import org.apache.kafka.timeline.TimelineHashSet;
+
+
+public class FeatureControlManager {
+    /**
+     * The features supported by this controller's software.
+     */
+    private final Map<String, VersionRange> supportedFeatures;
+
+    /**
+     * Maps feature names to finalized version ranges.
+     */
+    private final TimelineHashMap<String, VersionRange> finalizedVersions;
+
+    /**
+     * The latest feature epoch.
+     */
+    private final TimelineHashSet<Long> epoch;
+
+    FeatureControlManager(Map<String, VersionRange> supportedFeatures,
+                          SnapshotRegistry snapshotRegistry) {
+        this.supportedFeatures = supportedFeatures;
+        this.finalizedVersions = new TimelineHashMap<>(snapshotRegistry, 0);
+        this.epoch = new TimelineHashSet<>(snapshotRegistry, 0);
+    }
+
+    ControllerResult<Map<String, ApiError>> updateFeatures(
+            Map<String, VersionRange> updates, Set<String> downgradeables,
+            Map<Integer, Map<String, VersionRange>> brokerFeatures) {
+        TreeMap<String, ApiError> results = new TreeMap<>();
+        List<ApiMessageAndVersion> records = new ArrayList<>();
+        for (Entry<String, VersionRange> entry : updates.entrySet()) {
+            results.put(entry.getKey(), updateFeature(entry.getKey(), 
entry.getValue(),
+                downgradeables.contains(entry.getKey()), brokerFeatures, 
records));
+        }
+        return new ControllerResult<>(records, results);
+    }
+
+    private ApiError updateFeature(String featureName,
+                                   VersionRange newRange,
+                                   boolean downgradeable,
+                                   Map<Integer, Map<String, VersionRange>> 
brokerFeatures,
+                                   List<ApiMessageAndVersion> records) {
+        if (newRange.min() <= 0) {
+            return new ApiError(Errors.INVALID_UPDATE_VERSION,
+                "The lower value for the new range cannot be less than 1.");
+        }
+        if (newRange.max() <= 0) {
+            return new ApiError(Errors.INVALID_UPDATE_VERSION,
+                "The upper value for the new range cannot be less than 1.");
+        }
+        VersionRange localRange = supportedFeatures.get(featureName);

Review comment:
       Yes, that's the problem. From a consistency perspective, it seems that 
we should use the supported features from either all controller nodes or none.




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


Reply via email to