hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mbau...@apache.org
Subject svn commit: r1362268 - /hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
Date Mon, 16 Jul 2012 21:24:37 GMT
Author: mbautin
Date: Mon Jul 16 21:24:36 2012
New Revision: 1362268

URL: http://svn.apache.org/viewvc?rev=1362268&view=rev
Log:
[master] Refactor master RPC server initialization to reduce code duplication

Author: mbautin

Summary: A recent change that moved RPC server initialization right before starting RPC threads
if the master RPC port is explicitly specified introduced some code duplication. Refactoring
that code to reduce code duplication.

Test Plan: Unit tests

Reviewers: pkhemani

Reviewed By: pkhemani

Differential Revision: https://reviews.facebook.net/D4149

Modified:
    hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/master/HMaster.java

Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/master/HMaster.java?rev=1362268&r1=1362267&r2=1362268&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/master/HMaster.java (original)
+++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/master/HMaster.java Mon Jul
16 21:24:36 2012
@@ -254,10 +254,9 @@ public class HMaster extends HasThread i
     HServerAddress a = new HServerAddress(getMyAddress(this.conf));
     int port;
     if ((port = a.getPort()) == 0) {
-      this.rpcServer = HBaseRPC.getServer(this, a.getBindAddress(),
-          a.getPort(),
-          conf.getInt("hbase.regionserver.handler.count", 10),
-          false, conf);
+      // We initialize the RPC server here if the port is unknown (e.g. in unit tests).
+      // In production we try to start the RPC server immediately before starting RPC threads.
+      initRpcServer(a);
       port = this.rpcServer.getListenerAddress().getPort();
     }
     this.address = new HServerAddress(new InetSocketAddress(a.getBindAddress(),
@@ -374,6 +373,18 @@ public class HMaster extends HasThread i
     }
   }
 
+  private void initRpcServer(HServerAddress address) throws IOException {
+    if (this.rpcServer != null) {
+      LOG.info("Master RPC server is already initialized");
+      return;
+    }
+    LOG.info("Initializing master RPC server at " + address);
+    this.rpcServer = HBaseRPC.getServer(this, address.getBindAddress(),
+        address.getPort(),
+        conf.getInt("hbase.regionserver.handler.count", 10),
+        false, conf);
+  }
+
   public boolean shouldAssignRegionsWithFavoredNodes() {
     return shouldAssignRegionsWithFavoredNodes;
   }
@@ -1184,12 +1195,9 @@ public class HMaster extends HasThread i
       // Start the server so that region servers are running before we start
       // splitting logs and before we start assigning regions. XXX What will
       // happen if master starts receiving requests before regions are assigned?
-      if (this.rpcServer == null) {
-        this.rpcServer = HBaseRPC.getServer(this, this.address.getBindAddress(),
-            this.address.getPort(),
-            conf.getInt("hbase.regionserver.handler.count", 10),
-            false, conf);
-      }
+      // NOTE: If the master bind port is 0 (e.g. in unit tests) we initialize the RPC server
+      // earlier and do nothing here.
+      initRpcServer(this.address);
       this.rpcServer.start();
       if (LOG.isDebugEnabled()) {
         LOG.debug("Started service threads");



Mime
View raw message