Source:
<code>public synchronized boolean doTerminate() { Collection<ImmutableWorkerInfo> zkWorkers = runner.getWorkers(); log.debug("Workers: %d [%s]", zkWorkers.size(), zkWorkers); final DefaultWorkerBehaviorConfig workerConfig = ProvisioningUtil.getDefaultWorkerBehaviorConfig( workerConfigRef, "terminate" ); if (workerConfig == null) { log.info("No worker config found. Skip terminating."); 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; } category = ProvisioningUtil.getAutoscalerCategory(categoryAutoscaler); List<ImmutableWorkerInfo> categoryWorkers = workersByCategories.getOrDefault(category, Collections.emptyList()); <START> currentlyTerminatingMap.putIfAbsent(category, new HashSet<>()); Set<String> currentlyTerminating = this.currentlyTerminatingMap.get(category); <END> didTerminate = doTerminate( category, categoryWorkers, currentlyTerminating, categoryAutoscaler ) || didTerminate; } return didTerminate; }</code><technical_language>nit: replacement avoids instantiation of a new HashSet object call this method. suggestion Set<String> currentlyTerminating = currentlyTerminatingMap.computeIfAbsent( category, -> new HashSet<>() );</technical_language>

Target:
public synchronized boolean doTerminate() { Collection<ImmutableWorkerInfo> zkWorkers = runner.getWorkers(); log.debug("Workers: %d [%s]", zkWorkers.size(), zkWorkers); final DefaultWorkerBehaviorConfig workerConfig = ProvisioningUtil.getDefaultWorkerBehaviorConfig( workerConfigRef, "terminate" ); if (workerConfig == null) { log.info("No worker config found. Skip terminating."); 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; } category = ProvisioningUtil.getAutoscalerCategory(categoryAutoscaler); List<ImmutableWorkerInfo> categoryWorkers = workersByCategories.getOrDefault(category, Collections.emptyList()); Set<String> currentlyTerminating = currentlyTerminatingMap.computeIfAbsent( category, ignored -> new HashSet<>() ); didTerminate = doTerminate( category, categoryWorkers, currentlyTerminating, categoryAutoscaler ) || didTerminate; } return didTerminate; }