use of org.apache.hadoop.hbase.ServerName in project hbase by apache.
the class AssignmentManager method isCarryingRegion.
/**
* Check if the shutdown server carries the specific region.
* @return whether the serverName currently hosts the region
*/
private boolean isCarryingRegion(ServerName serverName, HRegionInfo hri) {
RegionState regionState = regionStates.getRegionTransitionState(hri);
ServerName transitionAddr = regionState != null ? regionState.getServerName() : null;
if (transitionAddr != null) {
boolean matchTransitionAddr = transitionAddr.equals(serverName);
LOG.debug("Checking region=" + hri.getRegionNameAsString() + ", transitioning on server=" + matchTransitionAddr + " server being checked: " + serverName + ", matches=" + matchTransitionAddr);
return matchTransitionAddr;
}
ServerName assignedAddr = regionStates.getRegionServerOfRegion(hri);
boolean matchAssignedAddr = serverName.equals(assignedAddr);
LOG.debug("based on AM, current region=" + hri.getRegionNameAsString() + " is on server=" + assignedAddr + ", server being checked: " + serverName);
return matchAssignedAddr;
}
use of org.apache.hadoop.hbase.ServerName in project hbase by apache.
the class AssignmentManager method prepareDaughterReplicaForAssignment.
private void prepareDaughterReplicaForAssignment(HRegionInfo daughterHri, HRegionInfo parentHri, int replicaId, Map<HRegionInfo, ServerName> map) {
HRegionInfo parentReplica = RegionReplicaUtil.getRegionInfoForReplica(parentHri, replicaId);
HRegionInfo daughterReplica = RegionReplicaUtil.getRegionInfoForReplica(daughterHri, replicaId);
LOG.debug("Created replica region for daughter " + daughterReplica);
ServerName sn;
if ((sn = regionStates.getRegionServerOfRegion(parentReplica)) != null) {
map.put(daughterReplica, sn);
} else {
List<ServerName> servers = serverManager.getOnlineServersList();
sn = servers.get((new Random(System.currentTimeMillis())).nextInt(servers.size()));
map.put(daughterReplica, sn);
}
}
use of org.apache.hadoop.hbase.ServerName in project hbase by apache.
the class AssignmentManager method rebuildUserRegions.
/**
* Rebuild the list of user regions and assignment information.
* Updates regionstates with findings as we go through list of regions.
* @return set of servers not online that hosted some regions according to a scan of hbase:meta
* @throws IOException
*/
Set<ServerName> rebuildUserRegions() throws IOException, KeeperException {
Set<TableName> disabledOrEnablingTables = tableStateManager.getTablesInStates(TableState.State.DISABLED, TableState.State.ENABLING);
Set<TableName> disabledOrDisablingOrEnabling = tableStateManager.getTablesInStates(TableState.State.DISABLED, TableState.State.DISABLING, TableState.State.ENABLING);
// Region assignment from META
List<Result> results = MetaTableAccessor.fullScanRegions(server.getConnection());
// Get any new but slow to checkin region server that joined the cluster
Set<ServerName> onlineServers = serverManager.getOnlineServers().keySet();
// Set of offline servers to be returned
Set<ServerName> offlineServers = new HashSet<>();
// Iterate regions in META
for (Result result : results) {
if (result == null && LOG.isDebugEnabled()) {
LOG.debug("null result from meta - ignoring but this is strange.");
continue;
}
// keep a track of replicas to close. These were the replicas of the originally
// unmerged regions. The master might have closed them before but it mightn't
// maybe because it crashed.
PairOfSameType<HRegionInfo> p = MetaTableAccessor.getMergeRegions(result);
if (p.getFirst() != null && p.getSecond() != null) {
int numReplicas = getNumReplicas(server, p.getFirst().getTable());
for (HRegionInfo merge : p) {
for (int i = 1; i < numReplicas; i++) {
replicasToClose.add(RegionReplicaUtil.getRegionInfoForReplica(merge, i));
}
}
}
RegionLocations rl = MetaTableAccessor.getRegionLocations(result);
if (rl == null) {
continue;
}
HRegionLocation[] locations = rl.getRegionLocations();
if (locations == null) {
continue;
}
for (HRegionLocation hrl : locations) {
if (hrl == null)
continue;
HRegionInfo regionInfo = hrl.getRegionInfo();
if (regionInfo == null)
continue;
int replicaId = regionInfo.getReplicaId();
State state = RegionStateStore.getRegionState(result, replicaId);
// but it couldn't maybe because it crashed
if (replicaId == 0 && state.equals(State.SPLIT)) {
for (HRegionLocation h : locations) {
replicasToClose.add(h.getRegionInfo());
}
}
ServerName lastHost = hrl.getServerName();
ServerName regionLocation = RegionStateStore.getRegionServer(result, replicaId);
regionStates.createRegionState(regionInfo, state, regionLocation, lastHost);
if (!regionStates.isRegionInState(regionInfo, State.OPEN)) {
// Region is not open (either offline or in transition), skip
continue;
}
TableName tableName = regionInfo.getTable();
if (!onlineServers.contains(regionLocation)) {
// Region is located on a server that isn't online
offlineServers.add(regionLocation);
} else if (!disabledOrEnablingTables.contains(tableName)) {
// Region is being served and on an active server
// add only if region not in disabled or enabling table
regionStates.regionOnline(regionInfo, regionLocation);
balancer.regionOnline(regionInfo, regionLocation);
}
// this will be used in rolling restarts
if (!disabledOrDisablingOrEnabling.contains(tableName) && !getTableStateManager().isTableState(tableName, TableState.State.ENABLED)) {
setEnabledTable(tableName);
}
}
}
return offlineServers;
}
use of org.apache.hadoop.hbase.ServerName in project hbase by apache.
the class DrainingServerTracker method add.
private void add(final List<String> servers) throws IOException {
synchronized (this.drainingServers) {
this.drainingServers.clear();
for (String n : servers) {
final ServerName sn = ServerName.valueOf(ZKUtil.getNodeName(n));
this.drainingServers.add(sn);
this.serverManager.addServerToDrainList(sn);
LOG.info("Draining RS node created, adding to list [" + sn + "]");
}
}
}
use of org.apache.hadoop.hbase.ServerName in project hbase by apache.
the class DrainingServerTracker method nodeDeleted.
@Override
public void nodeDeleted(final String path) {
if (path.startsWith(watcher.znodePaths.drainingZNode)) {
final ServerName sn = ServerName.valueOf(ZKUtil.getNodeName(path));
LOG.info("Draining RS node deleted, removing from list [" + sn + "]");
remove(sn);
}
}
Aggregations