HBASE-7861 Use the ServerName in the Connection#getClient and Connection#getAdmin code

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1446897 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
nkeywal 2013-02-16 14:13:46 +00:00
parent a0d6e79a4c
commit 900be56ea1
22 changed files with 186 additions and 145 deletions

View File

@ -85,12 +85,12 @@ public class DistributedHBaseCluster extends HBaseCluster {
@Override @Override
public AdminProtocol getAdminProtocol(ServerName serverName) throws IOException { public AdminProtocol getAdminProtocol(ServerName serverName) throws IOException {
return admin.getConnection().getAdmin(serverName.getHostname(), serverName.getPort()); return admin.getConnection().getAdmin(serverName);
} }
@Override @Override
public ClientProtocol getClientProtocol(ServerName serverName) throws IOException { public ClientProtocol getClientProtocol(ServerName serverName) throws IOException {
return admin.getConnection().getClient(serverName.getHostname(), serverName.getPort()); return admin.getConnection().getClient(serverName);
} }
@Override @Override
@ -193,7 +193,7 @@ public class DistributedHBaseCluster extends HBaseCluster {
return null; return null;
} }
AdminProtocol client = connection.getAdmin(regionLoc.getHostname(), regionLoc.getPort()); AdminProtocol client = connection.getAdmin(regionLoc.getServerName());
ServerInfo info = ProtobufUtil.getServerInfo(client); ServerInfo info = ProtobufUtil.getServerInfo(client);
return ProtobufUtil.toServerName(info.getServerName()); return ProtobufUtil.toServerName(info.getServerName());
} }

View File

