This is an automated email from the ASF dual-hosted git repository.

bharat 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 12e2918  HDDS-5280. Make XceiverClientManager creation when necessary 
in ContainerOperationClient (#2289)
12e2918 is described below

commit 12e291833b872916069f23ff5e41445f521c31b5
Author: Bharat Viswanadham <[email protected]>
AuthorDate: Tue Jun 1 16:00:36 2021 +0530

    HDDS-5280. Make XceiverClientManager creation when necessary in 
ContainerOperationClient (#2289)
---
 .../hdds/scm/cli/ContainerOperationClient.java     | 42 ++++++++++++++--------
 .../org/apache/hadoop/hdds/scm/cli/ScmOption.java  | 14 +++-----
 .../hadoop/ozone/insight/BaseInsightPoint.java     |  4 +--
 3 files changed, 33 insertions(+), 27 deletions(-)

diff --git 
a/hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/ContainerOperationClient.java
 
b/hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/ContainerOperationClient.java
index 7cbffa3..e48a719 100644
--- 
a/hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/ContainerOperationClient.java
+++ 
b/hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/ContainerOperationClient.java
@@ -69,16 +69,20 @@ public class ContainerOperationClient implements ScmClient {
   private final StorageContainerLocationProtocol
       storageContainerLocationClient;
   private final boolean containerTokenEnabled;
+  private final OzoneConfiguration configuration;
+  private XceiverClientManager xceiverClientManager;
 
-  public XceiverClientManager getXceiverClientManager() {
+  public synchronized XceiverClientManager getXceiverClientManager()
+      throws IOException {
+    if (this.xceiverClientManager == null) {
+      this.xceiverClientManager = newXCeiverClientManager(configuration);
+    }
     return xceiverClientManager;
   }
 
-  private final XceiverClientManager xceiverClientManager;
-
-  public ContainerOperationClient(OzoneConfiguration conf) throws IOException {
+  public ContainerOperationClient(OzoneConfiguration conf) {
+    this.configuration = conf;
     storageContainerLocationClient = newContainerRpcClient(conf);
-    this.xceiverClientManager = newXCeiverClientManager(conf);
     containerSizeB = (int) conf.getStorageSize(OZONE_SCM_CONTAINER_SIZE,
         OZONE_SCM_CONTAINER_SIZE_DEFAULT, StorageUnit.BYTES);
     boolean useRatis = conf.getBoolean(
@@ -125,13 +129,14 @@ public class ContainerOperationClient implements 
ScmClient {
   public ContainerWithPipeline createContainer(String owner)
       throws IOException {
     XceiverClientSpi client = null;
+    XceiverClientManager clientManager = getXceiverClientManager();
     try {
       ContainerWithPipeline containerWithPipeline =
           storageContainerLocationClient.
               allocateContainer(replicationType, replicationFactor, owner);
 
       Pipeline pipeline = containerWithPipeline.getPipeline();
-      client = xceiverClientManager.acquireClient(pipeline);
+      client = clientManager.acquireClient(pipeline);
 
       Preconditions.checkState(
           pipeline.isOpen(),
@@ -143,7 +148,7 @@ public class ContainerOperationClient implements ScmClient {
       return containerWithPipeline;
     } finally {
       if (client != null) {
-        xceiverClientManager.releaseClient(client, false);
+        clientManager.releaseClient(client, false);
       }
     }
   }
@@ -231,6 +236,7 @@ public class ContainerOperationClient implements ScmClient {
   public ContainerWithPipeline createContainer(HddsProtos.ReplicationType type,
       HddsProtos.ReplicationFactor factor, String owner) throws IOException {
     XceiverClientSpi client = null;
+    XceiverClientManager clientManager = getXceiverClientManager();
     try {
       // allocate container on SCM.
       ContainerWithPipeline containerWithPipeline =
@@ -238,13 +244,13 @@ public class ContainerOperationClient implements 
ScmClient {
               owner);
       Pipeline pipeline = containerWithPipeline.getPipeline();
       // connect to pipeline leader and allocate container on leader datanode.
-      client = xceiverClientManager.acquireClient(pipeline);
+      client = clientManager.acquireClient(pipeline);
       createContainer(client,
           containerWithPipeline.getContainerInfo().getContainerID());
       return containerWithPipeline;
     } finally {
       if (client != null) {
-        xceiverClientManager.releaseClient(client, false);
+        clientManager.releaseClient(client, false);
       }
     }
   }
@@ -333,7 +339,12 @@ public class ContainerOperationClient implements ScmClient 
{
   @Override
   public void close() {
     try {
-      xceiverClientManager.close();
+      if (xceiverClientManager != null) {
+        xceiverClientManager.close();
+      }
+      if (storageContainerLocationClient != null) {
+        storageContainerLocationClient.close();
+      }
     } catch (Exception ex) {
       LOG.error("Can't close " + this.getClass().getSimpleName(), ex);
     }
@@ -351,10 +362,11 @@ public class ContainerOperationClient implements 
ScmClient {
   public void deleteContainer(long containerId, Pipeline pipeline,
       boolean force) throws IOException {
     XceiverClientSpi client = null;
+    XceiverClientManager clientManager = getXceiverClientManager();
     try {
       String encodedToken = getEncodedContainerToken(containerId);
 
-      client = xceiverClientManager.acquireClient(pipeline);
+      client = clientManager.acquireClient(pipeline);
       ContainerProtocolCalls
           .deleteContainer(client, containerId, force, encodedToken);
       storageContainerLocationClient
@@ -365,7 +377,7 @@ public class ContainerOperationClient implements ScmClient {
       }
     } finally {
       if (client != null) {
-        xceiverClientManager.releaseClient(client, false);
+        clientManager.releaseClient(client, false);
       }
     }
   }
@@ -409,11 +421,11 @@ public class ContainerOperationClient implements 
ScmClient {
   @Override
   public ContainerDataProto readContainer(long containerID,
       Pipeline pipeline) throws IOException {
+    XceiverClientManager clientManager = getXceiverClientManager();
     String encodedToken = getEncodedContainerToken(containerID);
-
     XceiverClientSpi client = null;
     try {
-      client = xceiverClientManager.acquireClientForReadData(pipeline);
+      client = clientManager.acquireClientForReadData(pipeline);
       ReadContainerResponseProto response = ContainerProtocolCalls
           .readContainer(client, containerID, encodedToken);
       if (LOG.isDebugEnabled()) {
@@ -423,7 +435,7 @@ public class ContainerOperationClient implements ScmClient {
       return response.getContainerData();
     } finally {
       if (client != null) {
-        xceiverClientManager.releaseClient(client, false);
+        clientManager.releaseClient(client, false);
       }
     }
   }
diff --git 
a/hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/ScmOption.java 
b/hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/ScmOption.java
index d439681..3fb9e4d 100644
--- 
a/hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/ScmOption.java
+++ 
b/hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/ScmOption.java
@@ -53,16 +53,12 @@ public class ScmOption {
   private String scmServiceId;
 
   public ScmClient createScmClient() {
-    try {
-      GenericParentCommand parent = (GenericParentCommand)
-          spec.root().userObject();
-      OzoneConfiguration conf = parent.createOzoneConfiguration();
-      checkAndSetSCMAddressArg(conf);
+    GenericParentCommand parent = (GenericParentCommand)
+        spec.root().userObject();
+    OzoneConfiguration conf = parent.createOzoneConfiguration();
+    checkAndSetSCMAddressArg(conf);
 
-      return new ContainerOperationClient(conf);
-    } catch (IOException ex) {
-      throw new IllegalArgumentException("Can't create SCM client", ex);
-    }
+    return new ContainerOperationClient(conf);
   }
 
   private void checkAndSetSCMAddressArg(MutableConfigurationSource conf) {
diff --git 
a/hadoop-ozone/insight/src/main/java/org/apache/hadoop/ozone/insight/BaseInsightPoint.java
 
b/hadoop-ozone/insight/src/main/java/org/apache/hadoop/ozone/insight/BaseInsightPoint.java
index 2789d03..2a4cf88 100644
--- 
a/hadoop-ozone/insight/src/main/java/org/apache/hadoop/ozone/insight/BaseInsightPoint.java
+++ 
b/hadoop-ozone/insight/src/main/java/org/apache/hadoop/ozone/insight/BaseInsightPoint.java
@@ -17,7 +17,6 @@
  */
 package org.apache.hadoop.ozone.insight;
 
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -69,8 +68,7 @@ public abstract class BaseInsightPoint implements 
InsightPoint {
   /**
    * Create scm client.
    */
-  public ScmClient createScmClient(OzoneConfiguration ozoneConf)
-      throws IOException {
+  public ScmClient createScmClient(OzoneConfiguration ozoneConf) {
     if (!HddsUtils.getHostNameFromConfigKeys(ozoneConf,
         ScmConfigKeys.OZONE_SCM_CLIENT_ADDRESS_KEY).isPresent()) {
 

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

Reply via email to