You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hbase.apache.org by GitBox <gi...@apache.org> on 2019/11/08 19:13:20 UTC

[GitHub] [hbase] virajjasani commented on a change in pull request #807: HBASE-23259: Ability to start minicluster with pre-determined master ports

virajjasani commented on a change in pull request #807: HBASE-23259: Ability to start minicluster with pre-determined master ports
URL: https://github.com/apache/hbase/pull/807#discussion_r344325139
 
 

 ##########
 File path: hbase-server/src/main/java/org/apache/hadoop/hbase/LocalHBaseCluster.java
 ##########
 @@ -183,6 +178,47 @@ public LocalHBaseCluster(final Configuration conf, final int noMasters,
     }
   }
 
+  /**
+   * Create new LocalHBaseCluster using pre-defined master rpc ports. Every other port is picked
+   * randomly. This also populates the master addresses in the base and region server configs.
+   * @param conf Base configuration to use for the cluster.
+   * @param noMasters Number of masters.
+   * @param noRegionServers Number of region servers.
+   * @param masterClass Impl of master class
+   * @param regionServerClass Impl of RS class
+   * @param masterPorts Array of ports, 2 per master (RPC/INFO) to use.
+   */
+  public LocalHBaseCluster(final Configuration conf, final int noMasters,
+      final int noRegionServers, final Class<? extends HMaster> masterClass,
+      final Class<? extends HRegionServer> regionServerClass, final List<Integer> masterPorts)
+      throws IOException {
+    this.conf = conf;
+    Preconditions.checkArgument(masterPorts.size() == noMasters);
+    Preconditions.checkArgument(conf.getBoolean(LocalHBaseCluster.ASSIGN_RANDOM_PORTS, false));
+    this.masterClass = (Class<? extends HMaster>)
+        conf.getClass(HConstants.MASTER_IMPL, masterClass);
+    this.regionServerClass =
+        (Class<? extends HRegionServer>)conf.getClass(HConstants.REGION_SERVER_IMPL,
+        regionServerClass);
+    // Every port except the master ports are random.
+    conf.set(HConstants.MASTER_INFO_PORT, "0");
+    conf.set(HConstants.REGIONSERVER_PORT, "0");
+    conf.set(HConstants.REGIONSERVER_INFO_PORT, "0");
+    List<String> masterHostPorts = new ArrayList<>();
+    for (int i = 0, j = 0; i < noMasters; i++) {
+      Configuration c = new Configuration(conf);
+      conf.setInt(HConstants.MASTER_PORT, masterPorts.get(j++));
+      HMaster master = addMaster(c, i).getMaster();
+      masterHostPorts.add(
+          master.getServerName().getHostname() + ":" + master.getServerName().getPort());
+    }
+    // Populate the master addresses in the base configuration.
+    this.conf.set(HConstants.MASTER_ADDRS_KEY, Joiner.on(",").join(masterHostPorts));
 
 Review comment:
   String.join(",", masterHostPorts) can be used here

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services