Skip to content

Commit

Permalink
[Enhancement] only call getAliveComputeNodes once per OlapScanNode (#…
Browse files Browse the repository at this point in the history
…52168)

Signed-off-by: Connor Brennan <cbrennan@pinterest.com>
(cherry picked from commit f581449)

# Conflicts:
#	fe/fe-core/src/main/java/com/starrocks/planner/OlapScanNode.java
#	fe/fe-core/src/test/java/com/starrocks/server/WarehouseManagerTest.java
  • Loading branch information
ctbrennan authored and mergify[bot] committed Oct 24, 2024
1 parent a6264c9 commit d285e08
Show file tree
Hide file tree
Showing 2 changed files with 397 additions and 0 deletions.
27 changes: 27 additions & 0 deletions fe/fe-core/src/main/java/com/starrocks/planner/OlapScanNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,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'.
public OlapScanNode(PlanNodeId id, TupleDescriptor desc, String planNodeName) {
super(id, desc, planNodeName);
Expand Down Expand Up @@ -469,6 +473,25 @@ public List<TScanRangeLocations> updateScanRangeLocations(List<TScanRangeLocatio
return newLocations;
}


private void checkSomeAliveComputeNode() throws ErrorReportException {
// Note that it's theoretically possible that there were some living CN earlier in this query's execution, and then
// they all died, but in that case, the problem this will be surfaced later anyway.
if (alreadyFoundSomeLivingCn) {
return;
}
// We prefer to call getAliveComputeNodes infrequently, as it can come to dominate the execution time of a query in the
// frontend if there are many calls per request (e.g. one per partition when there are many partitions).
if (RunMode.getCurrentRunMode() == RunMode.SHARED_DATA) {
WarehouseManager warehouseManager = GlobalStateMgr.getCurrentState().getWarehouseMgr();
if (CollectionUtils.isEmpty(warehouseManager.getAliveComputeNodes(warehouseId))) {
Warehouse warehouse = warehouseManager.getWarehouse(warehouseId);
throw ErrorReportException.report(ErrorCode.ERR_NO_NODES_IN_WAREHOUSE, warehouse.getName());
}
}
alreadyFoundSomeLivingCn = true;
}

public void addScanRangeLocations(Partition partition,
PhysicalPartition physicalPartition,
MaterializedIndex index,
Expand All @@ -485,6 +508,10 @@ public void addScanRangeLocations(Partition partition,
selectedPartitionNames.add(partition.getName());
selectedPartitionVersions.add(visibleVersion);

<<<<<<< HEAD
=======
checkSomeAliveComputeNode();
>>>>>>> f581449f14 ([Enhancement] only call getAliveComputeNodes once per OlapScanNode (#52168))
for (Tablet tablet : tablets) {
long tabletId = tablet.getId();
LOG.debug("{} tabletId={}", (logNum++), tabletId);
Expand Down
Loading

0 comments on commit d285e08

Please sign in to comment.