/** * Unassign all regions, so that they go through the regular region * assignment flow (in assignment manager) and are re-opened. */ @Override protected void populatePool(ExecutorService pool) { LOG.debug("Creating threads for each region server "); for (Map.Entry<ServerName, List<HRegionInfo>> e : rsToRegions .entrySet()) { final List<HRegionInfo> hris = e.getValue(); // add plans for the regions that need to be reopened Map<String, RegionPlan> plans = new HashMap<String, RegionPlan>(); for (HRegionInfo hri : hris) { RegionPlan reOpenPlan = new RegionPlan(hri, null, assignmentManager.getRegionServerOfRegion(hri)); plans.put(hri.getEncodedName(), reOpenPlan); } assignmentManager.addPlans(plans); pool.execute(new Runnable() { public void run() { assignmentManager.unassign(hris); } }); } }
@Override public void process() { LOG.debug("Handling CLOSED event for " + regionInfo.getEncodedName()); // Check if this table is being disabled or not if (this.assignmentManager.getTableStateManager().isTableState(this.regionInfo.getTable(), ZooKeeperProtos.Table.State.DISABLED, ZooKeeperProtos.Table.State.DISABLING) || assignmentManager.getReplicasToClose().contains(regionInfo)) { assignmentManager.offlineDisabledRegion(regionInfo); return; } // ZK Node is in CLOSED state, assign it. assignmentManager.getRegionStates().updateRegionState( regionInfo, RegionState.State.CLOSED); // This below has to do w/ online enable/disable of a table assignmentManager.removeClosedRegion(regionInfo); assignmentManager.assign(regionInfo, true); } }
void regionOnline(HRegionInfo regionInfo, ServerName sn, long openSeqNum) { numRegionsOpened.incrementAndGet(); regionStates.regionOnline(regionInfo, sn, openSeqNum); // Remove plan if one. clearRegionPlan(regionInfo); balancer.regionOnline(regionInfo, sn); // Tell our listeners that a region was opened sendRegionOpenedNotification(regionInfo, sn); }
@Override public void process() { LOG.debug("Handling CLOSED event for " + regionInfo.getEncodedName()); // Check if this table is being disabled or not if (this.assignmentManager.getZKTable(). isDisablingOrDisabledTable(this.regionInfo.getTableNameAsString())) { assignmentManager.offlineDisabledRegion(regionInfo); return; } // ZK Node is in CLOSED state, assign it. // TODO: Should we remove the region from RIT too? We don't? Makes for // a 'forcing' log message when we go to update state from CLOSED to OFFLINE assignmentManager.setOffline(regionInfo); // This below has to do w/ online enable/disable of a table assignmentManager.removeClosedRegion(regionInfo); assignmentManager.assign(regionInfo, true); } }
/** * @param region * @param setOfflineInZK * @param forceNewPlan * @param hijack * - true new assignment is needed, false otherwise */ public void assign(HRegionInfo region, boolean setOfflineInZK, boolean forceNewPlan, boolean hijack) { // If hijack is true do not call disableRegionIfInRIT as // we have not yet moved the znode to OFFLINE state. if (!hijack && isDisabledorDisablingRegionInRIT(region)) { return; } if (this.serverManager.isClusterShutdown()) { LOG.info("Cluster shutdown is set; skipping assign of " + region.getRegionNameAsString()); return; } RegionState state = addToRegionsInTransition(region, hijack); synchronized (state) { assign(region, state, setOfflineInZK, forceNewPlan, hijack); } }
for (HRegionInfo region : regions) { String encodedName = region.getEncodedName(); if (!isDisabledorDisablingRegionInRIT(region)) { RegionState state = forceRegionStateToOffline(region, false); boolean onDeadServer = false; if (state != null) { onDeadServer = true; } else if (!useZKForAssignment || asyncSetOfflineInZooKeeper(state, cb, destination)) { RegionPlan plan = new RegionPlan(region, state.getServerName(), destination); plans.put(encodedName, plan); this.addPlans(plans); HRegionInfo region = regionOpenInfos.get(k).getFirst(); if (openingState == RegionOpeningState.ALREADY_OPENED) { processAlreadyOpenedRegion(region, destination); } else if (openingState == RegionOpeningState.FAILED_OPENING) { for (HRegionInfo region : failedToOpenRegions) { if (!regionStates.isRegionOnline(region)) { invokeAssign(region); if (!waitForAssignment(userRegionSet, true, userRegionSet.size(), System.currentTimeMillis())) { LOG.debug("some user regions are still in transition: " + userRegionSet);
if (this.services.getAssignmentManager().isCarryingRoot(serverName)) { LOG.info("Server " + serverName + " was carrying ROOT. Trying to assign."); this.services.getAssignmentManager().regionOffline( HRegionInfo.ROOT_REGIONINFO); verifyAndAssignRootWithRetries(); if (this.services.getAssignmentManager().isCarryingMeta(serverName)) { LOG.info("Server " + serverName + " was carrying META. Trying to assign."); this.services.getAssignmentManager().regionOffline( HRegionInfo.FIRST_META_REGIONINFO); this.services.getAssignmentManager().assignMeta(); } else { LOG.info("META has been assigned to otherwhere, skip assigning."); .processServerShutdown(this.serverName); Set<HRegionInfo> ritsGoingToServer = p.getFirst(); List<RegionState> ritsOnServer = p.getSecond(); if (!this.services.getAssignmentManager().isRegionAssigned(hri)) { if (!regionsToAssign.contains(hri)) { regionsToAssign.add(hri); this.services.getAssignmentManager().assign(hri, true);
HRegionInfo metaHri = RegionReplicaUtil.getRegionInfoForReplica(HRegionInfo.FIRST_META_REGIONINFO, i); if (am.isCarryingMetaReplica(this.serverName, metaHri) == AssignmentManager.ServerHostRegion.HOSTING_REGION) { if (LOG.isDebugEnabled()) { List<HRegionInfo> regionsInTransition = am.cleanOutCrashedServerReferences(serverName); if (LOG.isDebugEnabled()) { LOG.debug("Reassigning " + size(this.regionsOnCrashedServer) + RegionStates regionStates = am.getRegionStates(); for (HRegionInfo hri: this.regionsOnCrashedServer) { if (regionsInTransition.contains(hri)) continue; String encodedName = hri.getEncodedName(); Lock lock = am.acquireRegionLock(encodedName); try { RegionState rit = regionStates.getRegionTransitionState(hri); && am.getTableStateManager().isTableState(hri.getTable(), ZooKeeperProtos.Table.State.DISABLED, ZooKeeperProtos.Table.State.DISABLING) || am.getReplicasToClose().contains(hri)) { am.deleteClosingOrClosedNode(hri, rit.getServerName()); am.offlineDisabledRegion(hri); } else { LOG.warn("THIS SHOULD NOT HAPPEN: unexpected region in transition "
processDeadServersAndRecoverLostRegions(deadServers); failoverCleanupDone(); if (!failover) { assignAllUserRegions(allRegions); unassign(h);
regionOffline(region); return; String path = nee.getPath(); try { if (isSplitOrSplittingOrMergedOrMerging(path)) { LOG.debug(path + " is SPLIT or SPLITTING or MERGED or MERGING; " + "skipping unassign because region no longer exists -- its split or merge"); } else if (state.isFailedOpen()) { regionOffline(region); return; } else if (force && state.isPendingCloseOrClosing()) { unassign(region, state, versionOfClosingNode, dest, useZKForAssignment, null); } finally { lock.unlock(); assign(region, true);
/** * Use care with forceNewPlan. It could cause double assignment. */ public void assign(HRegionInfo region, boolean setOfflineInZK, boolean forceNewPlan) { if (isDisabledorDisablingRegionInRIT(region)) { return; } String encodedName = region.getEncodedName(); Lock lock = locker.acquireLock(encodedName); try { RegionState state = forceRegionStateToOffline(region, forceNewPlan); if (state != null) { if (regionStates.wasRegionOnDeadServer(encodedName)) { LOG.info("Skip assigning " + region.getRegionNameAsString() + ", it's host " + regionStates.getLastRegionServerOfRegion(encodedName) + " is dead but not processed yet"); return; } assign(state, setOfflineInZK && useZKForAssignment, forceNewPlan); } } finally { lock.unlock(); } }
synchronized (this.regionsInTransition) { for (HRegionInfo region: regions) { states.add(forceRegionStateToOffline(region)); destination)); this.addPlans(plans); new CreateUnassignedAsyncCallback(this.watcher, destination, counter); for (RegionState state: states) { if (!asyncSetOfflineInZooKeeper(state, cb, state)) { return;
processRegionInTransitionAndBlockUntilAssigned(HRegionInfo.ROOT_REGIONINFO); ServerName currentRootServer = null; boolean rootRegionLocation = catalogTracker.verifyRootRegionLocation(timeout); currentRootServer = this.catalogTracker.getRootLocation(); splitLogAndExpireIfOnline(currentRootServer); this.assignmentManager.assignRoot(); waitForRootAssignment(); assigned++; } else { this.assignmentManager.regionOnline(HRegionInfo.ROOT_REGIONINFO, this.catalogTracker.getRootLocation()); processRegionInTransitionAndBlockUntilAssigned(HRegionInfo.FIRST_META_REGIONINFO); boolean metaRegionLocation = this.catalogTracker.verifyMetaRegionLocation(timeout); if (!rit && !metaRegionLocation) { splitLogAndExpireIfOnline(currentMetaServer); assignmentManager.assignMeta(); enableSSHandWaitForMeta(); assigned++; this.assignmentManager.regionOnline(HRegionInfo.FIRST_META_REGIONINFO, this.catalogTracker.getMetaLocation());
assign(allRegions); } else { List<HRegionInfo> regions = new ArrayList<HRegionInfo>(regionsFromMetaScan); assign(regions); if (!tableStateManager.isTableState(tableName, ZooKeeperProtos.Table.State.ENABLED)) { setEnabledTable(tableName); assign(replicaRegionsNotRecordedInMeta(regionsFromMetaScan, server));
if (transitionInZK) { deleteClosingOrClosedNode(region, server); regionOffline(region); unassign(region, state, versionOfClosingNode, dest, transitionInZK, src); + ", it's not any more on " + server, t); if (transitionInZK) { deleteClosingOrClosedNode(region, server); regionOffline(region);
RegionStates regionStates = assignmentManager.getRegionStates(); RegionState metaState = MetaTableLocator.getMetaRegionState(getZooKeeper(), replicaId); HRegionInfo hri = RegionReplicaUtil.getRegionInfoForReplica(HRegionInfo.FIRST_META_REGIONINFO, processRegionInTransitionAndBlockUntilAssigned(hri); boolean metaRegionLocation = metaTableLocator.verifyMetaRegionLocation( this.getConnection(), this.getZooKeeper(), timeout, replicaId); assignmentManager.assignMeta(hri); this.assignmentManager.regionOnline( HRegionInfo.FIRST_META_REGIONINFO, currentMetaServer);
" on " + oldSn + " with " + sn); if (isServerOnline(sn)) { this.regions.put(regionInfo, sn); addToServers(sn, regionInfo); this.regions.notifyAll(); } else { clearRegionPlan(regionInfo); addToServersInUpdatingTimer(sn);
private List<HRegionInfo> checkForDisablingOrDisabledTables(Set<HRegionInfo> regionsFromRIT, List<HRegionInfo> toAssign, RegionState rit, AssignmentManager assignmentManager) { if (rit == null) { return toAssign; } if (!rit.isClosing() && !rit.isPendingClose()) { return toAssign; } if (!assignmentManager.getZKTable().isDisablingOrDisabledTable( rit.getRegion().getTableNameAsString())) { return toAssign; } HRegionInfo hri = rit.getRegion(); AssignmentManager am = assignmentManager; am.deleteClosingOrClosedNode(hri); am.regionOffline(hri); // To avoid region assignment if table is in disabling or disabled state. toAssign.remove(hri); regionsFromRIT.remove(hri); return toAssign; }
removeClosedRegion(regionInfo); clearRegionPlan(regionInfo); balancer.regionOffline(regionInfo); sendRegionClosedNotification(regionInfo);