FrankChen021 commented on code in PR #20314:
URL: https://github.com/apache/druid/pull/20314#discussion_r3989312176


##########
sql/src/main/java/org/apache/druid/sql/DirectStatement.java:
##########
@@ -196,20 +199,52 @@ public ResultSet plan()
     }
     long planningStartNanos = System.nanoTime();
     try (DruidPlanner planner = createPlanner()) {
-      validate(planner);
-      authorize(planner, authorizer());
+      // Bound the wall-clock time spent planning this query. A non-positive 
timeout disables this. The budget is
+      // measured from planningStartNanos (above), so any time already spent 
constructing the planner counts against
+      // it and a query cannot get a fresh full budget after an expensive 
planner/schema setup.
+      final long maxPlanningTimeMs = 
planner.getPlannerContext().getPlannerConfig().getMaxPlanningTimeMs();
+      final long remainingBudgetMs = 
remainingPlanningBudgetMs(maxPlanningTimeMs, planningStartNanos);

Review Comment:
   [P2] Enforce an exhausted deadline before proceeding
   
   `createPlanner()` still completes before `SqlPlanningTimeout.arm` is called, 
so a slow schema/planner construction can consume the entire configured 
planning budget without any watchdog interrupt. The fallback in 
`remainingPlanningBudgetMs` then schedules only 1 ms; if the following 
validation/planning returns before that callback runs, the final `isTimedOut()` 
check is false and a plan succeeds after the configured deadline. Check the 
elapsed deadline before proceeding or arm the effective deadline before planner 
construction.



-- 
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]

Reply via email to