junrao commented on code in PR #23152: URL: https://github.com/apache/kafka/pull/23152#discussion_r3823898782
########## metadata/src/main/java/org/apache/kafka/controller/RaftClientVotersSupplier.java: ########## @@ -0,0 +1,49 @@ +/* + * 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 org.apache.kafka.raft.RaftClient; + +import java.util.Set; +import java.util.function.Supplier; + +/** + * Checks if the provided node id is a voter according to the raft client. Review Comment: Hmm, this comment seems misplaced. There is node id provided to the supplier. ########## metadata/src/main/java/org/apache/kafka/controller/QuorumFeatures.java: ########## @@ -73,27 +76,27 @@ public static Map<String, VersionRange> defaultSupportedFeatureMap(boolean enabl public QuorumFeatures( int nodeId, Map<String, VersionRange> localSupportedFeatures, - List<Integer> quorumNodeIds + Supplier<Set<Integer>> votersSupplier Review Comment: Does the mean Feature update is broken without this PR in dynamic quorum? In dynamic quorum, the passed in quorumNodeIds is empty and that list is used in the following code for feature verifciation. ``` FeatureControlManager.reasonNotSupported (:360-362) for (int id : quorumFeatures.quorumNodeIds()) { if (!foundControllers.contains(id)) return Optional.of("controller " + id + " has not registered, ..."); } ``` ########## metadata/src/main/java/org/apache/kafka/controller/QuorumController.java: ########## @@ -511,7 +511,7 @@ private boolean isNodeIdRegistered(int nodeId) { if (clusterControl.brokerRegistrations().containsKey(nodeId)) { return true; } - if (featureControl.isControllerId(nodeId)) { + if (featureControl.isVoterId(nodeId)) { Review Comment: This is an existing issue, isVoterId() is true doesn't mean the voter is registered. Should we rename this method to sth like isNodeIdKnown()? ########## clients/src/main/java/org/apache/kafka/clients/admin/Admin.java: ########## @@ -1711,7 +1711,8 @@ default UnregisterControllerResult unregisterController(int controllerId) { * <li>{@link org.apache.kafka.common.errors.NotControllerException} * If the request does not arrive at the active controller.</li> * <li>{@link org.apache.kafka.common.errors.InvalidRequestException} - * If the request tries to unregister the current active controller id.</li> + * If the request tries to unregister the current active controller id or a controller id + * which is part of the voter set.</li> Review Comment: The latter covers the former. So, we can just say "If controller id is part of the voter set." Ditto in Controller. ########## metadata/src/main/java/org/apache/kafka/controller/FeatureControlManager.java: ########## @@ -104,7 +105,7 @@ public FeatureControlManager build() { localSupportedFeatures.put(MetadataVersion.FEATURE_NAME, VersionRange.of( MetadataVersion.MINIMUM_VERSION.featureLevel(), MetadataVersion.latestProduction().featureLevel())); - quorumFeatures = new QuorumFeatures(0, localSupportedFeatures, List.of(0)); + quorumFeatures = new QuorumFeatures(0, localSupportedFeatures, () -> Set.of(0)); Review Comment: This is an existing issue. It's a bit weird to provide a supplier for testing in the production code. It will be useful to at least add a comment. ########## metadata/src/main/java/org/apache/kafka/controller/QuorumFeatures.java: ########## @@ -107,30 +110,25 @@ public Optional<String> reasonNotLocallySupported( @Override public int hashCode() { - return Objects.hash(nodeId, localSupportedFeatures, quorumNodeIds); + return Objects.hash(nodeId, localSupportedFeatures); } @Override public boolean equals(Object o) { if (o == null || !(o.getClass().equals(QuorumFeatures.class))) return false; QuorumFeatures other = (QuorumFeatures) o; return nodeId == other.nodeId && - localSupportedFeatures.equals(other.localSupportedFeatures) && - quorumNodeIds.equals(other.quorumNodeIds); + localSupportedFeatures.equals(other.localSupportedFeatures); Review Comment: Could we add a comment that votersSupplier is excluded deliberately? ########## metadata/src/main/java/org/apache/kafka/controller/QuorumController.java: ########## @@ -2166,6 +2166,9 @@ public CompletableFuture<Void> unregisterController( () -> { if (nodeId == controllerId) { throw new InvalidRequestException("Controller cannot unregister itself while it is active."); + } else if (featureControl.isVoterId(controllerId)) { Review Comment: The check before this line now seems redundant. -- 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]
