[improvement](fixreplica) move to healthy replica when fix replica bad (#27934)

---------

Co-authored-by: yiguolei <yiguolei@gmail.com>
This commit is contained in:
yiguolei
2023-12-04 16:04:27 +08:00
committed by GitHub
parent 4d1aa131ee
commit 86c2b93e5b
2 changed files with 24 additions and 2 deletions

View File

@ -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();

View File

@ -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() {