use of org.apache.hadoop.hbase.ipc.HBaseRpcController in project hbase by apache.
the class ServerManager method sendRegionClose.
/**
* Sends an CLOSE RPC to the specified server to close the specified region.
* <p>
* A region server could reject the close request because it either does not
* have the specified region or the region is being split.
* @param server server to open a region
* @param region region to open
* @param dest - if the region is moved to another server, the destination server. null otherwise.
* @throws IOException
*/
public boolean sendRegionClose(ServerName server, HRegionInfo region, ServerName dest) throws IOException {
if (server == null)
throw new NullPointerException("Passed server is null");
AdminService.BlockingInterface admin = getRsAdmin(server);
if (admin == null) {
throw new IOException("Attempting to send CLOSE RPC to server " + server.toString() + " for region " + region.getRegionNameAsString() + " failed because no RPC connection found to this server");
}
HBaseRpcController controller = newRpcController();
return ProtobufUtil.closeRegion(controller, admin, server, region.getRegionName(), dest);
}
use of org.apache.hadoop.hbase.ipc.HBaseRpcController in project hbase by apache.
the class AsyncConnectionImpl method getRpcController.
private HBaseRpcController getRpcController() {
HBaseRpcController controller = this.rpcControllerFactory.newController();
controller.setCallTimeout((int) TimeUnit.NANOSECONDS.toMillis(connConf.getRpcTimeoutNs()));
return controller;
}
use of org.apache.hadoop.hbase.ipc.HBaseRpcController in project hbase by apache.
the class AsyncConnectionImpl method makeMasterStub.
private void makeMasterStub(CompletableFuture<MasterService.Interface> future) {
registry.getMasterAddress().whenComplete((sn, error) -> {
if (sn == null) {
String msg = "ZooKeeper available but no active master location found";
LOG.info(msg);
this.masterStubMakeFuture.getAndSet(null).completeExceptionally(new MasterNotRunningException(msg));
return;
}
try {
MasterService.Interface stub = createMasterStub(sn);
HBaseRpcController controller = getRpcController();
stub.isMasterRunning(controller, RequestConverter.buildIsMasterRunningRequest(), new RpcCallback<IsMasterRunningResponse>() {
@Override
public void run(IsMasterRunningResponse resp) {
if (controller.failed() || resp == null || (resp != null && !resp.getIsMasterRunning())) {
masterStubMakeFuture.getAndSet(null).completeExceptionally(new MasterNotRunningException("Master connection is not running anymore"));
} else {
masterStub.set(stub);
masterStubMakeFuture.set(null);
future.complete(stub);
}
}
});
} catch (IOException e) {
this.masterStubMakeFuture.getAndSet(null).completeExceptionally(new IOException("Failed to create async master stub", e));
}
});
}
use of org.apache.hadoop.hbase.ipc.HBaseRpcController in project hbase by apache.
the class HBaseAdmin method getCompactionState.
/**
* {@inheritDoc}
*/
@Override
public CompactionState getCompactionState(final TableName tableName, CompactType compactType) throws IOException {
AdminProtos.GetRegionInfoResponse.CompactionState state = AdminProtos.GetRegionInfoResponse.CompactionState.NONE;
checkTableExists(tableName);
// TODO: There is no timeout on this controller. Set one!
final HBaseRpcController rpcController = rpcControllerFactory.newController();
switch(compactType) {
case MOB:
final AdminProtos.AdminService.BlockingInterface masterAdmin = this.connection.getAdmin(getMasterAddress());
Callable<AdminProtos.GetRegionInfoResponse.CompactionState> callable = new Callable<AdminProtos.GetRegionInfoResponse.CompactionState>() {
@Override
public AdminProtos.GetRegionInfoResponse.CompactionState call() throws Exception {
HRegionInfo info = getMobRegionInfo(tableName);
GetRegionInfoRequest request = RequestConverter.buildGetRegionInfoRequest(info.getRegionName(), true);
GetRegionInfoResponse response = masterAdmin.getRegionInfo(rpcController, request);
return response.getCompactionState();
}
};
state = ProtobufUtil.call(callable);
break;
case NORMAL:
default:
ZooKeeperWatcher zookeeper = null;
try {
List<Pair<HRegionInfo, ServerName>> pairs;
if (TableName.META_TABLE_NAME.equals(tableName)) {
zookeeper = new ZooKeeperWatcher(conf, ZK_IDENTIFIER_PREFIX + connection.toString(), new ThrowableAbortable());
pairs = new MetaTableLocator().getMetaRegionsAndLocations(zookeeper);
} else {
pairs = MetaTableAccessor.getTableRegionsAndLocations(connection, tableName);
}
for (Pair<HRegionInfo, ServerName> pair : pairs) {
if (pair.getFirst().isOffline())
continue;
if (pair.getSecond() == null)
continue;
final ServerName sn = pair.getSecond();
final byte[] regionName = pair.getFirst().getRegionName();
final AdminService.BlockingInterface snAdmin = this.connection.getAdmin(sn);
try {
Callable<GetRegionInfoResponse> regionInfoCallable = new Callable<GetRegionInfoResponse>() {
@Override
public GetRegionInfoResponse call() throws Exception {
GetRegionInfoRequest request = RequestConverter.buildGetRegionInfoRequest(regionName, true);
return snAdmin.getRegionInfo(rpcController, request);
}
};
GetRegionInfoResponse response = ProtobufUtil.call(regionInfoCallable);
switch(response.getCompactionState()) {
case MAJOR_AND_MINOR:
return CompactionState.MAJOR_AND_MINOR;
case MAJOR:
if (state == AdminProtos.GetRegionInfoResponse.CompactionState.MINOR) {
return CompactionState.MAJOR_AND_MINOR;
}
state = AdminProtos.GetRegionInfoResponse.CompactionState.MAJOR;
break;
case MINOR:
if (state == AdminProtos.GetRegionInfoResponse.CompactionState.MAJOR) {
return CompactionState.MAJOR_AND_MINOR;
}
state = AdminProtos.GetRegionInfoResponse.CompactionState.MINOR;
break;
case NONE:
// nothing, continue
default:
}
} catch (NotServingRegionException e) {
if (LOG.isDebugEnabled()) {
LOG.debug("Trying to get compaction state of " + pair.getFirst() + ": " + StringUtils.stringifyException(e));
}
} catch (RemoteException e) {
if (e.getMessage().indexOf(NotServingRegionException.class.getName()) >= 0) {
if (LOG.isDebugEnabled()) {
LOG.debug("Trying to get compaction state of " + pair.getFirst() + ": " + StringUtils.stringifyException(e));
}
} else {
throw e;
}
}
}
} finally {
if (zookeeper != null) {
zookeeper.close();
}
}
break;
}
if (state != null) {
return ProtobufUtil.createCompactionState(state);
}
return null;
}
use of org.apache.hadoop.hbase.ipc.HBaseRpcController in project hbase by apache.
the class HBaseAdmin method getOnlineRegions.
@Override
public List<HRegionInfo> getOnlineRegions(final ServerName sn) throws IOException {
AdminService.BlockingInterface admin = this.connection.getAdmin(sn);
// TODO: There is no timeout on this controller. Set one!
HBaseRpcController controller = rpcControllerFactory.newController();
return ProtobufUtil.getOnlineRegions(controller, admin);
}
Aggregations