/** * Put region into OFFLINE mode (set state and clear location). * @return Last recorded server deploy */ public ServerName offline() { setState(State.OFFLINE); return setRegionLocation(null); }
private void acceptPlan(final HashMap<RegionInfo, RegionStateNode> regions, final Map<ServerName, List<RegionInfo>> plan) throws HBaseIOException { final ProcedureEvent<?>[] events = new ProcedureEvent[regions.size()]; final long st = System.currentTimeMillis(); if (plan == null) { throw new HBaseIOException("unable to compute plans for regions=" + regions.size()); } if (plan.isEmpty()) return; int evcount = 0; for (Map.Entry<ServerName, List<RegionInfo>> entry: plan.entrySet()) { final ServerName server = entry.getKey(); for (RegionInfo hri: entry.getValue()) { final RegionStateNode regionNode = regions.get(hri); regionNode.setRegionLocation(server); events[evcount++] = regionNode.getProcedureEvent(); } } ProcedureEvent.wakeEvents(getProcedureScheduler(), events); final long et = System.currentTimeMillis(); if (LOG.isTraceEnabled()) { LOG.trace("ASSIGN ACCEPT " + events.length + " -> " + StringUtils.humanTimeDiff(et - st)); } }
void regionFailedOpen(RegionStateNode regionNode, boolean giveUp) throws IOException { RegionState.State state = regionNode.getState(); ServerName regionLocation = regionNode.getRegionLocation(); if (giveUp) { regionNode.setState(State.FAILED_OPEN); regionNode.setRegionLocation(null); boolean succ = false; try { regionStateStore.updateRegionLocation(regionNode); succ = true; } finally { if (!succ) { // revert regionNode.setState(state); regionNode.setRegionLocation(regionLocation); } } } if (regionLocation != null) { regionStates.removeRegionFromServer(regionLocation, regionNode); } }
void regionClosed(RegionStateNode regionNode, boolean normally) throws IOException { RegionState.State state = regionNode.getState(); ServerName regionLocation = regionNode.getRegionLocation(); if (normally) { regionNode.transitionState(State.CLOSED, STATES_EXPECTED_ON_CLOSED); } else { // For SCP regionNode.transitionState(State.ABNORMALLY_CLOSED); } regionNode.setRegionLocation(null); boolean succ = false; try { regionStateStore.updateRegionLocation(regionNode); succ = true; } finally { if (!succ) { // revert regionNode.setState(state); regionNode.setRegionLocation(regionLocation); } } if (regionLocation != null) { regionNode.setLastHost(regionLocation); regionStates.removeRegionFromServer(regionLocation, regionNode); } }
private void queueAssign(MasterProcedureEnv env, RegionStateNode regionNode) throws ProcedureSuspendedException { // Here the assumption is that, the region must be in CLOSED state, so the region location // will be null. And if we fail to open the region and retry here, the forceNewPlan will be // true, and also we will set the region location to null. boolean retain = false; if (!forceNewPlan) { if (assignCandidate != null) { retain = assignCandidate.equals(regionNode.getLastHost()); regionNode.setRegionLocation(assignCandidate); } else if (regionNode.getLastHost() != null) { retain = true; LOG.info("Setting lastHost as the region location {}", regionNode.getLastHost()); regionNode.setRegionLocation(regionNode.getLastHost()); } } LOG.info("Starting {}; {}; forceNewPlan={}, retain={}", this, regionNode.toShortString(), forceNewPlan, retain); env.getAssignmentManager().queueAssign(regionNode); setNextState(RegionStateTransitionState.REGION_STATE_TRANSITION_OPEN); if (regionNode.getProcedureEvent().suspendIfNotReady(this)) { throw new ProcedureSuspendedException(); } }
regionNode.setRegionLocation(regionLocation); regionNode.setOpenSeqNum(openSeqNum);
public void start() throws IOException, KeeperException { if (!running.compareAndSet(false, true)) { return; } LOG.trace("Starting assignment manager"); // Start the Assignment Thread startAssignmentThread(); // load meta region state ZKWatcher zkw = master.getZooKeeper(); // it could be null in some tests if (zkw != null) { RegionState regionState = MetaTableLocator.getMetaRegionState(zkw); RegionStateNode regionNode = regionStates.getOrCreateRegionStateNode(RegionInfoBuilder.FIRST_META_REGIONINFO); regionNode.lock(); try { regionNode.setRegionLocation(regionState.getServerName()); regionNode.setState(regionState.getState()); setMetaAssigned(regionState.getRegion(), regionState.getState() == State.OPEN); } finally { regionNode.unlock(); } } }
private void closeRegion(MasterProcedureEnv env, RegionStateNode regionNode) throws IOException { if (regionNode.isInState(State.OPEN, State.CLOSING, State.MERGING, State.SPLITTING)) { // this is the normal case env.getAssignmentManager().regionClosing(regionNode); addChildProcedure( new CloseRegionProcedure(getRegion(), regionNode.getRegionLocation(), assignCandidate)); setNextState(RegionStateTransitionState.REGION_STATE_TRANSITION_CONFIRM_CLOSED); } else { forceNewPlan = true; regionNode.setRegionLocation(null); setNextState(RegionStateTransitionState.REGION_STATE_TRANSITION_GET_ASSIGN_CANDIDATE); } }
regionNode.setRegionLocation(null); setNextState(RegionStateTransitionState.REGION_STATE_TRANSITION_GET_ASSIGN_CANDIDATE);