-
Notifications
You must be signed in to change notification settings - Fork 5.5k
fix: Make scheduledFuture thread-safe in HttpNativeExecutionTaskResultFetcher #26649
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
base: master
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -23,6 +23,8 @@ | |
| import com.facebook.presto.spi.PrestoException; | ||
| import com.facebook.presto.spi.page.SerializedPage; | ||
|
|
||
| import javax.annotation.concurrent.GuardedBy; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import java.util.concurrent.CompletableFuture; | ||
|
|
@@ -67,10 +69,9 @@ public class HttpNativeExecutionTaskResultFetcher | |
| private final Object taskHasResult; | ||
| private final AtomicReference<Throwable> lastException = new AtomicReference<>(); | ||
|
|
||
| @GuardedBy("this") | ||
| private ScheduledFuture<?> scheduledFuture; | ||
|
|
||
| private volatile boolean completed; | ||
|
|
||
| private long token; | ||
|
|
||
| public HttpNativeExecutionTaskResultFetcher( | ||
|
|
@@ -86,15 +87,15 @@ public HttpNativeExecutionTaskResultFetcher( | |
| this.taskHasResult = requireNonNull(taskHasResult, "taskHasResult is null"); | ||
| } | ||
|
|
||
| public void start() | ||
| public synchronized void start() | ||
| { | ||
| scheduledFuture = scheduler.scheduleAtFixedRate(this::doGetResults, | ||
| 0, | ||
| (long) FETCH_INTERVAL.getValue(), | ||
| FETCH_INTERVAL.getUnit()); | ||
| } | ||
|
|
||
| public void stop(boolean success) | ||
| public synchronized void stop(boolean success) | ||
| { | ||
| if (scheduledFuture != null) { | ||
| scheduledFuture.cancel(false); | ||
|
|
@@ -129,7 +130,7 @@ public boolean hasPage() | |
| return !pageBuffer.isEmpty(); | ||
| } | ||
|
|
||
| private void throwIfFailed() | ||
| private synchronized void throwIfFailed() | ||
| { | ||
| if (scheduledFuture != null && scheduledFuture.isCancelled() && lastException.get() != null) { | ||
| Throwable failure = lastException.get(); | ||
|
|
@@ -140,11 +141,6 @@ private void throwIfFailed() | |
|
|
||
| private void doGetResults() | ||
| { | ||
| if (completed && scheduledFuture != null) { | ||
| scheduledFuture.cancel(false); | ||
| return; | ||
| } | ||
|
|
||
| if (bufferMemoryBytes.longValue() >= MAX_BUFFER_SIZE.toBytes()) { | ||
| return; | ||
| } | ||
|
|
@@ -159,7 +155,7 @@ private void doGetResults() | |
| } | ||
| } | ||
|
|
||
| private void onSuccess(PageBufferClient.PagesResponse pagesResponse) | ||
| private synchronized void onSuccess(PageBufferClient.PagesResponse pagesResponse) | ||
|
Member
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. @xin-zhang2 thanks for this change. I have a bit of concern about the For example, if another thread holds the lock on |
||
| { | ||
| List<SerializedPage> pages = pagesResponse.getPages(); | ||
| long bytes = 0; | ||
|
|
@@ -185,7 +181,6 @@ private void onSuccess(PageBufferClient.PagesResponse pagesResponse) | |
| } | ||
| token = nextToken; | ||
| if (pagesResponse.isClientComplete()) { | ||
| completed = true; | ||
| workerClient.abortResultsAsync(taskId); | ||
| if (scheduledFuture != null) { | ||
| scheduledFuture.cancel(false); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.