@ -33,33 +33,19 @@ import org.apache.hadoop.hbase.util.Addressing;
@InterfaceStability.Evolving @InterfaceStability.Evolving
public class HRegionLocation implements Comparable<HRegionLocation> { public class HRegionLocation implements Comparable<HRegionLocation> {
private final HRegionInfo regionInfo; private final HRegionInfo regionInfo;
private final String hostname; private final ServerName serverName;
private final int port;
private final long seqNum; private final long seqNum;
// Cache of the 'toString' result. // Cache of the 'toString' result.
private String cachedString = null; private String cachedString = null;
// Cache of the hostname + port // Cache of the hostname + port
private String cachedHostnamePort; private String cachedHostnamePort;
/** public HRegionLocation(HRegionInfo regionInfo, ServerName serverName, long seqNum) {
* Constructor
* @param regionInfo the HRegionInfo for the region
*/
public HRegionLocation(HRegionInfo regionInfo, final String hostname,
final int port, final long seqNum) {
this.regionInfo = regionInfo; this.regionInfo = regionInfo;
this.hostname = hostname; this.serverName = serverName;
this.port = port;
this.seqNum = seqNum; this.seqNum = seqNum;
} }
/**
* Test constructor w/o seqNum.
*/
public HRegionLocation(HRegionInfo regionInfo, final String hostname, final int port) {
this(regionInfo, hostname, port, 0);
}
/** /**
* @see java.lang.Object#toString() * @see java.lang.Object#toString()
*/ */
@ -67,8 +53,7 @@ public class HRegionLocation implements Comparable<HRegionLocation> {
public synchronized String toString() { public synchronized String toString() {
if (this.cachedString == null) { if (this.cachedString == null) {
this.cachedString = "region=" + this.regionInfo.getRegionNameAsString() + this.cachedString = "region=" + this.regionInfo.getRegionNameAsString() +
", hostname=" + this.hostname + ", port=" + this.port ", hostname=" + this.serverName + ", seqNum=" + seqNum;
+ ", seqNum=" + seqNum;
} }
return this.cachedString; return this.cachedString;
} }
@ -95,9 +80,7 @@ public class HRegionLocation implements Comparable<HRegionLocation> {
*/ */
@Override @Override
public int hashCode() { public int hashCode() {
int result = this.hostname.hashCode(); return this.serverName.hashCode();
result ^= this.port;
return result;
} }
/** @return HRegionInfo */ /** @return HRegionInfo */
@ -106,11 +89,11 @@ public class HRegionLocation implements Comparable<HRegionLocation> {
} }
public String getHostname() { public String getHostname() {
return this.hostname; return this.serverName.getHostname();
} }
public int getPort() { public int getPort() {
return this.port; return this.serverName.getPort();
} }
public long getSeqNum() { public long getSeqNum() {
@ -123,18 +106,16 @@ public class HRegionLocation implements Comparable<HRegionLocation> {
public synchronized String getHostnamePort() { public synchronized String getHostnamePort() {
if (this.cachedHostnamePort == null) { if (this.cachedHostnamePort == null) {
this.cachedHostnamePort = this.cachedHostnamePort =
Addressing.createHostAndPortStr(this.hostname, this.port); Addressing.createHostAndPortStr(this.getHostname(), this.getPort());
} }
return this.cachedHostnamePort; return this.cachedHostnamePort;
} }
// public ServerName getServerName() {
// Comparable return serverName;
// }
public int compareTo(HRegionLocation o) { public int compareTo(HRegionLocation o) {
int result = this.hostname.compareTo(o.getHostname()); return serverName.compareTo(o.getServerName());
if (result != 0) return result;
return this.port - o.getPort();
} }
} }

View File

@ -35,17 +35,19 @@ public class RegionMovedException extends NotServingRegionException {
private final String hostname; private final String hostname;
private final int port; private final int port;
private final long startCode;
private final long locationSeqNum; private final long locationSeqNum;
private static final String HOST_FIELD = "hostname="; private static final String HOST_FIELD = "hostname=";
private static final String PORT_FIELD = "port="; private static final String PORT_FIELD = "port=";
private static final String STARTCODE_FIELD = "startCode=";
private static final String LOCATIONSEQNUM_FIELD = "locationSeqNum="; private static final String LOCATIONSEQNUM_FIELD = "locationSeqNum=";
public RegionMovedException(final String hostname, final int port,
final long locationSeqNum) { public RegionMovedException(ServerName serverName, long locationSeqNum) {
super(); this.hostname = serverName.getHostname();
this.hostname = hostname; this.port = serverName.getPort();
this.port = port; this.startCode = serverName.getStartcode();
this.locationSeqNum = locationSeqNum; this.locationSeqNum = locationSeqNum;
} }
@ -57,6 +59,10 @@ public class RegionMovedException extends NotServingRegionException {
return port; return port;
} }
public ServerName getServerName(){
return new ServerName(hostname, port, startCode);
}
public long getLocationSeqNum() { public long getLocationSeqNum() {
return locationSeqNum; return locationSeqNum;
} }
@ -69,22 +75,27 @@ public class RegionMovedException extends NotServingRegionException {
public RegionMovedException(String s) { public RegionMovedException(String s) {
int posHostname = s.indexOf(HOST_FIELD) + HOST_FIELD.length(); int posHostname = s.indexOf(HOST_FIELD) + HOST_FIELD.length();
int posPort = s.indexOf(PORT_FIELD) + PORT_FIELD.length(); int posPort = s.indexOf(PORT_FIELD) + PORT_FIELD.length();
int posStartCode = s.indexOf(STARTCODE_FIELD) + STARTCODE_FIELD.length();
int posSeqNum = s.indexOf(LOCATIONSEQNUM_FIELD) + LOCATIONSEQNUM_FIELD.length(); int posSeqNum = s.indexOf(LOCATIONSEQNUM_FIELD) + LOCATIONSEQNUM_FIELD.length();
String tmpHostname = null; String tmpHostname = null;
int tmpPort = -1; int tmpPort = -1;
long tmpStartCode = -1;
long tmpSeqNum = HConstants.NO_SEQNUM; long tmpSeqNum = HConstants.NO_SEQNUM;
try { try {
// TODO: this whole thing is extremely brittle. // TODO: this whole thing is extremely brittle.
tmpHostname = s.substring(posHostname, s.indexOf(' ', posHostname)); tmpHostname = s.substring(posHostname, s.indexOf(' ', posHostname));
tmpPort = Integer.parseInt(s.substring(posPort, s.indexOf('.', posPort))); tmpPort = Integer.parseInt(s.substring(posPort, s.indexOf(' ', posPort)));
tmpStartCode = Long.parseLong(s.substring(posStartCode, s.indexOf('.', posStartCode)));
tmpSeqNum = Long.parseLong(s.substring(posSeqNum, s.indexOf('.', posSeqNum))); tmpSeqNum = Long.parseLong(s.substring(posSeqNum, s.indexOf('.', posSeqNum)));
} catch (Exception ignored) { } catch (Exception ignored) {
LOG.warn("Can't parse the hostname and the port from this string: " + s + ", continuing"); LOG.warn("Can't parse the hostname, port and startCode from this string: " +
s + ", continuing");
} }
hostname = tmpHostname; hostname = tmpHostname;
port = tmpPort; port = tmpPort;
startCode = tmpStartCode;
locationSeqNum = tmpSeqNum; locationSeqNum = tmpSeqNum;
} }
@ -92,8 +103,8 @@ public class RegionMovedException extends NotServingRegionException {
public String getMessage() { public String getMessage() {
// TODO: deserialization above depends on this. That is bad, but also means this // TODO: deserialization above depends on this. That is bad, but also means this
// should be modified carefully. // should be modified carefully.
return "Region moved to: " + HOST_FIELD + hostname + " " + PORT_FIELD + port + ". As of " return "Region moved to: " + HOST_FIELD + hostname + " " + PORT_FIELD + port + " " +
+ LOCATIONSEQNUM_FIELD + locationSeqNum + "."; STARTCODE_FIELD + startCode + ". As of " + LOCATIONSEQNUM_FIELD + locationSeqNum + ".";
} }
/** /**

View File

@ -497,7 +497,7 @@ public class CatalogTracker {
} }
AdminProtocol protocol = null; AdminProtocol protocol = null;
try { try {
protocol = connection.getAdmin(sn.getHostname(), sn.getPort()); protocol = connection.getAdmin(sn);
} catch (RetriesExhaustedException e) { } catch (RetriesExhaustedException e) {
if (e.getCause() != null && e.getCause() instanceof ConnectException) { if (e.getCause() != null && e.getCause() instanceof ConnectException) {
// Catch this; presume it means the cached connection has gone bad. // Catch this; presume it means the cached connection has gone bad.

View File

@ -539,7 +539,7 @@ public class HBaseAdmin implements Abortable, Closeable {
// Wait until all regions deleted // Wait until all regions deleted
ClientProtocol server = ClientProtocol server =
connection.getClient(firstMetaServer.getHostname(), firstMetaServer.getPort()); connection.getClient(firstMetaServer.getServerName());
for (int tries = 0; tries < (this.numRetries * this.retryLongerMultiplier); tries++) { for (int tries = 0; tries < (this.numRetries * this.retryLongerMultiplier); tries++) {
try { try {
@ -1153,8 +1153,7 @@ public class HBaseAdmin implements Abortable, Closeable {
"The servername cannot be null or empty."); "The servername cannot be null or empty.");
} }
ServerName sn = new ServerName(serverName); ServerName sn = new ServerName(serverName);
AdminProtocol admin = this.connection.getAdmin( AdminProtocol admin = this.connection.getAdmin(sn);
sn.getHostname(), sn.getPort());
// Close the region without updating zk state. // Close the region without updating zk state.
CloseRegionRequest request = CloseRegionRequest request =
RequestConverter.buildCloseRegionRequest(encodedRegionName, false); RequestConverter.buildCloseRegionRequest(encodedRegionName, false);
@ -1180,7 +1179,7 @@ public class HBaseAdmin implements Abortable, Closeable {
public void closeRegion(final ServerName sn, final HRegionInfo hri) public void closeRegion(final ServerName sn, final HRegionInfo hri)
throws IOException { throws IOException {
AdminProtocol admin = AdminProtocol admin =
this.connection.getAdmin(sn.getHostname(), sn.getPort()); this.connection.getAdmin(sn);
// Close the region without updating zk state. // Close the region without updating zk state.
ProtobufUtil.closeRegion(admin, hri.getRegionName(), false); ProtobufUtil.closeRegion(admin, hri.getRegionName(), false);
} }
@ -1191,7 +1190,7 @@ public class HBaseAdmin implements Abortable, Closeable {
public List<HRegionInfo> getOnlineRegions( public List<HRegionInfo> getOnlineRegions(
final ServerName sn) throws IOException { final ServerName sn) throws IOException {
AdminProtocol admin = AdminProtocol admin =
this.connection.getAdmin(sn.getHostname(), sn.getPort()); this.connection.getAdmin(sn);
return ProtobufUtil.getOnlineRegions(admin); return ProtobufUtil.getOnlineRegions(admin);
} }
@ -1254,7 +1253,7 @@ public class HBaseAdmin implements Abortable, Closeable {
private void flush(final ServerName sn, final HRegionInfo hri) private void flush(final ServerName sn, final HRegionInfo hri)
throws IOException { throws IOException {
AdminProtocol admin = AdminProtocol admin =
this.connection.getAdmin(sn.getHostname(), sn.getPort()); this.connection.getAdmin(sn);
FlushRegionRequest request = FlushRegionRequest request =
RequestConverter.buildFlushRegionRequest(hri.getRegionName()); RequestConverter.buildFlushRegionRequest(hri.getRegionName());
try { try {
@ -1424,7 +1423,7 @@ public class HBaseAdmin implements Abortable, Closeable {
final boolean major, final byte [] family) final boolean major, final byte [] family)
throws IOException { throws IOException {
AdminProtocol admin = AdminProtocol admin =
this.connection.getAdmin(sn.getHostname(), sn.getPort()); this.connection.getAdmin(sn);
CompactRegionRequest request = CompactRegionRequest request =
RequestConverter.buildCompactRegionRequest(hri.getRegionName(), major, family); RequestConverter.buildCompactRegionRequest(hri.getRegionName(), major, family);
try { try {
@ -1702,7 +1701,7 @@ public class HBaseAdmin implements Abortable, Closeable {
private void split(final ServerName sn, final HRegionInfo hri, private void split(final ServerName sn, final HRegionInfo hri,
byte[] splitPoint) throws IOException { byte[] splitPoint) throws IOException {
AdminProtocol admin = AdminProtocol admin =
this.connection.getAdmin(sn.getHostname(), sn.getPort()); this.connection.getAdmin(sn);
ProtobufUtil.split(admin, hri, splitPoint); ProtobufUtil.split(admin, hri, splitPoint);
} }
@ -1826,7 +1825,7 @@ public class HBaseAdmin implements Abortable, Closeable {
String hostname = Addressing.parseHostname(hostnamePort); String hostname = Addressing.parseHostname(hostnamePort);
int port = Addressing.parsePort(hostnamePort); int port = Addressing.parsePort(hostnamePort);
AdminProtocol admin = AdminProtocol admin =
this.connection.getAdmin(hostname, port); this.connection.getAdmin(new ServerName(hostname, port, 0));
StopServerRequest request = RequestConverter.buildStopServerRequest( StopServerRequest request = RequestConverter.buildStopServerRequest(
"Called by admin client " + this.connection.toString()); "Called by admin client " + this.connection.toString());
try { try {
@ -1836,6 +1835,7 @@ public class HBaseAdmin implements Abortable, Closeable {
} }
} }
/** /**
* @return cluster status * @return cluster status
* @throws IOException if a remote or network exception occurs * @throws IOException if a remote or network exception occurs
@ -1967,9 +1967,8 @@ public class HBaseAdmin implements Abortable, Closeable {
public synchronized byte[][] rollHLogWriter(String serverName) public synchronized byte[][] rollHLogWriter(String serverName)
throws IOException, FailedLogCloseException { throws IOException, FailedLogCloseException {
ServerName sn = new ServerName(serverName); ServerName sn = new ServerName(serverName);
AdminProtocol admin = this.connection.getAdmin( AdminProtocol admin = this.connection.getAdmin(sn);
sn.getHostname(), sn.getPort()); RollWALWriterRequest request = RequestConverter.buildRollWALWriterRequest();
RollWALWriterRequest request = RequestConverter.buildRollWALWriterRequest();;
try { try {
RollWALWriterResponse response = admin.rollWALWriter(null, request); RollWALWriterResponse response = admin.rollWALWriter(null, request);
int regionCount = response.getRegionToFlushCount(); int regionCount = response.getRegionToFlushCount();
@ -2029,7 +2028,7 @@ public class HBaseAdmin implements Abortable, Closeable {
} else { } else {
ServerName sn = regionServerPair.getSecond(); ServerName sn = regionServerPair.getSecond();
AdminProtocol admin = AdminProtocol admin =
this.connection.getAdmin(sn.getHostname(), sn.getPort()); this.connection.getAdmin(sn);
GetRegionInfoRequest request = RequestConverter.buildGetRegionInfoRequest( GetRegionInfoRequest request = RequestConverter.buildGetRegionInfoRequest(
regionServerPair.getFirst().getRegionName(), true); regionServerPair.getFirst().getRegionName(), true);
GetRegionInfoResponse response = admin.getRegionInfo(null, request); GetRegionInfoResponse response = admin.getRegionInfo(null, request);
@ -2045,7 +2044,7 @@ public class HBaseAdmin implements Abortable, Closeable {
try { try {
ServerName sn = pair.getSecond(); ServerName sn = pair.getSecond();
AdminProtocol admin = AdminProtocol admin =
this.connection.getAdmin(sn.getHostname(), sn.getPort()); this.connection.getAdmin(sn);
GetRegionInfoRequest request = RequestConverter.buildGetRegionInfoRequest( GetRegionInfoRequest request = RequestConverter.buildGetRegionInfoRequest(
pair.getFirst().getRegionName(), true); pair.getFirst().getRegionName(), true);
GetRegionInfoResponse response = admin.getRegionInfo(null, request); GetRegionInfoResponse response = admin.getRegionInfo(null, request);

View File

@ -32,6 +32,7 @@ import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.MasterAdminProtocol; import org.apache.hadoop.hbase.MasterAdminProtocol;
import org.apache.hadoop.hbase.MasterMonitorProtocol; import org.apache.hadoop.hbase.MasterMonitorProtocol;
import org.apache.hadoop.hbase.MasterNotRunningException; import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.ZooKeeperConnectionException; import org.apache.hadoop.hbase.ZooKeeperConnectionException;
import org.apache.hadoop.hbase.catalog.CatalogTracker; import org.apache.hadoop.hbase.catalog.CatalogTracker;
import org.apache.hadoop.hbase.client.coprocessor.Batch; import org.apache.hadoop.hbase.client.coprocessor.Batch;
@ -208,11 +209,23 @@ public interface HConnection extends Abortable, Closeable {
* @param port RegionServer port * @param port RegionServer port
* @return proxy for HRegionServer * @return proxy for HRegionServer
* @throws IOException if a remote or network exception occurs * @throws IOException if a remote or network exception occurs
* * @deprecated - use @link {#getAdmin(final ServerName serverName)} which takes into account
* the startCode
*/ */
@Deprecated
public AdminProtocol getAdmin(final String hostname, final int port) public AdminProtocol getAdmin(final String hostname, final int port)
throws IOException; throws IOException;
/**
* Establishes a connection to the region server at the specified address.
* @param serverName
* @return proxy for HRegionServer
* @throws IOException if a remote or network exception occurs
*/
public AdminProtocol getAdmin(final ServerName serverName)
throws IOException;
/** /**
* Establishes a connection to the region server at the specified address, and return * Establishes a connection to the region server at the specified address, and return
* a region client protocol. * a region client protocol.
@ -221,11 +234,25 @@ public interface HConnection extends Abortable, Closeable {
* @param port RegionServer port * @param port RegionServer port
* @return ClientProtocol proxy for RegionServer * @return ClientProtocol proxy for RegionServer
* @throws IOException if a remote or network exception occurs * @throws IOException if a remote or network exception occurs
* * @deprecated - use @link {#getClient(final ServerName serverName)} which takes into account
* the startCode
*/ */
@Deprecated
public ClientProtocol getClient(final String hostname, final int port) public ClientProtocol getClient(final String hostname, final int port)
throws IOException; throws IOException;
/**
* Establishes a connection to the region server at the specified address, and return
* a region client protocol.
*
* @param serverName
* @return ClientProtocol proxy for RegionServer
* @throws IOException if a remote or network exception occurs
*
*/
public ClientProtocol getClient(final ServerName serverName) throws IOException;
/** /**
* Establishes a connection to the region server at the specified address. * Establishes a connection to the region server at the specified address.
* @param hostname RegionServer hostname * @param hostname RegionServer hostname
@ -233,11 +260,23 @@ public interface HConnection extends Abortable, Closeable {
* @param getMaster - do we check if master is alive * @param getMaster - do we check if master is alive
* @return proxy for HRegionServer * @return proxy for HRegionServer
* @throws IOException if a remote or network exception occurs * @throws IOException if a remote or network exception occurs
* @deprecated use @link {#getAdmin(final ServerName serverName, boolean getMaster)}
* which takes into account the startCode.
*/ */
public AdminProtocol getAdmin(final String hostname, @Deprecated
final int port, boolean getMaster) public AdminProtocol getAdmin(final String hostname, final int port, boolean getMaster)
throws IOException; throws IOException;
/**
* Establishes a connection to the region server at the specified address.
* @param serverName
* @param getMaster - do we check if master is alive
* @return proxy for HRegionServer
* @throws IOException if a remote or network exception occurs
*/
public AdminProtocol getAdmin(final ServerName serverName, boolean getMaster)
throws IOException;
/** /**
* Find region location hosting passed row * Find region location hosting passed row
* @param tableName table name * @param tableName table name

View File

@ -85,7 +85,6 @@ import org.apache.hadoop.hbase.protobuf.generated.MasterMonitorProtos.GetTableDe
import org.apache.hadoop.hbase.security.User; import org.apache.hadoop.hbase.security.User;
import org.apache.hadoop.hbase.util.Addressing; import org.apache.hadoop.hbase.util.Addressing;
import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.hbase.util.Pair; import org.apache.hadoop.hbase.util.Pair;
import org.apache.hadoop.hbase.util.SoftValueSortedMap; import org.apache.hadoop.hbase.util.SoftValueSortedMap;
import org.apache.hadoop.hbase.util.Triple; import org.apache.hadoop.hbase.util.Triple;
@ -959,8 +958,7 @@ public class HConnectionManager {
LOG.debug("Looked up root region location, connection=" + this + LOG.debug("Looked up root region location, connection=" + this +
"; serverName=" + ((servername == null) ? "null" : servername)); "; serverName=" + ((servername == null) ? "null" : servername));
if (servername == null) return null; if (servername == null) return null;
return new HRegionLocation(HRegionInfo.ROOT_REGIONINFO, servername.getHostname(), return new HRegionLocation(HRegionInfo.ROOT_REGIONINFO, servername, 0);
servername.getPort(), 0);
} catch (InterruptedException e) { } catch (InterruptedException e) {
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
return null; return null;
@ -1008,8 +1006,8 @@ public class HConnectionManager {
return true; // don't cache it return true; // don't cache it
} }
// instantiate the location // instantiate the location
HRegionLocation loc = new HRegionLocation(regionInfo, serverName.getHostname(), HRegionLocation loc = new HRegionLocation(regionInfo, serverName,
serverName.getPort(), HRegionInfo.getSeqNumDuringOpen(result)); HRegionInfo.getSeqNumDuringOpen(result));
// cache this meta entry // cache this meta entry
cacheLocation(tableName, null, loc); cacheLocation(tableName, null, loc);
return true; return true;
@ -1063,7 +1061,7 @@ public class HConnectionManager {
// If null still, go around again. // If null still, go around again.
if (metaLocation == null) continue; if (metaLocation == null) continue;
ClientProtocol server = ClientProtocol server =
getClient(metaLocation.getHostname(), metaLocation.getPort()); getClient(metaLocation.getServerName());
Result regionInfoRow = null; Result regionInfoRow = null;
// This block guards against two threads trying to load the meta // This block guards against two threads trying to load the meta
@ -1133,8 +1131,8 @@ public class HConnectionManager {
} }
// Instantiate the location // Instantiate the location
location = new HRegionLocation(regionInfo, serverName.getHostname(), location = new HRegionLocation(regionInfo, serverName,
serverName.getPort(), HRegionInfo.getSeqNumDuringOpen(regionInfoRow)); HRegionInfo.getSeqNumDuringOpen(regionInfoRow));
cacheLocation(tableName, null, location); cacheLocation(tableName, null, location);
return location; return location;
} catch (TableNotFoundException e) { } catch (TableNotFoundException e) {
@ -1218,7 +1216,7 @@ public class HConnectionManager {
return possibleRegion; return possibleRegion;
} }
// Passed all the way through, so we got nothin - complete cache miss // Passed all the way through, so we got nothing - complete cache miss
return null; return null;
} }
@ -1368,24 +1366,46 @@ public class HConnectionManager {
} }
@Override @Override
public AdminProtocol getAdmin(final String hostname, @Deprecated
final int port) throws IOException { public AdminProtocol getAdmin(final String hostname, final int port) throws IOException {
return getAdmin(hostname, port, false); return getAdmin(new ServerName(hostname, port, 0L));
} }
@Override @Override
public AdminProtocol getAdmin(final ServerName serverName)
throws IOException {
return getAdmin(serverName, false);
}
@Override
@Deprecated
public ClientProtocol getClient(final String hostname, final int port) public ClientProtocol getClient(final String hostname, final int port)
throws IOException { throws IOException {
return (ClientProtocol)getProtocol(hostname, port, clientClass); return (ClientProtocol)getProtocol(hostname, port, clientClass);
} }
@Override @Override
public ClientProtocol getClient(final ServerName serverName)
throws IOException {
return (ClientProtocol)
getProtocol(serverName.getHostname(), serverName.getPort(), clientClass);
}
@Override
@Deprecated
public AdminProtocol getAdmin(final String hostname, final int port, public AdminProtocol getAdmin(final String hostname, final int port,
final boolean master) final boolean master)
throws IOException { throws IOException {
return (AdminProtocol)getProtocol(hostname, port, adminClass); return (AdminProtocol)getProtocol(hostname, port, adminClass);
} }
@Override
public AdminProtocol getAdmin(final ServerName serverName, final boolean master)
throws IOException {
return (AdminProtocol)getProtocol(
serverName.getHostname(), serverName.getPort(), adminClass);
}
/** /**
* Either the passed <code>isa</code> is null or <code>hostname</code> * Either the passed <code>isa</code> is null or <code>hostname</code>
* can be but not both. * can be but not both.
@ -1757,8 +1777,7 @@ public class HConnectionManager {
@Override @Override
public void connect(boolean reload) throws IOException { public void connect(boolean reload) throws IOException {
server = connection.getClient( server = connection.getClient(loc.getServerName());
loc.getHostname(), loc.getPort());
} }
}; };
return callable.withoutRetries(); return callable.withoutRetries();
@ -1767,8 +1786,8 @@ public class HConnectionManager {
} }
void updateCachedLocation(HRegionInfo hri, HRegionLocation source, void updateCachedLocation(HRegionInfo hri, HRegionLocation source,
String hostname, int port, long seqNum) { ServerName serverName, long seqNum) {
HRegionLocation newHrl = new HRegionLocation(hri, hostname, port, seqNum); HRegionLocation newHrl = new HRegionLocation(hri, serverName, seqNum);
synchronized (this.cachedRegionLocations) { synchronized (this.cachedRegionLocations) {
cacheLocation(hri.getTableName(), source, newHrl); cacheLocation(hri.getTableName(), source, newHrl);
} }
@ -1781,7 +1800,7 @@ public class HConnectionManager {
*/ */
void deleteCachedLocation(HRegionInfo hri, HRegionLocation source) { void deleteCachedLocation(HRegionInfo hri, HRegionLocation source) {
boolean isStaleDelete = false; boolean isStaleDelete = false;
HRegionLocation oldLocation = null; HRegionLocation oldLocation;
synchronized (this.cachedRegionLocations) { synchronized (this.cachedRegionLocations) {
Map<byte[], HRegionLocation> tableLocations = Map<byte[], HRegionLocation> tableLocations =
getTableLocations(hri.getTableName()); getTableLocations(hri.getTableName());
@ -1829,7 +1848,7 @@ public class HConnectionManager {
LOG.info("Region " + regionInfo.getRegionNameAsString() + " moved to " + LOG.info("Region " + regionInfo.getRegionNameAsString() + " moved to " +
rme.getHostname() + ":" + rme.getPort() + " according to " + source.getHostnamePort()); rme.getHostname() + ":" + rme.getPort() + " according to " + source.getHostnamePort());
updateCachedLocation( updateCachedLocation(
regionInfo, source, rme.getHostname(), rme.getPort(), rme.getLocationSeqNum()); regionInfo, source, rme.getServerName(), rme.getLocationSeqNum());
} else { } else {
deleteCachedLocation(regionInfo, source); deleteCachedLocation(regionInfo, source);
} }
@ -2124,8 +2143,7 @@ public class HConnectionManager {
} }
} }
public String getDescriptionAndClear() public String getDescriptionAndClear(){
{
if (exceptions.isEmpty()) { if (exceptions.isEmpty()) {
return ""; return "";
} }
@ -2134,7 +2152,7 @@ public class HConnectionManager {
actions.clear(); actions.clear();
addresses.clear(); addresses.clear();
return result; return result;
}; }
private RetriesExhaustedWithDetailsException makeException() { private RetriesExhaustedWithDetailsException makeException() {
return new RetriesExhaustedWithDetailsException(exceptions, actions, addresses); return new RetriesExhaustedWithDetailsException(exceptions, actions, addresses);

View File

@ -87,8 +87,7 @@ public abstract class ServerCallable<T> implements Callable<T> {
*/ */
public void connect(final boolean reload) throws IOException { public void connect(final boolean reload) throws IOException {
this.location = connection.getRegionLocation(tableName, row, reload); this.location = connection.getRegionLocation(tableName, row, reload);
this.server = connection.getClient(location.getHostname(), this.server = connection.getClient(location.getServerName());
location.getPort());
} }
/** @return the server name /** @return the server name

View File

@ -683,7 +683,7 @@ public class ServerManager {
AdminProtocol admin = this.serverConnections.get(sn); AdminProtocol admin = this.serverConnections.get(sn);
if (admin == null) { if (admin == null) {
LOG.debug("New connection to " + sn.toString()); LOG.debug("New connection to " + sn.toString());
admin = this.connection.getAdmin(sn.getHostname(), sn.getPort()); admin = this.connection.getAdmin(sn);
this.serverConnections.put(sn, admin); this.serverConnections.put(sn, admin);
} }
return admin; return admin;

View File

@ -2527,8 +2527,7 @@ public class HRegionServer implements ClientProtocol,
if (region == null) { if (region == null) {
MovedRegionInfo moveInfo = getMovedRegion(encodedRegionName); MovedRegionInfo moveInfo = getMovedRegion(encodedRegionName);
if (moveInfo != null) { if (moveInfo != null) {
throw new RegionMovedException(moveInfo.getServerName().getHostname(), throw new RegionMovedException(moveInfo.getServerName(), moveInfo.getSeqNum());
moveInfo.getServerName().getPort(), moveInfo.getSeqNum());
} else { } else {
throw new NotServingRegionException("Region is not online: " + encodedRegionName); throw new NotServingRegionException("Region is not online: " + encodedRegionName);
} }

View File

@ -764,7 +764,7 @@ public class ReplicationSource extends Thread
} }
ServerName address = ServerName address =
currentPeers.get(random.nextInt(this.currentPeers.size())); currentPeers.get(random.nextInt(this.currentPeers.size()));
return this.conn.getAdmin(address.getHostname(), address.getPort()); return this.conn.getAdmin(address);
} }
/** /**

View File

@ -3031,7 +3031,7 @@ public class HBaseFsck extends Configured implements Tool {
errors.progress(); errors.progress();
try { try {
AdminProtocol server = AdminProtocol server =
connection.getAdmin(rsinfo.getHostname(), rsinfo.getPort()); connection.getAdmin(rsinfo);
// list all online regions from this region server // list all online regions from this region server
List<HRegionInfo> regions = ProtobufUtil.getOnlineRegions(server); List<HRegionInfo> regions = ProtobufUtil.getOnlineRegions(server);

View File

@ -149,7 +149,7 @@ public class HBaseFsckRepair {
public static void closeRegionSilentlyAndWait(HBaseAdmin admin, public static void closeRegionSilentlyAndWait(HBaseAdmin admin,
ServerName server, HRegionInfo region) throws IOException, InterruptedException { ServerName server, HRegionInfo region) throws IOException, InterruptedException {
HConnection connection = admin.getConnection(); HConnection connection = admin.getConnection();
AdminProtocol rs = connection.getAdmin(server.getHostname(), server.getPort()); AdminProtocol rs = connection.getAdmin(server);
ProtobufUtil.closeRegion(rs, region.getRegionName(), false); ProtobufUtil.closeRegion(rs, region.getRegionName(), false);
long timeout = admin.getConfiguration() long timeout = admin.getConfiguration()
.getLong("hbase.hbck.close.timeout", 120000); .getLong("hbase.hbck.close.timeout", 120000);

View File

@ -37,24 +37,24 @@ public class TestHRegionLocation {
public void testHashAndEqualsCode() { public void testHashAndEqualsCode() {
ServerName hsa1 = new ServerName("localhost", 1234, -1L); ServerName hsa1 = new ServerName("localhost", 1234, -1L);
HRegionLocation hrl1 = new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO, HRegionLocation hrl1 = new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO,
hsa1.getHostname(), hsa1.getPort()); hsa1, HConstants.NO_SEQNUM);
HRegionLocation hrl2 = new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO, HRegionLocation hrl2 = new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO,
hsa1.getHostname(), hsa1.getPort()); hsa1, HConstants.NO_SEQNUM);
assertEquals(hrl1.hashCode(), hrl2.hashCode()); assertEquals(hrl1.hashCode(), hrl2.hashCode());
assertTrue(hrl1.equals(hrl2)); assertTrue(hrl1.equals(hrl2));
HRegionLocation hrl3 = new HRegionLocation(HRegionInfo.ROOT_REGIONINFO, HRegionLocation hrl3 = new HRegionLocation(HRegionInfo.ROOT_REGIONINFO,
hsa1.getHostname(), hsa1.getPort()); hsa1, HConstants.NO_SEQNUM);
assertNotSame(hrl1, hrl3); assertNotSame(hrl1, hrl3);
// They are equal because they have same location even though they are // They are equal because they have same location even though they are
// carrying different regions or timestamp. // carrying different regions or timestamp.
assertTrue(hrl1.equals(hrl3)); assertTrue(hrl1.equals(hrl3));
ServerName hsa2 = new ServerName("localhost", 12345, -1L); ServerName hsa2 = new ServerName("localhost", 12345, -1L);
HRegionLocation hrl4 = new HRegionLocation(HRegionInfo.ROOT_REGIONINFO, HRegionLocation hrl4 = new HRegionLocation(HRegionInfo.ROOT_REGIONINFO,
hsa2.getHostname(), hsa2.getPort()); hsa2, HConstants.NO_SEQNUM);
// These have same HRI but different locations so should be different. // These have same HRI but different locations so should be different.
assertFalse(hrl3.equals(hrl4)); assertFalse(hrl3.equals(hrl4));
HRegionLocation hrl5 = new HRegionLocation(hrl4.getRegionInfo(), HRegionLocation hrl5 = new HRegionLocation(hrl4.getRegionInfo(),
hrl4.getHostname(), hrl4.getPort(), hrl4.getSeqNum() + 1); hrl4.getServerName(), hrl4.getSeqNum() + 1);
assertTrue(hrl4.equals(hrl5)); assertTrue(hrl4.equals(hrl5));
} }
@ -62,7 +62,7 @@ public class TestHRegionLocation {
public void testToString() { public void testToString() {
ServerName hsa1 = new ServerName("localhost", 1234, -1L); ServerName hsa1 = new ServerName("localhost", 1234, -1L);
HRegionLocation hrl1 = new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO, HRegionLocation hrl1 = new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO,
hsa1.getHostname(), hsa1.getPort()); hsa1, HConstants.NO_SEQNUM);
System.out.println(hrl1.toString()); System.out.println(hrl1.toString());
} }
@ -70,10 +70,10 @@ public class TestHRegionLocation {
public void testCompareTo() { public void testCompareTo() {
ServerName hsa1 = new ServerName("localhost", 1234, -1L); ServerName hsa1 = new ServerName("localhost", 1234, -1L);
HRegionLocation hsl1 = HRegionLocation hsl1 =
new HRegionLocation(HRegionInfo.ROOT_REGIONINFO, hsa1.getHostname(), hsa1.getPort()); new HRegionLocation(HRegionInfo.ROOT_REGIONINFO, hsa1, HConstants.NO_SEQNUM);
ServerName hsa2 = new ServerName("localhost", 1235, -1L); ServerName hsa2 = new ServerName("localhost", 1235, -1L);
HRegionLocation hsl2 = HRegionLocation hsl2 =
new HRegionLocation(HRegionInfo.ROOT_REGIONINFO, hsa2.getHostname(), hsa2.getPort()); new HRegionLocation(HRegionInfo.ROOT_REGIONINFO, hsa2, HConstants.NO_SEQNUM);
assertTrue(hsl1.compareTo(hsl1) == 0); assertTrue(hsl1.compareTo(hsl1) == 0);
assertTrue(hsl2.compareTo(hsl2) == 0); assertTrue(hsl2.compareTo(hsl2) == 0);
int compare1 = hsl1.compareTo(hsl2); int compare1 = hsl1.compareTo(hsl2);

View File

@ -339,8 +339,7 @@ public class TestCatalogTracker {
Mockito.mock(AdminProtocol.class); Mockito.mock(AdminProtocol.class);
Mockito.when(implementation.getRegionInfo((RpcController)Mockito.any(), Mockito.when(implementation.getRegionInfo((RpcController)Mockito.any(),
(GetRegionInfoRequest)Mockito.any())).thenThrow(connectException); (GetRegionInfoRequest)Mockito.any())).thenThrow(connectException);
Mockito.when(connection.getAdmin(Mockito.anyString(), Mockito.when(connection.getAdmin(Mockito.any(ServerName.class), Mockito.anyBoolean())).
Mockito.anyInt(), Mockito.anyBoolean())).
thenReturn(implementation); thenReturn(implementation);
final CatalogTracker ct = constructAndStartCatalogTracker(connection); final CatalogTracker ct = constructAndStartCatalogTracker(connection);
try { try {
@ -475,8 +474,8 @@ public class TestCatalogTracker {
* {@link HConnection#getConfiguration()} is called, a 'location' when * {@link HConnection#getConfiguration()} is called, a 'location' when
* {@link HConnection#getRegionLocation(byte[], byte[], boolean)} is called, * {@link HConnection#getRegionLocation(byte[], byte[], boolean)} is called,
* and that returns the passed {@link AdminProtocol} instance when * and that returns the passed {@link AdminProtocol} instance when
* {@link HConnection#getAdmin(String, int)} is called, returns the passed * {@link HConnection#getAdmin(ServerName)} is called, returns the passed
* {@link ClientProtocol} instance when {@link HConnection#getClient(String, int)} * {@link ClientProtocol} instance when {@link HConnection#getClient(ServerName)}
* is called (Be sure call * is called (Be sure call
* {@link HConnectionManager#deleteConnection(org.apache.hadoop.conf.Configuration)} * {@link HConnectionManager#deleteConnection(org.apache.hadoop.conf.Configuration)}
* when done with this mocked Connection. * when done with this mocked Connection.
@ -489,8 +488,7 @@ public class TestCatalogTracker {
Mockito.doNothing().when(connection).close(); Mockito.doNothing().when(connection).close();
// Make it so we return any old location when asked. // Make it so we return any old location when asked.
final HRegionLocation anyLocation = final HRegionLocation anyLocation =
new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO, SN.getHostname(), new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO, SN, HConstants.NO_SEQNUM);
SN.getPort());
Mockito.when(connection.getRegionLocation((byte[]) Mockito.any(), Mockito.when(connection.getRegionLocation((byte[]) Mockito.any(),
(byte[]) Mockito.any(), Mockito.anyBoolean())). (byte[]) Mockito.any(), Mockito.anyBoolean())).
thenReturn(anyLocation); thenReturn(anyLocation);
@ -499,12 +497,12 @@ public class TestCatalogTracker {
thenReturn(anyLocation); thenReturn(anyLocation);
if (admin != null) { if (admin != null) {
// If a call to getHRegionConnection, return this implementation. // If a call to getHRegionConnection, return this implementation.
Mockito.when(connection.getAdmin(Mockito.anyString(), Mockito.anyInt())). Mockito.when(connection.getAdmin(Mockito.any(ServerName.class))).
thenReturn(admin); thenReturn(admin);
} }
if (client != null) { if (client != null) {
// If a call to getClient, return this implementation. // If a call to getClient, return this implementation.
Mockito.when(connection.getClient(Mockito.anyString(), Mockito.anyInt())). Mockito.when(connection.getClient(Mockito.any(ServerName.class))).
thenReturn(client); thenReturn(client);
} }
return connection; return connection;

View File

@ -120,7 +120,7 @@ public class TestMetaReaderEditorNoCluster {
/** /**
* Test that MetaReader will ride over server throwing * Test that MetaReader will ride over server throwing
* "Server not running" IOEs. * "Server not running" IOEs.
* @see https://issues.apache.org/jira/browse/HBASE-3446 * @see @link {https://issues.apache.org/jira/browse/HBASE-3446}
* @throws IOException * @throws IOException
* @throws InterruptedException * @throws InterruptedException
*/ */
@ -133,7 +133,7 @@ public class TestMetaReaderEditorNoCluster {
// This is a servername we use in a few places below. // This is a servername we use in a few places below.
ServerName sn = new ServerName("example.com", 1234, System.currentTimeMillis()); ServerName sn = new ServerName("example.com", 1234, System.currentTimeMillis());
HConnection connection = null; HConnection connection;
CatalogTracker ct = null; CatalogTracker ct = null;
try { try {
// Mock an ClientProtocol. Our mock implementation will fail a few // Mock an ClientProtocol. Our mock implementation will fail a few
@ -178,8 +178,7 @@ public class TestMetaReaderEditorNoCluster {
// Fix the location lookup so it 'works' though no network. First // Fix the location lookup so it 'works' though no network. First
// make an 'any location' object. // make an 'any location' object.
final HRegionLocation anyLocation = final HRegionLocation anyLocation =
new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO, sn.getHostname(), new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO, sn, HConstants.NO_SEQNUM);
sn.getPort());
// Return the any location object when locateRegion is called in HTable // Return the any location object when locateRegion is called in HTable
// constructor and when its called by ServerCallable (it uses getRegionLocation). // constructor and when its called by ServerCallable (it uses getRegionLocation).
// The ugly format below comes of 'Important gotcha on spying real objects!' from // The ugly format below comes of 'Important gotcha on spying real objects!' from
@ -192,7 +191,7 @@ public class TestMetaReaderEditorNoCluster {
// Now shove our HRI implementation into the spied-upon connection. // Now shove our HRI implementation into the spied-upon connection.
Mockito.doReturn(implementation). Mockito.doReturn(implementation).
when(connection).getClient(Mockito.anyString(), Mockito.anyInt()); when(connection).getClient(Mockito.any(ServerName.class));
// Now start up the catalogtracker with our doctored Connection. // Now start up the catalogtracker with our doctored Connection.
ct = new CatalogTracker(zkw, null, connection, ABORTABLE); ct = new CatalogTracker(zkw, null, connection, ABORTABLE);

View File

@ -20,12 +20,11 @@ package org.apache.hadoop.hbase.client;
import java.io.IOException; import java.io.IOException;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.HRegionLocation; import org.apache.hadoop.hbase.HRegionLocation;
import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.ZooKeeperConnectionException; import org.apache.hadoop.hbase.ZooKeeperConnectionException;
import org.apache.hadoop.hbase.client.AdminProtocol;
import org.apache.hadoop.hbase.client.ClientProtocol;
import org.apache.hadoop.hbase.client.HConnectionManager.HConnectionImplementation; import org.apache.hadoop.hbase.client.HConnectionManager.HConnectionImplementation;
import org.apache.hadoop.hbase.client.HConnectionManager.HConnectionKey; import org.apache.hadoop.hbase.client.HConnectionManager.HConnectionKey;
import org.mockito.Mockito; import org.mockito.Mockito;
@ -44,7 +43,7 @@ public class HConnectionTestingUtility {
* configuration instance. Minimally the mock will return * configuration instance. Minimally the mock will return
* <code>conf</conf> when {@link HConnection#getConfiguration()} is invoked. * <code>conf</conf> when {@link HConnection#getConfiguration()} is invoked.
* Be sure to shutdown the connection when done by calling * Be sure to shutdown the connection when done by calling
* {@link HConnectionManager#deleteConnection(Configuration, boolean)} else it * {@link HConnectionManager#deleteConnection(HConnectionKey, boolean)} else it
* will stick around; this is probably not what you want. * will stick around; this is probably not what you want.
* @param conf configuration * @param conf configuration
* @return HConnection object for <code>conf</code> * @return HConnection object for <code>conf</code>
@ -70,7 +69,7 @@ public class HConnectionTestingUtility {
* more of the popular {@link HConnection} methods so they do 'normal' * more of the popular {@link HConnection} methods so they do 'normal'
* operation (see return doc below for list). Be sure to shutdown the * operation (see return doc below for list). Be sure to shutdown the
* connection when done by calling * connection when done by calling
* {@link HConnectionManager#deleteConnection(Configuration, boolean)} else it * {@link HConnectionManager#deleteConnection(HConnectionKey, boolean)} else it
* will stick around; this is probably not what you want. * will stick around; this is probably not what you want.
* *
* @param conf Configuration to use * @param conf Configuration to use
@ -86,10 +85,10 @@ public class HConnectionTestingUtility {
* {@link HConnection#getConfiguration()} is called, a 'location' when * {@link HConnection#getConfiguration()} is called, a 'location' when
* {@link HConnection#getRegionLocation(byte[], byte[], boolean)} is called, * {@link HConnection#getRegionLocation(byte[], byte[], boolean)} is called,
* and that returns the passed {@link AdminProtocol} instance when * and that returns the passed {@link AdminProtocol} instance when
* {@link HConnection#getAdmin(String, int)} is called, returns the passed * {@link HConnection#getAdmin(ServerName)} is called, returns the passed
* {@link ClientProtocol} instance when {@link HConnection#getClient(String, int)} * {@link ClientProtocol} instance when {@link HConnection#getClient(ServerName)}
* is called (Be sure call * is called (Be sure call
* {@link HConnectionManager#deleteConnection(org.apache.hadoop.conf.Configuration, boolean)} * {@link HConnectionManager#deleteConnection(HConnectionKey, boolean)}
* when done with this mocked Connection. * when done with this mocked Connection.
* @throws IOException * @throws IOException
*/ */
@ -100,7 +99,7 @@ public class HConnectionTestingUtility {
HConnection c = HConnectionTestingUtility.getMockedConnection(conf); HConnection c = HConnectionTestingUtility.getMockedConnection(conf);
Mockito.doNothing().when(c).close(); Mockito.doNothing().when(c).close();
// Make it so we return a particular location when asked. // Make it so we return a particular location when asked.
final HRegionLocation loc = new HRegionLocation(hri, sn.getHostname(), sn.getPort()); final HRegionLocation loc = new HRegionLocation(hri, sn, HConstants.NO_SEQNUM);
Mockito.when(c.getRegionLocation((byte[]) Mockito.any(), Mockito.when(c.getRegionLocation((byte[]) Mockito.any(),
(byte[]) Mockito.any(), Mockito.anyBoolean())). (byte[]) Mockito.any(), Mockito.anyBoolean())).
thenReturn(loc); thenReturn(loc);
@ -108,12 +107,12 @@ public class HConnectionTestingUtility {
thenReturn(loc); thenReturn(loc);
if (admin != null) { if (admin != null) {
// If a call to getAdmin, return this implementation. // If a call to getAdmin, return this implementation.
Mockito.when(c.getAdmin(Mockito.anyString(), Mockito.anyInt())). Mockito.when(c.getAdmin(Mockito.any(ServerName.class))).
thenReturn(admin); thenReturn(admin);
} }
if (client != null) { if (client != null) {
// If a call to getClient, return this client. // If a call to getClient, return this client.
Mockito.when(c.getClient(Mockito.anyString(), Mockito.anyInt())). Mockito.when(c.getClient(Mockito.any(ServerName.class))).
thenReturn(client); thenReturn(client);
} }
return c; return c;
@ -123,12 +122,13 @@ public class HConnectionTestingUtility {
* Get a Mockito spied-upon {@link HConnection} that goes with the passed * Get a Mockito spied-upon {@link HConnection} that goes with the passed
* <code>conf</code> configuration instance. * <code>conf</code> configuration instance.
* Be sure to shutdown the connection when done by calling * Be sure to shutdown the connection when done by calling
* {@link HConnectionManager#deleteConnection(Configuration, boolean)} else it * {@link HConnectionManager#deleteConnection(HConnectionKey, boolean)} else it
* will stick around; this is probably not what you want. * will stick around; this is probably not what you want.
* @param conf configuration * @param conf configuration
* @return HConnection object for <code>conf</code> * @return HConnection object for <code>conf</code>
* @throws ZooKeeperConnectionException * @throws ZooKeeperConnectionException
* @see http://mockito.googlecode.com/svn/branches/1.6/javadoc/org/mockito/Mockito.html#spy(T) * @see @link
* {http://mockito.googlecode.com/svn/branches/1.6/javadoc/org/mockito/Mockito.html#spy(T)}
*/ */
public static HConnection getSpiedConnection(final Configuration conf) public static HConnection getSpiedConnection(final Configuration conf)
throws ZooKeeperConnectionException { throws ZooKeeperConnectionException {

View File

@ -115,8 +115,7 @@ public class TestFromClientSide3 {
HConnection conn = HConnectionManager.getConnection(TEST_UTIL HConnection conn = HConnectionManager.getConnection(TEST_UTIL
.getConfiguration()); .getConfiguration());
HRegionLocation loc = table.getRegionLocation(row, true); HRegionLocation loc = table.getRegionLocation(row, true);
AdminProtocol server = conn.getAdmin(loc.getHostname(), loc AdminProtocol server = conn.getAdmin(loc.getServerName());
.getPort());
byte[] regName = loc.getRegionInfo().getRegionName(); byte[] regName = loc.getRegionInfo().getRegionName();
for (int i = 0; i < nFlushes; i++) { for (int i = 0; i < nFlushes; i++) {
@ -163,8 +162,7 @@ public class TestFromClientSide3 {
// Verify we have multiple store files. // Verify we have multiple store files.
HRegionLocation loc = hTable.getRegionLocation(row, true); HRegionLocation loc = hTable.getRegionLocation(row, true);
byte[] regionName = loc.getRegionInfo().getRegionName(); byte[] regionName = loc.getRegionInfo().getRegionName();
AdminProtocol server = connection.getAdmin( AdminProtocol server = connection.getAdmin(loc.getServerName());
loc.getHostname(), loc.getPort());
assertTrue(ProtobufUtil.getStoreFiles( assertTrue(ProtobufUtil.getStoreFiles(
server, regionName, FAMILY).size() > 1); server, regionName, FAMILY).size() > 1);
@ -177,7 +175,7 @@ public class TestFromClientSide3 {
loc = hTable.getRegionLocation(row, true); loc = hTable.getRegionLocation(row, true);
if (!loc.getRegionInfo().isOffline()) { if (!loc.getRegionInfo().isOffline()) {
regionName = loc.getRegionInfo().getRegionName(); regionName = loc.getRegionInfo().getRegionName();
server = connection.getAdmin(loc.getHostname(), loc.getPort()); server = connection.getAdmin(loc.getServerName());
if (ProtobufUtil.getStoreFiles( if (ProtobufUtil.getStoreFiles(
server, regionName, FAMILY).size() <= 1) { server, regionName, FAMILY).size() <= 1) {
break; break;
@ -211,7 +209,7 @@ public class TestFromClientSide3 {
Thread.sleep(10 * 1000); Thread.sleep(10 * 1000);
loc = hTable.getRegionLocation(row, true); loc = hTable.getRegionLocation(row, true);
regionName = loc.getRegionInfo().getRegionName(); regionName = loc.getRegionInfo().getRegionName();
server = connection.getAdmin(loc.getHostname(), loc.getPort()); server = connection.getAdmin(loc.getServerName());
int sfCount = ProtobufUtil.getStoreFiles( int sfCount = ProtobufUtil.getStoreFiles(
server, regionName, FAMILY).size(); server, regionName, FAMILY).size();
assertTrue(sfCount > 1); assertTrue(sfCount > 1);
@ -236,8 +234,7 @@ public class TestFromClientSide3 {
loc = hTable.getRegionLocation(row, true); loc = hTable.getRegionLocation(row, true);
regionName = loc.getRegionInfo().getRegionName(); regionName = loc.getRegionInfo().getRegionName();
try { try {
server = connection.getAdmin(loc.getHostname(), loc server = connection.getAdmin(loc.getServerName());
.getPort());
if (ProtobufUtil.getStoreFiles( if (ProtobufUtil.getStoreFiles(
server, regionName, FAMILY).size() < sfCount) { server, regionName, FAMILY).size() < sfCount) {
break; break;

View File

@ -151,8 +151,8 @@ public class TestHCM {
final int nextPort = conn.getCachedLocation(TABLE_NAME, ROW).getPort() + 1; final int nextPort = conn.getCachedLocation(TABLE_NAME, ROW).getPort() + 1;
HRegionLocation loc = conn.getCachedLocation(TABLE_NAME, ROW); HRegionLocation loc = conn.getCachedLocation(TABLE_NAME, ROW);
conn.updateCachedLocation(loc.getRegionInfo(), loc, "127.0.0.1", nextPort, conn.updateCachedLocation(loc.getRegionInfo(), loc, new ServerName("127.0.0.1", nextPort,
HConstants.LATEST_TIMESTAMP); HConstants.LATEST_TIMESTAMP), HConstants.LATEST_TIMESTAMP);
Assert.assertEquals(conn.getCachedLocation(TABLE_NAME, ROW).getPort(), nextPort); Assert.assertEquals(conn.getCachedLocation(TABLE_NAME, ROW).getPort(), nextPort);
conn.forceDeleteCachedLocation(TABLE_NAME.clone(), ROW.clone()); conn.forceDeleteCachedLocation(TABLE_NAME.clone(), ROW.clone());
@ -349,34 +349,34 @@ public class TestHCM {
HRegionLocation location = conn.getCachedLocation(TABLE_NAME2, ROW); HRegionLocation location = conn.getCachedLocation(TABLE_NAME2, ROW);
assertNotNull(location); assertNotNull(location);
HRegionLocation anySource = new HRegionLocation(location.getRegionInfo(), HRegionLocation anySource = new HRegionLocation(location.getRegionInfo(), new ServerName(
location.getHostname(), location.getPort() - 1); location.getHostname(), location.getPort() - 1, 0L), HConstants.NO_SEQNUM);
// Same server as already in cache reporting - overwrites any value despite seqNum. // Same server as already in cache reporting - overwrites any value despite seqNum.
int nextPort = location.getPort() + 1; int nextPort = location.getPort() + 1;
conn.updateCachedLocation(location.getRegionInfo(), location, conn.updateCachedLocation(location.getRegionInfo(), location,
"127.0.0.1", nextPort, location.getSeqNum() - 1); new ServerName("127.0.0.1", nextPort, 0), location.getSeqNum() - 1);
location = conn.getCachedLocation(TABLE_NAME2, ROW); location = conn.getCachedLocation(TABLE_NAME2, ROW);
Assert.assertEquals(nextPort, location.getPort()); Assert.assertEquals(nextPort, location.getPort());
// No source specified - same. // No source specified - same.
nextPort = location.getPort() + 1; nextPort = location.getPort() + 1;
conn.updateCachedLocation(location.getRegionInfo(), location, conn.updateCachedLocation(location.getRegionInfo(), location,
"127.0.0.1", nextPort, location.getSeqNum() - 1); new ServerName("127.0.0.1", nextPort, 0), location.getSeqNum() - 1);
location = conn.getCachedLocation(TABLE_NAME2, ROW); location = conn.getCachedLocation(TABLE_NAME2, ROW);
Assert.assertEquals(nextPort, location.getPort()); Assert.assertEquals(nextPort, location.getPort());
// Higher seqNum - overwrites lower seqNum. // Higher seqNum - overwrites lower seqNum.
nextPort = location.getPort() + 1; nextPort = location.getPort() + 1;
conn.updateCachedLocation(location.getRegionInfo(), anySource, conn.updateCachedLocation(location.getRegionInfo(), anySource,
"127.0.0.1", nextPort, location.getSeqNum() + 1); new ServerName("127.0.0.1", nextPort, 0), location.getSeqNum() + 1);
location = conn.getCachedLocation(TABLE_NAME2, ROW); location = conn.getCachedLocation(TABLE_NAME2, ROW);
Assert.assertEquals(nextPort, location.getPort()); Assert.assertEquals(nextPort, location.getPort());
// Lower seqNum - does not overwrite higher seqNum. // Lower seqNum - does not overwrite higher seqNum.
nextPort = location.getPort() + 1; nextPort = location.getPort() + 1;
conn.updateCachedLocation(location.getRegionInfo(), anySource, conn.updateCachedLocation(location.getRegionInfo(), anySource,
"127.0.0.1", nextPort, location.getSeqNum() - 1); new ServerName("127.0.0.1", nextPort, 0), location.getSeqNum() - 1);
location = conn.getCachedLocation(TABLE_NAME2, ROW); location = conn.getCachedLocation(TABLE_NAME2, ROW);
Assert.assertEquals(nextPort - 1, location.getPort()); Assert.assertEquals(nextPort - 1, location.getPort());
} }

View File

@ -37,10 +37,12 @@ import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.HRegionLocation; import org.apache.hadoop.hbase.HRegionLocation;
import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.LargeTests; import org.apache.hadoop.hbase.LargeTests;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.TableExistsException; import org.apache.hadoop.hbase.TableExistsException;
import org.apache.hadoop.hbase.client.ClientProtocol; import org.apache.hadoop.hbase.client.ClientProtocol;
import org.apache.hadoop.hbase.client.HConnection; import org.apache.hadoop.hbase.client.HConnection;
@ -269,7 +271,7 @@ public class TestLoadIncrementalHFilesSplitRecovery {
Mockito.doNothing().when(c).close(); Mockito.doNothing().when(c).close();
// Make it so we return a particular location when asked. // Make it so we return a particular location when asked.
final HRegionLocation loc = new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO, final HRegionLocation loc = new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO,
"example.org", 1234); new ServerName("example.org", 1234, 0), HConstants.NO_SEQNUM);
Mockito.when(c.getRegionLocation((byte[]) Mockito.any(), Mockito.when(c.getRegionLocation((byte[]) Mockito.any(),
(byte[]) Mockito.any(), Mockito.anyBoolean())). (byte[]) Mockito.any(), Mockito.anyBoolean())).
thenReturn(loc); thenReturn(loc);
@ -278,7 +280,7 @@ public class TestLoadIncrementalHFilesSplitRecovery {
ClientProtocol hri = Mockito.mock(ClientProtocol.class); ClientProtocol hri = Mockito.mock(ClientProtocol.class);
Mockito.when(hri.bulkLoadHFile((RpcController)Mockito.any(), (BulkLoadHFileRequest)Mockito.any())). Mockito.when(hri.bulkLoadHFile((RpcController)Mockito.any(), (BulkLoadHFileRequest)Mockito.any())).
thenThrow(new ServiceException(new IOException("injecting bulk load error"))); thenThrow(new ServiceException(new IOException("injecting bulk load error")));
Mockito.when(c.getClient(Mockito.anyString(), Mockito.anyInt())). Mockito.when(c.getClient(Mockito.any(ServerName.class))).
thenReturn(hri); thenReturn(hri);
return c; return c;
} }

View File

@ -165,8 +165,7 @@ public class TestHRegionServerBulkLoad {
public Void call() throws Exception { public Void call() throws Exception {
LOG.debug("compacting " + location + " for row " LOG.debug("compacting " + location + " for row "
+ Bytes.toStringBinary(row)); + Bytes.toStringBinary(row));
AdminProtocol server = connection.getAdmin( AdminProtocol server = connection.getAdmin(location.getServerName());
location.getHostname(), location.getPort());
CompactRegionRequest request = CompactRegionRequest request =
RequestConverter.buildCompactRegionRequest( RequestConverter.buildCompactRegionRequest(
location.getRegionInfo().getRegionName(), true, null); location.getRegionInfo().getRegionName(), true, null);

View File

@ -505,7 +505,7 @@ public class TestHBaseFsck {
HConnection connection = admin.getConnection(); HConnection connection = admin.getConnection();
for (ServerName hsi : regionServers) { for (ServerName hsi : regionServers) {
AdminProtocol server = AdminProtocol server =
connection.getAdmin(hsi.getHostname(), hsi.getPort()); connection.getAdmin(hsi);
// list all online regions from this region server // list all online regions from this region server
List<HRegionInfo> regions = ProtobufUtil.getOnlineRegions(server); List<HRegionInfo> regions = ProtobufUtil.getOnlineRegions(server);