瀏覽代碼

HDFS-12466. Ozone: KSM: Make ozone.ksm.address as mandatory property for client. Contributed by Nandakumar.

Weiwei Yang 7 年之前
父節點
當前提交
3b290fe3bf

+ 0 - 1
hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/ozone/client/OzoneClientFactory.java

@@ -158,7 +158,6 @@ public final class OzoneClientFactory {
       return ctor.newInstance(getConfiguration());
     } catch (Exception e) {
       final String message = "Couldn't create protocol " + protocolClass;
-      LOG.warn(message, e);
       if (e.getCause() instanceof IOException) {
         throw (IOException) e.getCause();
       } else {

+ 26 - 0
hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/ozone/client/OzoneClientUtils.java

@@ -321,6 +321,32 @@ public final class OzoneClientUtils {
             port.or(OZONE_KSM_PORT_DEFAULT));
   }
 
+  /**
+   * Retrieve the socket address that should be used by clients to connect
+   * to KSM.
+   * @param conf
+   * @return Target InetSocketAddress for the KSM service endpoint.
+   */
+  public static InetSocketAddress getKsmAddressForClients(
+      Configuration conf) {
+    final Optional<String> host = getHostNameFromConfigKeys(conf,
+        OZONE_KSM_ADDRESS_KEY);
+
+    if (!host.isPresent()) {
+      throw new IllegalArgumentException(
+          OZONE_KSM_ADDRESS_KEY + " must be defined. See" +
+              " https://wiki.apache.org/hadoop/Ozone#Configuration for" +
+              " details on configuring Ozone.");
+    }
+
+    // If no port number is specified then we'll just try the defaultBindPort.
+    final Optional<Integer> port = getPortNumberFromConfigKeys(conf,
+        OZONE_KSM_ADDRESS_KEY);
+
+    return NetUtils.createSocketAddr(
+        host.get() + ":" + port.or(OZONE_KSM_PORT_DEFAULT));
+  }
+
   /**
    * Retrieve the socket address that is used by CBlock Service.
    * @param conf

+ 13 - 12
hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/ozone/client/rpc/RpcClient.java

@@ -106,6 +106,19 @@ public class RpcClient implements ClientProtocol {
     this.groupRights = conf.getEnum(KSMConfigKeys.OZONE_KSM_GROUP_RIGHTS,
         KSMConfigKeys.OZONE_KSM_GROUP_RIGHTS_DEFAULT);
 
+    long ksmVersion =
+        RPC.getProtocolVersion(KeySpaceManagerProtocolPB.class);
+    InetSocketAddress ksmAddress = OzoneClientUtils
+        .getKsmAddressForClients(conf);
+    RPC.setProtocolEngine(conf, KeySpaceManagerProtocolPB.class,
+        ProtobufRpcEngine.class);
+    this.keySpaceManagerClient =
+        new KeySpaceManagerProtocolClientSideTranslatorPB(
+            RPC.getProxy(KeySpaceManagerProtocolPB.class, ksmVersion,
+                ksmAddress, UserGroupInformation.getCurrentUser(), conf,
+                NetUtils.getDefaultSocketFactory(conf),
+                Client.getRpcTimeout(conf)));
+
     long scmVersion =
         RPC.getProtocolVersion(StorageContainerLocationProtocolPB.class);
     InetSocketAddress scmAddress =
@@ -119,18 +132,6 @@ public class RpcClient implements ClientProtocol {
                 NetUtils.getDefaultSocketFactory(conf),
                 Client.getRpcTimeout(conf)));
 
-    long ksmVersion =
-        RPC.getProtocolVersion(KeySpaceManagerProtocolPB.class);
-    InetSocketAddress ksmAddress = OzoneClientUtils.getKsmAddress(conf);
-    RPC.setProtocolEngine(conf, KeySpaceManagerProtocolPB.class,
-        ProtobufRpcEngine.class);
-    this.keySpaceManagerClient =
-        new KeySpaceManagerProtocolClientSideTranslatorPB(
-            RPC.getProxy(KeySpaceManagerProtocolPB.class, ksmVersion,
-                ksmAddress, UserGroupInformation.getCurrentUser(), conf,
-                NetUtils.getDefaultSocketFactory(conf),
-                Client.getRpcTimeout(conf)));
-
     this.xceiverClientManager = new XceiverClientManager(conf);
 
     int configuredChunkSize = conf.getInt(

+ 1 - 1
hadoop-hdfs-project/hadoop-hdfs/src/main/resources/ozone-default.xml

@@ -529,7 +529,7 @@
 
   <property>
     <name>ozone.ksm.address</name>
-    <value>0.0.0.0</value>
+    <value></value>
     <description>
       The address of the Ozone KSM service.
     </description>