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 c842f7d7183 HDDS-17682. Stop BlockDataStreamOutput#executePutBlock
recursive calls when datastream close fails (#11945)
c842f7d7183 is described below
commit c842f7d71835200eaaa39e61a718b2b0fe3105bd
Author: Rui Wang <[email protected]>
AuthorDate: Fri Nov 6 04:27:42 2026 +0800
HDDS-17682. Stop BlockDataStreamOutput#executePutBlock recursive calls when
datastream close fails (#11945)
---
.../hdds/scm/storage/BlockDataStreamOutput.java | 22 ++++++++++------------
.../hdds/scm/storage/MockDatanodePipeline.java | 21 ++++++++++++++++++++-
.../scm/storage/TestBlockDataStreamOutput.java | 15 +++++++++++++++
3 files changed, 45 insertions(+), 13 deletions(-)
diff --git
a/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/BlockDataStreamOutput.java
b/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/BlockDataStreamOutput.java
index 9bf727841aa..c25c66ace8d 100644
---
a/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/BlockDataStreamOutput.java
+++
b/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/BlockDataStreamOutput.java
@@ -459,18 +459,16 @@ public void executePutBlock(boolean sync, boolean close)
throws IOException {
final ContainerCommandRequestProto putBlockRequest
= ContainerProtocolCalls.getPutBlockRequest(
xceiverClient.getPipeline(), blockData, false, true,
tokenString);
- dataStreamCloseReply = executePutBlockClose(putBlockRequest,
- PUT_BLOCK_REQUEST_LENGTH_MAX, out);
- dataStreamCloseReply.whenComplete((reply, e) -> {
- if (e != null || reply == null || !reply.isSuccess()) {
- LOG.warn("Failed executePutBlockClose, reply=" + reply, e);
- try {
- executePutBlock(false, true);
- } catch (IOException ex) {
- throw new CompletionException(ex);
- }
- }
- });
+ dataStreamCloseReply = executePutBlockClose(putBlockRequest,
PUT_BLOCK_REQUEST_LENGTH_MAX, out)
+ .whenComplete((reply, e) -> {
+ if (e != null || reply == null || !reply.isSuccess()) {
+ LOG.warn("Failed executePutBlockClose, reply=" + reply, e);
+ final IOException ioe = new IOException("Failed to close the
data stream for blockID " + blockID
+ + ", reply=" + reply, e);
+ setIoException(ioe);
+ throw new CompletionException(ioe);
+ }
+ });
if (putBlockWithoutRaft) {
// PutBlock is supposed to be committed after the data stream close so
there
// is no need to continue.
diff --git
a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/MockDatanodePipeline.java
b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/MockDatanodePipeline.java
index c3cb97b7aa3..4cd480f3798 100644
---
a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/MockDatanodePipeline.java
+++
b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/MockDatanodePipeline.java
@@ -98,6 +98,9 @@ public class MockDatanodePipeline {
private volatile Supplier<Throwable> watchFailure = null;
private volatile int watchFailAfter = Integer.MAX_VALUE;
+ private volatile boolean streamCloseFailure;
+ private final AtomicInteger streamCloseCount = new AtomicInteger(0);
+
public MockDatanodePipeline() throws IOException {
this(new BlockID(1, 1));
}
@@ -190,7 +193,12 @@ public MockDatanodePipeline(BlockID blockID) throws
IOException {
receivedChunks.remove(receivedChunks.size() - 1);
}
src.position(src.limit());
- return CompletableFuture.completedFuture(dataStreamReply(size));
+ streamCloseCount.incrementAndGet();
+ final DataStreamReply reply = dataStreamReply(size);
+ if (streamCloseFailure) {
+ when(reply.isSuccess()).thenReturn(false);
+ }
+ return CompletableFuture.completedFuture(reply);
}
}
int count = chunkCount.incrementAndGet();
@@ -270,6 +278,11 @@ public Type getStreamInitType() {
return streamInitType;
}
+ /** @return the number of writes with {@link StandardWriteOption#CLOSE}. */
+ public int getStreamCloseCount() {
+ return streamCloseCount.get();
+ }
+
/** Concatenate all received chunks into a single byte array. */
public byte[] getAllReceivedData() {
int total = receivedChunks.stream().mapToInt(c -> c.length).sum();
@@ -302,6 +315,12 @@ public MockDatanodePipeline failWatchAfter(int n,
Supplier<Throwable> err) {
return this;
}
+ /** Reply to the write with {@link StandardWriteOption#CLOSE} with an
unsuccessful reply. */
+ public MockDatanodePipeline failStreamClose() {
+ this.streamCloseFailure = true;
+ return this;
+ }
+
/** Reply to stream commands without a payload, as a datanode which does not
handle them does. */
public MockDatanodePipeline withUnsupportedCommand() {
this.commandUnsupported = true;
diff --git
a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestBlockDataStreamOutput.java
b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestBlockDataStreamOutput.java
index 7d742d8d142..3001a17616f 100644
---
a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestBlockDataStreamOutput.java
+++
b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestBlockDataStreamOutput.java
@@ -314,6 +314,21 @@ void closeAfterWriteFailureThrows() throws Exception {
.hasRootCauseMessage("chunk write failed due to injected failure");
}
+ @ParameterizedTest
+ @ValueSource(booleans = {false, true})
+ void failedStreamCloseIsNotRetried(boolean putBlockWithoutRaft) throws
Exception {
+ MockDatanodePipeline pipeline = new
MockDatanodePipeline().failStreamClose();
+ OzoneClientConfig config = createConfig();
+ config.setDatastreamPutBlockWithoutRaftEnabled(putBlockWithoutRaft);
+ BlockDataStreamOutput stream = createStream(pipeline, config);
+ byte[] data = randomBytes(50);
+ stream.write(ByteBuffer.wrap(data), 0, data.length);
+
+ IOException e = assertThrows(IOException.class, stream::close);
+ assertThat(e).hasStackTraceContaining("Failed to close the data stream");
+ assertEquals(1, pipeline.getStreamCloseCount(), "A failed stream close
must not be retried");
+ }
+
@Test
void writeAfterCloseThrows() throws Exception {
MockDatanodePipeline pipeline = new MockDatanodePipeline();
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]