Skip to content

Commit

Permalink
Ignore NotInTransactionException while obtaining stats
Browse files Browse the repository at this point in the history
If query gets cancelled during planning transaction is removed from
transaction manager and we start getting errors while trying to get
table stats. Ignore such failures to avoid log pollution.
  • Loading branch information
losipiuk committed Oct 25, 2024
1 parent 06b6786 commit a28b656
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package io.trino.cost;

import io.airlift.log.Logger;
import io.trino.NotInTransactionException;
import io.trino.Session;
import io.trino.sql.planner.iterative.GroupReference;
import io.trino.sql.planner.iterative.Lookup;
Expand Down Expand Up @@ -89,14 +90,29 @@ public PlanNodeStatsEstimate getStats(PlanNode node)
return stats;
}
catch (RuntimeException e) {
if (shouldIgnoreStatsCalculatorFailure(e)) {
// some failures are okay to ignore
return PlanNodeStatsEstimate.unknown();
}

if (isIgnoreStatsCalculatorFailures(session)) {
// log or fail for others, depeding on the session setting
log.error(e, "Error occurred when computing stats for query %s", session.getQueryId());
return PlanNodeStatsEstimate.unknown();
}
throw e;
}
}

boolean shouldIgnoreStatsCalculatorFailure(RuntimeException e)
{
if (e instanceof NotInTransactionException) {
// it is common to get NotInTransactionException if query gets cancelled during planning
return true;
}
return false;
}

private PlanNodeStatsEstimate getGroupStats(GroupReference groupReference)
{
int group = groupReference.getGroupId();
Expand Down

0 comments on commit a28b656

Please sign in to comment.