This is an automated email from the ASF dual-hosted git repository.

morrysnow pushed a commit to branch branch-3.1
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-3.1 by this push:
     new 579a9028edf branch-3.1: [fix](TabletSched)Prioritize non-drop replicas 
as src replicas #53006 (#53035)
579a9028edf is described below

commit 579a9028edf4cf6e37afcb138cacbe343468d386
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Thu Jul 10 23:39:45 2025 +0800

    branch-3.1: [fix](TabletSched)Prioritize non-drop replicas as src replicas 
#53006 (#53035)
    
    Cherry-picked from #53006
    
    Co-authored-by: deardeng <[email protected]>
---
 .../org/apache/doris/clone/TabletSchedCtx.java     | 28 +++++++++++++---------
 .../org/apache/doris/clone/TabletSchedCtxTest.java | 27 +++++++++++++++++----
 2 files changed, 40 insertions(+), 15 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/clone/TabletSchedCtx.java 
b/fe/fe-core/src/main/java/org/apache/doris/clone/TabletSchedCtx.java
index 61069590080..9e63a4fa1c4 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/clone/TabletSchedCtx.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/clone/TabletSchedCtx.java
@@ -86,7 +86,8 @@ public class TabletSchedCtx implements 
Comparable<TabletSchedCtx> {
 
     public static final int FINISHED_COUNTER_THRESHOLD = 4;
 
-    private static VersionCountComparator VERSION_COUNTER_COMPARATOR = new 
VersionCountComparator();
+    private static CloneSrcComparator CLONE_SRC_COMPARATOR
+            = new CloneSrcComparator();
 
     public enum Type {
         BALANCE, REPAIR
@@ -638,9 +639,12 @@ public class TabletSchedCtx implements 
Comparable<TabletSchedCtx> {
             throw new SchedException(Status.UNRECOVERABLE, "unable to find 
copy source replica");
         }
 
+        // make candidates more random
+        Collections.shuffle(candidates);
+
         // choose a replica which slot is available from candidates.
-        // sort replica by version count asc, so that we prefer to choose 
replicas with fewer versions
-        Collections.sort(candidates, VERSION_COUNTER_COMPARATOR);
+        // sort replica by version count asc and isUserDrop, so that we prefer 
to choose replicas with fewer versions
+        Collections.sort(candidates, CLONE_SRC_COMPARATOR);
         for (Replica srcReplica : candidates) {
             long replicaBeId = srcReplica.getBackendIdWithoutException();
             PathSlot slot = backendsWorkingSlots.get(replicaBeId);
@@ -1370,19 +1374,21 @@ public class TabletSchedCtx implements 
Comparable<TabletSchedCtx> {
         return sb.toString();
     }
 
-    // Comparator to sort the replica with version count, asc
-    public static class VersionCountComparator implements Comparator<Replica> {
+    // Comparator to sort the replica with version count and isUserDrop, if 
isUserDrop true, put it to end.
+    // In same isUserDrop, version count asc
+    // such as [(100, true), (50, false), (-1, false), (200, false), (-1, true)
+    // after sort [(50, false), (200, false), (-1, false), (100, ture), (-1, 
true)]
+    public static class CloneSrcComparator implements Comparator<Replica> {
         @Override
         public int compare(Replica r1, Replica r2) {
+            boolean isUserDrop1 = r1.isUserDrop();
+            boolean isUserDrop2 = r2.isUserDrop();
             long verCount1 = r1.getVisibleVersionCount() == -1 ? 
Long.MAX_VALUE : r1.getVisibleVersionCount();
             long verCount2 = r2.getVisibleVersionCount() == -1 ? 
Long.MAX_VALUE : r2.getVisibleVersionCount();
-            if (verCount1 < verCount2) {
-                return -1;
-            } else if (verCount1 > verCount2) {
-                return 1;
-            } else {
-                return 0;
+            if (isUserDrop1 == isUserDrop2) {
+                return Long.compare(verCount1, verCount2);
             }
+            return Boolean.compare(isUserDrop1, isUserDrop2);
         }
     }
 
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/clone/TabletSchedCtxTest.java 
b/fe/fe-core/src/test/java/org/apache/doris/clone/TabletSchedCtxTest.java
index bc9d7f25d8a..8b316c474a8 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/clone/TabletSchedCtxTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/clone/TabletSchedCtxTest.java
@@ -160,34 +160,53 @@ public class TabletSchedCtxTest extends TestWithFeService 
{
 
     @Test
     public void testVersionCountComparator() {
-        TabletSchedCtx.VersionCountComparator countComparator = new 
TabletSchedCtx.VersionCountComparator();
+        TabletSchedCtx.CloneSrcComparator countComparator
+                = new TabletSchedCtx.CloneSrcComparator();
         List<Replica> replicaList = Lists.newArrayList();
         Replica replica1 = new Replica();
         replica1.setVisibleVersionCount(100);
         replica1.setState(Replica.ReplicaState.NORMAL);
+        // user drop true
+        replica1.setUserDropTime(System.currentTimeMillis());
 
         Replica replica2 = new Replica();
         replica2.setVisibleVersionCount(50);
         replica2.setState(Replica.ReplicaState.NORMAL);
+        // user drop false
+        replica2.setUserDropTime(-1);
 
         Replica replica3 = new Replica();
         replica3.setVisibleVersionCount(-1);
         replica3.setState(Replica.ReplicaState.NORMAL);
+        // user drop false
+        replica3.setUserDropTime(-1);
 
         Replica replica4 = new Replica();
         replica4.setVisibleVersionCount(200);
         replica4.setState(Replica.ReplicaState.NORMAL);
+        // user drop false
+        replica4.setUserDropTime(-1);
+
+        Replica replica5 = new Replica();
+        replica5.setVisibleVersionCount(-1);
+        replica5.setState(Replica.ReplicaState.NORMAL);
+        // user drop true
+        replica5.setUserDropTime(System.currentTimeMillis());
 
         replicaList.add(replica1);
         replicaList.add(replica2);
         replicaList.add(replica3);
         replicaList.add(replica4);
+        replicaList.add(replica5);
 
         Collections.sort(replicaList, countComparator);
+        // user drop false
         Assert.assertEquals(50, replicaList.get(0).getVisibleVersionCount());
-        Assert.assertEquals(100, replicaList.get(1).getVisibleVersionCount());
-        Assert.assertEquals(200, replicaList.get(2).getVisibleVersionCount());
-        Assert.assertEquals(-1, replicaList.get(3).getVisibleVersionCount());
+        Assert.assertEquals(200, replicaList.get(1).getVisibleVersionCount());
+        Assert.assertEquals(-1, replicaList.get(2).getVisibleVersionCount());
+        // user drop true
+        Assert.assertEquals(100, replicaList.get(3).getVisibleVersionCount());
+        Assert.assertEquals(-1, replicaList.get(4).getVisibleVersionCount());
     }
 
     @Test


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to