use of org.apache.hadoop.hbase.shaded.com.google.protobuf.BlockingRpcChannel in project hbase by apache.
the class TestHMasterRPCException method testRPCException.
@Test
public void testRPCException() throws IOException, InterruptedException, KeeperException {
ServerName sm = master.getServerName();
boolean fakeZNodeDelete = false;
for (int i = 0; i < 20; i++) {
try {
BlockingRpcChannel channel = rpcClient.createBlockingRpcChannel(sm, User.getCurrent(), 0);
MasterProtos.MasterService.BlockingInterface stub = MasterProtos.MasterService.newBlockingStub(channel);
assertTrue(stub.isMasterRunning(null, IsMasterRunningRequest.getDefaultInstance()).getIsMasterRunning());
return;
} catch (ServiceException ex) {
IOException ie = ProtobufUtil.handleRemoteException(ex);
// No SocketTimeoutException here. RpcServer is already started after the construction of
// HMaster.
assertTrue(ie.getMessage().startsWith("org.apache.hadoop.hbase.ipc.ServerNotRunningYetException: Server is not running yet"));
LOG.info("Expected exception: ", ie);
if (!fakeZNodeDelete) {
testUtil.getZooKeeperWatcher().getRecoverableZooKeeper().delete(testUtil.getZooKeeperWatcher().znodePaths.masterAddressZNode, -1);
fakeZNodeDelete = true;
}
}
Thread.sleep(1000);
}
}
use of org.apache.hadoop.hbase.shaded.com.google.protobuf.BlockingRpcChannel in project hbase by apache.
the class HRegionServer method createRegionServerStatusStub.
/**
* Get the current master from ZooKeeper and open the RPC connection to it. To get a fresh
* connection, the current rssStub must be null. Method will block until a master is available.
* You can break from this block by requesting the server stop.
* @param refresh If true then master address will be read from ZK, otherwise use cached data
* @return master + port, or null if server has been stopped
*/
@VisibleForTesting
protected synchronized ServerName createRegionServerStatusStub(boolean refresh) {
if (rssStub != null) {
return masterAddressTracker.getMasterAddress();
}
ServerName sn = null;
long previousLogTime = 0;
RegionServerStatusService.BlockingInterface intRssStub = null;
LockService.BlockingInterface intLockStub = null;
boolean interrupted = false;
try {
while (keepLooping()) {
sn = this.masterAddressTracker.getMasterAddress(refresh);
if (sn == null) {
if (!keepLooping()) {
// give up with no connection.
LOG.debug("No master found and cluster is stopped; bailing out");
return null;
}
if (System.currentTimeMillis() > (previousLogTime + 1000)) {
LOG.debug("No master found; retry");
previousLogTime = System.currentTimeMillis();
}
// let's try pull it from ZK directly
refresh = true;
if (sleep(200)) {
interrupted = true;
}
continue;
}
// If we are on the active master, use the shortcut
if (this instanceof HMaster && sn.equals(getServerName())) {
intRssStub = ((HMaster) this).getMasterRpcServices();
intLockStub = ((HMaster) this).getMasterRpcServices();
break;
}
try {
BlockingRpcChannel channel = this.rpcClient.createBlockingRpcChannel(sn, userProvider.getCurrent(), shortOperationTimeout);
intRssStub = RegionServerStatusService.newBlockingStub(channel);
intLockStub = LockService.newBlockingStub(channel);
break;
} catch (IOException e) {
if (System.currentTimeMillis() > (previousLogTime + 1000)) {
e = e instanceof RemoteException ? ((RemoteException) e).unwrapRemoteException() : e;
if (e instanceof ServerNotRunningYetException) {
LOG.info("Master isn't available yet, retrying");
} else {
LOG.warn("Unable to connect to master. Retrying. Error was:", e);
}
previousLogTime = System.currentTimeMillis();
}
if (sleep(200)) {
interrupted = true;
}
}
}
} finally {
if (interrupted) {
Thread.currentThread().interrupt();
}
}
this.rssStub = intRssStub;
this.lockStub = intLockStub;
return sn;
}
Aggregations