himanshug commented on a change in pull request #9350: Overlord to support
autoscalers per indexer/middlemanager category
URL: https://github.com/apache/druid/pull/9350#discussion_r391175967
##########
File path:
indexing-service/src/main/java/org/apache/druid/indexing/overlord/autoscaling/PendingTaskBasedWorkerProvisioningStrategy.java
##########
@@ -333,67 +377,136 @@ public synchronized boolean doTerminate()
{
Collection<ImmutableWorkerInfo> zkWorkers = runner.getWorkers();
log.debug("Workers: %d [%s]", zkWorkers.size(), zkWorkers);
- final DefaultWorkerBehaviorConfig workerConfig =
getDefaultWorkerBehaviorConfig(workerConfigRef, "terminate", log);
+ final DefaultWorkerBehaviorConfig workerConfig =
ProvisioningUtil.getDefaultWorkerBehaviorConfig(
+ workerConfigRef,
+ "terminate"
+ );
if (workerConfig == null) {
+ log.info("No worker config found. Skip terminating.");
return false;
}
- log.info("Currently provisioning: %d %s", currentlyProvisioning.size(),
currentlyProvisioning);
- if (!currentlyProvisioning.isEmpty()) {
- log.debug("Already provisioning nodes, Not Terminating any nodes.");
- return false;
+ boolean didTerminate = false;
+
+ Map<String, List<ImmutableWorkerInfo>> workersByCategories =
ProvisioningUtil.getWorkersByCategories(zkWorkers);
+
+ Set<String> allCategories = workersByCategories.keySet();
+ log.debug(
+ "Workers of %d categories: %s",
+ workersByCategories.size(),
+ allCategories
+ );
+
+ Map<String, AutoScaler> autoscalersByCategory =
ProvisioningUtil.mapAutoscalerByCategory(workerConfig.getAutoScalers());
+
+ for (String category : allCategories) {
+ Set<String> currentlyProvisioning =
this.currentlyProvisioningMap.getOrDefault(
+ category,
+ Collections.emptySet()
+ );
+ log.info(
+ "Currently provisioning of category %s: %d %s",
+ category,
+ currentlyProvisioning.size(),
+ currentlyProvisioning
+ );
+ if (!currentlyProvisioning.isEmpty()) {
+ log.debug("Already provisioning nodes of category %s, Not
Terminating any nodes.", category);
+ return false;
+ }
+
+ AutoScaler categoryAutoscaler =
ProvisioningUtil.getAutoscalerByCategory(category, autoscalersByCategory);
+ if (categoryAutoscaler == null) {
+ log.error("No autoScaler available, cannot execute doTerminate for
workers of category %s", category);
+ continue;
+ }
+ // Correct category name by selected autoscaler
+ category = ProvisioningUtil.getAutoscalerCategory(categoryAutoscaler);
+
+ List<ImmutableWorkerInfo> categoryWorkers =
workersByCategories.getOrDefault(category, Collections.emptyList());
+ currentlyTerminatingMap.putIfAbsent(category, new HashSet<>());
+ Set<String> currentlyTerminating =
this.currentlyTerminatingMap.get(category);
Review comment:
nit: following replacement avoids instantiation of a new HashSet object on
each call to this method.
```suggestion
Set<String> currentlyTerminating =
currentlyTerminatingMap.computeIfAbsent(
category,
ignored -> new HashSet<>()
);
```
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]