diff --git a/fe/fe-core/src/main/java/com/starrocks/planner/OlapScanNode.java b/fe/fe-core/src/main/java/com/starrocks/planner/OlapScanNode.java index 04c57777b2fa2..cbc0246f702c0 100644 --- a/fe/fe-core/src/main/java/com/starrocks/planner/OlapScanNode.java +++ b/fe/fe-core/src/main/java/com/starrocks/planner/OlapScanNode.java @@ -189,6 +189,10 @@ public class OlapScanNode extends ScanNode { private long totalScanRangeBytes = 0; + // Set to true after it's confirmed at some point during the execution of this request that there is some living CN. + // Set just once per query. + private boolean alreadyFoundSomeLivingCn = false; + // Constructs node to scan given data files of table 'tbl'. // Constructs node to scan given data files of table 'tbl'. public OlapScanNode(PlanNodeId id, TupleDescriptor desc, String planNodeName) { @@ -500,6 +504,25 @@ public List updateScanRangeLocations(List() { + @Mock + public SystemInfoService getClusterInfo() { + return systemInfo; + } + }; + + new MockUp() { + @Mock + public ComputeNode getBackendOrComputeNode(long nodeId) { + return b1; + } + }; + + new MockUp() { + @Mock + public List getWorkersByWorkerGroup(long workerGroupId) throws UserException { + if (workerGroupId == StarOSAgent.DEFAULT_WORKER_GROUP_ID) { + return Lists.newArrayList(b1.getId()); + } + return Lists.newArrayList(); + } + }; + + new MockUp() { + @Mock + public NodeMgr getNodeMgr() { + return nodeMgr; + } + + @Mock + public StarOSAgent getStarOSAgent() { + return starOSAgent; + } + + @Mock + public WarehouseManager getWarehouseMgr() { + return mockWarehouseMgr; + } + + }; + + ComputeNode livingCn = new ComputeNode(); + livingCn.setAlive(true); + new Expectations() { + { + // This is the point of the test -- we only want to call this once even though we're calling + // addScanRangeLocations multiple times. + mockWarehouseMgr.getAliveComputeNodes(WarehouseManager.DEFAULT_WAREHOUSE_ID); + times = 1; + result = Lists.newArrayList(livingCn); + } + }; + new MockUp() { + @Mock + public RunMode getCurrentRunMode() { + return RunMode.SHARED_DATA; + } + }; + + OlapScanNode scanNode = newOlapScanNode(); + Partition partition = new Partition(123, "aaa", null, null); + MaterializedIndex index = new MaterializedIndex(1, MaterializedIndex.IndexState.NORMAL); + scanNode.addScanRangeLocations(partition, partition, index, Collections.emptyList(), 1); + // Since this is the second call to addScanRangeLocations on the same OlapScanNode, we do not expect another call to + // getAliveComputeNodes. + scanNode.addScanRangeLocations(partition, partition, index, Collections.emptyList(), 1); + } + private OlapScanNode newOlapScanNode() { TupleDescriptor desc = new TupleDescriptor(new TupleId(0)); OlapTable table = new OlapTable();