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

yiguolei 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 86c2b93e5bd [improvement](fixreplica) move to healthy replica when fix 
replica bad (#27934)
86c2b93e5bd is described below

commit 86c2b93e5bd72fdabbaa8b95e72c60fe58776732
Author: yiguolei <[email protected]>
AuthorDate: Mon Dec 4 16:04:27 2023 +0800

    [improvement](fixreplica) move to healthy replica when fix replica bad 
(#27934)
    
    
    ---------
    
    Co-authored-by: yiguolei <[email protected]>
---
 .../java/org/apache/doris/planner/OlapScanNode.java     | 17 +++++++++++++++--
 .../main/java/org/apache/doris/qe/SessionVariable.java  |  9 +++++++++
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/planner/OlapScanNode.java 
b/fe/fe-core/src/main/java/org/apache/doris/planner/OlapScanNode.java
index 530a9a78305..84b54f7e4de 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/planner/OlapScanNode.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/planner/OlapScanNode.java
@@ -774,8 +774,21 @@ public class OlapScanNode extends ScanNode {
                 // sort by replica id
                 replicas.sort(Replica.ID_COMPARATOR);
                 Replica replica = replicas.get(useFixReplica >= 
replicas.size() ? replicas.size() - 1 : useFixReplica);
-                replicas.clear();
-                replicas.add(replica);
+                if 
(ConnectContext.get().getSessionVariable().fallbackOtherReplicaWhenFixedCorrupt)
 {
+                    Backend backend = 
Env.getCurrentSystemInfo().getBackend(replica.getBackendId());
+                    // If the fixed replica is bad, then not clear the 
replicas using random replica
+                    if (backend == null || !backend.isAlive()) {
+                        LOG.debug("backend {} not exists or is not alive for 
replica {}", replica.getBackendId(),
+                                replica.getId());
+                        Collections.shuffle(replicas);
+                    } else {
+                        replicas.clear();
+                        replicas.add(replica);
+                    }
+                } else {
+                    replicas.clear();
+                    replicas.add(replica);
+                }
             }
 
             final long coolDownReplicaId = tablet.getCooldownReplicaId();
diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java 
b/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java
index 7224b82d91d..a54a54c5ae3 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java
@@ -462,6 +462,10 @@ public class SessionVariable implements Serializable, 
Writable {
     public static final String 
MATERIALIZED_VIEW_REWRITE_ENABLE_CONTAIN_FOREIGN_TABLE
             = "materialized_view_rewrite_enable_contain_foreign_table";
 
+    // When set use fix replica = true, the fixed replica maybe bad, try to 
use the health one if
+    // this session variable is set to true.
+    public static final String FALLBACK_OTHER_REPLICA_WHEN_FIXED_CORRUPT = 
"fallback_other_replica_when_fixed_corrupt";
+
     public static final List<String> DEBUG_VARIABLES = ImmutableList.of(
             SKIP_DELETE_PREDICATE,
             SKIP_DELETE_BITMAP,
@@ -1442,6 +1446,11 @@ public class SessionVariable implements Serializable, 
Writable {
             "Set to true to enable Decimal256 type" })
     public boolean enableDecimal256 = false;
 
+    @VariableMgr.VarAttr(name = FALLBACK_OTHER_REPLICA_WHEN_FIXED_CORRUPT, 
needForward = true,
+            description = { "当开启use_fix_replica时遇到故障,是否漂移到其他健康的副本",
+                "use other health replica when the use_fix_replica meet error" 
})
+    public boolean fallbackOtherReplicaWhenFixedCorrupt = false;
+
     // If this fe is in fuzzy mode, then will use initFuzzyModeVariables to 
generate some variables,
     // not the default value set in the code.
     public void initFuzzyModeVariables() {


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

Reply via email to