gabriellefu commented on code in PR #23092:
URL: https://github.com/apache/kafka/pull/23092#discussion_r3759662258


##########
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/streams/assignor/AssignmentConfigsImpl.java:
##########
@@ -0,0 +1,88 @@
+/*
+ * 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.coordinator.group.streams.assignor;
+
+import org.apache.kafka.coordinator.group.GroupCoordinatorConfig;
+import 
org.apache.kafka.coordinator.group.api.streams.assignor.AssignmentConfigs;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * The assignment configurations for a streams group.
+ *
+ * @param numStandbyReplicas      The number of standby replicas for each task.
+ * @param rackAwareAssignmentTags The client tags used to distribute standby 
tasks across racks.
+ */
+public record AssignmentConfigsImpl(
+    int numStandbyReplicas,
+    List<String> rackAwareAssignmentTags
+) implements AssignmentConfigs {
+
+    // The names under which the configurations are passed to the assignor and 
recorded for the group.
+    public static final String NUM_STANDBY_REPLICAS_CONFIG = 
"num.standby.replicas";
+    public static final String RACK_AWARE_ASSIGNMENT_TAGS_CONFIG = 
"rack.aware.assignment.tags";
+
+    /**
+     * The configs of a group that has none of them set, holding the default 
value of every configuration.
+     */
+    public static final AssignmentConfigsImpl DEFAULT = new 
AssignmentConfigsImpl(
+        GroupCoordinatorConfig.STREAMS_GROUP_NUM_STANDBY_REPLICAS_DEFAULT,
+        // The parsed form of 
STREAMS_GROUP_RACK_AWARE_ASSIGNMENT_TAGS_DEFAULT, which ConfigDef spells as "".
+        List.of()
+    );
+
+    public AssignmentConfigsImpl {
+        // The list is exposed to a custom assignor through the public 
AssignmentConfigs interface.
+        rackAwareAssignmentTags = 
List.copyOf(Objects.requireNonNull(rackAwareAssignmentTags));
+    }
+
+    /**
+     * Converts the raw assignment configs computed for the group into the 
typed configs passed to the assignor.
+     */
+    public static AssignmentConfigsImpl fromMap(Map<String, String> configs) {
+        // The map is empty when it was replayed from a group metadata record 
written before the last assignment
+        // configs were persisted.
+        if (configs.isEmpty()) {
+            return DEFAULT;
+        }
+        // The rack-aware assignment tags are only set when any are 
configured, and are joined from values that
+        // ConfigDef has already validated to be non-empty and free of 
surrounding whitespace.
+        String rackAwareAssignmentTags = 
configs.get(RACK_AWARE_ASSIGNMENT_TAGS_CONFIG);
+        return new AssignmentConfigsImpl(
+            Integer.parseInt(configs.get(NUM_STANDBY_REPLICAS_CONFIG)),

Review Comment:
   In the original code, for replicas, there are two path, one is the whole map 
is empty, then it's ok to not having replicas set and here we return DEFAULT, 
other than that, the replicas should always be in the config



##########
group-coordinator/src/test/java/org/apache/kafka/coordinator/group/streams/MockTaskAssignor.java:
##########
@@ -31,7 +32,7 @@ public class MockTaskAssignor implements TaskAssignor {
 
     private final String name;
     private GroupAssignment preparedGroupAssignment = null;
-    private Map<String, String> assignmentConfigs = Map.of();
+    private AssignmentConfigs assignmentConfigs = null;

Review Comment:
   oh my mistake, cause it will be equalavent to DEFAULT before as a empty map, 
I will update here
   



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

Reply via email to