Skip to content
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

Handle race conditition in receiving final task info #25333

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1670,6 +1670,7 @@ public Void onSinkInstanceHandleAcquired(SinkInstanceHandleAcquiredEvent sinkIns
// the code below is a stop-gap to mitigate this issue and unblock or fail query
// until we find and fix the bug
AtomicBoolean finalTaskInfoReceived = new AtomicBoolean();
AtomicBoolean taskCompletedEventSent = new AtomicBoolean();
task.addStateChangeListener(taskStatus -> {
if (!taskStatus.getState().isDone()) {
return;
Expand All @@ -1683,8 +1684,10 @@ public Void onSinkInstanceHandleAcquired(SinkInstanceHandleAcquiredEvent sinkIns
}, NO_FINAL_TASK_INFO_CHECK_INTERVAL.toMillis(), MILLISECONDS);
case CANCELED, ABORTED, FAILED -> scheduledExecutorService.schedule(() -> {
if (!finalTaskInfoReceived.get()) {
log.error("Did not receive final task info for task %s after it %s; internal inconsistency; marking task failed in scheduler to unblock query progression", taskStatus.getState(), task.getTaskId());
eventQueue.add(new RemoteTaskCompletedEvent(taskStatus));
if (taskCompletedEventSent.compareAndSet(false, true)) {
log.error("Did not receive final task info for task %s after it %s; internal inconsistency; marking task failed in scheduler to unblock query progression", task.getTaskId(), taskStatus.getState());
eventQueue.add(new RemoteTaskCompletedEvent(taskStatus));
}
}
}, NO_FINAL_TASK_INFO_CHECK_INTERVAL.toMillis(), MILLISECONDS);
default -> throw new IllegalStateException("Unexpected task state: " + taskStatus.getState());
Expand All @@ -1693,7 +1696,14 @@ public Void onSinkInstanceHandleAcquired(SinkInstanceHandleAcquiredEvent sinkIns

task.addFinalTaskInfoListener(_ -> finalTaskInfoReceived.set(true));
task.addFinalTaskInfoListener(taskExecutionStats::update);
task.addFinalTaskInfoListener(taskInfo -> eventQueue.add(new RemoteTaskCompletedEvent(taskInfo.taskStatus())));
task.addFinalTaskInfoListener(taskInfo -> {
if (taskCompletedEventSent.compareAndSet(false, true)) {
eventQueue.add(new RemoteTaskCompletedEvent(taskInfo.taskStatus()));
}
else {
log.warn("Final task info for task %s received late; state = %s", task.getTaskId(), taskInfo.taskStatus().getState());
}
});
nodeLease.attachTaskId(task.getTaskId());
task.start();
if (queryStateMachine.getQueryState() == QueryState.STARTING) {
Expand Down
Loading