Skip to content

Commit 9f83258

Browse files
committed
[FE](debug) Add selected BE logics
1 parent a368dfe commit 9f83258

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
import java.util.Arrays;
6464
import java.util.BitSet;
6565
import java.util.HashMap;
66+
import java.util.HashSet;
6667
import java.util.List;
6768
import java.util.Locale;
6869
import java.util.Map;
@@ -277,6 +278,8 @@ public class SessionVariable implements Serializable, Writable {
277278

278279
public static final String BLOCK_ENCRYPTION_MODE = "block_encryption_mode";
279280

281+
public static final String SELECTED_BACKEND_IDS = "selected_backend_ids";
282+
280283
public static final String AUTO_BROADCAST_JOIN_THRESHOLD = "auto_broadcast_join_threshold";
281284

282285
public static final String ENABLE_PROJECTION = "enable_projection";
@@ -1241,6 +1244,9 @@ public void setEnableLeftZigZag(boolean enableLeftZigZag) {
12411244
@VariableMgr.VarAttr(name = ENABLE_NEREIDS_RULES, needForward = true)
12421245
public String enableNereidsRules = "";
12431246

1247+
@VariableMgr.VarAttr(name = SELECTED_BACKEND_IDS, needForward = true)
1248+
public String selectedBackendIds = "";
1249+
12441250
@VariableMgr.VarAttr(name = ENABLE_NEW_COST_MODEL, needForward = true)
12451251
private boolean enableNewCostModel = false;
12461252

@@ -3182,6 +3188,18 @@ public boolean getEnableNewCostModel() {
31823188
return this.enableNewCostModel;
31833189
}
31843190

3191+
public Set<Long> getSelectedBackendIds() {
3192+
Set<Long> ids = new HashSet<>();
3193+
if (selectedBackendIds.isEmpty()) {
3194+
return ids;
3195+
}
3196+
String[] selectedBes = selectedBackendIds.split(",");
3197+
for (String be : selectedBes) {
3198+
ids.add(Long.valueOf(be));
3199+
}
3200+
return ids;
3201+
}
3202+
31853203
public void setDisableNereidsRules(String disableNereidsRules) {
31863204
this.disableNereidsRules = disableNereidsRules;
31873205
}

fe/fe-core/src/main/java/org/apache/doris/qe/SimpleScheduler.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.util.Iterator;
3838
import java.util.List;
3939
import java.util.Map;
40+
import java.util.Set;
4041
import java.util.concurrent.atomic.AtomicLong;
4142
import java.util.stream.Collectors;
4243

@@ -131,6 +132,21 @@ public static TNetworkAddress getHost(ImmutableMap<Long, Backend> backends,
131132
if (backends.isEmpty()) {
132133
throw new UserException(SystemInfoService.NO_SCAN_NODE_BACKEND_AVAILABLE_MSG);
133134
}
135+
if (ConnectContext.get() != null
136+
&& !ConnectContext.get().getSessionVariable().getSelectedBackendIds().isEmpty()) {
137+
Set<Long> beIds = ConnectContext.get().getSessionVariable().getSelectedBackendIds();
138+
long id = nextId.getAndIncrement() % beIds.size();
139+
Long selectedId = beIds.stream().skip(id).filter(e -> backends.containsKey(e)
140+
&& isAvailable(backends.get(e))).findFirst().orElse(null);
141+
Backend backend = backends.getOrDefault(selectedId, null);
142+
if (isAvailable(backend)) {
143+
backendIdRef.setRef(selectedId);
144+
return new TNetworkAddress(backend.getHost(), backend.getBePort());
145+
}
146+
// no backend returned
147+
throw new UserException(SystemInfoService.NO_SCAN_NODE_BACKEND_AVAILABLE_MSG
148+
+ " BEID: " + selectedId + " host: " + backend.getHost());
149+
}
134150
long id = nextId.getAndIncrement() % backends.size();
135151
Map.Entry<Long, Backend> backendEntry = backends.entrySet().stream().skip(id).filter(
136152
e -> isAvailable(e.getValue())).findFirst().orElse(null);
@@ -148,6 +164,22 @@ public static TNetworkAddress getHost(ImmutableMap<Long, Backend> backends,
148164
+ getBackendErrorMsg(Lists.newArrayList(backends.keySet()), backends, 3));
149165
}
150166

167+
public static TNetworkAddress getHost(ImmutableMap<Long, Backend> backends,
168+
Reference<Long> backendIdRef, Long beId)
169+
throws UserException {
170+
if (backends.isEmpty()) {
171+
throw new UserException(SystemInfoService.NO_SCAN_NODE_BACKEND_AVAILABLE_MSG);
172+
}
173+
Backend backend = backends.getOrDefault(beId, null);
174+
if (backend != null && isAvailable(backend)) {
175+
backendIdRef.setRef(beId);
176+
return new TNetworkAddress(backend.getHost(), backend.getBePort());
177+
}
178+
// no backend returned
179+
throw new UserException(SystemInfoService.NO_SCAN_NODE_BACKEND_AVAILABLE_MSG
180+
+ " BEID: " + beId + " host: " + backend.getHost());
181+
}
182+
151183
// get the reason why backends can not be chosen.
152184
private static String getBackendErrorMsg(List<Long> backendIds, ImmutableMap<Long, Backend> backends, int limit) {
153185
List<String> res = Lists.newArrayList();

0 commit comments

Comments
 (0)