github-actions[bot] commented on code in PR #61318:
URL: https://github.com/apache/doris/pull/61318#discussion_r2930191895
##########
fe/fe-core/src/main/java/org/apache/doris/catalog/CloudTabletStatMgr.java:
##########
@@ -365,4 +370,28 @@ private GetTabletStatsResponse
getTabletStats(GetTabletStatsRequest request)
public List<OlapTable.Statistics> getCloudTableStats() {
return this.cloudTableStatsList;
}
+
+ public long getTotalTableSize() {
+ return this.totalTableSize;
+ }
+
+ private void filterTopTableStatsByDataSize(List<OlapTable.Statistics>
newCloudTableStatsList) {
+ int limit = Config.prom_output_table_metrics_limit;
+ if (newCloudTableStatsList.size() <= limit) {
+ this.cloudTableStatsList = newCloudTableStatsList;
+ return;
+ }
+ // only copy elements if number of tables >
prom_output_table_metrics_limit
+ PriorityQueue<OlapTable.Statistics> topStats = new
PriorityQueue<>(limit,
+ Comparator.comparingLong(OlapTable.Statistics::getDataSize));
+ for (OlapTable.Statistics stats : newCloudTableStatsList) {
+ if (topStats.size() < limit) {
+ topStats.offer(stats);
+ } else if (!topStats.isEmpty() && stats.getDataSize() >
topStats.peek().getDataSize()) {
Review Comment:
**Bug (Edge Case):** If `Config.prom_output_table_metrics_limit` is set to
`0` (or negative), `new PriorityQueue<>(limit, ...)` will throw
`IllegalArgumentException` because `PriorityQueue` requires `initialCapacity >=
1`. This would crash the `CloudTabletStatMgr` daemon thread, halting all tablet
stat updates.
The guard `newCloudTableStatsList.size() <= limit` does NOT protect against
this: when `limit=0` and the list is non-empty, the condition is `false`, so we
fall through to the `PriorityQueue` constructor.
Suggestion:
```java
int limit = Config.prom_output_table_metrics_limit;
if (limit <= 0 || newCloudTableStatsList.size() <= limit) {
this.cloudTableStatsList = newCloudTableStatsList;
return;
}
```
Alternatively, clamp: `int limit = Math.max(1,
Config.prom_output_table_metrics_limit);`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]