Prune QueryStats when pruning QueryInfo
When expired queries are pruned by the SqlQueryManager QueryStats were not pruned
at all, which may hold onto a good amount of memory through the OperatorStats.
Especially the ExchangeClientStatus (implements OperatorInfo) can get huge in a large
cluster.
@@ -775,7 +775,7 @@ public class QueryStateMachine
queryInfo.getSelf(),
queryInfo.getFieldNames(),
queryInfo.getQuery(),
- queryInfo.getQueryStats(),
+ pruneQueryStats(queryInfo.getQueryStats()),
queryInfo.getSetSessionProperties(),
queryInfo.getResetSessionProperties(),
queryInfo.getAddedPreparedStatements(),
@@ -793,6 +793,46 @@ public class QueryStateMachine
finalQueryInfo.compareAndSet(finalInfo, Optional.of(prunedQueryInfo));
}
+ private QueryStats pruneQueryStats(QueryStats queryStats)
+ {
+ return new QueryStats(
+ queryStats.getCreateTime(),
+ queryStats.getExecutionStartTime(),
+ queryStats.getLastHeartbeat(),
+ queryStats.getEndTime(),
+ queryStats.getElapsedTime(),
+ queryStats.getQueuedTime(),
+ queryStats.getAnalysisTime(),
+ queryStats.getDistributedPlanningTime(),
+ queryStats.getTotalPlanningTime(),
+ queryStats.getFinishingTime(),
+ queryStats.getTotalTasks(),
+ queryStats.getRunningTasks(),
+ queryStats.getCompletedTasks(),
+ queryStats.getTotalDrivers(),
+ queryStats.getQueuedDrivers(),
+ queryStats.getRunningDrivers(),
+ queryStats.getBlockedDrivers(),
+ queryStats.getCompletedDrivers(),
+ queryStats.getCumulativeMemory(),
+ queryStats.getTotalMemoryReservation(),
+ queryStats.getPeakMemoryReservation(),
+ queryStats.isScheduled(),
+ queryStats.getTotalScheduledTime(),
+ queryStats.getTotalCpuTime(),
+ queryStats.getTotalUserTime(),
+ queryStats.getTotalBlockedTime(),
+ queryStats.isFullyBlocked(),
+ queryStats.getBlockedReasons(),
+ queryStats.getRawInputDataSize(),
+ queryStats.getRawInputPositions(),
+ queryStats.getProcessedInputDataSize(),
+ queryStats.getProcessedInputPositions(),
+ queryStats.getOutputDataSize(),
+ queryStats.getOutputPositions(),
+ ImmutableList.of()); // Remove the operator summaries as OperatorInfo (especially ExchangeClientStatus) can hold onto a large amount of memory
+ }
+
private long tickerNanos()
{
return ticker.read();
