This is an automated email from the ASF dual-hosted git repository.
adoroszlai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git
The following commit(s) were added to refs/heads/master by this push:
new 9d0b20c9a9a HDDS-17889. respFuture is already completed in
writeChunkToContainer (#12129)
9d0b20c9a9a is described below
commit 9d0b20c9a9afd0999fc4e2457b4977a009ea05ae
Author: Tsz-Wo Nicholas Sze <[email protected]>
AuthorDate: Sun Nov 22 23:27:19 2026 -0800
HDDS-17889. respFuture is already completed in writeChunkToContainer
(#12129)
---
.../hadoop/hdds/scm/storage/BlockOutputStream.java | 26 ++++-----
.../hdds/scm/storage/ECBlockOutputStream.java | 24 +-------
.../storage/TestBlockOutputStreamCorrectness.java | 67 +++++++++++++++++++++-
3 files changed, 78 insertions(+), 39 deletions(-)
diff --git
a/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/BlockOutputStream.java
b/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/BlockOutputStream.java
index ff6fddf0719..73711414d54 100644
---
a/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/BlockOutputStream.java
+++
b/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/BlockOutputStream.java
@@ -597,11 +597,7 @@ CompletableFuture<PutBlockResult> executePutBlock(boolean
close,
asyncReply = putBlockAsync(xceiverClient, blockData, close ||
isBlockFull, tokenString, containerAutoCreate());
CompletableFuture<ContainerCommandResponseProto> future =
asyncReply.getResponse();
flushFuture = future.thenCombineAsync(putBlockReplyHandled, (e, ignored)
-> {
- try {
- validateResponse(e);
- } catch (IOException sce) {
- throw new CompletionException(sce);
- }
+ validateResponse(e, true);
// if the ioException is not set, putBlock is successful
if (getIoException() == null && !force) {
handleSuccessfulPutBlock(e.getPutBlock().getCommittedBlockLength(),
@@ -800,21 +796,25 @@ public void close() throws IOException {
void waitOnFlushFuture() throws InterruptedException, ExecutionException {
}
- void validateResponse(
- ContainerCommandResponseProto responseProto)
- throws IOException {
+ void validateResponse(ContainerCommandResponseProto responseProto, boolean
throwCompletionException) {
try {
// if the ioException is already set, it means a prev request has failed
// just throw the exception. The current operation will fail with the
// original error
IOException exception = getIoException();
if (exception != null) {
- throw exception;
+ if (throwCompletionException) {
+ throw new CompletionException(exception);
+ } else {
+ return;
+ }
}
ContainerProtocolCalls.validateContainerResponse(responseProto);
} catch (StorageContainerException sce) {
setIoException(sce);
- throw sce;
+ if (throwCompletionException) {
+ throw new CompletionException(sce);
+ }
}
}
@@ -966,11 +966,7 @@ private CompletableFuture<PutBlockResult>
writeChunkToContainer(
CompletableFuture<ContainerCommandResponseProto>
respFuture = asyncReply.getResponse();
validateFuture = respFuture.thenCombineAsync(putBlockReplyHandled, (e,
ignored) -> {
- try {
- validateResponse(e);
- } catch (IOException sce) {
- respFuture.completeExceptionally(sce);
- }
+ validateResponse(e, true);
// if the ioException is not set, putBlock is successful
if (getIoException() == null && putBlockPiggybacking) {
handleSuccessfulPutBlock(e.getWriteChunk().getCommittedBlockLength(),
diff --git
a/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/ECBlockOutputStream.java
b/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/ECBlockOutputStream.java
index 5f33e02f4d5..0773b3d455c 100644
---
a/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/ECBlockOutputStream.java
+++
b/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/ECBlockOutputStream.java
@@ -299,11 +299,7 @@ public CompletableFuture<PutBlockResult>
executePutBlock(boolean close,
CompletableFuture<ContainerProtos.ContainerCommandResponseProto> future =
asyncReply.getResponse();
flushFuture = future.thenApplyAsync(e -> {
- try {
- validateResponse(e);
- } catch (IOException sce) {
- throw new CompletionException(sce);
- }
+ validateResponse(e, false);
// if the ioException is not set, putBlock is successful
if (getIoException() == null) {
BlockID responseBlockID = BlockID.getFromProtobuf(
@@ -356,22 +352,4 @@ public CompletableFuture<PutBlockResult>
executePutBlock(boolean close,
public DatanodeDetails getDatanodeDetails() {
return datanodeDetails;
}
-
- @Override
- void validateResponse(
- ContainerProtos.ContainerCommandResponseProto responseProto)
- throws IOException {
- try {
- // if the ioException is already set, it means a prev request has failed
- // just throw the exception. The current operation will fail with the
- // original error
- IOException exception = getIoException();
- if (exception != null) {
- return;
- }
- ContainerProtocolCalls.validateContainerResponse(responseProto);
- } catch (IOException sce) {
- setIoException(sce);
- }
- }
}
diff --git
a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestBlockOutputStreamCorrectness.java
b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestBlockOutputStreamCorrectness.java
index b9ea29066cc..ca5e1f51a4b 100644
---
a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestBlockOutputStreamCorrectness.java
+++
b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestBlockOutputStreamCorrectness.java
@@ -30,6 +30,7 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import java.io.IOException;
+import java.nio.ByteBuffer;
import java.util.ArrayDeque;
import java.util.Collections;
import java.util.Deque;
@@ -37,6 +38,7 @@
import java.util.Map;
import java.util.concurrent.AbstractExecutorService;
import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
@@ -152,6 +154,61 @@ void
testUnackedBuffersFollowAckedLengthWhenReplyHandlersRunLate() throws IOExce
assertThatThrownBy(outputStream::close).isInstanceOf(IOException.class);
}
+ /**
+ * A failed WriteChunk reply must complete the returned future exceptionally.
+ * A later WriteChunk must also fail, with the earlier error, even if its
own reply is successful.
+ */
+ @Test
+ void testFailedWriteChunkCompletesExceptionally() throws Exception {
+ final MockXceiverClientSpi xceiverClient = new
MockXceiverClientSpi(MockPipeline.createRatisPipeline());
+ final BlockOutputStream outputStream = createBlockOutputStream(new
BufferPool(BUFFER_SIZE, 16), xceiverClient,
+ newFixedThreadPool(2));
+ try {
+ xceiverClient.setReplyResult(Result.CLOSED_CONTAINER_IO);
+
assertFailed(outputStream.writeChunkToContainer(ChunkBuffer.wrap(ByteBuffer.wrap(DATA,
0, BUFFER_SIZE))));
+ final IOException ioe = outputStream.getIoException();
+ assertThat(ioe).isNotNull();
+
+ xceiverClient.setReplyResult(Result.SUCCESS);
+ assertFailed(outputStream.writeChunkToContainer(
+ ChunkBuffer.wrap(ByteBuffer.wrap(DATA, BUFFER_SIZE,
BUFFER_SIZE).slice())));
+ assertThat(outputStream.getIoException()).isSameAs(ioe);
+ } finally {
+ outputStream.cleanup(false);
+ }
+ }
+
+ /**
+ * For EC, a failed WriteChunk reply must also complete the returned future
exceptionally,
+ * and set the IOException checked by the EC key output stream.
+ */
+ @Test
+ void testFailedEcWriteChunkCompletesExceptionally() throws Exception {
+ final ECReplicationConfig replicationConfig = new ECReplicationConfig(3,
2);
+ final DatanodeDetails datanodeDetails =
MockDatanodeDetails.randomDatanodeDetails();
+ final Pipeline pipeline = Pipeline.newBuilder()
+ .setId(datanodeDetails.getID())
+ .setReplicationConfig(replicationConfig)
+ .setNodes(ImmutableList.of(datanodeDetails))
+ .setState(Pipeline.PipelineState.CLOSED)
+ .setReplicaIndexes(ImmutableMap.of(datanodeDetails, 2))
+ .build();
+ final MockXceiverClientSpi xceiverClient = new
MockXceiverClientSpi(pipeline);
+ xceiverClient.setReplyResult(Result.CLOSED_CONTAINER_IO);
+ final ECBlockOutputStream outputStream = createECBlockOutputStream(new
OzoneClientConfig(), replicationConfig,
+ new BlockID(1, 1), xceiverClient, true);
+ try {
+ assertFailed(outputStream.write(ByteBuffer.wrap(DATA, 0, BUFFER_SIZE)));
+ assertThat(outputStream.getIoException()).isNotNull();
+ } finally {
+ outputStream.cleanup(false);
+ }
+ }
+
+ private static void
assertFailed(CompletableFuture<ContainerCommandResponseProto> future) {
+ assertThatThrownBy(future::get).isInstanceOf(ExecutionException.class);
+ }
+
/**
* Tests an EC offline reconstruction scenario in which none of the
ChunkInfo in an EC stripe have stripeChecksum.
* Such ChunkInfo will exist for any EC data that was written in a version
in which the ChunkInfo protobuf message did
@@ -293,9 +350,17 @@ private BlockOutputStream
createBlockOutputStream(BufferPool bufferPool, Xceiver
private ECBlockOutputStream createECBlockOutputStream(OzoneClientConfig
clientConfig,
ECReplicationConfig repConfig, BlockID blockID, Pipeline pipeline,
boolean containerAutoCreate) throws IOException {
+ return createECBlockOutputStream(clientConfig, repConfig, blockID, new
MockXceiverClientSpi(pipeline),
+ containerAutoCreate);
+ }
+
+ private ECBlockOutputStream createECBlockOutputStream(OzoneClientConfig
clientConfig,
+ ECReplicationConfig repConfig, BlockID blockID, XceiverClientSpi
xceiverClient,
+ boolean containerAutoCreate) throws IOException {
+ final Pipeline pipeline = xceiverClient.getPipeline();
final XceiverClientManager xcm = mock(XceiverClientManager.class);
when(xcm.acquireClient(any()))
- .thenReturn(new MockXceiverClientSpi(pipeline));
+ .thenReturn(xceiverClient);
ContainerClientMetrics clientMetrics = ContainerClientMetrics.acquire();
StreamBufferArgs streamBufferArgs =
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]