greenwich commented on code in PR #11838:
URL: https://github.com/apache/ozone/pull/11838#discussion_r4749874560


##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/KeyManagerImpl.java:
##########
@@ -2381,23 +2388,57 @@ private Node getClientNode(String clientMachine,
     return getOtherNode(clientMachine, clusterMap);
   }
 
-  private Node getOtherNode(String clientMachine,
-                            NetworkTopology clusterMap) {
+  @VisibleForTesting
+  public Node getOtherNode(String clientMachine,
+                           NetworkTopology clusterMap) {
+    ClientNodeCache cache = clientNodeCache.get();
+    if (cache == null || cache.clusterMap != clusterMap) {
+      cache = new ClientNodeCache(clusterMap, clientNodeCacheExpiry);
+      clientNodeCache.set(cache);
+    }
+    Optional<Node> cached = cache.nodes.getIfPresent(clientMachine);
+    if (cached != null) {
+      return cached.orElse(null);
+    }
     try {
       String clientLocation = resolveNodeLocation(clientMachine);
-      if (clientLocation != null) {
-        Node rack = clusterMap.getNode(clientLocation);
-        if (rack instanceof InnerNode) {
-          return new NodeImpl(clientMachine, clientLocation,
-              (InnerNode) rack, rack.getLevel() + 1,
-              NODE_COST_DEFAULT);
-        }
+      if (clientLocation == null) {
+        return null;
       }
+      // A client whose rack is not in this map is cached too: that only 
changes with the map.
+      Node rack = clusterMap.getNode(clientLocation);
+      Optional<Node> node = rack instanceof InnerNode
+          ? Optional.of(new NodeImpl(clientMachine, clientLocation, 
(InnerNode) rack, rack.getLevel() + 1,
+              NODE_COST_DEFAULT))
+          : Optional.empty();
+      cache.nodes.put(clientMachine, node);
+      return node.orElse(null);
     } catch (Exception e) {
       LOG.info("Could not resolve client {}: {}",
           clientMachine, e.getMessage());
+      return null;
+    }
+  }
+
+  /**
+   * Non-datanode clients resolved against one cluster map. The client node is 
linked to that map's
+   * rack, and OM replaces the map instance on refresh, so the cache is 
replaced along with it.
+   * Entries also expire after the topology refresh interval, which bounds 
staleness for mappings
+   * that do not cache their own results.
+   */
+  private static final class ClientNodeCache {
+    private static final int MAX_SIZE = 10_000;
+
+    private final NetworkTopology clusterMap;
+    private final Cache<String, Optional<Node>> nodes;
+
+    private ClientNodeCache(NetworkTopology clusterMap, Duration expiry) {

Review Comment:
   @ChenSammi, Sure, I removed the cache from this PR. Will file another Jira.



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