himanshukandwal commented on code in PR #2649:
URL: https://github.com/apache/helix/pull/2649#discussion_r1364900496
##########
helix-core/src/main/java/org/apache/helix/controller/stages/CurrentStateComputationStage.java:
##########
@@ -339,4 +333,61 @@ private void
reportResourcePartitionCapacityMetrics(ExecutorService executorServ
return null;
});
}
+
+ void handleResourceCapacityCalculation(ClusterEvent event,
ResourceControllerDataProvider cache,
+ CurrentStateOutput currentStateOutput) {
+ Map<String, Resource> resourceMap =
event.getAttribute(AttributeName.RESOURCES.name());
+ if (skipCapacityCalculation(cache, resourceMap, event)) {
+ return;
+ }
+
+ Map<String, Resource> wagedEnabledResourceMap = resourceMap.entrySet()
+ .stream()
+ .filter(entry ->
WagedValidationUtil.isWagedEnabled(cache.getIdealState(entry.getKey())))
+ .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
+
+ if (wagedEnabledResourceMap.isEmpty()) {
+ return;
+ }
+
+ // Phase 1: Rebuild Always
+ WagedInstanceCapacity capacityProvider = new WagedInstanceCapacity(cache);
+ WagedResourceWeightsProvider weightProvider = new
WagedResourceWeightsProvider(cache);
+
+ capacityProvider.process(cache, currentStateOutput,
wagedEnabledResourceMap, weightProvider);
+ cache.setWagedCapacityProviders(capacityProvider, weightProvider);
+ }
+
+ /**
+ * Function that checks whether we should return early, without any action
on the capacity map or not.
+ *
+ * @param cache it is the cluster level cache for the resources.
+ * @param event the cluster event that is undergoing processing.
+ * @return true, of the condition evaluate to true and no action is needed,
else false.
+ */
+ static boolean skipCapacityCalculation(ResourceControllerDataProvider cache,
Map<String, Resource> resourceMap,
+ ClusterEvent event) {
+ if (resourceMap == null || resourceMap.isEmpty()) {
+ return true;
+ }
+
+ if (Objects.isNull(cache.getWagedInstanceCapacity())) {
+ return false;
+ }
+
+ switch (event.getEventType()) {
+ case ClusterConfigChange:
+ case InstanceConfigChange:
+ case ResourceConfigChange:
+ case ControllerChange:
+ case LiveInstanceChange:
+ case CurrentStateChange:
+ case PeriodicalRebalance:
+ case MessageChange:
+ return false;
+ default:
+ return true;
+ }
+ }
Review Comment:
Thanks Junkai. Discussed offline, I have added a TODO to revisit and handle
this logic by event-type and depending on the resource type.
--
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]