jiajunwang commented on a change in pull request #525: Add waged rebalancer
monitoring mbean metrics
URL: https://github.com/apache/helix/pull/525#discussion_r338739587
##########
File path:
helix-core/src/main/java/org/apache/helix/controller/rebalancer/util/ResourceUsageCalculator.java
##########
@@ -33,4 +41,58 @@
}
return newParticipantUsage;
}
+
+ /**
+ * Count total number of all partitions in the collection of resource
assignments.
+ * @param assignments collection of resource assignments
+ * @return total number of all partitions in the collection of resource
assignments.
+ */
+ public static int
countResourceAssignmentPartitions(Collection<ResourceAssignment> assignments) {
+ return assignments.stream()
+ .mapToInt(resourceAssignment ->
resourceAssignment.getMappedPartitions().size())
+ .sum();
+ }
+
+ /**
+ * Measure baseline divergence between baseline assignment and best possible
assignment at
+ * partition level. Baseline divergence = (total number of common partitions
for each key)
+ * / (total number of different partitions for each key)
+ * @param baseline baseline assignment
+ * @param bestPossibleAssignment best possible assignment
+ * @return double value range at [0.0, 1.0]
+ */
+ public static double measureBaselineDivergence(Map<String,
ResourceAssignment> baseline,
+ Map<String, ResourceAssignment> bestPossibleAssignment) {
+ MapDifference<String, ResourceAssignment> mapDifference =
+ Maps.difference(baseline, bestPossibleAssignment);
+ Map<String, ResourceAssignment> matchedAssignment =
mapDifference.entriesInCommon();
+ Map<String, MapDifference.ValueDifference<ResourceAssignment>>
differentAssignment =
+ mapDifference.entriesDiffering();
+
+ // For each matched assignment, count all partitions and sum up.
+ int numMatchedPartitions =
countResourceAssignmentPartitions(matchedAssignment.values());
Review comment:
As we discussed, please verify the replica level divergence.
----------------------------------------------------------------
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]