You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by nd...@apache.org on 2019/11/21 17:47:17 UTC

[hbase] branch branch-1 updated: HBASE-23259: Populate master address end points in cluster/rs configs (#807) (#858)

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

ndimiduk pushed a commit to branch branch-1
in repository https://gitbox.apache.org/repos/asf/hbase.git


The following commit(s) were added to refs/heads/branch-1 by this push:
     new eb5e94a  HBASE-23259: Populate master address end points in cluster/rs configs (#807) (#858)
eb5e94a is described below

commit eb5e94aced6b4feec10b2ffac56e94a994d9c157
Author: Bharath Vissapragada <bh...@apache.org>
AuthorDate: Thu Nov 21 09:47:05 2019 -0800

    HBASE-23259: Populate master address end points in cluster/rs configs (#807) (#858)
    
    All the clients need to know the master RPC end points while using master
    based registry for creating cluster connections. This patch amends the
    test cluster utility to populate these configs in the base configuration
    object used to spin up the cluster.
    
    The config key added here ("hbase.master.addrs") is used in the subsequent
    patches for HBASE-18095.
    
    Signed-off-by: Nick Dimiduk <nd...@apache.org>
    (cherry picked from commit 834ccb4bf6c22fc2a8aab172490fba75c7a40f1c)
---
 .../java/org/apache/hadoop/hbase/HConstants.java   |  5 ++
 .../org/apache/hadoop/hbase/LocalHBaseCluster.java | 12 ++++-
 .../hadoop/hbase/TestHBaseTestingUtility.java      | 54 +++++++++++++++++++---
 3 files changed, 64 insertions(+), 7 deletions(-)

diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java
index 16d96a2..4607de9 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java
@@ -175,6 +175,11 @@ public final class HConstants {
   /** Configuration key for master web API port */
   public static final String MASTER_INFO_PORT = "hbase.master.info.port";
 
+  /** Configuration key for the list of master host:ports **/
+  public static final String MASTER_ADDRS_KEY = "hbase.master.addrs";
+
+  public static final String MASTER_ADDRS_DEFAULT =  "localhost:" + DEFAULT_MASTER_PORT;
+
   /** Parameter name for the master type being backup (waits for primary to go inactive). */
   public static final String MASTER_TYPE_BACKUP = "hbase.master.backup";
 
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/LocalHBaseCluster.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/LocalHBaseCluster.java
index 042037e..4f9cd3b 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/LocalHBaseCluster.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/LocalHBaseCluster.java
@@ -24,6 +24,7 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
+import com.google.common.base.Joiner;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.hbase.classification.InterfaceAudience;
@@ -161,6 +162,15 @@ public class LocalHBaseCluster {
     for (int i = 0; i < noMasters; i++) {
       addMaster(new Configuration(conf), i);
     }
+
+    // Populate the master address host ports in the config. This is needed if a master based
+    // registry is configured for client metadata services (HBASE-18095)
+    List<String> masterHostPorts = new ArrayList<>();
+    for (JVMClusterUtil.MasterThread masterThread: getMasters()) {
+      masterHostPorts.add(masterThread.getMaster().getServerName().getAddress().toString());
+    }
+    conf.set(HConstants.MASTER_ADDRS_KEY, Joiner.on(",").join(masterHostPorts));
+
     // Start the HRegionServers.
     this.regionServerClass =
       (Class<? extends HRegionServer>)conf.getClass(HConstants.REGION_SERVER_IMPL,
@@ -214,7 +224,7 @@ public class LocalHBaseCluster {
   }
 
   public JVMClusterUtil.MasterThread addMaster(Configuration c, final int index)
-  throws IOException {
+      throws IOException {
     // Create each master with its own Configuration instance so each has
     // its HConnection instance rather than share (see HBASE_INSTANCES down in
     // the guts of HConnectionManager.
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestHBaseTestingUtility.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestHBaseTestingUtility.java
index 82d9ae0..96fa8ea 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestHBaseTestingUtility.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestHBaseTestingUtility.java
@@ -1,5 +1,4 @@
-/**
- *
+/*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -18,21 +17,19 @@
  */
 package org.apache.hadoop.hbase;
 
-
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertTrue;
-
 import java.io.File;
 import java.io.IOException;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
-import java.util.Random;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.FileUtil;
 import org.apache.hadoop.fs.Path;
@@ -420,5 +417,50 @@ public class TestHBaseTestingUtility {
     
     hbt.shutdownMiniMapReduceCluster();
   }
+
+  @Test
+  public void testOverridingOfDefaultPorts() throws Exception {
+    // confirm that default port properties being overridden to random
+    Configuration defaultConfig = HBaseConfiguration.create();
+    defaultConfig.setInt(HConstants.MASTER_INFO_PORT, HConstants.DEFAULT_MASTER_INFOPORT);
+    defaultConfig.setInt(HConstants.REGIONSERVER_INFO_PORT,
+            HConstants.DEFAULT_REGIONSERVER_INFOPORT);
+    HBaseTestingUtility htu = new HBaseTestingUtility(defaultConfig);
+    try {
+      MiniHBaseCluster defaultCluster = htu.startMiniCluster();
+      final String masterHostPort =
+              defaultCluster.getMaster().getServerName().getAddress().toString();
+      assertNotEquals(HConstants.DEFAULT_MASTER_INFOPORT,
+              defaultCluster.getConfiguration().getInt(HConstants.MASTER_INFO_PORT, 0));
+      assertNotEquals(HConstants.DEFAULT_REGIONSERVER_INFOPORT,
+              defaultCluster.getConfiguration().getInt(HConstants.REGIONSERVER_INFO_PORT, 0));
+      assertEquals(masterHostPort,
+              defaultCluster.getConfiguration().get(HConstants.MASTER_ADDRS_KEY));
+    } finally {
+      htu.shutdownMiniCluster();
+    }
+
+    // confirm that nonDefault (custom) port settings are NOT overridden
+    Configuration altConfig = HBaseConfiguration.create();
+    final int nonDefaultMasterInfoPort = 3333;
+    final int nonDefaultRegionServerPort = 4444;
+    altConfig.setInt(HConstants.MASTER_INFO_PORT, nonDefaultMasterInfoPort);
+    altConfig.setInt(HConstants.REGIONSERVER_INFO_PORT, nonDefaultRegionServerPort);
+    altConfig.setBoolean(LocalHBaseCluster.ASSIGN_RANDOM_PORTS, false);
+    htu = new HBaseTestingUtility(altConfig);
+    try {
+      MiniHBaseCluster customCluster = htu.startMiniCluster();
+      final String masterHostPort =
+              customCluster.getMaster().getServerName().getAddress().toString();
+      assertEquals(nonDefaultMasterInfoPort,
+              customCluster.getConfiguration().getInt(HConstants.MASTER_INFO_PORT, 0));
+      assertEquals(nonDefaultRegionServerPort,
+              customCluster.getConfiguration().getInt(HConstants.REGIONSERVER_INFO_PORT, 0));
+      assertEquals(masterHostPort,
+              customCluster.getConfiguration().get(HConstants.MASTER_ADDRS_KEY));
+    } finally {
+      htu.shutdownMiniCluster();
+    }
+  }
 }