nozjkoitop commented on code in PR #16889:
URL: https://github.com/apache/druid/pull/16889#discussion_r1776874976


##########
indexing-service/src/main/java/org/apache/druid/indexing/overlord/ImmutableWorkerInfo.java:
##########
@@ -225,6 +270,79 @@ private int getWorkerParallelIndexCapacity(double 
parallelIndexTaskSlotRatio)
     return workerParallelIndexCapacity;
   }
 
+  private boolean hasSufficientWorkerCapacity(Task task)
+  {
+    int capacityRemaining = worker.getCapacity() - getCurrCapacityUsed();
+    int requiredCapacity = task.getTaskResource().getRequiredCapacity();
+    return capacityRemaining >= requiredCapacity;
+  }
+
+  private boolean isAvailabilityGroupAvailable(Task task)
+  {
+    return 
!getAvailabilityGroups().contains(task.getTaskResource().getAvailabilityGroup());
+  }
+
+  private boolean canRunTaskBasedOnCustomLimit(Task task, Map<String, Integer> 
limitsMap, Map<String, Double> ratiosMap)
+  {
+    final Integer limit = getLimitForTask(task.getType(), limitsMap, 
ratiosMap);
+
+    if (limit == null) {
+      return true; // No limit specified, so task can run
+    }
+
+    int currentCapacityUsed = 
getCurrCapacityUsedByTaskType().getOrDefault(task.getType(), 0);
+    int requiredCapacity = task.getTaskResource().getRequiredCapacity();
+
+    return hasCapacityBasedOnLimit(limit, currentCapacityUsed, 
requiredCapacity);
+  }
+
+  private Integer getLimitForTask(
+      String taskType,
+      Map<String, Integer> limitsMap,
+      Map<String, Double> ratiosMap
+  )
+  {
+    Integer absoluteLimit = limitsMap.get(taskType);
+    Double ratioLimit = ratiosMap.get(taskType);
+
+    if (absoluteLimit == null && ratioLimit == null) {
+      return null;
+    }
+
+    // Validate the absolute limit if present
+    if (absoluteLimit != null) {
+      Preconditions.checkArgument(absoluteLimit >= 0, "Absolute limit for task 
%s must be non-negative.", taskType);
+    }
+
+    // Validate the ratio limit if present
+    if (ratioLimit != null) {
+      Preconditions.checkArgument(ratioLimit >= 0.0 && ratioLimit <= 1.0,
+                                  "Ratio for task %s must be between 0.0 and 
1.0 inclusive.", taskType
+      );
+    }
+
+    final int totalCapacity = worker.getCapacity();
+
+    Integer ratioBasedLimit = ratioLimit != null ? 
calculateTaskCapacityFromRatio(ratioLimit, totalCapacity) : null;
+
+    if (absoluteLimit != null && ratioBasedLimit != null) {
+      return Math.min(absoluteLimit, ratioBasedLimit);
+    }
+
+    return absoluteLimit != null ? absoluteLimit : ratioBasedLimit;
+  }
+
+  private boolean hasCapacityBasedOnLimit(int limit, int currentCapacityUsed, 
int requiredCapacity)

Review Comment:
   Done, thanks for notice 



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to