Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions hbase-common/src/main/java/org/apache/hadoop/hbase/util/DNS.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,21 @@ public final class DNS {
// the specification of server hostname is optional. The hostname should be resolvable from
// both master and region server
@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.CONFIG)
public static final String RS_HOSTNAME_KEY = "hbase.regionserver.hostname";
public static final String UNSAFE_RS_HOSTNAME_KEY = "hbase.unsafe.regionserver.hostname";
@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.CONFIG)
public static final String MASTER_HOSTNAME_KEY = "hbase.master.hostname";

private static boolean HAS_NEW_DNS_GET_DEFAULT_HOST_API;
private static Method GET_DEFAULT_HOST_METHOD;

/**
* @deprecated since 2.4.0 and in 3.0.0, to be removed in 4.0.0.
* Use {@link DNS#UNSAFE_RS_HOSTNAME_KEY} instead.
*/
@Deprecated
@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.CONFIG)
public static final String RS_HOSTNAME_KEY = "hbase.regionserver.hostname";

static {
try {
GET_DEFAULT_HOST_METHOD = org.apache.hadoop.net.DNS.class
Expand All @@ -50,6 +58,7 @@ public final class DNS {
} catch (Exception e) {
HAS_NEW_DNS_GET_DEFAULT_HOST_API = false; // FindBugs: Causes REC_CATCH_EXCEPTION. Suppressed
}
Configuration.addDeprecation(RS_HOSTNAME_KEY, UNSAFE_RS_HOSTNAME_KEY);
}

public enum ServerType {
Expand Down Expand Up @@ -106,7 +115,7 @@ public static String getHostname(@NonNull Configuration conf, @NonNull ServerTyp
hostname = conf.get(MASTER_HOSTNAME_KEY);
break;
case REGIONSERVER:
hostname = conf.get(RS_HOSTNAME_KEY);
hostname = conf.get(UNSAFE_RS_HOSTNAME_KEY);
break;
default:
hostname = null;
Expand Down
6 changes: 3 additions & 3 deletions hbase-common/src/main/resources/hbase-default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1119,19 +1119,19 @@ possible configurations would overwhelm and obscure the important.
http://docs.oracle.com/javase/1.5.0/docs/api/java/net/Socket.html#getTcpNoDelay()</description>
</property>
<property>
<name>hbase.regionserver.hostname</name>
<name>hbase.unsafe.regionserver.hostname</name>
<value></value>
<description>This config is for experts: don't set its value unless you really know what you are doing.
When set to a non-empty value, this represents the (external facing) hostname for the underlying server.
See https://issues.apache.org/jira/browse/HBASE-12954 for details.</description>
</property>
<property>
<name>hbase.regionserver.hostname.disable.master.reversedns</name>
<name>hbase.unsafe.regionserver.hostname.disable.master.reversedns</name>
<value>false</value>
<description>This config is for experts: don't set its value unless you really know what you are doing.
When set to true, regionserver will use the current node hostname for the servername and HMaster will
skip reverse DNS lookup and use the hostname sent by regionserver instead. Note that this config and
hbase.regionserver.hostname are mutually exclusive. See https://issues.apache.org/jira/browse/HBASE-18226
hbase.unsafe.regionserver.hostname are mutually exclusive. See https://issues.apache.org/jira/browse/HBASE-18226
for more details.</description>
</property>
<!-- The following properties configure authentication information for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public static void setupServer() throws Exception {
HBaseKerberosUtils.setKeytabFileForTesting(serviceKeytab.getAbsolutePath());
// Why doesn't `setKeytabFileForTesting` do this?
conf.set("hbase.master.keytab.file", serviceKeytab.getAbsolutePath());
conf.set("hbase.regionserver.hostname", "localhost");
conf.set("hbase.unsafe.regionserver.hostname", "localhost");
conf.set("hbase.master.hostname", "localhost");
HBaseKerberosUtils.setSecuredConfiguration(conf,
SERVICE_PRINCIPAL+ "@" + KDC.getRealm(), SPNEGO_SERVICE_PRINCIPAL+ "@" + KDC.getRealm());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import static org.apache.hadoop.hbase.HConstants.DEFAULT_HBASE_SPLIT_WAL_MAX_SPLITTER;
import static org.apache.hadoop.hbase.HConstants.HBASE_SPLIT_WAL_COORDINATED_BY_ZK;
import static org.apache.hadoop.hbase.HConstants.HBASE_SPLIT_WAL_MAX_SPLITTER;
import static org.apache.hadoop.hbase.util.DNS.RS_HOSTNAME_KEY;
import static org.apache.hadoop.hbase.util.DNS.UNSAFE_RS_HOSTNAME_KEY;

import java.io.IOException;
import java.lang.management.MemoryType;
Expand Down Expand Up @@ -467,13 +467,31 @@ public class HRegionServer extends Thread implements
protected String useThisHostnameInstead;

/**
* HBASE-18226: This config and hbase.regionserver.hostname are mutually exclusive.
* Exception will be thrown if both are used.
* @deprecated since 2.4.0 and in 3.0.0, to be removed in 4.0.0.
* Use {@link HRegionServer#UNSAFE_RS_HOSTNAME_DISABLE_MASTER_REVERSEDNS_KEY} instead.
*/
@Deprecated
@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.CONFIG)
final static String RS_HOSTNAME_DISABLE_MASTER_REVERSEDNS_KEY =
"hbase.regionserver.hostname.disable.master.reversedns";

/**
* HBASE-18226: This config and hbase.unasfe.regionserver.hostname are mutually exclusive.
* Exception will be thrown if both are used.
*/
@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.CONFIG)
final static String UNSAFE_RS_HOSTNAME_DISABLE_MASTER_REVERSEDNS_KEY =
"hbase.unsafe.regionserver.hostname.disable.master.reversedns";

/**
* HBASE-24667: This config hbase.regionserver.hostname.disable.master.reversedns will be replaced by
* hbase.unsafe.regionserver.hostname.disable.master.reversedns. Keep the old config keys here for backward
* compatibility.
*/
static {
Configuration.addDeprecation(RS_HOSTNAME_DISABLE_MASTER_REVERSEDNS_KEY, UNSAFE_RS_HOSTNAME_DISABLE_MASTER_REVERSEDNS_KEY);
}

/**
* This servers startcode.
*/
Expand Down Expand Up @@ -691,12 +709,12 @@ private void initNamedQueueRecorder(Configuration conf) {

// HMaster should override this method to load the specific config for master
protected String getUseThisHostnameInstead(Configuration conf) throws IOException {
String hostname = conf.get(RS_HOSTNAME_KEY);
if (conf.getBoolean(RS_HOSTNAME_DISABLE_MASTER_REVERSEDNS_KEY, false)) {
String hostname = conf.get(UNSAFE_RS_HOSTNAME_KEY);
if (conf.getBoolean(UNSAFE_RS_HOSTNAME_DISABLE_MASTER_REVERSEDNS_KEY, false)) {
if (!StringUtils.isBlank(hostname)) {
String msg = RS_HOSTNAME_DISABLE_MASTER_REVERSEDNS_KEY + " and " + RS_HOSTNAME_KEY +
" are mutually exclusive. Do not set " + RS_HOSTNAME_DISABLE_MASTER_REVERSEDNS_KEY +
" to true while " + RS_HOSTNAME_KEY + " is used";
String msg = UNSAFE_RS_HOSTNAME_DISABLE_MASTER_REVERSEDNS_KEY + " and " + UNSAFE_RS_HOSTNAME_KEY +
" are mutually exclusive. Do not set " + UNSAFE_RS_HOSTNAME_DISABLE_MASTER_REVERSEDNS_KEY +
" to true while " + UNSAFE_RS_HOSTNAME_KEY + " is used";
throw new IOException(msg);
} else {
return rpcServices.isa.getHostName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.hadoop.hbase.regionserver;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

Expand Down Expand Up @@ -76,7 +77,7 @@ public void teardown() throws Exception {
@Test
public void testInvalidRegionServerHostnameAbortsServer() throws Exception {
String invalidHostname = "hostAddr.invalid";
TEST_UTIL.getConfiguration().set(DNS.RS_HOSTNAME_KEY, invalidHostname);
TEST_UTIL.getConfiguration().set(DNS.UNSAFE_RS_HOSTNAME_KEY, invalidHostname);
HRegionServer hrs = null;
try {
hrs = new HRegionServer(TEST_UTIL.getConfiguration());
Expand Down Expand Up @@ -105,7 +106,7 @@ public void testRegionServerHostname() throws Exception {
LOG.info("Found " + hostName + " on " + ni + ", addr=" + addr);

TEST_UTIL.getConfiguration().set(DNS.MASTER_HOSTNAME_KEY, hostName);
TEST_UTIL.getConfiguration().set(DNS.RS_HOSTNAME_KEY, hostName);
TEST_UTIL.getConfiguration().set(DNS.UNSAFE_RS_HOSTNAME_KEY, hostName);
StartMiniClusterOption option = StartMiniClusterOption.builder()
.numMasters(NUM_MASTERS).numRegionServers(NUM_RS).numDataNodes(NUM_RS).build();
TEST_UTIL.startMiniCluster(option);
Expand All @@ -127,6 +128,29 @@ public void testRegionServerHostname() throws Exception {
}
}

@Test
public void testDeprecatedConfigs() throws Exception {
Configuration conf = TEST_UTIL.getConfiguration();
new HRegionServer(conf);
conf.setBoolean(HRegionServer.RS_HOSTNAME_DISABLE_MASTER_REVERSEDNS_KEY, false);
assertFalse(conf.getBoolean(HRegionServer.UNSAFE_RS_HOSTNAME_DISABLE_MASTER_REVERSEDNS_KEY, true));
conf.setBoolean(HRegionServer.RS_HOSTNAME_DISABLE_MASTER_REVERSEDNS_KEY, true);
assertTrue(conf.getBoolean(HRegionServer.UNSAFE_RS_HOSTNAME_DISABLE_MASTER_REVERSEDNS_KEY, false));
conf.setBoolean(HRegionServer.UNSAFE_RS_HOSTNAME_DISABLE_MASTER_REVERSEDNS_KEY, true);
assertTrue(conf.getBoolean(HRegionServer.RS_HOSTNAME_DISABLE_MASTER_REVERSEDNS_KEY, false));
conf.setBoolean(HRegionServer.UNSAFE_RS_HOSTNAME_DISABLE_MASTER_REVERSEDNS_KEY, false);
assertFalse(conf.getBoolean(HRegionServer.RS_HOSTNAME_DISABLE_MASTER_REVERSEDNS_KEY, true));

conf.setBoolean(DNS.RS_HOSTNAME_KEY, false);
assertFalse(conf.getBoolean(DNS.UNSAFE_RS_HOSTNAME_KEY, true));
conf.setBoolean(DNS.RS_HOSTNAME_KEY, true);
assertTrue(conf.getBoolean(DNS.UNSAFE_RS_HOSTNAME_KEY, false));
conf.setBoolean(DNS.UNSAFE_RS_HOSTNAME_KEY, true);
assertTrue(conf.getBoolean(DNS.RS_HOSTNAME_KEY, false));
conf.setBoolean(DNS.UNSAFE_RS_HOSTNAME_KEY, false);
assertFalse(conf.getBoolean(DNS.RS_HOSTNAME_KEY, true));
}

@Test
public void testConflictRegionServerHostnameConfigurationsAbortServer() throws Exception {
Enumeration<NetworkInterface> netInterfaceList = NetworkInterface.getNetworkInterfaces();
Expand All @@ -143,10 +167,10 @@ public void testConflictRegionServerHostnameConfigurationsAbortServer() throws E
LOG.info("Found " + hostName + " on " + ni);

TEST_UTIL.getConfiguration().set(DNS.MASTER_HOSTNAME_KEY, hostName);
// "hbase.regionserver.hostname" and "hbase.regionserver.hostname.disable.master.reversedns"
// "hbase.unsafe.regionserver.hostname" and "hbase.unsafe.regionserver.hostname.disable.master.reversedns"
// are mutually exclusive. Exception should be thrown if both are used.
TEST_UTIL.getConfiguration().set(DNS.RS_HOSTNAME_KEY, hostName);
TEST_UTIL.getConfiguration().setBoolean(HRegionServer.RS_HOSTNAME_DISABLE_MASTER_REVERSEDNS_KEY, true);
TEST_UTIL.getConfiguration().set(DNS.UNSAFE_RS_HOSTNAME_KEY, hostName);
TEST_UTIL.getConfiguration().setBoolean(HRegionServer.UNSAFE_RS_HOSTNAME_DISABLE_MASTER_REVERSEDNS_KEY, true);
try {
StartMiniClusterOption option = StartMiniClusterOption.builder()
.numMasters(NUM_MASTERS).numRegionServers(NUM_RS).numDataNodes(NUM_RS).build();
Expand All @@ -155,8 +179,8 @@ public void testConflictRegionServerHostnameConfigurationsAbortServer() throws E
Throwable t1 = e.getCause();
Throwable t2 = t1.getCause();
assertTrue(t1.getMessage()+" - "+t2.getMessage(), t2.getMessage().contains(
HRegionServer.RS_HOSTNAME_DISABLE_MASTER_REVERSEDNS_KEY + " and " +
DNS.RS_HOSTNAME_KEY + " are mutually exclusive"));
HRegionServer.UNSAFE_RS_HOSTNAME_DISABLE_MASTER_REVERSEDNS_KEY + " and " +
DNS.UNSAFE_RS_HOSTNAME_KEY + " are mutually exclusive"));
return;
} finally {
TEST_UTIL.shutdownMiniCluster();
Expand All @@ -168,7 +192,7 @@ public void testConflictRegionServerHostnameConfigurationsAbortServer() throws E

@Test
public void testRegionServerHostnameReportedToMaster() throws Exception {
TEST_UTIL.getConfiguration().setBoolean(HRegionServer.RS_HOSTNAME_DISABLE_MASTER_REVERSEDNS_KEY,
TEST_UTIL.getConfiguration().setBoolean(HRegionServer.UNSAFE_RS_HOSTNAME_DISABLE_MASTER_REVERSEDNS_KEY,
true);
StartMiniClusterOption option = StartMiniClusterOption.builder()
.numMasters(NUM_MASTERS).numRegionServers(NUM_RS).numDataNodes(NUM_RS).build();
Expand Down