RocMarshal commented on code in PR #25504: URL: https://github.com/apache/flink/pull/25504#discussion_r1833835398
########## flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/adaptive/allocator/TaskBalancedSlotSharingStrategy.java: ########## @@ -0,0 +1,77 @@ +/* + * 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.flink.runtime.scheduler.adaptive.allocator; + +import org.apache.flink.runtime.jobgraph.JobVertexID; +import org.apache.flink.runtime.jobmanager.scheduler.SlotSharingGroup; +import org.apache.flink.runtime.scheduler.TaskBalancedExecutionSlotSharingGroupBuilder; +import org.apache.flink.runtime.scheduler.adaptive.allocator.SlotSharingSlotAllocator.ExecutionSlotSharingGroup; +import org.apache.flink.runtime.scheduler.strategy.ExecutionVertexID; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * The implementation of the {@link SlotSharingStrategy} based on tasks balanced strategy. TODO: The + * implementation will be used in the followed jira issues done. + * https://issues.apache.org/jira/browse/FLINK-35966 + * https://issues.apache.org/jira/browse/FLINK-33391. + */ +enum TaskBalancedSlotSharingStrategy implements SlotSharingStrategy { + INSTANCE; + + @Override + public List<ExecutionSlotSharingGroup> getExecutionSlotSharingGroups( + JobInformation jobInformation, VertexParallelism vertexParallelism) { + return new TaskBalancedExecutionSlotSharingGroupBuilder( + getAllVertices(jobInformation, vertexParallelism), + jobInformation.getSlotSharingGroups(), + jobInformation.getCoLocationGroups()) + .build().values().stream() + .map( + fromGroup -> + new ExecutionSlotSharingGroup( + fromGroup.getExecutionVertexIds())) + .collect(Collectors.toList()); + } + + static Map<JobVertexID, List<ExecutionVertexID>> getAllVertices( + JobInformation jobInformation, VertexParallelism vertexParallelism) { + final Map<JobVertexID, List<ExecutionVertexID>> jobVertexToExecutionVertices = + new HashMap<>(); Review Comment: Based on strategy defined in the https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=263429715#FLIP370:SupportBalancedTasksScheduling-2.1.1InaSlotSharingGroup In the current slot dimension balancing strategy, we focus on balancing the number of tasks and do not care about the relationship between task predecessor and successor. Therefore, in the subsequent processing, we do not need any information related to the order of tasks temporarily. In other words, I don't disagree with using TreeMap, we can do it anytime as needed. If the understanding is incorrect, please correct me. Pls let me know what's your opinon~ Thank you! -- 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: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org