/** * Set new {@link State} but only if currently in <code>expected</code> State (if not, throw * {@link UnexpectedStateException}. */ public void transitionState(final State update, final State... expected) throws UnexpectedStateException { if (!setState(update, expected)) { throw new UnexpectedStateException("Expected " + Arrays.toString(expected) + " so could move to " + update + " but current state=" + getState()); } }
private void updateRegionMergeTransition(final ServerName serverName, final TransitionCode state, final RegionInfo merged, final RegionInfo hriA, final RegionInfo hriB) throws IOException { checkMetaLoaded(merged); if (state != TransitionCode.READY_TO_MERGE) { throw new UnexpectedStateException("Unsupported merge regionState=" + state + " for regionA=" + hriA + " regionB=" + hriB + " merged=" + merged + " maybe an old RS (< 2.0) had the operation in progress"); } // Submit the Merge procedure if (LOG.isDebugEnabled()) { LOG.debug("Handling merge request from RS=" + merged + ", merged=" + merged); } master.getMasterProcedureExecutor().submitProcedure(createMergeProcedure(hriA, hriB)); // If the RS is < 2.0 throw an exception to abort the operation, we are handling the merge if (master.getServerManager().getVersionNumber(serverName) < 0x0200000) { throw new UnsupportedOperationException(String.format( "Merge not handled yet: regionState=%s merged=%s hriA=%s hriB=%s", state, merged, hriA, hriB)); } }
public void reportTransition(MasterProcedureEnv env, RegionStateNode regionNode, ServerName serverName, TransitionCode code, long seqId) throws IOException { // It is possible that the previous reportRegionStateTransition call was succeeded at master // side, but before returning the result to region server, the rpc connection was broken, or the // master restarted. The region server will try calling reportRegionStateTransition again under // this scenario, so here we need to check whether this is a retry. switch (code) { case OPENED: reportTransitionOpen(env, regionNode, serverName, seqId); break; case FAILED_OPEN: reportTransitionFailedOpen(env, regionNode, serverName); break; case CLOSED: reportTransitionClosed(env, regionNode, serverName); break; default: throw new UnexpectedStateException("Received report unexpected " + code + " transition, " + regionNode.toShortString() + ", " + this + ", expected OPENED or FAILED_OPEN or CLOSED."); } }
/** * The passed snapshot was successfully persisted; it can be let go. * @param id Id of the snapshot to clean out. * @see MemStore#snapshot() */ @Override public void clearSnapshot(long id) throws UnexpectedStateException { if (this.snapshotId == -1) return; // already cleared if (this.snapshotId != id) { throw new UnexpectedStateException("Current snapshot id is " + this.snapshotId + ",passed " + id); } // OK. Passed in snapshot is same as current snapshot. If not-empty, // create a new snapshot and let the old one go. Segment oldSnapshot = this.snapshot; if (!this.snapshot.isEmpty()) { this.snapshot = SegmentFactory.instance().createImmutableSegment(this.comparator); } this.snapshotId = NO_SNAPSHOT_ID; oldSnapshot.close(); }
private void updateRegionSplitTransition(final ServerName serverName, final TransitionCode state, final RegionInfo parent, final RegionInfo hriA, final RegionInfo hriB) throws IOException { checkMetaLoaded(parent); if (state != TransitionCode.READY_TO_SPLIT) { throw new UnexpectedStateException("unsupported split regionState=" + state + " for parent region " + parent + " maybe an old RS (< 2.0) had the operation in progress"); } // sanity check on the request if (!Bytes.equals(hriA.getEndKey(), hriB.getStartKey())) { throw new UnsupportedOperationException( "unsupported split request with bad keys: parent=" + parent + " hriA=" + hriA + " hriB=" + hriB); } // Submit the Split procedure final byte[] splitKey = hriB.getStartKey(); if (LOG.isDebugEnabled()) { LOG.debug("Split request from " + serverName + ", parent=" + parent + " splitKey=" + Bytes.toStringBinary(splitKey)); } master.getMasterProcedureExecutor().submitProcedure(createSplitProcedure(parent, splitKey)); // If the RS is < 2.0 throw an exception to abort the operation, we are handling the split if (master.getServerManager().getVersionNumber(serverName) < 0x0200000) { throw new UnsupportedOperationException(String.format( "Split handled by the master: parent=%s hriA=%s hriB=%s", parent.getShortNameToLog(), hriA, hriB)); } }
if (regionNode == null) { throw new UnexpectedStateException(String.format( "Server %s was trying to transition region %s to %s. but the region was removed.", serverName, regionInfo, state));
throw new UnexpectedStateException("Received report unexpected " + TransitionCode.OPENED + " transition openSeqNum=" + openSeqNum + ", " + regionNode + ", proc=" + this);
@Test (expected=NullPointerException.class) public void testWaitServerReportEventWithNullServer() throws UnexpectedStateException { // Test what happens if we pass in null server. I'd expect it throws NPE. if (this.am.waitServerReportEvent(null, null)) throw new UnexpectedStateException(); }