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 773c030dbc0 HDDS-17606. Disable short-circuit read of EC key (#12089)
773c030dbc0 is described below

commit 773c030dbc0a29d246d6b64599158abb1982008e
Author: Gargi Jaiswal <[email protected]>
AuthorDate: Fri Nov 20 00:57:50 2026 +0530

    HDDS-17606. Disable short-circuit read of EC key (#12089)
---
 .../hadoop/hdds/scm/XceiverClientManager.java      | 12 +++-
 .../hdds/scm/TestXceiverClientManagerSC.java       | 81 ++++++++++++++++++++++
 2 files changed, 91 insertions(+), 2 deletions(-)

diff --git 
a/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/XceiverClientManager.java
 
b/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/XceiverClientManager.java
index 5d5e35b1bf3..4baa72aff69 100644
--- 
a/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/XceiverClientManager.java
+++ 
b/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/XceiverClientManager.java
@@ -161,7 +161,8 @@ public Cache<String, XceiverClientSpi> getClientCache() {
    * the cached otherwise create a new one.
    *
    * @param pipeline the container pipeline for the client connection
-   * @param allowShortCircuit create a short-circuit read client or not if 
applicable
+   * @param allowShortCircuit create a short-circuit read client or not if 
applicable;
+   *     ignored for EC pipelines and EC replica reads, which always use a 
gRPC client
    * @return XceiverClientSpi connected to a container
    * @throws IOException if a XceiverClientSpi cannot be acquired
    */
@@ -260,6 +261,11 @@ protected XceiverClientSpi getClient(Pipeline pipeline, 
boolean topologyAware, b
     }
   }
 
+  private static boolean isECReplica(Pipeline pipeline) {
+    return pipeline.getType() == HddsProtos.ReplicationType.STAND_ALONE
+        && pipeline.getReplicaIndexes().values().stream().anyMatch(index -> 
index > 0);
+  }
+
   private String getPipelineCacheKey(Pipeline pipeline, boolean topologyAware, 
boolean allowShortCircuit) {
     StringBuilder key = new StringBuilder()
         
.append(pipeline.getId().getId()).append('-').append(pipeline.getType());
@@ -267,7 +273,9 @@ private String getPipelineCacheKey(Pipeline pipeline, 
boolean topologyAware, boo
     DatanodeDetails localDN = null;
     boolean shortCircuitPipeline = false;
 
-    if ((!isEC) && allowShortCircuit && isShortCircuitEnabled()) {
+    // Short-circuit reads are not supported for EC keys. EC key reads use a 
single-node STAND_ALONE pipeline per
+    // replica, which is recognized by its non-zero replica index.
+    if (allowShortCircuit && !isEC && isShortCircuitEnabled() && 
!isECReplica(pipeline)) {
       int port = 0;
       InetSocketAddress localAddr = null;
       for (DatanodeDetails dn : pipeline.getNodes()) {
diff --git 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/hdds/scm/TestXceiverClientManagerSC.java
 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/hdds/scm/TestXceiverClientManagerSC.java
index 996fb8e6457..6f5d5eb275b 100644
--- 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/hdds/scm/TestXceiverClientManagerSC.java
+++ 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/hdds/scm/TestXceiverClientManagerSC.java
@@ -18,17 +18,29 @@
 package org.apache.hadoop.hdds.scm;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.io.File;
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.hadoop.hdds.client.ECReplicationConfig;
+import org.apache.hadoop.hdds.client.StandaloneReplicationConfig;
 import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.hdds.protocol.DatanodeDetails;
 import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
 import org.apache.hadoop.hdds.scm.XceiverClientManager.ScmClientConfig;
 import 
org.apache.hadoop.hdds.scm.container.common.helpers.ContainerWithPipeline;
+import org.apache.hadoop.hdds.scm.pipeline.Pipeline;
+import org.apache.hadoop.hdds.scm.pipeline.PipelineID;
 import 
org.apache.hadoop.hdds.scm.protocolPB.StorageContainerLocationProtocolClientSideTranslatorPB;
 import org.apache.hadoop.io.IOUtils;
 import org.apache.hadoop.net.unix.DomainSocket;
+import org.apache.hadoop.ozone.HddsDatanodeService;
 import org.apache.hadoop.ozone.MiniOzoneCluster;
 import org.apache.hadoop.ozone.OzoneConsts;
 import org.apache.hadoop.ozone.container.common.SCMTestUtils;
@@ -37,6 +49,8 @@
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.Timeout;
 import org.junit.jupiter.api.io.TempDir;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.EnumSource;
 
 /**
  * Test for short-circuit enabled XceiverClientManager.
@@ -104,4 +118,71 @@ public void testAllocateShortCircuitClient() throws 
IOException {
       assertTrue(client3 instanceof XceiverClientGrpc);
     }
   }
+
+  /**
+   * The client a read is expected to get. EC reads, both the single-replica 
pipeline that
+   * {@code ECBlockInputStream} builds and the full EC pipeline, stay on gRPC. 
A standalone pipeline with no replica
+   * index short-circuits.
+   */
+  private enum ReadClient {
+    EC_REPLICA(XceiverClientGrpc.class),
+    EC_PIPELINE(ECXceiverClientGrpc.class),
+    STANDALONE(XceiverClientShortCircuit.class);
+
+    private final Class<? extends XceiverClientSpi> clientType;
+
+    ReadClient(Class<? extends XceiverClientSpi> clientType) {
+      this.clientType = clientType;
+    }
+  }
+
+  @ParameterizedTest
+  @EnumSource(ReadClient.class)
+  public void testReadClientType(ReadClient readClient) throws IOException {
+    try (XceiverClientManager clientManager = new XceiverClientManager(config,
+        config.getObject(ScmClientConfig.class), null)) {
+      XceiverClientSpi client = 
clientManager.acquireClientForReadData(pipeline(readClient), true);
+      assertInstanceOf(readClient.clientType, client);
+      clientManager.releaseClient(client, true);
+    }
+  }
+
+  private static Pipeline pipeline(ReadClient readClient) {
+    DatanodeDetails dn = 
cluster.getHddsDatanodes().get(0).getDatanodeDetails();
+    switch (readClient) {
+    case EC_REPLICA:
+      // same pipeline as ECBlockInputStream creates to read one replica of an 
EC block group
+      return Pipeline.newBuilder()
+          
.setReplicationConfig(StandaloneReplicationConfig.getInstance(HddsProtos.ReplicationFactor.ONE))
+          .setNodes(Collections.singletonList(dn))
+          .setId(dn.getID())
+          .setReplicaIndexes(Collections.singletonMap(dn, 1))
+          .setState(Pipeline.PipelineState.CLOSED)
+          .build();
+    case EC_PIPELINE:
+      List<DatanodeDetails> nodes = new ArrayList<>();
+      Map<DatanodeDetails, Integer> replicaIndexes = new HashMap<>();
+      for (HddsDatanodeService datanode : cluster.getHddsDatanodes()) {
+        DatanodeDetails node = datanode.getDatanodeDetails();
+        nodes.add(node);
+        replicaIndexes.put(node, nodes.size());
+      }
+      return Pipeline.newBuilder()
+          .setReplicationConfig(new ECReplicationConfig(2, 1))
+          .setNodes(nodes)
+          .setId(PipelineID.randomId())
+          .setReplicaIndexes(replicaIndexes)
+          .setState(Pipeline.PipelineState.CLOSED)
+          .build();
+    case STANDALONE:
+      return Pipeline.newBuilder()
+          
.setReplicationConfig(StandaloneReplicationConfig.getInstance(HddsProtos.ReplicationFactor.ONE))
+          .setNodes(Collections.singletonList(dn))
+          .setId(PipelineID.randomId())
+          .setState(Pipeline.PipelineState.CLOSED)
+          .build();
+    default:
+      throw new IllegalStateException("Unexpected read client " + readClient);
+    }
+  }
 }


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

Reply via email to