You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by da...@apache.org on 2023/06/16 05:57:25 UTC

[doris] branch master updated: [fix](replica) do not delete the only one replica (#20872)

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

dataroaring pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 1a62c79970 [fix](replica) do not delete the only one replica (#20872)
1a62c79970 is described below

commit 1a62c7997053607bd794f75c4ca737fe84aa57d8
Author: Yongqiang YANG <98...@users.noreply.github.com>
AuthorDate: Fri Jun 16 13:57:18 2023 +0800

    [fix](replica) do not delete the only one replica (#20872)
---
 .../org/apache/doris/clone/TabletScheduler.java    | 26 +++++++++++++---------
 .../org/apache/doris/master/ReportHandler.java     | 10 ++++++---
 2 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/clone/TabletScheduler.java b/fe/fe-core/src/main/java/org/apache/doris/clone/TabletScheduler.java
index c9cf4b1948..dbf3d46237 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/clone/TabletScheduler.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/clone/TabletScheduler.java
@@ -968,16 +968,6 @@ public class TabletScheduler extends MasterDaemon {
         if (chosenReplica == null) {
             return false;
         }
-        List<Replica> replicas = tabletCtx.getTablet().getReplicas();
-        int eqOrNewVersionCount = 0;
-        for (Replica replica : replicas) {
-            if (replica.getVersion() >= chosenReplica.getVersion()) {
-                eqOrNewVersionCount++;
-            }
-        }
-        if (eqOrNewVersionCount == 1) {
-            return false;
-        }
         deleteReplicaInternal(tabletCtx, chosenReplica, "src replica of rebalance", force);
 
         return true;
@@ -1078,6 +1068,22 @@ public class TabletScheduler extends MasterDaemon {
 
     private void deleteReplicaInternal(TabletSchedCtx tabletCtx,
             Replica replica, String reason, boolean force) throws SchedException {
+
+        List<Replica> replicas = tabletCtx.getTablet().getReplicas();
+        int matchupReplicaCount = 0;
+        for (Replica tmpReplica : replicas) {
+            if (tmpReplica.getVersion() >= replica.getVersion()) {
+                matchupReplicaCount++;
+            }
+        }
+
+        if (matchupReplicaCount <= 1) {
+            LOG.info("can not delete only one replica, tabletId = {} replicaId = {}", tabletCtx.getTabletId(),
+                     replica.getId());
+            throw new SchedException(Status.FINISHED, "the only one latest replia can not be dropped, tabletId = "
+                                        + tabletCtx.getTabletId() + ", replicaId = " + replica.getId());
+        }
+
         /*
          * Before deleting a replica, we should make sure that
          * there is no running txn on it and no more txns will be on it.
diff --git a/fe/fe-core/src/main/java/org/apache/doris/master/ReportHandler.java b/fe/fe-core/src/main/java/org/apache/doris/master/ReportHandler.java
index 8267732f5d..726be73ffb 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/master/ReportHandler.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/master/ReportHandler.java
@@ -854,6 +854,7 @@ public class ReportHandler extends Daemon {
             TTabletInfo backendTabletInfo = backendTablet.getTabletInfos().get(0);
             boolean needDelete = false;
             TabletMeta tabletMeta = null;
+            LOG.debug("process tablet [{}], backend[{}]", tabletId, backendId);
             if (!tabletFoundInMeta.contains(tabletId)) {
                 if (isBackendReplicaHealthy(backendTabletInfo)) {
                     // if this tablet meta is still in invertedIndex. try to add it.
@@ -862,8 +863,9 @@ public class ReportHandler extends Daemon {
                     if (tabletMeta != null && addReplica(tabletId, tabletMeta, backendTabletInfo, backendId)) {
                         // update counter
                         ++addToMetaCounter;
+                        LOG.debug("add to meta. tablet[{}], backend[{}]", tabletId, backendId);
                     } else {
-                        LOG.debug("failed add to meta. tablet[{}], backend[{}]", tabletId, backendId);
+                        LOG.info("failed add to meta. tablet[{}], backend[{}]", tabletId, backendId);
                         needDelete = true;
                     }
                 } else {
@@ -878,7 +880,7 @@ public class ReportHandler extends Daemon {
                 DropReplicaTask task = new DropReplicaTask(backendId, tabletId, replicaId,
                         backendTabletInfo.getSchemaHash(), isDropTableOrPartition);
                 batchTask.addTask(task);
-                LOG.debug("delete tablet[{}] from backend[{}] because not found in meta", tabletId, backendId);
+                LOG.info("delete tablet[{}] from backend[{}] because not found in meta", tabletId, backendId);
                 ++deleteFromBackendCounter;
             }
         } // end for backendTabletIds
@@ -1139,7 +1141,9 @@ public class ReportHandler extends Daemon {
                 Set<Long> backendsSet = colocateTableIndex.getTabletBackendsByGroup(groupId, tabletOrderIdx);
                 TabletStatus status =
                         tablet.getColocateHealthStatus(visibleVersion, replicaAlloc, backendsSet);
-                return status != TabletStatus.HEALTHY;
+                if (status == TabletStatus.HEALTHY) {
+                    return false;
+                }
             }
 
             SystemInfoService infoService = Env.getCurrentSystemInfo();


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org