From 18882d6f9a5830f21099a9a7cdfe57aa594a688b Mon Sep 17 00:00:00 2001 From: Jan Hentschel Date: Mon, 5 Apr 2021 22:10:04 +0200 Subject: [PATCH] HBASE-24305 Prepare deprecations in ServerName (#1666) (#3121) Signed-off-by: Duo Zhang Signed-off-by: stack --- .../hadoop/hbase/client/HBaseAdmin.java | 2 +- .../hbase/client/TestClientNoCluster.java | 2 +- .../org/apache/hadoop/hbase/ServerName.java | 129 ++++++++++-------- .../apache/hadoop/hbase/TestServerName.java | 19 ++- .../favored/FavoredNodeAssignmentHelper.java | 8 +- .../hbase/favored/FavoredNodesManager.java | 8 +- .../favored/StartcodeAgnosticServerName.java | 2 +- .../master/AssignmentVerificationReport.java | 2 +- .../master/RegionPlacementMaintainer.java | 2 +- .../master/balancer/BaseLoadBalancer.java | 27 ++-- .../balancer/FavoredStochasticBalancer.java | 8 +- .../apache/hadoop/hbase/util/HBaseFsck.java | 2 +- .../apache/hadoop/hbase/MetaMockingUtil.java | 2 +- .../hadoop/hbase/TestMetaTableAccessor.java | 2 +- .../hbase/TestMetaTableAccessorNoCluster.java | 2 +- .../client/TestConnectionImplementation.java | 4 +- .../client/TestShortCircuitConnection.java | 2 +- .../TestFavoredNodeAssignmentHelper.java | 2 +- .../hbase/master/TestRegionPlacement.java | 2 +- .../master/balancer/TestBaseLoadBalancer.java | 14 +- .../TestFavoredStochasticBalancerPickers.java | 3 +- .../MasterProcedureTestingUtility.java | 2 +- .../regionserver/TestRegionServerAbort.java | 2 +- 23 files changed, 129 insertions(+), 119 deletions(-) rename {hbase-server => hbase-common}/src/test/java/org/apache/hadoop/hbase/TestServerName.java (93%) diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java index 532481eba3b..488a4daacd5 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java @@ -3696,7 +3696,7 @@ public class HBaseAdmin implements Admin { 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-client/src/test/java/org/apache/hadoop/hbase/client/TestClientNoCluster.java b/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestClientNoCluster.java index 2a4bcf6d129..d79164cc77b 100644 --- a/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestClientNoCluster.java +++ b/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestClientNoCluster.java @@ -657,7 +657,7 @@ public class TestClientNoCluster extends Configured implements Tool { static CellProtos.Cell getServer(final ByteString row, final ServerName sn) { CellProtos.Cell.Builder cellBuilder = getBaseCellBuilder(row); cellBuilder.setQualifier(SERVER_QUALIFIER_BYTESTRING); - cellBuilder.setValue(ByteString.copyFromUtf8(sn.getHostAndPort())); + cellBuilder.setValue(ByteString.copyFromUtf8(sn.getAddress().toString())); return cellBuilder.build(); } 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 34ac1e54ed0..d15d86bfad2 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,26 +116,25 @@ public class ServerName implements Comparable, 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; + if (InetAddresses.isInetAddress(hostname)) { + return hostname; + } + String[] parts = hostname.split("\\."); + if (parts.length == 0) { + return hostname; + } return parts[0]; } @@ -194,7 +189,11 @@ public class ServerName implements Comparable, 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 +205,40 @@ public class ServerName implements Comparable, 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,37 +269,33 @@ public class ServerName implements Comparable, 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 <hostname> ',' <port> ',' <startcode> + * startcode formatted as <hostname> ',' <port> ',' <startcode> * @deprecated Since 2.0. Use {@link ServerName#valueOf(String, int, long)} instead. */ @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(); + return hostName.toLowerCase(Locale.ROOT) + SERVERNAME_SEPARATOR + port + + SERVERNAME_SEPARATOR + startcode; } /** * @param hostAndPort String in form of <hostname> ':' <port> - * @param startcode + * @param startcode the startcode to use * @return Server name made of the concatenation of hostname, port and - * startcode formatted as <hostname> ',' <port> ',' <startcode> + * startcode formatted as <hostname> ',' <port> ',' <startcode> * @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 ':' "); + public static String getServerName(final String hostAndPort, final long startcode) { + int index = hostAndPort.indexOf(':'); + if (index <= 0) { + throw new IllegalArgumentException("Expected ':' "); + } return getServerName(hostAndPort.substring(0, index), Integer.parseInt(hostAndPort.substring(index + 1)), startcode); } @@ -366,24 +375,25 @@ public class ServerName implements Comparable, 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 other 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 +417,8 @@ public class ServerName implements Comparable, 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 +426,14 @@ public class ServerName implements Comparable, 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 93% 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 fcbe9c9e08e..977d07423ad 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 sns = new HashSet(); + Set sns = new HashSet<>(); sns.add(sn2); sns.add(sn1); sns.add(sn1); @@ -57,9 +54,9 @@ public class TestServerName { @Test public void testGetHostNameMinusDomain() { assertEquals("2607:f0d0:1002:51::4", - ServerName.getHostNameMinusDomain("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")); + 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")); @@ -143,12 +140,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-server/src/main/java/org/apache/hadoop/hbase/favored/FavoredNodeAssignmentHelper.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/favored/FavoredNodeAssignmentHelper.java index a754c6b8e43..90483d2665a 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/favored/FavoredNodeAssignmentHelper.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/favored/FavoredNodeAssignmentHelper.java @@ -601,7 +601,7 @@ public class FavoredNodeAssignmentHelper { } if (randomServer != null) { - return ServerName.valueOf(randomServer.getHostAndPort(), randomServer.getStartcode()); + return ServerName.valueOf(randomServer.getAddress(), randomServer.getStartcode()); } else { return null; } @@ -629,7 +629,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(); @@ -773,7 +773,7 @@ public class FavoredNodeAssignmentHelper { List 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 primaryRSMap = new HashMap<>(1); primaryRSMap.put(hri, primary); @@ -782,7 +782,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-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 e7d145036ae..16f0934a291 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> getReplicaLoad(List servers) { Map> result = Maps.newHashMap(); for (ServerName sn : servers) { - ServerName serverWithNoStartCode = ServerName.valueOf(sn.getHostAndPort(), NON_STARTCODE); + ServerName serverWithNoStartCode = ServerName.valueOf(sn.getAddress(), NON_STARTCODE); List countList = Lists.newArrayList(); if (primaryRSToRegionMap.containsKey(serverWithNoStartCode)) { countList.add(primaryRSToRegionMap.get(serverWithNoStartCode).size()); @@ -285,7 +285,7 @@ public class FavoredNodesManager { public synchronized Set getRegionsOfFavoredNode(ServerName serverName) { Set 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/favored/StartcodeAgnosticServerName.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/favored/StartcodeAgnosticServerName.java index d1f9f450f1d..2a7600079d7 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/favored/StartcodeAgnosticServerName.java +++ b/hbase-server/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-server/src/main/java/org/apache/hadoop/hbase/master/AssignmentVerificationReport.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/AssignmentVerificationReport.java index 5c084bf4ebc..420eef7dbaf 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/AssignmentVerificationReport.java +++ b/hbase-server/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-server/src/main/java/org/apache/hadoop/hbase/master/RegionPlacementMaintainer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/RegionPlacementMaintainer.java index 12e9485e96f..a93f7a9e11e 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/RegionPlacementMaintainer.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/RegionPlacementMaintainer.java @@ -716,7 +716,7 @@ public class RegionPlacementMaintainer { " region servers with its corresponding favored nodes"); for (Map.Entry entry : failedUpdateMap.entrySet() ) { - LOG.error("Failed to update " + entry.getKey().getHostAndPort() + + LOG.error("Failed to update " + entry.getKey().getAddress() + " because of " + entry.getValue().getMessage()); } } 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 0d513b02056..91215c7e265 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 @@ -56,6 +56,7 @@ 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.namequeues.NamedQueueRecorder; +import org.apache.hadoop.hbase.net.Address; import org.apache.yetus.audience.InterfaceAudience; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -174,7 +175,7 @@ public abstract class BaseLoadBalancer implements LoadBalancer { Integer[] serverIndicesSortedByRegionCount; Integer[] serverIndicesSortedByLocality; - Map serversToIndex; + Map serversToIndex; Map hostsToIndex; Map racksToIndex; Map tablesToIndex; @@ -243,15 +244,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); @@ -303,7 +304,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. @@ -334,7 +335,7 @@ public abstract class BaseLoadBalancer implements LoadBalancer { } for (Entry> 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()); @@ -506,8 +507,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())); } } } @@ -752,10 +753,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 @@ -815,10 +816,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)); } @@ -1012,7 +1013,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 9024dde6600..e0b008acde5 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 @@ -600,8 +600,8 @@ public class FavoredStochasticBalancer extends StochasticLoadBalancer implements int currentServer) { List 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; @@ -664,8 +664,8 @@ public class FavoredStochasticBalancer extends StochasticLoadBalancer implements int currentServerIndex) { List 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 c7157b2b2b0..42988319387 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 @@ -1772,7 +1772,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 c84c18fcad1..e5cbfaf1584 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 @@ -79,7 +79,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 0abfb4ea065..3bcf9067618 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 @@ -514,7 +514,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/TestMetaTableAccessorNoCluster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestMetaTableAccessorNoCluster.java index ca03cb6f149..75a86e2e67c 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestMetaTableAccessorNoCluster.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestMetaTableAccessorNoCluster.java @@ -169,7 +169,7 @@ public class TestMetaTableAccessorNoCluster { RegionInfo.toByteArray(RegionInfoBuilder.FIRST_META_REGIONINFO))); kvs.add(new KeyValue(rowToVerify, HConstants.CATALOG_FAMILY, HConstants.SERVER_QUALIFIER, - Bytes.toBytes(sn.getHostAndPort()))); + Bytes.toBytes(sn.getAddress().toString()))); kvs.add(new KeyValue(rowToVerify, HConstants.CATALOG_FAMILY, HConstants.STARTCODE_QUALIFIER, Bytes.toBytes(sn.getStartcode()))); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestConnectionImplementation.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestConnectionImplementation.java index b388603bcfa..59844770a61 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestConnectionImplementation.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestConnectionImplementation.java @@ -664,7 +664,7 @@ public class TestConnectionImplementation { } Assert.assertNotNull("Cached connection is null", conn.getCachedLocation(TABLE_NAME, ROW)); Assert.assertEquals( - "Previous server was " + curServer.getServerName().getHostAndPort(), + "Previous server was " + curServer.getServerName().getAddress(), destServerName.getPort(), conn.getCachedLocation(TABLE_NAME, ROW).getRegionLocation().getPort()); @@ -715,7 +715,7 @@ public class TestConnectionImplementation { // Cache is updated with the right value. Assert.assertNotNull(conn.getCachedLocation(TABLE_NAME, ROW)); Assert.assertEquals( - "Previous server was "+destServer.getServerName().getHostAndPort(), + "Previous server was "+destServer.getServerName().getAddress(), curServer.getServerName().getPort(), conn.getCachedLocation(TABLE_NAME, ROW).getRegionLocation().getPort()); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestShortCircuitConnection.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestShortCircuitConnection.java index beaa59be3e6..991cfb9e481 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestShortCircuitConnection.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestShortCircuitConnection.java @@ -84,7 +84,7 @@ public class TestShortCircuitConnection { ClientService.BlockingInterface client = connection.getClient(regionServer.getServerName()); assertTrue(admin instanceof RSRpcServices); assertTrue(client instanceof RSRpcServices); - ServerName anotherSn = ServerName.valueOf(regionServer.getServerName().getHostAndPort(), + ServerName anotherSn = ServerName.valueOf(regionServer.getServerName().getAddress(), EnvironmentEdgeManager.currentTime()); admin = connection.getAdmin(anotherSn); client = connection.getClient(anotherSn); 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 bc721e11c8c..a42410a2aab 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 1d78e13583f..87028f3a9f4 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 137d50db479..794ffd3230b 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 @@ -494,8 +494,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)); } @@ -544,11 +544,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 6a050a8d6f0..73071c7f6ac 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 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 45a8cca7457..c798c694fcc 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 @@ -266,7 +266,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 5f4120f034f..94b53cc7e3e 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 @@ -170,7 +170,7 @@ public class TestRegionServerAbort { public void testStopOverrideFromCoprocessor() throws Exception { Admin admin = testUtil.getHBaseAdmin(); 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());