-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Fix possible StackOverflowError in BufferingSplitSource #19369
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 |
|---|---|---|
|
|
@@ -17,7 +17,7 @@ | |
| import com.google.common.util.concurrent.Futures; | ||
| import com.google.common.util.concurrent.ListenableFuture; | ||
| import com.google.common.util.concurrent.SettableFuture; | ||
| import io.trino.annotation.NotThreadSafe; | ||
| import com.google.errorprone.annotations.ThreadSafe; | ||
| import io.trino.metadata.Split; | ||
| import io.trino.spi.connector.CatalogHandle; | ||
| import io.trino.spi.connector.ConnectorSplit; | ||
|
|
@@ -33,7 +33,7 @@ | |
| import static io.trino.split.MockSplitSource.Action.FINISH; | ||
| import static io.trino.testing.TestingHandles.TEST_CATALOG_HANDLE; | ||
|
|
||
| @NotThreadSafe | ||
| @ThreadSafe | ||
| public class MockSplitSource | ||
| implements SplitSource | ||
| { | ||
|
|
@@ -58,22 +58,22 @@ public MockSplitSource() | |
| { | ||
| } | ||
|
|
||
| public MockSplitSource setBatchSize(int batchSize) | ||
| public synchronized MockSplitSource setBatchSize(int batchSize) | ||
| { | ||
| checkArgument(atSplitDepletion == DO_NOTHING, "cannot modify batch size once split completion action is set"); | ||
| this.batchSize = batchSize; | ||
| return this; | ||
| } | ||
|
|
||
| public MockSplitSource increaseAvailableSplits(int count) | ||
| public synchronized MockSplitSource increaseAvailableSplits(int count) | ||
| { | ||
| checkArgument(atSplitDepletion == DO_NOTHING, "cannot increase available splits once split completion action is set"); | ||
| totalSplits += count; | ||
| doGetNextBatch(); | ||
| return this; | ||
| } | ||
|
|
||
| public MockSplitSource atSplitCompletion(Action action) | ||
| public synchronized MockSplitSource atSplitCompletion(Action action) | ||
| { | ||
| atSplitDepletion = action; | ||
| doGetNextBatch(); | ||
|
|
@@ -86,9 +86,13 @@ public CatalogHandle getCatalogHandle() | |
| throw new UnsupportedOperationException(); | ||
| } | ||
|
|
||
| private void doGetNextBatch() | ||
| private synchronized void doGetNextBatch() | ||
| { | ||
| checkState(splitsProduced <= totalSplits); | ||
| if (nextBatchFuture.isDone()) { | ||
|
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. could it end up being active loop?
Member
Author
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. This code is added to prevent a problem of waiting forever because of splits being produced after a future is already done. |
||
| // if nextBatchFuture is already done, we need to wait until new future is created through getNextBatch to produce splits | ||
| return; | ||
| } | ||
| if (splitsProduced == totalSplits) { | ||
| switch (atSplitDepletion) { | ||
| case FAIL: | ||
|
|
@@ -111,7 +115,7 @@ private void doGetNextBatch() | |
| } | ||
|
|
||
| @Override | ||
| public ListenableFuture<SplitBatch> getNextBatch(int maxSize) | ||
| public synchronized ListenableFuture<SplitBatch> getNextBatch(int maxSize) | ||
| { | ||
| checkState(nextBatchFuture.isDone(), "concurrent getNextBatch invocation"); | ||
| nextBatchFuture = SettableFuture.create(); | ||
|
|
@@ -128,7 +132,7 @@ public void close() | |
| } | ||
|
|
||
| @Override | ||
| public boolean isFinished() | ||
| public synchronized boolean isFinished() | ||
| { | ||
| return splitsProduced == totalSplits && atSplitDepletion == FINISH; | ||
| } | ||
|
|
@@ -139,7 +143,7 @@ public Optional<List<Object>> getTableExecuteSplitsInfo() | |
| return Optional.empty(); | ||
| } | ||
|
|
||
| public int getNextBatchInvocationCount() | ||
| public synchronized int getNextBatchInvocationCount() | ||
| { | ||
| return nextBatchInvocationCount; | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.