use of org.apache.hadoop.hbase.HRegionInfo in project hbase by apache.
the class RSGroupAdminServer method rsGroupGetRegionsInTransition.
private Map<String, RegionState> rsGroupGetRegionsInTransition(String groupName) throws IOException {
Map<String, RegionState> rit = Maps.newTreeMap();
AssignmentManager am = master.getAssignmentManager();
for (TableName tableName : getRSGroupInfo(groupName).getTables()) {
for (HRegionInfo regionInfo : am.getRegionStates().getRegionsOfTable(tableName)) {
RegionState state = am.getRegionStates().getRegionTransitionState(regionInfo);
if (state != null) {
rit.put(regionInfo.getEncodedName(), state);
}
}
}
return rit;
}
use of org.apache.hadoop.hbase.HRegionInfo in project hbase by apache.
the class CatalogJanitor method getMergedRegionsAndSplitParents.
/**
* Scans hbase:meta and returns a number of scanned rows, and a map of merged
* regions, and an ordered map of split parents. if the given table name is
* null, return merged regions and split parents of all tables, else only the
* specified table
* @param tableName null represents all tables
* @return triple of scanned rows, and map of merged regions, and map of split
* parent regioninfos
* @throws IOException
*/
Triple<Integer, Map<HRegionInfo, Result>, Map<HRegionInfo, Result>> getMergedRegionsAndSplitParents(final TableName tableName) throws IOException {
final boolean isTableSpecified = (tableName != null);
// TODO: Only works with single hbase:meta region currently. Fix.
final AtomicInteger count = new AtomicInteger(0);
// Keep Map of found split parents. There are candidates for cleanup.
// Use a comparator that has split parents come before its daughters.
final Map<HRegionInfo, Result> splitParents = new TreeMap<>(new SplitParentFirstComparator());
final Map<HRegionInfo, Result> mergedRegions = new TreeMap<>();
// This visitor collects split parents and counts rows in the hbase:meta table
MetaTableAccessor.Visitor visitor = new MetaTableAccessor.Visitor() {
@Override
public boolean visit(Result r) throws IOException {
if (r == null || r.isEmpty())
return true;
count.incrementAndGet();
HRegionInfo info = MetaTableAccessor.getHRegionInfo(r);
// Keep scanning
if (info == null)
return true;
if (isTableSpecified && info.getTable().compareTo(tableName) > 0) {
// Another table, stop scanning
return false;
}
if (info.isSplitParent())
splitParents.put(info, r);
if (r.getValue(HConstants.CATALOG_FAMILY, HConstants.MERGEA_QUALIFIER) != null) {
mergedRegions.put(info, r);
}
// Returning true means "keep scanning"
return true;
}
};
// Run full scan of hbase:meta catalog table passing in our custom visitor with
// the start row
MetaTableAccessor.scanMetaForTableRegions(this.connection, visitor, tableName);
return new Triple<>(count.get(), mergedRegions, splitParents);
}
use of org.apache.hadoop.hbase.HRegionInfo in project hbase by apache.
the class GeneralBulkAssigner method getTimeoutOnRIT.
@Override
protected long getTimeoutOnRIT() {
// Guess timeout. Multiply the max number of regions on a server
// by how long we think one region takes opening.
Configuration conf = server.getConfiguration();
long perRegionOpenTimeGuesstimate = conf.getLong("hbase.bulk.assignment.perregion.open.time", 1000);
int maxRegionsPerServer = 1;
for (List<HRegionInfo> regionList : bulkPlan.values()) {
int size = regionList.size();
if (size > maxRegionsPerServer) {
maxRegionsPerServer = size;
}
}
long timeout = perRegionOpenTimeGuesstimate * maxRegionsPerServer + conf.getLong("hbase.regionserver.rpc.startup.waittime", 60000) + conf.getLong("hbase.bulk.assignment.perregionserver.rpc.waittime", 30000) * bulkPlan.size();
LOG.debug("Timeout-on-RIT=" + timeout);
return timeout;
}
use of org.apache.hadoop.hbase.HRegionInfo in project hbase by apache.
the class AssignmentManager method retrySendRegionOpen.
/**
* At master failover, for pending_open region, make sure
* sendRegionOpen RPC call is sent to the target regionserver
*/
private void retrySendRegionOpen(final RegionState regionState) {
this.executorService.submit(new EventHandler(server, EventType.M_MASTER_RECOVERY) {
@Override
public void process() throws IOException {
HRegionInfo hri = regionState.getRegion();
ServerName serverName = regionState.getServerName();
ReentrantLock lock = locker.acquireLock(hri.getEncodedName());
try {
for (int i = 1; i <= maximumAttempts; i++) {
if (!serverManager.isServerOnline(serverName) || server.isStopped() || server.isAborted()) {
// No need any more
return;
}
try {
if (!regionState.equals(regionStates.getRegionState(hri))) {
// Region is not in the expected state any more
return;
}
List<ServerName> favoredNodes = ServerName.EMPTY_SERVER_LIST;
if (shouldAssignFavoredNodes(hri)) {
FavoredNodesManager fnm = ((MasterServices) server).getFavoredNodesManager();
favoredNodes = fnm.getFavoredNodesWithDNPort(hri);
}
serverManager.sendRegionOpen(serverName, hri, favoredNodes);
// we're done
return;
} catch (Throwable t) {
if (t instanceof RemoteException) {
t = ((RemoteException) t).unwrapRemoteException();
}
if (t instanceof FailedServerException && i < maximumAttempts) {
// retry too soon. Retry after the failed_server_expiry time
try {
Configuration conf = this.server.getConfiguration();
long sleepTime = 1 + conf.getInt(RpcClient.FAILED_SERVER_EXPIRY_KEY, RpcClient.FAILED_SERVER_EXPIRY_DEFAULT);
if (LOG.isDebugEnabled()) {
LOG.debug(serverName + " is on failed server list; waiting " + sleepTime + "ms", t);
}
Thread.sleep(sleepTime);
continue;
} catch (InterruptedException ie) {
LOG.warn("Failed to assign " + hri.getRegionNameAsString() + " since interrupted", ie);
regionStates.updateRegionState(hri, State.FAILED_OPEN);
Thread.currentThread().interrupt();
return;
}
}
if (serverManager.isServerOnline(serverName) && t instanceof java.net.SocketTimeoutException) {
// reset the try count
i--;
} else {
LOG.info("Got exception in retrying sendRegionOpen for " + regionState + "; try=" + i + " of " + maximumAttempts, t);
}
Threads.sleep(100);
}
}
// Run out of attempts
regionStates.updateRegionState(hri, State.FAILED_OPEN);
} finally {
lock.unlock();
}
}
});
}
use of org.apache.hadoop.hbase.HRegionInfo in project hbase by apache.
the class AssignmentManager method onRegionSplit.
private String onRegionSplit(final RegionState current, final HRegionInfo hri, final ServerName serverName, final RegionStateTransition transition) {
// it could be a reportRegionTransition RPC retry.
if (current == null || !current.isSplittingOrSplitOnServer(serverName)) {
return hri.getShortNameToLog() + " is not splitting on " + serverName;
}
// Just return in case of retrying
if (current.isSplit()) {
return null;
}
final HRegionInfo a = HRegionInfo.convert(transition.getRegionInfo(1));
final HRegionInfo b = HRegionInfo.convert(transition.getRegionInfo(2));
RegionState rs_a = regionStates.getRegionState(a);
RegionState rs_b = regionStates.getRegionState(b);
if (rs_a == null || !rs_a.isSplittingNewOnServer(serverName) || rs_b == null || !rs_b.isSplittingNewOnServer(serverName)) {
return "Some daughter is not known to be splitting on " + serverName + ", a=" + rs_a + ", b=" + rs_b;
}
if (TEST_SKIP_SPLIT_HANDLING) {
return "Skipping split message, TEST_SKIP_SPLIT_HANDLING is set";
}
regionOffline(hri, State.SPLIT);
regionOnline(a, serverName, 1);
regionOnline(b, serverName, 1);
// User could disable the table before master knows the new region.
if (getTableStateManager().isTableState(hri.getTable(), TableState.State.DISABLED, TableState.State.DISABLING)) {
invokeUnAssign(a);
invokeUnAssign(b);
} else {
Callable<Object> splitReplicasCallable = new Callable<Object>() {
@Override
public Object call() {
doSplittingOfReplicas(hri, a, b);
return null;
}
};
threadPoolExecutorService.submit(splitReplicasCallable);
}
return null;
}
Aggregations