diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 8d875eba3d..a0255edf34 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -133,6 +133,9 @@ Trunk (unreleased changes) HDFS-2580. NameNode#main(...) can make use of GenericOptionsParser. (harsh) + HDFS-3880. Use Builder to build RPC server in HDFS. + (Brandon Li vias suresh) + OPTIMIZATIONS BUG FIXES diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java index 55d4571ad7..e4c36134e6 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java @@ -417,10 +417,15 @@ private void initIpcServer(Configuration conf) throws IOException { new ClientDatanodeProtocolServerSideTranslatorPB(this); BlockingService service = ClientDatanodeProtocolService .newReflectiveBlockingService(clientDatanodeProtocolXlator); - ipcServer = RPC.getServer(ClientDatanodeProtocolPB.class, service, ipcAddr - .getHostName(), ipcAddr.getPort(), conf.getInt( - DFS_DATANODE_HANDLER_COUNT_KEY, DFS_DATANODE_HANDLER_COUNT_DEFAULT), - false, conf, blockPoolTokenSecretManager); + ipcServer = new RPC.Builder(conf) + .setProtocol(ClientDatanodeProtocolPB.class) + .setInstance(service) + .setBindAddress(ipcAddr.getHostName()) + .setPort(ipcAddr.getPort()) + .setNumHandlers( + conf.getInt(DFS_DATANODE_HANDLER_COUNT_KEY, + DFS_DATANODE_HANDLER_COUNT_DEFAULT)).setVerbose(false) + .setSecretManager(blockPoolTokenSecretManager).build(); InterDatanodeProtocolServerSideTranslatorPB interDatanodeProtocolXlator = new InterDatanodeProtocolServerSideTranslatorPB(this); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/journalservice/JournalService.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/journalservice/JournalService.java index e8d7073670..4764259506 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/journalservice/JournalService.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/journalservice/JournalService.java @@ -283,8 +283,9 @@ private static RPC.Server createRpcServer(Configuration conf, new JournalProtocolServerSideTranslatorPB(impl); BlockingService service = JournalProtocolService.newReflectiveBlockingService(xlator); - return RPC.getServer(JournalProtocolPB.class, service, - address.getHostName(), address.getPort(), 1, false, conf, null); + return new RPC.Builder(conf).setProtocol(JournalProtocolPB.class) + .setInstance(service).setBindAddress(address.getHostName()) + .setPort(address.getPort()).setNumHandlers(1).setVerbose(false).build(); } private void verifyEpoch(long e) throws FencedException { diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java index 1c80c8a794..2f4037bea9 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java @@ -206,12 +206,15 @@ public NameNodeRpcServer(Configuration conf, NameNode nn) conf.getInt(DFS_NAMENODE_SERVICE_HANDLER_COUNT_KEY, DFS_NAMENODE_SERVICE_HANDLER_COUNT_DEFAULT); // Add all the RPC protocols that the namenode implements - this.serviceRpcServer = - RPC.getServer(org.apache.hadoop.hdfs.protocolPB. - ClientNamenodeProtocolPB.class, clientNNPbService, - dnSocketAddr.getHostName(), dnSocketAddr.getPort(), - serviceHandlerCount, - false, conf, namesystem.getDelegationTokenSecretManager()); + this.serviceRpcServer = new RPC.Builder(conf) + .setProtocol( + org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolPB.class) + .setInstance(clientNNPbService) + .setBindAddress(dnSocketAddr.getHostName()) + .setPort(dnSocketAddr.getPort()).setNumHandlers(serviceHandlerCount) + .setVerbose(false) + .setSecretManager(namesystem.getDelegationTokenSecretManager()) + .build(); DFSUtil.addPBProtocol(conf, HAServiceProtocolPB.class, haPbService, serviceRpcServer); DFSUtil.addPBProtocol(conf, NamenodeProtocolPB.class, NNPbService, @@ -232,11 +235,13 @@ public NameNodeRpcServer(Configuration conf, NameNode nn) serviceRPCAddress = null; } // Add all the RPC protocols that the namenode implements - this.clientRpcServer = RPC.getServer( - org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolPB.class, - clientNNPbService, socAddr.getHostName(), - socAddr.getPort(), handlerCount, false, conf, - namesystem.getDelegationTokenSecretManager()); + this.clientRpcServer = new RPC.Builder(conf) + .setProtocol( + org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolPB.class) + .setInstance(clientNNPbService).setBindAddress(socAddr.getHostName()) + .setPort(socAddr.getPort()).setNumHandlers(handlerCount) + .setVerbose(false) + .setSecretManager(namesystem.getDelegationTokenSecretManager()).build(); DFSUtil.addPBProtocol(conf, HAServiceProtocolPB.class, haPbService, clientRpcServer); DFSUtil.addPBProtocol(conf, NamenodeProtocolPB.class, NNPbService, diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/security/TestClientProtocolWithDelegationToken.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/security/TestClientProtocolWithDelegationToken.java index e54b8bccc2..1eaa0caea3 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/security/TestClientProtocolWithDelegationToken.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/security/TestClientProtocolWithDelegationToken.java @@ -80,9 +80,11 @@ public void testDelegationTokenRpc() throws Exception { DFSConfigKeys.DFS_NAMENODE_DELEGATION_TOKEN_MAX_LIFETIME_DEFAULT, 3600000, mockNameSys); sm.startThreads(); - final Server server = RPC.getServer(ClientProtocol.class, mockNN, ADDRESS, - 0, 5, true, conf, sm); - + final Server server = new RPC.Builder(conf) + .setProtocol(ClientProtocol.class).setInstance(mockNN) + .setBindAddress(ADDRESS).setPort(0).setNumHandlers(5).setVerbose(true) + .setSecretManager(sm).build(); + server.start(); final UserGroupInformation current = UserGroupInformation.getCurrentUser(); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/security/token/block/TestBlockToken.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/security/token/block/TestBlockToken.java index a9b5562188..f32b70dc3d 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/security/token/block/TestBlockToken.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/security/token/block/TestBlockToken.java @@ -231,8 +231,9 @@ private Server createMockDatanode(BlockTokenSecretManager sm, ProtobufRpcEngine.class); BlockingService service = ClientDatanodeProtocolService .newReflectiveBlockingService(mockDN); - return RPC.getServer(ClientDatanodeProtocolPB.class, service, ADDRESS, 0, 5, - true, conf, sm); + return new RPC.Builder(conf).setProtocol(ClientDatanodeProtocolPB.class) + .setInstance(service).setBindAddress(ADDRESS).setPort(0) + .setNumHandlers(5).setVerbose(true).setSecretManager(sm).build(); } @Test