smengcl commented on code in PR #11617:
URL: https://github.com/apache/ozone/pull/11617#discussion_r4693315543


##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/ScmConfig.java:
##########
@@ -102,6 +102,17 @@ public class ScmConfig extends ReconfigurableConfig {
   )
   private String ecPipelineChoosePolicyName;
 
+  @Config(key = "hdds.scm.block.allocation.prefer.client.local",
+      type = ConfigType.BOOLEAN,
+      defaultValue = "false",
+      tags = { ConfigTag.SCM, ConfigTag.PIPELINE, ConfigTag.PERFORMANCE },
+      description = "If true, when allocating a Ratis block for a client that 
runs on a datanode host, SCM prefers "
+          + "an open pipeline that contains that datanode, so one replica is 
local to the writer (like the HDFS "
+          + "first replica). Falls back to the pipeline choose policy when no 
such pipeline has a usable container. "
+          + "OM reads the same key to pass the client address to SCM on every 
block allocation."
+  )
+  private boolean preferClientLocalPipeline;

Review Comment:
   It's on by default now (and read by SCM only). 
`ozone.client.read.short-circuit` is a client setting that OM and SCM never 
see, so they can't tie the default to it, but defaulting to true covers the 
same case.
   



##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/pipeline/WritableRatisContainerProvider.java:
##########
@@ -143,14 +153,35 @@ public ContainerInfo getContainer(final long size,
 
   @Nullable
   private ContainerInfo getContainer(ReplicationConfig repConfig, String owner,
-      ExcludeList excludeList, PipelineRequestInformation req) {
+      ExcludeList excludeList, PipelineRequestInformation req, DatanodeDetails 
client) {
     // Acquire pipeline manager lock, to avoid any updates to pipeline
     // while allocate container happens. This is to avoid scenario like
     // mentioned in HDDS-5655.
     pipelineManager.acquireReadLock();
     try {
       List<Pipeline> availablePipelines = findPipelinesByState(repConfig,

Review Comment:
   The partition is now one pass over the OPEN pipelines that 
`findPipelinesByState` already returns, with no node list copies. A cache keyed 
by datanode would need invalidation on every pipeline state and leader change, 
so I'd leave it for a follow-up if profiling shows the scan matters.
   



##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/SCMBlockProtocolServer.java:
##########
@@ -235,12 +238,15 @@ public List<AllocatedBlock> allocateBlock(
           num, size, excludeList);
     }
     try {
+      final Node client = getClientNode(clientMachine);
+      final DatanodeDetails localDatanode = preferClientLocalPipeline && 
client instanceof DatanodeDetails
+          ? (DatanodeDetails) client : null;
       for (int i = 0; i < num; i++) {
-        AllocatedBlock block = scm.getScmBlockManager()
-            .allocateBlock(size, replicationConfig, owner, excludeList);
+        AllocatedBlock block = localDatanode == null
+            ? scm.getScmBlockManager().allocateBlock(size, replicationConfig, 
owner, excludeList)
+            : scm.getScmBlockManager().allocateBlock(size, replicationConfig, 
owner, excludeList, localDatanode);

Review Comment:
   Done in cac17fa8f8, `allocateBlock` now always gets `localDatanode`.
   



##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/ScmConfig.java:
##########
@@ -102,6 +102,17 @@ public class ScmConfig extends ReconfigurableConfig {
   )
   private String ecPipelineChoosePolicyName;
 
+  @Config(key = "hdds.scm.block.allocation.prefer.client.local",

Review Comment:
   The key now defaults to true, and only SCM reads it. OM always sends the 
client address, and a new optional `sortDatanodes` field in 
`AllocateScmBlockRequestProto` tells SCM whether to sort. So nothing needs to 
be set on OM, and a write that didn't ask for sorting no longer makes SCM sort 
or resolve the client. I kept the key on SCM as an off switch: on clusters 
where a gateway or another busy writer runs on a datanode host, locality puts 
that host's writes on its local datanode, and operators need a way out without 
a new release.
   



##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/ScmConfig.java:
##########
@@ -102,6 +102,17 @@ public class ScmConfig extends ReconfigurableConfig {
   )
   private String ecPipelineChoosePolicyName;
 
+  @Config(key = "hdds.scm.block.allocation.prefer.client.local",

Review Comment:
   Right, SCM only sees OM's caller. The config description now says so. With 
the space check (see the thread below), a gateway's local datanode falls back 
once it has no room for another container, and operators can turn the key off 
on SCM.
   



##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/pipeline/WritableRatisContainerProvider.java:
##########
@@ -153,14 +163,35 @@ public ContainerInfo getContainer(final long size,
 
   @Nullable
   private ContainerInfo getContainer(ReplicationConfig repConfig, String owner,
-      ExcludeList excludeList, PipelineRequestInformation req) {
+      ExcludeList excludeList, PipelineRequestInformation req, DatanodeDetails 
client) {
     // Acquire pipeline manager lock, to avoid any updates to pipeline
     // while allocate container happens. This is to avoid scenario like
     // mentioned in HDDS-5655.
     pipelineManager.acquireReadLock();
     try {
       List<Pipeline> availablePipelines = findPipelinesByState(repConfig,
           excludeList, Pipeline.PipelineState.OPEN);
+      if (client != null) {
+        // Try pipelines with a replica on the writer's datanode first, like 
the HDFS first replica.
+        // Among those, prefer pipelines led by that datanode, since Ratis 
writes go through the leader.
+        List<Pipeline> leaderPipelines = new ArrayList<>();
+        List<Pipeline> localPipelines = new ArrayList<>();
+        for (Pipeline pipeline : availablePipelines) {
+          if (client.getID().equals(pipeline.getLeaderId())) {
+            leaderPipelines.add(pipeline);
+          } else if (pipeline.getNodes().contains(client)) {
+            localPipelines.add(pipeline);
+          }
+        }
+        availablePipelines.removeAll(leaderPipelines);
+        availablePipelines.removeAll(localPipelines);
+        for (List<Pipeline> preferred : Arrays.asList(leaderPipelines, 
localPipelines)) {

Review Comment:
   Done. SCM now skips the preference when the client's datanode has no room 
for another container (`NodeManager.hasAvailableSpace`, the same slot check 
pipeline creation uses). It also skips it when more than one datanode is 
registered at the client's address, so they don't all pile onto one. I left out 
a load check, since SCM has no per-datanode write-load signal comparable to the 
xceiver count HDFS uses.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to