-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Enhancement] Add some logs to help online businesses quickly find the queries that cause FE oom #51528
Conversation
Signed-off-by: before-Sunrise <[email protected]>
Quality Gate passedIssues Measures |
} | ||
|
||
} | ||
|
||
/** | ||
* We query meta to get request's data location | ||
* extra result info will pass to backend ScanNode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The most risky bug in this code is:
A potential integer overflow when calculating totalScanRangeBytes
, which could lead to incorrect memory checks and potential OOM issues.
You can modify the code like this:
@@ -188,6 +189,11 @@ public class OlapScanNode extends ScanNode {
private VectorSearchOptions vectorSearchOptions = new VectorSearchOptions();
+ private boolean calculatedScanRange = false;
+
+ private long totalScanRangeBytes = 0;
+
+ // 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) {
super(id, desc, planNodeName);
@@ -641,6 +647,11 @@ public void addScanRangeLocations(Partition partition,
scanRangeLocations.setScan_range(scanRange);
bucketSeq2locations.put(tabletId2BucketSeq.get(tabletId), scanRangeLocations);
+ if (!calculatedScanRange && scanRangeLocations != null) {
+ long scanRangeSize = SizeEstimator.estimate(scanRangeLocations);
+ checkIfScanRangeNumSafe(scanRangeSize);
+ calculatedScanRange = true;
+ }
result.add(scanRangeLocations);
}
@@ -731,6 +742,32 @@ private void computeTabletInfo() throws UserException {
}
}
+ public void checkIfScanRangeNumSafe(long scanRangeSize) {
+ long totalPartitionNum = 0;
+ long totalTabletsNum = 0;
+ for (long partitionId : selectedPartitionIds) {
+ final Partition partition = olapTable.getPartition(partitionId);
+ List<PhysicalPartition> physicalPartitions = (List<PhysicalPartition>) partition.getSubPartitions();
+ totalPartitionNum += physicalPartitions.size();
+ for (PhysicalPartition physicalPartition : physicalPartitions) {
+ final MaterializedIndex selectedTable = physicalPartition.getIndex(selectedIndexId);
+ totalTabletsNum += selectedTable.getTablets().size();
+ }
+ }
+
+ totalScanRangeBytes = Math.multiplyExact(scanRangeSize, totalTabletsNum); // Prevent overflow
+ if (totalScanRangeBytes > 1024 * 1024) {
+ Runtime runtime = Runtime.getRuntime();
+ long freeMemory = runtime.freeMemory();
+ if (totalScanRangeBytes > freeMemory / 2) {
+ LOG.warn(
+ "Try to allocate too many scan ranges for table {}, which may cause FE OOM, Partition Num:{}, tablet Num:{}, Scan Range Total Bytes:{}",
+ olapTable.getName(), totalPartitionNum, totalTabletsNum, totalScanRangeBytes);
+ }
+ }
+
+ }
+
/**
* We query meta to get request's data location
* extra result info will pass to backend ScanNode
[Java-Extensions Incremental Coverage Report]✅ pass : 0 / 0 (0%) |
[FE Incremental Coverage Report]✅ pass : 41 / 51 (80.39%) file detail
|
[BE Incremental Coverage Report]✅ pass : 0 / 0 (0%) |
@Mergifyio backport branch-3.3 |
@Mergifyio backport branch-3.2 |
✅ Backports have been created
|
✅ Backports have been created
|
…e queries that cause FE oom (#51528) Signed-off-by: before-Sunrise <[email protected]> (cherry picked from commit 5dd17dc) # Conflicts: # fe/fe-core/src/main/java/com/starrocks/common/Config.java # fe/fe-core/src/main/java/com/starrocks/planner/OlapScanNode.java
…e queries that cause FE oom (#51528) Signed-off-by: before-Sunrise <[email protected]> (cherry picked from commit 5dd17dc) # Conflicts: # fe/fe-core/src/main/java/com/starrocks/common/Config.java # fe/fe-core/src/main/java/com/starrocks/planner/OlapScanNode.java
…e queries that cause FE oom (StarRocks#51528) Signed-off-by: before-Sunrise <[email protected]>
…e queries that cause FE oom (backport #51528) (#51534) Signed-off-by: before-Sunrise <[email protected]>
…e queries that cause FE oom (backport #51528) (#51534) Signed-off-by: before-Sunrise <[email protected]> (cherry picked from commit 7f42a15) # Conflicts: # fe/fe-core/src/main/java/com/starrocks/common/Config.java # fe/fe-core/src/main/java/com/starrocks/planner/OlapScanNode.java
…e queries that cause FE oom (backport #51528) (#51547) Signed-off-by: before-Sunrise <[email protected]>
…e queries that cause FE oom (StarRocks#51528) Signed-off-by: before-Sunrise <[email protected]> Signed-off-by: zhiminr.ren <[email protected]>
Why I'm doing:
What I'm doing:
Fixes #issue
What type of PR is this:
Does this PR entail a change in behavior?
If yes, please specify the type of change:
Checklist:
Bugfix cherry-pick branch check: