This is an automated email from the ASF dual-hosted git repository.

amaliujia 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 5fbecadb4ec HDDS-16910. Raftless PutBlock commit should only happen 
for pipelines whose datanodes all support committing PutBlock (#11561)
5fbecadb4ec is described below

commit 5fbecadb4ec4bae239d8c30b046d8e1a5d328ea9
Author: Rui Wang <[email protected]>
AuthorDate: Sat Oct 17 19:32:27 2026 +0800

    HDDS-16910. Raftless PutBlock commit should only happen for pipelines whose 
datanodes all support committing PutBlock (#11561)
---
 .../apache/hadoop/hdds/scm/OzoneClientConfig.java  |  3 ++-
 .../hdds/scm/storage/BlockDataStreamOutput.java    | 24 ++++++++++++++++++----
 .../scm/storage/TestBlockDataStreamOutput.java     | 18 ++++++++++++++++
 .../java/org/apache/hadoop/hdds/HDDSVersion.java   |  2 ++
 .../client/rpc/TestBlockDataStreamOutput.java      | 17 +++++++++------
 5 files changed, 53 insertions(+), 11 deletions(-)

diff --git 
a/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/OzoneClientConfig.java
 
b/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/OzoneClientConfig.java
index ade379c1a24..6dbf2103489 100644
--- 
a/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/OzoneClientConfig.java
+++ 
b/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/OzoneClientConfig.java
@@ -324,7 +324,8 @@ public class OzoneClientConfig {
           "instead of a separate WriteAsync PutBlock, so that it does not go 
through the Raft log: " +
           "StreamInitWithPutBlock is used so that datanodes commit PutBlock 
when the data stream closes, " +
           "and the PutBlock triggered by a flush in the middle of the stream 
is sent as a data stream command. " +
-          "All the datanodes must support committing PutBlock through the data 
stream.",
+          "It takes effect only for pipelines whose datanodes all support 
committing PutBlock through the data " +
+          "stream; otherwise PutBlock goes through the Raft log.",
       tags = ConfigTag.CLIENT)
   private boolean datastreamPutBlockWithoutRaftEnabled = false;
 
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 05a3623ada8..0b5562efd03 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
@@ -17,6 +17,7 @@
 
 package org.apache.hadoop.hdds.scm.storage;
 
+import static org.apache.hadoop.hdds.HDDSVersion.STREAM_PUTBLOCK_WITHOUT_RAFT;
 import static 
org.apache.hadoop.hdds.scm.storage.ContainerProtocolCalls.putBlockAsync;
 
 import com.google.common.base.Preconditions;
@@ -143,6 +144,8 @@ public class BlockDataStreamOutput implements 
ByteBufferStreamOutput {
   // buffers for which putBlock is yet to be executed
   private List<StreamBuffer> buffersForPutBlock;
   private boolean isDatastreamPipelineMode;
+  // Whether PutBlock is committed through the data stream instead of the Raft 
log; fixed for the stream lifetime.
+  private final boolean putBlockWithoutRaft;
 
   /**
    * Creates a new BlockDataStreamOutput.
@@ -162,6 +165,8 @@ public BlockDataStreamOutput(
     this.xceiverClientFactory = xceiverClientManager;
     this.config = config;
     this.isDatastreamPipelineMode = config.isDatastreamPipelineMode();
+    this.putBlockWithoutRaft = config.isDatastreamPutBlockWithoutRaftEnabled()
+        && allDatanodesSupportStreamPutBlock(pipeline);
     this.syncSize = config.getDataStreamSyncSize();
     this.blockID = new AtomicReference<>(blockID);
     KeyValue keyValue =
@@ -198,6 +203,17 @@ public BlockDataStreamOutput(
     metrics = XceiverClientManager.getXceiverClientMetrics();
   }
 
+  private static boolean allDatanodesSupportStreamPutBlock(Pipeline pipeline) {
+    for (DatanodeDetails dn : pipeline.getNodes()) {
+      if (!STREAM_PUTBLOCK_WITHOUT_RAFT.isSupportedBy(dn.getCurrentVersion())) 
{
+        LOG.debug("Datanode {} at version {} does not support {}; PutBlock 
goes through Raft for pipeline {}",
+            dn, dn.getCurrentVersion(), STREAM_PUTBLOCK_WITHOUT_RAFT, 
pipeline.getId());
+        return false;
+      }
+    }
+    return true;
+  }
+
   private DataStreamOutput setupStream(Pipeline pipeline) throws IOException {
     for (DatanodeDetails dn : pipeline.getNodes()) {
       if (!dn.hasPort(DatanodeDetails.Port.Name.RATIS_DATASTREAM)) {
@@ -216,7 +232,7 @@ private DataStreamOutput setupStream(Pipeline pipeline) 
throws IOException {
     // TODO: The datanode UUID is not used meaningfully, consider deprecating
     //  it or remove it completely if possible
     String id = pipeline.getFirstNode().getUuidString();
-    ContainerProtos.Type streamInitType = 
config.isDatastreamPutBlockWithoutRaftEnabled()
+    ContainerProtos.Type streamInitType = putBlockWithoutRaft
         ? ContainerProtos.Type.StreamInitWithPutBlock
         : ContainerProtos.Type.StreamInit;
     ContainerProtos.ContainerCommandRequestProto.Builder builder =
@@ -428,7 +444,7 @@ public void executePutBlock(boolean close,
       byteBufferList = null;
     }
     waitFuturesComplete();
-    if (close && config.isDatastreamPutBlockWithoutRaftEnabled()) {
+    if (close && putBlockWithoutRaft) {
       // Wait for boundary PutBlock(s) before appending the stream-close 
PutBlock.
       waitPutBlockCommandFuturesComplete();
     }
@@ -453,12 +469,12 @@ public void executePutBlock(boolean close,
           }
         }
       });
-      if (config.isDatastreamPutBlockWithoutRaftEnabled()) {
+      if (putBlockWithoutRaft) {
         // PutBlock is supposed to be committed after the data stream close so 
there
         // is no need to continue.
         return;
       }
-    } else if (config.isDatastreamPutBlockWithoutRaftEnabled()) {
+    } else if (putBlockWithoutRaft) {
       executePutBlockCommand(blockData, byteBufferList);
       return;
     }
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 b9de99ad016..c998e6e7ae7 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
@@ -28,6 +28,7 @@
 import java.util.ArrayList;
 import java.util.List;
 import org.apache.commons.lang3.RandomUtils;
+import org.apache.hadoop.hdds.HDDSVersion;
 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.Type;
@@ -89,6 +90,23 @@ void streamInitTypeFollowsClientConfig(boolean 
putBlockWithoutRaft) throws Excep
     }
   }
 
+  @Test
+  void putBlockGoesThroughRaftWhenDatanodeDoesNotSupportStreamPutBlock() 
throws Exception {
+    MockDatanodePipeline pipeline = new MockDatanodePipeline();
+    
pipeline.getPipeline().getNodes().get(1).setCurrentVersion(HDDSVersion.ZDU);
+    OzoneClientConfig config = createConfig();
+    config.setDatastreamPutBlockWithoutRaftEnabled(true);
+    byte[] data = randomBytes(400);
+    try (BlockDataStreamOutput stream = createStream(pipeline, config)) {
+      assertEquals(Type.StreamInit, pipeline.getStreamInitType());
+      stream.write(ByteBuffer.wrap(data), 0, data.length);
+      assertEquals(1, pipeline.getReceivedPutBlocks().size());
+    }
+    assertEquals(0, pipeline.getReceivedCommands().size());
+    assertEquals(2, pipeline.getReceivedPutBlocks().size());
+    assertArrayEquals(data, pipeline.getAllReceivedData());
+  }
+
   @Test
   void writeSubChunkThenClose() throws Exception {
     MockDatanodePipeline pipeline = new MockDatanodePipeline();
diff --git 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HDDSVersion.java 
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HDDSVersion.java
index 1a3e2223436..01e4a11ad62 100644
--- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HDDSVersion.java
+++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HDDSVersion.java
@@ -42,6 +42,8 @@ public enum HDDSVersion implements ComponentVersion {
 
   ZDU(100, "Version that supports zero downtime upgrade"),
 
+  STREAM_PUTBLOCK_WITHOUT_RAFT(101, "PutBlock can be committed through a Ratis 
data stream without the Raft log."),
+
   UNKNOWN_VERSION(-1, "Used when a version cannot be deserialized to any 
version recognized by this" +
       " component, which may indicate it came from a component in a newer 
version");
 
diff --git 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/client/rpc/TestBlockDataStreamOutput.java
 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/client/rpc/TestBlockDataStreamOutput.java
index ca56caa2191..95ef5ebe8b2 100644
--- 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/client/rpc/TestBlockDataStreamOutput.java
+++ 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/client/rpc/TestBlockDataStreamOutput.java
@@ -186,6 +186,12 @@ static OzoneClientConfig 
newClientConfig(ConfigurationSource source,
     return clientConfig;
   }
 
+  /** Whether PutBlock is committed through the data stream for this test 
cluster (config plus DN version). */
+  private static boolean isStreamPutBlockWithoutRaftActive(OzoneClientConfig 
config) {
+    return config.isDatastreamPutBlockWithoutRaftEnabled()
+        && 
HDDSVersion.STREAM_PUTBLOCK_WITHOUT_RAFT.isSupportedBy(DN_OLD_VERSION);
+  }
+
   static OzoneClient newClient(OzoneConfiguration conf,
                                OzoneClientConfig config) throws IOException {
     OzoneConfiguration copy = new OzoneConfiguration(conf);
@@ -218,7 +224,7 @@ public void testStreamWrite(int dataLength, boolean 
putBlockWithoutRaft) throws
       testWrite(client, dataLength);
       // Forced container close before stream close relies on async PutBlock 
recovery;
       // that path is not used when PutBlock is committed only on data stream 
close.
-      if (!putBlockWithoutRaft) {
+      if (!isStreamPutBlockWithoutRaftActive(config)) {
         testWriteWithFailure(client, dataLength);
       }
     }
@@ -294,11 +300,10 @@ public void testPutBlockAtBoundary(boolean flushDelay, 
boolean putBlockWithoutRa
       key.close();
       // Since data length is 500, first putBlock will be at 400 (flush 
boundary).
       // Close commits via WriteAsync PutBlock only when PutBlock does not go 
through the data stream.
-      int expectedPutBlocks = putBlockWithoutRaft ? 1 : 2;
-      assertEquals(
-          metrics.getContainerOpCountMetrics(ContainerProtos.Type.PutBlock),
-          putBlockCount + expectedPutBlocks);
-      if (putBlockWithoutRaft) {
+      int expectedPutBlocks = isStreamPutBlockWithoutRaftActive(config) ? 1 : 
2;
+      assertEquals(putBlockCount + expectedPutBlocks,
+          metrics.getContainerOpCountMetrics(ContainerProtos.Type.PutBlock));
+      if (isStreamPutBlockWithoutRaftActive(config)) {
         // No PutBlock went through Raft, so there is no log index to use as 
block commit sequence id.
         assertEquals(0, entry.getBlockID().getBlockCommitSequenceId());
       } else {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to