szetszwo commented on code in PR #11235:
URL: https://github.com/apache/ozone/pull/11235#discussion_r4554475219


##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/key/OMKeyRequest.java:
##########
@@ -214,32 +215,22 @@ protected List<OmKeyLocationInfo> allocateBlock(
     final int numBlocks = (int) 
Math.min(ozoneManager.getPreallocateBlocksMax(),
         (requestedSize - 1) / (scmBlockSize * dataGroupSize) + 1);
 
-    final String scmClientMachine;
-    final String omClientMachine;
-    // Sorted order cached by datanode set so blocks whose pipelines share the
-    // same datanodes are sorted once (mirrors the read path's caching). Keyed 
by
-    // the UUID set so it is order-insensitive and dedups across pipelines.
-    final Map<Set<String>, List<? extends DatanodeDetails>> sortedByNodes;
     final String remoteAddress = userInfo.getRemoteAddress();
     final NetworkTopology clusterMap = shouldSortDatanodes
         && keyManager.isSortDatanodesForWriteEnabled()
         ? ozoneManager.getClusterMapAllowNull() : null;
-    if (!shouldSortDatanodes) {
-      scmClientMachine = "";
-      omClientMachine = "";
-      sortedByNodes = null;
-    } else if (clusterMap != null && !remoteAddress.isEmpty()) {
-      // Sort in OM: SCM skips sorting (empty machine), OM sorts by 
remoteAddress.
-      scmClientMachine = "";
-      omClientMachine = remoteAddress;
-      sortedByNodes = new HashMap<>();
-    } else {
-      // Sort in SCM (or keep order when remoteAddress is empty, since SCM 
skips
-      // sorting for an empty client machine).
-      scmClientMachine = remoteAddress;
-      omClientMachine = "";
-      sortedByNodes = null;
-    }
+    // Resolve the client once per request, before the block loop, so the
+    // DNS-to-switch mapping is consulted at most once.
+    final Node omClient = clusterMap != null && !remoteAddress.isEmpty()

Review Comment:
   - We probably need shouldSortDatanodes == true?  BTW, the previous 
if-then-else is easier to understand.
   - We could use a MemoizedSupplier to do lazy initialization
   ```diff
   @@ -215,7 +220,7 @@ protected List<OmKeyLocationInfo> allocateBlock(
            (requestedSize - 1) / (scmBlockSize * dataGroupSize) + 1);
    
        final String scmClientMachine;
   -    final String omClientMachine;
   +    final Supplier<Node> omClient;
        // Sorted order cached by datanode set so blocks whose pipelines share 
the
        // same datanodes are sorted once (mirrors the read path's caching). 
Keyed by
        // the UUID set so it is order-insensitive and dedups across pipelines.
   @@ -226,18 +231,18 @@ protected List<OmKeyLocationInfo> allocateBlock(
            ? ozoneManager.getClusterMapAllowNull() : null;
        if (!shouldSortDatanodes) {
          scmClientMachine = "";
   -      omClientMachine = "";
   +      omClient = null;
          sortedByNodes = null;
        } else if (clusterMap != null && !remoteAddress.isEmpty()) {
          // Sort in OM: SCM skips sorting (empty machine), OM sorts by 
remoteAddress.
          scmClientMachine = "";
   -      omClientMachine = remoteAddress;
   +      omClient = JavaUtils.memoize(() -> 
keyManager.resolveClientForWrite(remoteAddress, clusterMap));
          sortedByNodes = new HashMap<>();
        } else {
          // Sort in SCM (or keep order when remoteAddress is empty, since SCM 
skips
          // sorting for an empty client machine).
          scmClientMachine = remoteAddress;
   -      omClientMachine = "";
   +      omClient = null;
          sortedByNodes = null;
        }
   ```



-- 
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