-
Notifications
You must be signed in to change notification settings - Fork 3.4k
HBASE-26311 Balancer gets stuck in cohosted replica distribution #3724
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5038e40
4c39345
0156ce4
cdb44cc
f3c04a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,17 +66,21 @@ void applyCostsChange(Consumer<double[]> consumer) { | |
| } | ||
|
|
||
| private static double computeCost(double[] stats) { | ||
| if (stats == null || stats.length == 0) { | ||
| return 0; | ||
| } | ||
| double totalCost = 0; | ||
| double total = getSum(stats); | ||
|
|
||
| double count = stats.length; | ||
| double mean = total / count; | ||
|
|
||
| for (int i = 0; i < stats.length; i++) { | ||
| double n = stats[i]; | ||
| double diff = Math.abs(mean - n); | ||
| double diff = (mean - n) * (mean - n); | ||
huaxiangsun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| totalCost += diff; | ||
| } | ||
| // No need to compute standard deviation with division by cluster size when scaling. | ||
| totalCost = Math.sqrt(totalCost); | ||
|
Comment on lines
+79
to
+83
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using the standard deviation instead of linear deviation to assign higher penalty on outliers and therefore unstuck balancer when even region count distribution cannot be achieved with other constraint such as rack/host constraints
huaxiangsun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return CostFunction.scale(getMinSkew(total, count), | ||
| getMaxSkew(total, count), totalCost); | ||
| } | ||
|
|
@@ -94,18 +98,22 @@ private static double getSum(double[] stats) { | |
| * @param total is total number of regions | ||
| */ | ||
| public static double getMinSkew(double total, double numServers) { | ||
| if (numServers == 0) { | ||
| return 0; | ||
| } | ||
| double mean = total / numServers; | ||
| // It's possible that there aren't enough regions to go around | ||
| double min; | ||
| if (numServers > total) { | ||
| min = ((numServers - total) * mean + (1 - mean) * total) ; | ||
| min = ((numServers - total) * mean * mean + (1 - mean) * (1 - mean) * total) ; | ||
huaxiangsun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } else { | ||
| // Some will have 1 more than everything else. | ||
| int numHigh = (int) (total - (Math.floor(mean) * numServers)); | ||
| int numLow = (int) (numServers - numHigh); | ||
| min = numHigh * (Math.ceil(mean) - mean) + numLow * (mean - Math.floor(mean)); | ||
| min = numHigh * (Math.ceil(mean) - mean) * (Math.ceil(mean) - mean) + | ||
huaxiangsun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| numLow * (mean - Math.floor(mean)) * (mean - Math.floor(mean)); | ||
| } | ||
| return min; | ||
| return Math.sqrt(min); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question as above. |
||
| } | ||
|
|
||
| /** | ||
|
|
@@ -114,7 +122,10 @@ public static double getMinSkew(double total, double numServers) { | |
| * a zero sum cost for this to make sense. | ||
| */ | ||
| public static double getMaxSkew(double total, double numServers) { | ||
| if (numServers == 0) { | ||
| return 0; | ||
| } | ||
| double mean = total / numServers; | ||
| return (total - mean) + (numServers - 1) * mean; | ||
| return Math.sqrt((total - mean) * (total - mean) + (numServers - 1) * mean * mean); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks to the refactoring of cached double cost array, I am doing some cleaning up and refactoring here for table skew cost function.