ivandika3 commented on code in PR #9696:
URL: https://github.com/apache/ozone/pull/9696#discussion_r2901498086


##########
hadoop-ozone/freon/src/main/java/org/apache/hadoop/ozone/freon/OmMetadataGenerator.java:
##########
@@ -165,18 +183,42 @@ public Void call() throws Exception {
     OzoneConfiguration conf = createOzoneConfiguration();
     replicationConfig = replication.fromParamsOrConfig(conf);
 
-    try (OzoneClient rpcClient = createOzoneClient(omServiceID, conf)) {
-      ensureVolumeAndBucketExist(rpcClient, volumeName, bucketName);
-      ozoneManagerClient = createOmClient(conf, omServiceID);
-      bucket = rpcClient.getObjectStore().getVolume(volumeName)
-          .getBucket(bucketName);
+    if (clientsNo <= 0) {
+      clientsNo = 1;
+    }
+
+    try (OzoneClient ozClient = createOzoneClient(omServiceID, conf)) {
+      ensureVolumeAndBucketExist(ozClient, volumeName, bucketName);
+
+      ozoneClients = new OzoneClient[clientsNo];
+      List<String> followerOMNodeIds = null;
+      int currentFollowerAffinityIndex = 0;
+      if (enableFollowerAffinity) {
+        followerOMNodeIds = getOMFollowerNodeIds(ozClient);
+      }
+      for (int i = 0; i < clientsNo; i++) {
+        OzoneClient ozoneClient = createOzoneClient(omServiceID, conf);
+        if (enableFollowerAffinity) {
+          // Point the client proxy to the followers in a round-robin fashion
+          // This balances the read loads on the OM followers
+          changeInitialProxyForFollowerRead(ozoneClient,
+              followerOMNodeIds.get(currentFollowerAffinityIndex));
+          currentFollowerAffinityIndex = (currentFollowerAffinityIndex + 1) % 
followerOMNodeIds.size();
+        }
+        ozoneClients[i] = ozoneClient;

Review Comment:
   Thanks, updated.



##########
hadoop-ozone/freon/src/main/java/org/apache/hadoop/ozone/freon/OmMetadataGenerator.java:
##########
@@ -464,4 +522,44 @@ enum Operation {
     INFO_VOLUME,
     MIXED,
   }
+
+  private List<String> getOMFollowerNodeIds(OzoneClient ozoneClient) throws 
IOException {
+    List<OMRoleInfo> omRoleInfos = ozoneClient.getProxy().getOmRoleInfos();
+    String leaderOMNodeId = null;
+    List<String> followerOMNodeIds = new ArrayList<>();
+    for (OMRoleInfo omRoleInfo : omRoleInfos) {
+      if (omRoleInfo.getServerRole().equals("LEADER")) {
+        if (leaderOMNodeId != null) {
+          // This situation should be rare
+          throw new IllegalStateException("There are more than one leader 
detected, please retry again");
+        }
+        leaderOMNodeId = omRoleInfo.getNodeId();
+      } else if (omRoleInfo.getServerRole().equals("FOLLOWER")) {
+        followerOMNodeIds.add(omRoleInfo.getNodeId());
+      }
+    }
+    if (followerOMNodeIds.isEmpty()) {
+      throw new IllegalArgumentException("There is no follower in the OM 
service, please retry again");
+    }
+    return followerOMNodeIds;
+  }
+
+  private void changeInitialProxyForFollowerRead(OzoneClient ozoneClient, 
String omNodeId) {
+    OzoneManagerProtocolClientSideTranslatorPB ozoneManagerClient =
+        (OzoneManagerProtocolClientSideTranslatorPB)
+            ozoneClient.getProxy().getOzoneManagerClient();
+
+    OmTransport transport = ozoneManagerClient.getTransport();
+
+    if (transport instanceof Hadoop3OmTransport) {

Review Comment:
   Thanks, updated.



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