-
Notifications
You must be signed in to change notification settings - Fork 5.5k
fix: Do not cache futures as they can be cancelled on timeout #26367
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,7 +27,6 @@ | |
| import com.facebook.presto.execution.RemoteTask; | ||
| import com.facebook.presto.execution.RemoteTaskFactory; | ||
| import com.facebook.presto.execution.SqlStageExecution; | ||
| import com.facebook.presto.execution.StageExecutionId; | ||
| import com.facebook.presto.execution.StageExecutionInfo; | ||
| import com.facebook.presto.execution.StageExecutionState; | ||
| import com.facebook.presto.execution.StageId; | ||
|
|
@@ -424,7 +423,6 @@ private void schedule() | |
| Set<StageId> completedStages = new HashSet<>(); | ||
|
|
||
| List<ExecutionSchedule> sectionExecutionSchedules = new LinkedList<>(); | ||
| Map<StageExecutionId, ListenableFuture<?>> blockedStages = new HashMap<>(); | ||
|
|
||
| while (!Thread.currentThread().isInterrupted()) { | ||
| // remove finished section | ||
|
|
@@ -447,6 +445,8 @@ private void schedule() | |
| .forEach(sectionExecutionSchedules::add); | ||
|
|
||
| while (sectionExecutionSchedules.stream().noneMatch(ExecutionSchedule::isFinished)) { | ||
| List<ListenableFuture<?>> blockedStages = new ArrayList<>(); | ||
|
|
||
| List<StageExecutionAndScheduler> executionsToSchedule = sectionExecutionSchedules.stream() | ||
| .flatMap(schedule -> schedule.getStagesToSchedule().stream()) | ||
| .collect(toImmutableList()); | ||
|
|
@@ -459,12 +459,6 @@ private void schedule() | |
| SqlStageExecution stageExecution = stageExecutionAndScheduler.getStageExecution(); | ||
| stageExecution.beginScheduling(); | ||
|
|
||
| ListenableFuture<?> stillBlocked = blockedStages.get(stageExecution.getStageExecutionId()); | ||
| if (stillBlocked != null && !stillBlocked.isDone()) { | ||
| continue; | ||
| } | ||
| blockedStages.remove(stageExecution.getStageExecutionId()); | ||
|
|
||
| // perform some scheduling work | ||
| ScheduleResult result = stageExecutionAndScheduler.getStageScheduler() | ||
| .schedule(); | ||
|
|
@@ -482,7 +476,7 @@ private void schedule() | |
| stageExecution.schedulingComplete(); | ||
| } | ||
| else if (!result.getBlocked().isDone()) { | ||
| blockedStages.put(stageExecution.getStageExecutionId(), result.getBlocked()); | ||
| blockedStages.add(result.getBlocked()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (bug_risk): Adding blocked futures to a List may allow duplicates for the same stage. Previously, the Map ensured only one future per stage; switching to a List allows multiple futures for the same stage if schedule() is called repeatedly before completion. This may lead to redundant cancellations and missed wake-ups if futures aren't managed correctly. |
||
| } | ||
| else { | ||
| allBlocked = false; | ||
|
|
@@ -547,12 +541,12 @@ else if (!result.getBlocked().isDone()) { | |
| // wait for a state change and then schedule again | ||
| if (allBlocked && !blockedStages.isEmpty()) { | ||
| try (TimeStat.BlockTimer timer = schedulerStats.getSleepTime().time()) { | ||
| tryGetFutureValue(whenAnyComplete(blockedStages.values()), 1, SECONDS); | ||
| } | ||
| for (ListenableFuture<?> blockedStage : blockedStages.values()) { | ||
| blockedStage.cancel(true); | ||
| tryGetFutureValue(whenAnyComplete(blockedStages), 1, SECONDS); | ||
| } | ||
| } | ||
| for (ListenableFuture<?> blockedStage : blockedStages) { | ||
| blockedStage.cancel(true); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
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.
issue (bug_risk): Switching from a Map to a List for blockedStages may affect duplicate handling.
The previous Map structure ensured each stage was only tracked once, preventing duplicates. With a List, the same stage could be added multiple times, potentially causing redundant actions. Please review if this could introduce bugs when a stage is scheduled more than once before completion.