You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@helix.apache.org by GitBox <gi...@apache.org> on 2021/09/16 17:57:31 UTC

[GitHub] [helix] alirezazamani commented on a change in pull request #1875: Fix adding a task to a job after deleting old tasks

alirezazamani commented on a change in pull request #1875:
URL: https://github.com/apache/helix/pull/1875#discussion_r710351245



##########
File path: helix-core/src/main/java/org/apache/helix/task/ThreadCountBasedTaskAssignmentCalculator.java
##########
@@ -65,10 +66,26 @@ public ThreadCountBasedTaskAssignmentCalculator(TaskAssigner taskAssigner,
       Map<String, IdealState> idealStateMap) {
     Map<String, TaskConfig> taskMap = jobCfg.getTaskConfigMap();
     Map<String, Integer> taskIdMap = jobCtx.getTaskIdPartitionMap();
+    // Check if a gap exists in the context due to previouslys
+    // removed tasks. If yes, the missing pIDs should be considered
+    // for newly added tasks
+    Set<Integer> existingPartitions = jobCtx.getPartitionSet();
+    Set<Integer> missingPartitions = new HashSet<>();
+    if (existingPartitions.size() != 0) {
+      for (int pId = 0; pId < Collections.max(existingPartitions); pId++) {
+        if (!existingPartitions.contains(pId)) {
+          missingPartitions.add(pId);
+        }
+      }
+    }
     for (TaskConfig taskCfg : taskMap.values()) {
       String taskId = taskCfg.getId();
-      int nextPartition = jobCtx.getPartitionSet().size();
       if (!taskIdMap.containsKey(taskId)) {
+        int nextPartition = jobCtx.getPartitionSet().size();
+        if (missingPartitions.size()!=0) {
+          nextPartition = missingPartitions.iterator().next();
+          missingPartitions.remove(nextPartition);
+        }
         jobCtx.setTaskIdForPartition(nextPartition, taskId);
       }
     }

Review comment:
       I thought about it actually. It was already duplicated. I think we keep a generic one for backward compatibility.




-- 
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: reviews-unsubscribe@helix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org