You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ja...@apache.org on 2020/05/08 07:42:12 UTC
[hbase] branch master updated: HBASE-24305 Removed deprecations in
ServerName (#1666)
This is an automated email from the ASF dual-hosted git repository.
janh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/master by this push:
new 03e5a14 HBASE-24305 Removed deprecations in ServerName (#1666)
03e5a14 is described below
commit 03e5a1402d4c119655beedeb96ccf80856e38666
Author: Jan Hentschel <ja...@ultratendency.com>
AuthorDate: Fri May 8 09:41:55 2020 +0200
HBASE-24305 Removed deprecations in ServerName (#1666)
Signed-off-by: Duo Zhang <zh...@apache.org>
Signed-off-by: stack <st...@apache.org>
---
.../hadoop/hbase/backup/util/BackupUtils.java | 4 +-
.../hbase/favored/FavoredNodeAssignmentHelper.java | 8 +-
.../hbase/favored/StartcodeAgnosticServerName.java | 2 +-
.../hbase/master/AssignmentVerificationReport.java | 2 +-
.../java/org/apache/hadoop/hbase/ServerName.java | 213 +++++++--------------
.../org/apache/hadoop/hbase/TestServerName.java | 29 +--
.../apache/hadoop/hbase/rest/RegionsResource.java | 2 +-
.../hadoop/hbase/favored/FavoredNodesManager.java | 8 +-
.../hbase/master/balancer/BaseLoadBalancer.java | 27 +--
.../master/balancer/FavoredStochasticBalancer.java | 8 +-
.../org/apache/hadoop/hbase/util/HBaseFsck.java | 2 +-
.../org/apache/hadoop/hbase/MetaMockingUtil.java | 2 +-
.../apache/hadoop/hbase/TestMetaTableAccessor.java | 2 +-
.../favored/TestFavoredNodeAssignmentHelper.java | 2 +-
.../hadoop/hbase/master/TestRegionPlacement.java | 2 +-
.../master/balancer/TestBaseLoadBalancer.java | 14 +-
.../TestFavoredStochasticBalancerPickers.java | 3 +-
.../procedure/MasterProcedureTestingUtility.java | 2 +-
.../hbase/regionserver/TestRegionServerAbort.java | 2 +-
19 files changed, 117 insertions(+), 217 deletions(-)
diff --git a/hbase-backup/src/main/java/org/apache/hadoop/hbase/backup/util/BackupUtils.java b/hbase-backup/src/main/java/org/apache/hadoop/hbase/backup/util/BackupUtils.java
index ff1a109..f45c94a 100644
--- a/hbase-backup/src/main/java/org/apache/hadoop/hbase/backup/util/BackupUtils.java
+++ b/hbase-backup/src/main/java/org/apache/hadoop/hbase/backup/util/BackupUtils.java
@@ -367,9 +367,9 @@ public final class BackupUtils {
String n = p.getName();
int idx = n.lastIndexOf(LOGNAME_SEPARATOR);
String s = URLDecoder.decode(n.substring(0, idx), "UTF8");
- return ServerName.parseHostname(s) + ":" + ServerName.parsePort(s);
+ return ServerName.valueOf(s).getAddress().toString();
} catch (Exception e) {
- LOG.warn("Skip log file (can't parse): " + p);
+ LOG.warn("Skip log file (can't parse): {}", p);
return null;
}
}
diff --git a/hbase-balancer/src/main/java/org/apache/hadoop/hbase/favored/FavoredNodeAssignmentHelper.java b/hbase-balancer/src/main/java/org/apache/hadoop/hbase/favored/FavoredNodeAssignmentHelper.java
index 4b73522..2e81c31 100644
--- a/hbase-balancer/src/main/java/org/apache/hadoop/hbase/favored/FavoredNodeAssignmentHelper.java
+++ b/hbase-balancer/src/main/java/org/apache/hadoop/hbase/favored/FavoredNodeAssignmentHelper.java
@@ -600,7 +600,7 @@ public class FavoredNodeAssignmentHelper {
}
if (randomServer != null) {
- return ServerName.valueOf(randomServer.getHostAndPort(), randomServer.getStartcode());
+ return ServerName.valueOf(randomServer.getAddress(), randomServer.getStartcode());
} else {
return null;
}
@@ -628,7 +628,7 @@ public class FavoredNodeAssignmentHelper {
StringBuilder strBuf = new StringBuilder();
int i = 0;
for (ServerName node : nodes) {
- strBuf.append(node.getHostAndPort());
+ strBuf.append(node.getAddress());
if (++i != nodes.size()) strBuf.append(";");
}
return strBuf.toString();
@@ -772,7 +772,7 @@ public class FavoredNodeAssignmentHelper {
List<ServerName> favoredNodesForRegion = new ArrayList<>(FAVORED_NODES_NUM);
ServerName primary = servers.get(random.nextInt(servers.size()));
- favoredNodesForRegion.add(ServerName.valueOf(primary.getHostAndPort(), ServerName.NON_STARTCODE));
+ favoredNodesForRegion.add(ServerName.valueOf(primary.getAddress(), ServerName.NON_STARTCODE));
Map<RegionInfo, ServerName> primaryRSMap = new HashMap<>(1);
primaryRSMap.put(hri, primary);
@@ -781,7 +781,7 @@ public class FavoredNodeAssignmentHelper {
ServerName[] secondaryAndTertiaryNodes = secondaryAndTertiaryRSMap.get(hri);
if (secondaryAndTertiaryNodes != null && secondaryAndTertiaryNodes.length == 2) {
for (ServerName sn : secondaryAndTertiaryNodes) {
- favoredNodesForRegion.add(ServerName.valueOf(sn.getHostAndPort(), ServerName.NON_STARTCODE));
+ favoredNodesForRegion.add(ServerName.valueOf(sn.getAddress(), ServerName.NON_STARTCODE));
}
return favoredNodesForRegion;
} else {
diff --git a/hbase-balancer/src/main/java/org/apache/hadoop/hbase/favored/StartcodeAgnosticServerName.java b/hbase-balancer/src/main/java/org/apache/hadoop/hbase/favored/StartcodeAgnosticServerName.java
index d1f9f45..2a76000 100644
--- a/hbase-balancer/src/main/java/org/apache/hadoop/hbase/favored/StartcodeAgnosticServerName.java
+++ b/hbase-balancer/src/main/java/org/apache/hadoop/hbase/favored/StartcodeAgnosticServerName.java
@@ -61,7 +61,7 @@ class StartcodeAgnosticServerName extends ServerName {
@Override
public int hashCode() {
- return getHostAndPort().hashCode();
+ return getAddress().hashCode();
}
// Do not need @Override #equals() because super.equals() delegates to compareTo(), which ends
diff --git a/hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/AssignmentVerificationReport.java b/hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/AssignmentVerificationReport.java
index 346555b..3a528f4 100644
--- a/hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/AssignmentVerificationReport.java
+++ b/hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/AssignmentVerificationReport.java
@@ -619,7 +619,7 @@ public class AssignmentVerificationReport {
if ((i++) % 3 == 0) {
System.out.print("\n\t\t\t");
}
- System.out.print(addr.getHostAndPort() + " ; ");
+ System.out.print(addr.getAddress() + " ; ");
}
System.out.println("\n");
}
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/ServerName.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/ServerName.java
index 34ac1e5..adac0c2 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/ServerName.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/ServerName.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
@@ -23,16 +22,13 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.regex.Pattern;
-
import org.apache.hadoop.hbase.net.Address;
import org.apache.hadoop.hbase.util.Addressing;
import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.yetus.audience.InterfaceAudience;
import org.apache.hbase.thirdparty.com.google.common.collect.Interner;
import org.apache.hbase.thirdparty.com.google.common.collect.Interners;
import org.apache.hbase.thirdparty.com.google.common.net.InetAddresses;
-import org.apache.yetus.audience.InterfaceAudience;
-
-
/**
* Name of a particular incarnation of an HBase Server.
@@ -120,63 +116,24 @@ public class ServerName implements Comparable<ServerName>, Serializable {
this.address.getPort(), startcode);
}
- private ServerName(final String serverName) {
- this(parseHostname(serverName), parsePort(serverName),
- parseStartcode(serverName));
- }
-
private ServerName(final String hostAndPort, final long startCode) {
this(Address.fromString(hostAndPort), startCode);
}
/**
- * @param hostname
+ * @param hostname the hostname string to get the actual hostname from
* @return hostname minus the domain, if there is one (will do pass-through on ip addresses)
- * @deprecated Since 2.0. This is for internal use only.
*/
- @Deprecated
- // Make this private in hbase-3.0.
- static String getHostNameMinusDomain(final String hostname) {
- if (InetAddresses.isInetAddress(hostname)) return hostname;
- String [] parts = hostname.split("\\.");
- if (parts == null || parts.length == 0) return hostname;
- return parts[0];
- }
-
- /**
- * @deprecated Since 2.0. Use {@link #valueOf(String)}
- */
- @Deprecated
- // This is unused. Get rid of it.
- public static String parseHostname(final String serverName) {
- if (serverName == null || serverName.length() <= 0) {
- throw new IllegalArgumentException("Passed hostname is null or empty");
+ private static String getHostNameMinusDomain(final String hostname) {
+ if (InetAddresses.isInetAddress(hostname)) {
+ return hostname;
}
- if (!Character.isLetterOrDigit(serverName.charAt(0))) {
- throw new IllegalArgumentException("Bad passed hostname, serverName=" + serverName);
+ String[] parts = hostname.split("\\.");
+ if (parts.length == 0) {
+ return hostname;
}
- int index = serverName.indexOf(SERVERNAME_SEPARATOR);
- return serverName.substring(0, index);
- }
-
- /**
- * @deprecated Since 2.0. Use {@link #valueOf(String)}
- */
- @Deprecated
- // This is unused. Get rid of it.
- public static int parsePort(final String serverName) {
- String [] split = serverName.split(SERVERNAME_SEPARATOR);
- return Integer.parseInt(split[1]);
- }
- /**
- * @deprecated Since 2.0. Use {@link #valueOf(String)}
- */
- @Deprecated
- // This is unused. Get rid of it.
- public static long parseStartcode(final String serverName) {
- int index = serverName.lastIndexOf(SERVERNAME_SEPARATOR);
- return Long.parseLong(serverName.substring(index + 1));
+ return parts[0];
}
/**
@@ -194,7 +151,11 @@ public class ServerName implements Comparable<ServerName>, Serializable {
* a shared immutable object as an internal optimization.
*/
public static ServerName valueOf(final String serverName) {
- return INTERN_POOL.intern(new ServerName(serverName));
+ final String hostname = serverName.substring(0, serverName.indexOf(SERVERNAME_SEPARATOR));
+ final int port = Integer.parseInt(serverName.split(SERVERNAME_SEPARATOR)[1]);
+ final long statuscode =
+ Long.parseLong(serverName.substring(serverName.lastIndexOf(SERVERNAME_SEPARATOR) + 1));
+ return INTERN_POOL.intern(new ServerName(hostname, port, statuscode));
}
/**
@@ -206,26 +167,40 @@ public class ServerName implements Comparable<ServerName>, Serializable {
return INTERN_POOL.intern(new ServerName(hostAndPort, startCode));
}
+ /**
+ * Retrieve an instance of {@link ServerName}. Callers should use the {@link #equals(Object)}
+ * method to compare returned instances, though we may return a shared immutable object as an
+ * internal optimization.
+ *
+ * @param address the {@link Address} to use for getting the {@link ServerName}
+ * @param startcode the startcode to use for getting the {@link ServerName}
+ * @return the constructed {@link ServerName}
+ * @see #valueOf(String, int, long)
+ */
+ public static ServerName valueOf(final Address address, final long startcode) {
+ return valueOf(address.getHostname(), address.getPort(), startcode);
+ }
+
@Override
public String toString() {
return getServerName();
}
/**
- * @return Return a SHORT version of {@link ServerName#toString()}, one that has the host only,
- * minus the domain, and the port only -- no start code; the String is for us internally mostly
- * tying threads to their server. Not for external use. It is lossy and will not work in
- * in compares, etc.
+ * @return Return a SHORT version of {@link #toString()}, one that has the host only,
+ * minus the domain, and the port only -- no start code; the String is for us internally mostly
+ * tying threads to their server. Not for external use. It is lossy and will not work in
+ * in compares, etc.
*/
public String toShortString() {
return Addressing.createHostAndPortStr(
- getHostNameMinusDomain(this.address.getHostname()),
- this.address.getPort());
+ getHostNameMinusDomain(this.address.getHostname()),
+ this.address.getPort());
}
/**
* @return {@link #getServerName()} as bytes with a short-sized prefix with
- * the ServerName#VERSION of this class.
+ * the {@link #VERSION} of this class.
*/
public synchronized byte [] getVersionedBytes() {
if (this.bytes == null) {
@@ -256,83 +231,21 @@ public class ServerName implements Comparable<ServerName>, Serializable {
/**
* For internal use only.
- * @param hostName
- * @param port
- * @param startcode
+ * @param hostName the name of the host to use
+ * @param port the port on the host to use
+ * @param startcode the startcode to use for formatting
* @return Server name made of the concatenation of hostname, port and
- * startcode formatted as <code><hostname> ',' <port> ',' <startcode></code>
- * @deprecated Since 2.0. Use {@link ServerName#valueOf(String, int, long)} instead.
+ * startcode formatted as <code><hostname> ',' <port> ',' <startcode></code>
*/
- @Deprecated
- // TODO: Make this private in hbase-3.0.
- static String getServerName(String hostName, int port, long startcode) {
- final StringBuilder name = new StringBuilder(hostName.length() + 1 + 5 + 1 + 13);
- name.append(hostName.toLowerCase(Locale.ROOT));
- name.append(SERVERNAME_SEPARATOR);
- name.append(port);
- name.append(SERVERNAME_SEPARATOR);
- name.append(startcode);
- return name.toString();
- }
-
- /**
- * @param hostAndPort String in form of <hostname> ':' <port>
- * @param startcode
- * @return Server name made of the concatenation of hostname, port and
- * startcode formatted as <code><hostname> ',' <port> ',' <startcode></code>
- * @deprecated Since 2.0. Use {@link ServerName#valueOf(String, long)} instead.
- */
- @Deprecated
- public static String getServerName(final String hostAndPort,
- final long startcode) {
- int index = hostAndPort.indexOf(":");
- if (index <= 0) throw new IllegalArgumentException("Expected <hostname> ':' <port>");
- return getServerName(hostAndPort.substring(0, index),
- Integer.parseInt(hostAndPort.substring(index + 1)), startcode);
- }
-
- /**
- * @return Hostname and port formatted as described at
- * {@link Addressing#createHostAndPortStr(String, int)}
- * @deprecated Since 2.0. Use {@link #getAddress()} instead.
- */
- @Deprecated
- public String getHostAndPort() {
- return this.address.toString();
+ private static String getServerName(String hostName, int port, long startcode) {
+ return hostName.toLowerCase(Locale.ROOT) + SERVERNAME_SEPARATOR + port
+ + SERVERNAME_SEPARATOR + startcode;
}
public Address getAddress() {
return this.address;
}
- /**
- * @param serverName ServerName in form specified by {@link #getServerName()}
- * @return The server start code parsed from <code>servername</code>
- * @deprecated Since 2.0. Use instance of ServerName to pull out start code.
- */
- @Deprecated
- public static long getServerStartcodeFromServerName(final String serverName) {
- int index = serverName.lastIndexOf(SERVERNAME_SEPARATOR);
- return Long.parseLong(serverName.substring(index + 1));
- }
-
- /**
- * Utility method to excise the start code from a server name
- * @param inServerName full server name
- * @return server name less its start code
- * @deprecated Since 2.0. Use {@link #getAddress()}
- */
- @Deprecated
- public static String getServerNameLessStartCode(String inServerName) {
- if (inServerName != null && inServerName.length() > 0) {
- int index = inServerName.lastIndexOf(SERVERNAME_SEPARATOR);
- if (index > 0) {
- return inServerName.substring(0, index);
- }
- }
- return inServerName;
- }
-
@Override
public int compareTo(ServerName other) {
int compare;
@@ -366,24 +279,25 @@ public class ServerName implements Comparable<ServerName>, Serializable {
@Override
public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null) return false;
- if (!(o instanceof ServerName)) return false;
+ if (this == o) {
+ return true;
+ }
+ if (o == null) {
+ return false;
+ }
+ if (!(o instanceof ServerName)) {
+ return false;
+ }
return this.compareTo((ServerName)o) == 0;
}
/**
- * @param left
- * @param right
- * @return True if <code>other</code> has same hostname and port.
+ * @param left the first server address to compare
+ * @param right the second server address to compare
+ * @return {@code true} if {@code left} and {@code right} have the same hostname and port.
*/
- public static boolean isSameAddress(final ServerName left,
- final ServerName right) {
- // TODO: Make this left.getAddress().equals(right.getAddress())
- if (left == null) return false;
- if (right == null) return false;
- return left.getHostname().compareToIgnoreCase(right.getHostname()) == 0 &&
- left.getPort() == right.getPort();
+ public static boolean isSameAddress(final ServerName left, final ServerName right) {
+ return left.getAddress().equals(right.getAddress());
}
/**
@@ -407,8 +321,8 @@ public class ServerName implements Comparable<ServerName>, Serializable {
}
/**
- * @param str Either an instance of {@link ServerName#toString()} or a
- * "'<hostname>' ':' '<port>'".
+ * @param str Either an instance of {@link #toString()} or a
+ * "'<hostname>' ':' '<port>'".
* @return A ServerName instance.
*/
public static ServerName parseServerName(final String str) {
@@ -416,13 +330,14 @@ public class ServerName implements Comparable<ServerName>, Serializable {
valueOf(str, NON_STARTCODE);
}
-
/**
- * @return true if the String follows the pattern of {@link ServerName#toString()}, false
- * otherwise.
+ * @return true if the String follows the pattern of {@link #toString()}, false
+ * otherwise.
*/
public static boolean isFullServerName(final String str){
- if (str == null ||str.isEmpty()) return false;
+ if (str == null ||str.isEmpty()) {
+ return false;
+ }
return SERVERNAME_PATTERN.matcher(str).matches();
}
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestServerName.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestServerName.java
similarity index 83%
rename from hbase-server/src/test/java/org/apache/hadoop/hbase/TestServerName.java
rename to hbase-common/src/test/java/org/apache/hadoop/hbase/TestServerName.java
index fcbe9c9..d55b0e6 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestServerName.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestServerName.java
@@ -1,4 +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
@@ -22,17 +22,14 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
-
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;
-
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Addressing;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.ClassRule;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@@ -47,7 +44,7 @@ public class TestServerName {
public void testHash() {
ServerName sn1 = ServerName.parseServerName("asf903.gq1.ygridcore.net,52690,1517835491385");
ServerName sn2 = ServerName.parseServerName("asf903.gq1.ygridcore.net,42231,1517835491329");
- Set<ServerName> sns = new HashSet<ServerName>();
+ Set<ServerName> sns = new HashSet<>();
sns.add(sn2);
sns.add(sn1);
sns.add(sn1);
@@ -55,20 +52,6 @@ public class TestServerName {
}
@Test
- public void testGetHostNameMinusDomain() {
- assertEquals("2607:f0d0:1002:51::4",
- ServerName.getHostNameMinusDomain("2607:f0d0:1002:51::4"));
- assertEquals("2607:f0d0:1002:0051:0000:0000:0000:0004",
- ServerName.getHostNameMinusDomain("2607:f0d0:1002:0051:0000:0000:0000:0004"));
- assertEquals("1.1.1.1", ServerName.getHostNameMinusDomain("1.1.1.1"));
- assertEquals("x", ServerName.getHostNameMinusDomain("x"));
- assertEquals("x", ServerName.getHostNameMinusDomain("x.y.z"));
- assertEquals("asf000", ServerName.getHostNameMinusDomain("asf000.sp2.ygridcore.net"));
- ServerName sn = ServerName.valueOf("asf000.sp2.ygridcore.net", 1, 1);
- assertEquals("asf000.sp2.ygridcore.net,1,1", sn.toString());
- }
-
- @Test
public void testShortString() {
ServerName sn = ServerName.valueOf("asf000.sp2.ygridcore.net", 1, 1);
assertEquals("asf000:1", sn.toShortString());
@@ -143,12 +126,12 @@ public class TestServerName {
assertSame(sn1, ServerName.valueOf("www.example.org", 1234, 5671));
}
- @Ignore // Enable and let fun for hours to make sure weak references working fine.
@Test
public void testInterningDoesWeakReferences() {
- for (int i = 0; i < Integer.MAX_VALUE; i++) {
- ServerName.valueOf("www.example.org", 1234, i++);
+ for (int i = 0; i < 5000; i++) {
+ final int startcode = i++;
+ final ServerName sn1 = ServerName.valueOf("www.example.org", 1234, startcode);
+ assertSame(sn1, ServerName.valueOf("www.example.org", 1234, startcode));
}
}
}
-
diff --git a/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/RegionsResource.java b/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/RegionsResource.java
index 8e93acf..b70c13d 100644
--- a/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/RegionsResource.java
+++ b/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/RegionsResource.java
@@ -87,7 +87,7 @@ public class RegionsResource extends ResourceBase {
ServerName addr = e.getSecond();
model.add(
new TableRegionModel(tableName.getNameAsString(), hri.getRegionId(),
- hri.getStartKey(), hri.getEndKey(), addr.getHostAndPort()));
+ hri.getStartKey(), hri.getEndKey(), addr.getAddress().toString()));
}
ResponseBuilder response = Response.ok(model);
response.cacheControl(cacheControl);
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/favored/FavoredNodesManager.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/favored/FavoredNodesManager.java
index 77334db..a34e3a3 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/favored/FavoredNodesManager.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/favored/FavoredNodesManager.java
@@ -209,7 +209,7 @@ public class FavoredNodesManager {
primaryRSToRegionMap.put(serverToUse, regionList);
serverToUse = ServerName
- .valueOf(servers.get(SECONDARY.ordinal()).getHostAndPort(), NON_STARTCODE);
+ .valueOf(servers.get(SECONDARY.ordinal()).getAddress(), NON_STARTCODE);
regionList = secondaryRSToRegionMap.get(serverToUse);
if (regionList == null) {
regionList = new ArrayList<>();
@@ -217,7 +217,7 @@ public class FavoredNodesManager {
regionList.add(hri);
secondaryRSToRegionMap.put(serverToUse, regionList);
- serverToUse = ServerName.valueOf(servers.get(TERTIARY.ordinal()).getHostAndPort(),
+ serverToUse = ServerName.valueOf(servers.get(TERTIARY.ordinal()).getAddress(),
NON_STARTCODE);
regionList = teritiaryRSToRegionMap.get(serverToUse);
if (regionList == null) {
@@ -238,7 +238,7 @@ public class FavoredNodesManager {
public synchronized Map<ServerName, List<Integer>> getReplicaLoad(List<ServerName> servers) {
Map<ServerName, List<Integer>> result = Maps.newHashMap();
for (ServerName sn : servers) {
- ServerName serverWithNoStartCode = ServerName.valueOf(sn.getHostAndPort(), NON_STARTCODE);
+ ServerName serverWithNoStartCode = ServerName.valueOf(sn.getAddress(), NON_STARTCODE);
List<Integer> countList = Lists.newArrayList();
if (primaryRSToRegionMap.containsKey(serverWithNoStartCode)) {
countList.add(primaryRSToRegionMap.get(serverWithNoStartCode).size());
@@ -286,7 +286,7 @@ public class FavoredNodesManager {
public synchronized Set<RegionInfo> getRegionsOfFavoredNode(ServerName serverName) {
Set<RegionInfo> regionInfos = Sets.newHashSet();
- ServerName serverToUse = ServerName.valueOf(serverName.getHostAndPort(), NON_STARTCODE);
+ ServerName serverToUse = ServerName.valueOf(serverName.getAddress(), NON_STARTCODE);
if (primaryRSToRegionMap.containsKey(serverToUse)) {
regionInfos.addAll(primaryRSToRegionMap.get(serverToUse));
}
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/BaseLoadBalancer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/BaseLoadBalancer.java
index 7d05c41..d044f1a 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/BaseLoadBalancer.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/BaseLoadBalancer.java
@@ -55,6 +55,7 @@ import org.apache.hadoop.hbase.master.MasterServices;
import org.apache.hadoop.hbase.master.RackManager;
import org.apache.hadoop.hbase.master.RegionPlan;
import org.apache.hadoop.hbase.master.balancer.BaseLoadBalancer.Cluster.Action.Type;
+import org.apache.hadoop.hbase.net.Address;
import org.apache.hbase.thirdparty.com.google.common.annotations.VisibleForTesting;
import org.apache.hbase.thirdparty.com.google.common.base.Joiner;
import org.apache.hbase.thirdparty.com.google.common.collect.ArrayListMultimap;
@@ -163,7 +164,7 @@ public abstract class BaseLoadBalancer implements LoadBalancer {
Integer[] serverIndicesSortedByRegionCount;
Integer[] serverIndicesSortedByLocality;
- Map<String, Integer> serversToIndex;
+ Map<Address, Integer> serversToIndex;
Map<String, Integer> hostsToIndex;
Map<String, Integer> racksToIndex;
Map<String, Integer> tablesToIndex;
@@ -232,15 +233,15 @@ public abstract class BaseLoadBalancer implements LoadBalancer {
}
continue;
}
- if (serversToIndex.get(sn.getAddress().toString()) == null) {
- serversToIndex.put(sn.getHostAndPort(), numServers++);
+ if (serversToIndex.get(sn.getAddress()) == null) {
+ serversToIndex.put(sn.getAddress(), numServers++);
}
if (!hostsToIndex.containsKey(sn.getHostname())) {
hostsToIndex.put(sn.getHostname(), numHosts++);
serversPerHostList.add(new ArrayList<>(1));
}
- int serverIndex = serversToIndex.get(sn.getHostAndPort());
+ int serverIndex = serversToIndex.get(sn.getAddress());
int hostIndex = hostsToIndex.get(sn.getHostname());
serversPerHostList.get(hostIndex).add(serverIndex);
@@ -292,7 +293,7 @@ public abstract class BaseLoadBalancer implements LoadBalancer {
LOG.warn("SERVERNAME IS NULL, skipping " + entry.getValue());
continue;
}
- int serverIndex = serversToIndex.get(entry.getKey().getHostAndPort());
+ int serverIndex = serversToIndex.get(entry.getKey().getAddress());
// keep the servername if this is the first server name for this hostname
// or this servername has the newest startcode.
@@ -323,7 +324,7 @@ public abstract class BaseLoadBalancer implements LoadBalancer {
}
for (Entry<ServerName, List<RegionInfo>> entry : clusterState.entrySet()) {
- int serverIndex = serversToIndex.get(entry.getKey().getHostAndPort());
+ int serverIndex = serversToIndex.get(entry.getKey().getAddress());
regionPerServerIndex = serverIndexToRegionsOffset[serverIndex];
int hostIndex = hostsToIndex.get(entry.getKey().getHostname());
@@ -495,8 +496,8 @@ public abstract class BaseLoadBalancer implements LoadBalancer {
regionLocations[regionIndex] = new int[loc.size()];
for (int i = 0; i < loc.size(); i++) {
regionLocations[regionIndex][i] = loc.get(i) == null ? -1
- : (serversToIndex.get(loc.get(i).getHostAndPort()) == null ? -1
- : serversToIndex.get(loc.get(i).getHostAndPort()));
+ : (serversToIndex.get(loc.get(i).getAddress()) == null ? -1
+ : serversToIndex.get(loc.get(i).getAddress()));
}
}
}
@@ -741,10 +742,10 @@ public abstract class BaseLoadBalancer implements LoadBalancer {
* @return true or false
*/
boolean wouldLowerAvailability(RegionInfo regionInfo, ServerName serverName) {
- if (!serversToIndex.containsKey(serverName.getHostAndPort())) {
+ if (!serversToIndex.containsKey(serverName.getAddress())) {
return false; // safeguard against race between cluster.servers and servers from LB method args
}
- int server = serversToIndex.get(serverName.getHostAndPort());
+ int server = serversToIndex.get(serverName.getAddress());
int region = regionsToIndex.get(regionInfo);
// Region replicas for same region should better assign to different servers
@@ -804,10 +805,10 @@ public abstract class BaseLoadBalancer implements LoadBalancer {
}
void doAssignRegion(RegionInfo regionInfo, ServerName serverName) {
- if (!serversToIndex.containsKey(serverName.getHostAndPort())) {
+ if (!serversToIndex.containsKey(serverName.getAddress())) {
return;
}
- int server = serversToIndex.get(serverName.getHostAndPort());
+ int server = serversToIndex.get(serverName.getAddress());
int region = regionsToIndex.get(regionInfo);
doAction(new AssignRegionAction(region, server));
}
@@ -1003,7 +1004,7 @@ public abstract class BaseLoadBalancer implements LoadBalancer {
public String toString() {
StringBuilder desc = new StringBuilder("Cluster={servers=[");
for(ServerName sn:servers) {
- desc.append(sn.getHostAndPort()).append(", ");
+ desc.append(sn.getAddress().toString()).append(", ");
}
desc.append("], serverIndicesSortedByRegionCount=")
.append(Arrays.toString(serverIndicesSortedByRegionCount))
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/FavoredStochasticBalancer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/FavoredStochasticBalancer.java
index 7651d72..57fd73d 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/FavoredStochasticBalancer.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/FavoredStochasticBalancer.java
@@ -597,8 +597,8 @@ public class FavoredStochasticBalancer extends StochasticLoadBalancer implements
int currentServer) {
List<Integer> fnIndex = new ArrayList<>();
for (ServerName sn : favoredNodes) {
- if (cluster.serversToIndex.containsKey(sn.getHostAndPort())) {
- fnIndex.add(cluster.serversToIndex.get(sn.getHostAndPort()));
+ if (cluster.serversToIndex.containsKey(sn.getAddress())) {
+ fnIndex.add(cluster.serversToIndex.get(sn.getAddress()));
}
}
float locality = 0;
@@ -661,8 +661,8 @@ public class FavoredStochasticBalancer extends StochasticLoadBalancer implements
int currentServerIndex) {
List<Integer> fnIndex = new ArrayList<>();
for (ServerName sn : favoredNodes) {
- if (cluster.serversToIndex.containsKey(sn.getHostAndPort())) {
- fnIndex.add(cluster.serversToIndex.get(sn.getHostAndPort()));
+ if (cluster.serversToIndex.containsKey(sn.getAddress())) {
+ fnIndex.add(cluster.serversToIndex.get(sn.getAddress()));
}
}
int leastLoadedFN = -1;
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java
index 0e0f9e2..39da91b 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java
@@ -1765,7 +1765,7 @@ public class HBaseFsck extends Configured implements Closeable {
try {
f.get();
} catch(ExecutionException e) {
- LOG.warn("Could not process regionserver " + item.rsinfo.getHostAndPort(),
+ LOG.warn("Could not process regionserver {}", item.rsinfo.getAddress(),
e.getCause());
}
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/MetaMockingUtil.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/MetaMockingUtil.java
index 723b9da..bdfdbe4 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/MetaMockingUtil.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/MetaMockingUtil.java
@@ -80,7 +80,7 @@ public class MetaMockingUtil {
if (sn != null) {
kvs.add(new KeyValue(region.getRegionName(),
HConstants.CATALOG_FAMILY, HConstants.SERVER_QUALIFIER,
- Bytes.toBytes(sn.getHostAndPort())));
+ Bytes.toBytes(sn.getAddress().toString())));
kvs.add(new KeyValue(region.getRegionName(),
HConstants.CATALOG_FAMILY, HConstants.STARTCODE_QUALIFIER,
Bytes.toBytes(sn.getStartcode())));
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestMetaTableAccessor.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestMetaTableAccessor.java
index 087076f..afc703e 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestMetaTableAccessor.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestMetaTableAccessor.java
@@ -508,7 +508,7 @@ public class TestMetaTableAccessor {
Result result = meta.get(get);
assertTrue(Bytes.equals(
result.getValue(HConstants.CATALOG_FAMILY, MetaTableAccessor.getServerColumn(replicaId)),
- Bytes.toBytes(serverName.getHostAndPort())));
+ Bytes.toBytes(serverName.getAddress().toString())));
assertTrue(Bytes.equals(
result.getValue(HConstants.CATALOG_FAMILY, MetaTableAccessor.getStartCodeColumn(replicaId)),
Bytes.toBytes(serverName.getStartcode())));
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/favored/TestFavoredNodeAssignmentHelper.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/favored/TestFavoredNodeAssignmentHelper.java
index bc721e1..a42410a 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/favored/TestFavoredNodeAssignmentHelper.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/favored/TestFavoredNodeAssignmentHelper.java
@@ -476,7 +476,7 @@ public class TestFavoredNodeAssignmentHelper {
for (int attempts = 0 ; attempts < MAX_ATTEMPTS; attempts++) {
ServerName sn = helper.getOneRandomServer(rack, skipServers);
assertNotEquals("Skip server should not be selected ",
- skipSN.getHostAndPort(), sn.getHostAndPort());
+ skipSN.getAddress(), sn.getAddress());
assertTrue("Server:" + sn + " does not belong to list: " + servers, servers.contains(sn));
}
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRegionPlacement.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRegionPlacement.java
index aa9408b..f03e99a 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRegionPlacement.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRegionPlacement.java
@@ -450,7 +450,7 @@ public class TestRegionPlacement {
assertNotNull(addrFromRS);
assertNotNull(addrFromPlan);
- assertTrue("Region server " + rs.getServerName().getHostAndPort()
+ assertTrue("Region server " + rs.getServerName().getAddress()
+ " has the " + positions[j] +
" for region " + region.getRegionInfo().getRegionNameAsString() + " is " +
addrFromRS + " which is inconsistent with the plan "
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestBaseLoadBalancer.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestBaseLoadBalancer.java
index d017fa1..0bdbbd0 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestBaseLoadBalancer.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestBaseLoadBalancer.java
@@ -495,8 +495,8 @@ public class TestBaseLoadBalancer extends BalancerTestBase {
// test move
ServerName sn = oldServers.get(0);
int r0 = ArrayUtils.indexOf(cluster.regions, clusterState.get(sn).get(0));
- int f0 = cluster.serversToIndex.get(sn.getHostAndPort());
- int t0 = cluster.serversToIndex.get(servers.get(1).getHostAndPort());
+ int f0 = cluster.serversToIndex.get(sn.getAddress());
+ int t0 = cluster.serversToIndex.get(servers.get(1).getAddress());
cluster.doAction(new MoveRegionAction(r0, f0, t0));
}
@@ -545,11 +545,11 @@ public class TestBaseLoadBalancer extends BalancerTestBase {
int r42 = ArrayUtils.indexOf(cluster.regions, regions.get(42));
int r43 = ArrayUtils.indexOf(cluster.regions, regions.get(43));
- int s0 = cluster.serversToIndex.get(servers.get(0).getHostAndPort());
- int s1 = cluster.serversToIndex.get(servers.get(1).getHostAndPort());
- int s4 = cluster.serversToIndex.get(servers.get(4).getHostAndPort());
- int s5 = cluster.serversToIndex.get(servers.get(5).getHostAndPort());
- int s9 = cluster.serversToIndex.get(servers.get(9).getHostAndPort());
+ int s0 = cluster.serversToIndex.get(servers.get(0).getAddress());
+ int s1 = cluster.serversToIndex.get(servers.get(1).getAddress());
+ int s4 = cluster.serversToIndex.get(servers.get(4).getAddress());
+ int s5 = cluster.serversToIndex.get(servers.get(5).getAddress());
+ int s9 = cluster.serversToIndex.get(servers.get(9).getAddress());
// region 0 locations
assertEquals(1, cluster.regionLocations[r0].length);
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestFavoredStochasticBalancerPickers.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestFavoredStochasticBalancerPickers.java
index 7677eb6..f2226f6 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestFavoredStochasticBalancerPickers.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestFavoredStochasticBalancerPickers.java
@@ -212,7 +212,8 @@ public class TestFavoredStochasticBalancerPickers extends BalancerTestBase {
assertEquals(cluster.servers[moveRegionAction.fromServer], mostLoadedServer);
if (!region.getTable().isSystemTable()) {
List<ServerName> favNodes = fnm.getFavoredNodes(region);
- assertTrue(favNodes.contains(ServerName.valueOf(destinationServer.getHostAndPort(), -1)));
+ assertTrue(favNodes.contains(
+ ServerName.valueOf(destinationServer.getAddress(), -1)));
userRegionPicked = true;
}
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/MasterProcedureTestingUtility.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/MasterProcedureTestingUtility.java
index bd0b465..ea409b0 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/MasterProcedureTestingUtility.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/MasterProcedureTestingUtility.java
@@ -267,7 +267,7 @@ public class MasterProcedureTestingUtility {
if (location == null) continue;
ServerName serverName = location.getServerName();
// Make sure that regions are assigned to server
- if (serverName != null && serverName.getHostAndPort() != null) {
+ if (serverName != null && serverName.getAddress() != null) {
actualRegCount.incrementAndGet();
}
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerAbort.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerAbort.java
index 2b8953e..277cb81 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerAbort.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerAbort.java
@@ -164,7 +164,7 @@ public class TestRegionServerAbort {
public void testStopOverrideFromCoprocessor() throws Exception {
Admin admin = testUtil.getAdmin();
HRegionServer regionserver = cluster.getRegionServer(0);
- admin.stopRegionServer(regionserver.getServerName().getHostAndPort());
+ admin.stopRegionServer(regionserver.getServerName().getAddress().toString());
// regionserver should have failed to stop due to coprocessor
assertFalse(cluster.getRegionServer(0).isAborted());