-
Notifications
You must be signed in to change notification settings - Fork 9k
HADOOP-19569. S3A: stream write/close fails badly once FS is closed #7700
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
Draft
steveloughran
wants to merge
4
commits into
apache:trunk
Choose a base branch
from
steveloughran:s3/HADOOP-19569-stream-write-fs-close
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,71 +16,77 @@ | |
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.hadoop.fs.s3a; | ||
|
||
import org.apache.hadoop.util.BlockingThreadPoolExecutorService; | ||
import org.apache.hadoop.util.SemaphoredDelegatingExecutor; | ||
import org.apache.hadoop.util.StopWatch; | ||
|
||
import org.junit.AfterClass; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.Timeout; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
package org.apache.hadoop.util; | ||
|
||
import java.util.concurrent.Callable; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Future; | ||
import java.util.concurrent.RejectedExecutionException; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import org.apache.hadoop.test.AbstractHadoopTestBase; | ||
|
||
import static org.apache.hadoop.test.LambdaTestUtils.intercept; | ||
|
||
/** | ||
* Basic test for S3A's blocking executor service. | ||
* Test for the blocking executor service. | ||
*/ | ||
public class ITestBlockingThreadPoolExecutorService { | ||
public class TestBlockingThreadPoolExecutorService extends AbstractHadoopTestBase { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger( | ||
ITestBlockingThreadPoolExecutorService.class); | ||
TestBlockingThreadPoolExecutorService.class); | ||
|
||
private static final int NUM_ACTIVE_TASKS = 4; | ||
|
||
private static final int NUM_WAITING_TASKS = 2; | ||
|
||
private static final int TASK_SLEEP_MSEC = 100; | ||
|
||
private static final int SHUTDOWN_WAIT_MSEC = 200; | ||
|
||
private static final int SHUTDOWN_WAIT_TRIES = 5; | ||
|
||
private static final int BLOCKING_THRESHOLD_MSEC = 50; | ||
|
||
private static final Integer SOME_VALUE = 1337; | ||
|
||
private static BlockingThreadPoolExecutorService tpe; | ||
private BlockingThreadPoolExecutorService tpe; | ||
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. [nitpick] Since the thread pool executor is now an instance variable with setup/teardown methods, ensure that each test properly initializes and destroys the executor to avoid interference between tests. Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
|
||
@Rule | ||
public Timeout testTimeout = new Timeout(60, TimeUnit.SECONDS); | ||
|
||
@AfterClass | ||
public static void afterClass() throws Exception { | ||
@Before | ||
public void setup() throws Exception { | ||
ensureCreated(); | ||
} | ||
|
||
@After | ||
public void teardown() throws Exception { | ||
ensureDestroyed(); | ||
} | ||
|
||
|
||
/** | ||
* Basic test of running one trivial task. | ||
*/ | ||
@Test | ||
public void testSubmitCallable() throws Exception { | ||
ensureCreated(); | ||
Future<Integer> f = tpe.submit(callableSleeper); | ||
Integer v = f.get(); | ||
assertEquals(SOME_VALUE, v); | ||
Assertions.assertThat(v).isEqualTo(SOME_VALUE); | ||
} | ||
|
||
/** | ||
* More involved test, including detecting blocking when at capacity. | ||
*/ | ||
@Test | ||
public void testSubmitRunnable() throws Exception { | ||
ensureCreated(); | ||
verifyQueueSize(tpe, NUM_ACTIVE_TASKS + NUM_WAITING_TASKS); | ||
} | ||
|
||
|
@@ -102,27 +108,30 @@ protected void verifyQueueSize(ExecutorService executorService, | |
assertDidBlock(stopWatch); | ||
} | ||
|
||
@Test | ||
public void testShutdown() throws Exception { | ||
// Cover create / destroy, regardless of when this test case runs | ||
ensureCreated(); | ||
ensureDestroyed(); | ||
|
||
// Cover create, execute, destroy, regardless of when test case runs | ||
ensureCreated(); | ||
testSubmitRunnable(); | ||
ensureDestroyed(); | ||
} | ||
|
||
@Test | ||
public void testChainedQueue() throws Throwable { | ||
ensureCreated(); | ||
int size = 2; | ||
ExecutorService wrapper = new SemaphoredDelegatingExecutor(tpe, | ||
size, true); | ||
verifyQueueSize(wrapper, size); | ||
} | ||
|
||
@Test | ||
public void testShutdownQueueRejectsOperations() throws Throwable { | ||
tpe.shutdown(); | ||
Assertions.assertThat(tpe.isShutdown()) | ||
.describedAs("%s should be shutdown", tpe) | ||
.isTrue(); | ||
// runnable | ||
intercept(RejectedExecutionException.class, () -> | ||
tpe.submit(failToRun)); | ||
// callable | ||
intercept(RejectedExecutionException.class, () -> | ||
tpe.submit(() -> 0)); | ||
intercept(RejectedExecutionException.class, () -> | ||
tpe.execute(failToRun)); | ||
} | ||
|
||
// Helper functions, etc. | ||
|
||
private void assertDidBlock(StopWatch sw) { | ||
|
@@ -135,28 +144,27 @@ private void assertDidBlock(StopWatch sw) { | |
} | ||
} | ||
|
||
private Runnable sleeper = new Runnable() { | ||
@Override | ||
public void run() { | ||
String name = Thread.currentThread().getName(); | ||
try { | ||
Thread.sleep(TASK_SLEEP_MSEC); | ||
} catch (InterruptedException e) { | ||
LOG.info("Thread {} interrupted.", name); | ||
Thread.currentThread().interrupt(); | ||
} | ||
} | ||
private Runnable failToRun = () -> { | ||
throw new RuntimeException("This runnable raises and exception"); | ||
}; | ||
|
||
private Callable<Integer> callableSleeper = new Callable<Integer>() { | ||
@Override | ||
public Integer call() throws Exception { | ||
sleeper.run(); | ||
return SOME_VALUE; | ||
private Runnable sleeper = () -> { | ||
String name = Thread.currentThread().getName(); | ||
try { | ||
Thread.sleep(TASK_SLEEP_MSEC); | ||
} catch (InterruptedException e) { | ||
LOG.info("Thread {} interrupted.", name); | ||
Thread.currentThread().interrupt(); | ||
} | ||
}; | ||
|
||
private Callable<Integer> callableSleeper = () -> { | ||
sleeper.run(); | ||
return SOME_VALUE; | ||
}; | ||
|
||
private class LatchedSleeper implements Runnable { | ||
|
||
private final CountDownLatch latch; | ||
|
||
LatchedSleeper(CountDownLatch latch) { | ||
|
@@ -178,7 +186,7 @@ public void run() { | |
/** | ||
* Helper function to create thread pool under test. | ||
*/ | ||
private static void ensureCreated() throws Exception { | ||
private void ensureCreated() throws Exception { | ||
if (tpe == null) { | ||
LOG.debug("Creating thread pool"); | ||
tpe = BlockingThreadPoolExecutorService.newInstance( | ||
|
@@ -191,7 +199,7 @@ private static void ensureCreated() throws Exception { | |
* Helper function to terminate thread pool under test, asserting that | ||
* shutdown -> terminate works as expected. | ||
*/ | ||
private static void ensureDestroyed() throws Exception { | ||
private void ensureDestroyed() throws Exception { | ||
if (tpe == null) { | ||
return; | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
[nitpick] The InnerExecutorRejection handler now shuts down the service upon rejection. Consider enhancing the error handling logic or adding more detailed documentation to explain the shutdown behavior in case of task rejection.
Copilot uses AI. Check for mistakes.