saurabhd336 commented on code in PR #11077:
URL: https://github.com/apache/pinot/pull/11077#discussion_r1263552337


##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/PinotHelixResourceManager.java:
##########
@@ -4128,6 +4138,33 @@ public PeriodicTaskInvocationResponse 
invokeControllerPeriodicTask(String tableN
     return new PeriodicTaskInvocationResponse(periodicTaskRequestId, 
messageCount > 0);
   }
 
+  /**
+   * Construct a map of all the tags and their respective minimum instance 
requirements.
+   * The minimum instance requirement is computed by
+   * - for BROKER tenant tag set it to 1.
+   * - for SERVER tenant tag iterate over all the tables of that tenant and 
find the maximum table replication.
+   * - for rest of the tags just set it to 0
+   * @return map of tags and their minimum instance requirements
+   */
+  public Map<String, Integer> minimumInstancesRequiredForTags() {
+    Map<String, Integer> tagMinServerMap = new HashMap<>();
+    for (InstanceConfig instanceConfig : getAllHelixInstanceConfigs()) {
+      for (String tag : instanceConfig.getTags()) {
+        tagMinServerMap.put(tag, TagNameUtils.isBrokerTag(tag) ? 1 : 0);
+      }
+    }
+    for (TableConfig tableConfig : getAllTableConfigs()) {
+      String serverTag = 
TagNameUtils.getServerTagForTenant(tableConfig.getTenantConfig().getServer(),
+          tableConfig.getTableType());
+      int maxReplication = 
Math.max(Objects.requireNonNullElse(tagMinServerMap.get(serverTag), 0),
+          tableConfig.getReplication());
+      tagMinServerMap.put(serverTag, maxReplication);

Review Comment:
   Can be replaced with
   ``tagMinServerMap.put(serverTag, 
Math.max(tagMinServerMap.getOrDefault(serverTag, 0), 
tableConfig.getReplication()) )```



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