HBASE-24305 Prepare deprecations in ServerName (#1666) (#3121)

Signed-off-by: Duo Zhang <zhangduo@apache.org>
Signed-off-by: stack <stack@apache.org>
This commit is contained in:
Jan Hentschel 2021-04-05 22:10:04 +02:00 committed by GitHub
parent 1fa07cea80
commit 18882d6f9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 129 additions and 119 deletions

View File

@ -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();
}
}

View File

@ -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();
}

View File

@ -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<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;
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<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,13 +205,27 @@ 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,
* @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.
@ -225,7 +238,7 @@ public class ServerName implements Comparable<ServerName>, Serializable {
/**
* @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,9 +269,9 @@ 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>&lt;hostname&gt; ',' &lt;port&gt; ',' &lt;startcode&gt;</code>
* @deprecated Since 2.0. Use {@link ServerName#valueOf(String, int, long)} instead.
@ -266,27 +279,23 @@ public class ServerName implements Comparable<ServerName>, Serializable {
@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 &lt;hostname&gt; ':' &lt;port&gt;
* @param startcode
* @param startcode the startcode to use
* @return Server name made of the concatenation of hostname, port and
* startcode formatted as <code>&lt;hostname&gt; ',' &lt;port&gt; ',' &lt;startcode&gt;</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>");
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);
}
@ -366,24 +375,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,7 +417,7 @@ public class ServerName implements Comparable<ServerName>, Serializable {
}
/**
* @param str Either an instance of {@link ServerName#toString()} or a
* @param str Either an instance of {@link #toString()} or a
* "'&lt;hostname&gt;' ':' '&lt;port&gt;'".
* @return A ServerName instance.
*/
@ -416,13 +426,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
* @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();
}
}

View File

@ -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);
@ -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));
}
}
}

View File

@ -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<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);
@ -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 {

View File

@ -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());
@ -285,7 +285,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));
}

View File

@ -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

View File

@ -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");
}

View File

@ -716,7 +716,7 @@ public class RegionPlacementMaintainer {
" region servers with its corresponding favored nodes");
for (Map.Entry<ServerName, Exception> entry :
failedUpdateMap.entrySet() ) {
LOG.error("Failed to update " + entry.getKey().getHostAndPort() +
LOG.error("Failed to update " + entry.getKey().getAddress() +
" because of " + entry.getValue().getMessage());
}
}

View File

@ -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<String, Integer> serversToIndex;
Map<Address, Integer> serversToIndex;
Map<String, Integer> hostsToIndex;
Map<String, Integer> racksToIndex;
Map<String, Integer> 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<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());
@ -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))

View File

@ -600,8 +600,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;
@ -664,8 +664,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;

View File

@ -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());
}
}

View File

@ -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())));

View File

@ -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())));

View File

@ -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())));

View File

@ -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());

View File

@ -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);

View File

@ -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));
}
}

View File

@ -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 "

View File

@ -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);

View File

@ -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;
}
}

View File

@ -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();
}
}

View File

@ -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());