From 86c2b93e5bd72fdabbaa8b95e72c60fe58776732 Mon Sep 17 00:00:00 2001 From: yiguolei <676222867@qq.com> Date: Mon, 4 Dec 2023 16:04:27 +0800 Subject: [PATCH] [improvement](fixreplica) move to healthy replica when fix replica bad (#27934) --------- Co-authored-by: yiguolei --- .../org/apache/doris/planner/OlapScanNode.java | 17 +++++++++++++++-- .../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 530a9a7830..84b54f7e4d 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 7224b82d91..a54a54c5ae 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 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() {