yangzhg commented on a change in pull request #8553:
URL: https://github.com/apache/incubator-doris/pull/8553#discussion_r831857583



##########
File path: 
fe/fe-core/src/main/java/org/apache/doris/clone/BackendLoadStatistic.java
##########
@@ -315,6 +315,60 @@ public BalanceStatus isFit(long tabletSize, TStorageMedium 
medium,
         return status;
     }
 
+     /*
+     * Check whether the backend can be more balance if we migrate a tablet 
with size 'tabletSize' from
+     * `srcPath` to 'destPath'
+     * 1. recalculate the load score of src and dest path after migrate the 
tablet.
+     * 2. if the summary of the diff between the new score and average score 
becomes smaller, we consider it
+     *    as more balance.
+     */
+    public boolean isMoreBalanced(long srcPath, long destPath, long tabletId, 
long tabletSize,
+                                  TStorageMedium medium) {
+        long totalCapacity = 0;
+        long totalUsedCapacity = 0;
+        RootPathLoadStatistic srcPathStat = null;
+        RootPathLoadStatistic destPathStat = null;
+        for (RootPathLoadStatistic pathStat : pathStatistics) {
+            if (pathStat.getStorageMedium() == medium) {
+                totalCapacity += pathStat.getCapacityB();
+                totalUsedCapacity += pathStat.getUsedCapacityB();
+                if (pathStat.getPathHash() == srcPath) {
+                    srcPathStat = pathStat;
+                } else if (pathStat.getPathHash() == destPath) {
+                    destPathStat = pathStat;
+                }
+            }
+        }
+        if (srcPathStat == null || destPathStat == null) {
+            LOG.info("migrate {}(size: {}) from {} to {} failed, medium: {}, 
src or dest path stat does not exist.",
+                    tabletId, tabletSize, srcPath, destPath, medium);
+            return false;
+        }
+        double avgUsedPercent = totalCapacity == 0 ? 0.0 : totalUsedCapacity / 
(double) totalCapacity;
+        double currentSrcPathScore = srcPathStat.getCapacityB() == 0
+            ? 0.0 : srcPathStat.getUsedCapacityB() / (double) 
srcPathStat.getCapacityB();
+        double currentDestPathScore = destPathStat.getCapacityB() == 0
+            ? 0.0 : destPathStat.getUsedCapacityB() / (double) 
destPathStat.getCapacityB();
+
+        double newSrcPathScore = srcPathStat.getCapacityB() == 0
+            ? 0.0 : (srcPathStat.getUsedCapacityB() - tabletSize) / (double) 
srcPathStat.getCapacityB();
+        double newDestPathScore = destPathStat.getCapacityB() == 0
+            ? 0.0 : (destPathStat.getUsedCapacityB() + tabletSize) / (double) 
destPathStat.getCapacityB();
+
+        double currentDiff = Math.abs(currentSrcPathScore - avgUsedPercent)
+            + Math.abs(currentDestPathScore - avgUsedPercent);
+        double newDiff = Math.abs(newSrcPathScore - avgUsedPercent) + 
Math.abs(newDestPathScore - avgUsedPercent);
+
+        LOG.info("after migrate {}(size: {}) from {} to {}, medium: {}, the 
load score changed."

Review comment:
       should this be debug level?




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