chihsuan commented on code in PR #11029:
URL: https://github.com/apache/ozone/pull/11029#discussion_r3822442959
##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/hdds/scm/TestXceiverClientMetrics.java:
##########
@@ -105,54 +107,61 @@ public void testMetrics(@TempDir Path metaDir) throws
Exception {
assertCounter("CreateContainerLatencyNumOps", 1L, containerMetrics);
breakFlag = false;
- latch = new CountDownLatch(1);
-
- int numRequest = 10;
- List<CompletableFuture<ContainerCommandResponseProto>> computeResults
- = new ArrayList<>();
- // start new thread to send async requests
- Thread sendThread = new Thread(() -> {
- while (!breakFlag) {
+ int numSenderThreads = 10;
+ latch = new CountDownLatch(numSenderThreads);
+ List<CompletableFuture<ContainerCommandResponseProto>> computeResults =
+ Collections.synchronizedList(new ArrayList<>());
+ AtomicReference<Exception> firstSenderError = new AtomicReference<>();
+
+ for (int i = 0; i < numSenderThreads; i++) {
+ Thread sendThread = new Thread(() -> {
try {
- // use async interface for testing pending metrics
- for (int i = 0; i < numRequest; i++) {
- BlockID blockID = ContainerTestHelper.
-
getTestBlockID(container.getContainerInfo().getContainerID());
- ContainerProtos.ContainerCommandRequestProto smallFileRequest;
-
- smallFileRequest = ContainerTestHelper.getWriteSmallFileRequest(
- client.getPipeline(), blockID, 1024);
- CompletableFuture<ContainerProtos.ContainerCommandResponseProto>
- response =
- client.sendCommandAsync(smallFileRequest).getResponse();
- computeResults.add(response);
+ while (!breakFlag) {
+ try {
+ BlockID blockID = ContainerTestHelper.getTestBlockID(
+ container.getContainerInfo().getContainerID());
+ ContainerCommandRequestProto smallFileRequest =
+ ContainerTestHelper.getWriteSmallFileRequest(
+ client.getPipeline(), blockID, 1024);
+ computeResults.add(
+ client.sendCommandAsync(smallFileRequest).getResponse());
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ firstSenderError.compareAndSet(null, e);
+ break;
+ } catch (Exception e) {
+ firstSenderError.compareAndSet(null, e);
Review Comment:
Could we keep a small backoff between attempts? Otherwise, ten threads may
spin for 60 seconds on repeated failures and grow computeResults without bound.
##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/hdds/scm/TestXceiverClientMetrics.java:
##########
@@ -105,54 +107,61 @@ public void testMetrics(@TempDir Path metaDir) throws
Exception {
assertCounter("CreateContainerLatencyNumOps", 1L, containerMetrics);
breakFlag = false;
- latch = new CountDownLatch(1);
-
- int numRequest = 10;
- List<CompletableFuture<ContainerCommandResponseProto>> computeResults
- = new ArrayList<>();
- // start new thread to send async requests
- Thread sendThread = new Thread(() -> {
- while (!breakFlag) {
+ int numSenderThreads = 10;
+ latch = new CountDownLatch(numSenderThreads);
+ List<CompletableFuture<ContainerCommandResponseProto>> computeResults =
+ Collections.synchronizedList(new ArrayList<>());
+ AtomicReference<Exception> firstSenderError = new AtomicReference<>();
+
+ for (int i = 0; i < numSenderThreads; i++) {
+ Thread sendThread = new Thread(() -> {
try {
- // use async interface for testing pending metrics
- for (int i = 0; i < numRequest; i++) {
- BlockID blockID = ContainerTestHelper.
-
getTestBlockID(container.getContainerInfo().getContainerID());
- ContainerProtos.ContainerCommandRequestProto smallFileRequest;
-
- smallFileRequest = ContainerTestHelper.getWriteSmallFileRequest(
- client.getPipeline(), blockID, 1024);
- CompletableFuture<ContainerProtos.ContainerCommandResponseProto>
- response =
- client.sendCommandAsync(smallFileRequest).getResponse();
- computeResults.add(response);
+ while (!breakFlag) {
+ try {
+ BlockID blockID = ContainerTestHelper.getTestBlockID(
+ container.getContainerInfo().getContainerID());
+ ContainerCommandRequestProto smallFileRequest =
+ ContainerTestHelper.getWriteSmallFileRequest(
+ client.getPipeline(), blockID, 1024);
+ computeResults.add(
+ client.sendCommandAsync(smallFileRequest).getResponse());
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ firstSenderError.compareAndSet(null, e);
+ break;
+ } catch (Exception e) {
+ firstSenderError.compareAndSet(null, e);
+ }
}
-
- Thread.sleep(1000);
- } catch (Exception ignored) {
+ } finally {
+ latch.countDown();
}
+ });
+ sendThread.start();
+ }
+
+ try {
+ GenericTestUtils.waitFor(() -> {
+ // check if pending metric count is increased
+ MetricsRecordBuilder metric =
getMetrics(XceiverClientMetrics.SOURCE_NAME);
+ long pendingOps = getLongCounter("PendingOps", metric);
+ long pendingPutSmallFileOps =
getLongCounter("numPendingPutSmallFile", metric);
+
+ if (pendingOps > 0 && pendingPutSmallFileOps > 0) {
+ // reset break flag
+ breakFlag = true;
+ return true;
+ } else {
+ return false;
+ }
+ }, 10, 60000);
+ } catch (TimeoutException e) {
+ Exception senderError = firstSenderError.get();
+ if (senderError != null) {
+ e.addSuppressed(senderError);
}
-
- latch.countDown();
- });
- sendThread.start();
-
- GenericTestUtils.waitFor(() -> {
- // check if pending metric count is increased
- MetricsRecordBuilder metric =
- getMetrics(XceiverClientMetrics.SOURCE_NAME);
- long pendingOps = getLongCounter("PendingOps", metric);
- long pendingPutSmallFileOps =
- getLongCounter("numPendingPutSmallFile", metric);
-
- if (pendingOps > 0 && pendingPutSmallFileOps > 0) {
- // reset break flag
- breakFlag = true;
- return true;
- } else {
- return false;
- }
- }, 100, 60000);
+ throw e;
Review Comment:
On timeout, `breakFlag` is never set, so the ten non-daemon sender threads
may keep the test JVM alive. Could we stop and await them in a finally block?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]