[Fix](point query) OlapScanNode reuslt could be memleak since it's cached (#16406)

Cached OlapScanNode each time call `addScanRangeLocations` will add TScanRangeLocations to result.
So `result` could grow too large and lead `getReplicaNumPerHost` a cpu hot spot in it's loop.
This commit is contained in:
lihangyu
2023-02-03 21:42:53 +08:00
committed by GitHub
parent 5e232a30d8
commit 54c85e36ad
2 changed files with 12 additions and 12 deletions

View File

@ -978,6 +978,7 @@ public class OlapScanNode extends ScanNode {
computePartitionInfo();
scanBackendIds.clear();
scanTabletIds.clear();
result.clear();
try {
getScanRangeLocations();
} catch (AnalysisException e) {

View File

@ -1615,24 +1615,23 @@ public class Coordinator {
// Populates scan_range_assignment_.
// <fragment, <server, nodeId>>
private void computeScanRangeAssignment() throws Exception {
if (isPointQuery) {
// Fast path for evaluate Backend for point query
List<TScanRangeLocations> locations = ((OlapScanNode) scanNodes.get(0)).lazyEvaluateRangeLocations();
Preconditions.checkNotNull(locations);
return;
}
Map<TNetworkAddress, Long> assignedBytesPerHost = Maps.newHashMap();
Map<TNetworkAddress, Long> replicaNumPerHost = getReplicaNumPerHost();
Collections.shuffle(scanNodes);
// set scan ranges/locations for scan nodes
for (ScanNode scanNode : scanNodes) {
List<TScanRangeLocations> locations;
if (isPointQuery) {
// Fast path for evaluate Backend for point query
locations = ((OlapScanNode) scanNode).lazyEvaluateRangeLocations();
Preconditions.checkNotNull(locations);
return;
} else {
// the parameters of getScanRangeLocations may ignore, It doesn't take effect
locations = scanNode.getScanRangeLocations(0);
if (locations == null) {
// only analysis olap scan node
continue;
}
// the parameters of getScanRangeLocations may ignore, It doesn't take effect
locations = scanNode.getScanRangeLocations(0);
if (locations == null) {
// only analysis olap scan node
continue;
}
Collections.shuffle(locations);
Set<Integer> scanNodeIds = fragmentIdToScanNodeIds.computeIfAbsent(scanNode.getFragmentId(),