Skip to content
Open
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 @@ -24,12 +24,14 @@

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.hadoop.hdds.client.BlockID;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos;
import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandRequestProto;
import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandResponseProto;
import org.apache.hadoop.hdds.scm.container.common.helpers.ContainerWithPipeline;
Expand Down Expand Up @@ -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 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should keep the try inside the loop? With the current structure, the first transient error permanently stops the sender, whereas the previous code retried.

@shuan1026 shuan1026 Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. try/catch is back inside the while loop.

// 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;
}

// blocking until we stop sending async requests
latch.await();
Expand All @@ -167,6 +176,12 @@ public void testMetrics(@TempDir Path metaDir) throws Exception {
return true;
}, 100, 60000);

GenericTestUtils.waitFor(() -> {
MetricsRecordBuilder metric = getMetrics(XceiverClientMetrics.SOURCE_NAME);
long pendingOps = getLongCounter("PendingOps", metric);
long pendingPutSmallFileOps = getLongCounter("numPendingPutSmallFile", metric);
return pendingOps == 0 && pendingPutSmallFileOps == 0;
}, 10, 5000);
// the counter value of pending metrics should be decreased to 0
containerMetrics = getMetrics(XceiverClientMetrics.SOURCE_NAME);
assertCounter("PendingOps", 0L, containerMetrics);
Expand Down