@Test public void testRollback() throws IOException { final int rowcount = TEST_UTIL.loadRegion(this.parent, CF); assertTrue(rowcount > 0); int parentRowCount = countRows(this.parent); assertEquals(rowcount, parentRowCount); HRegion spiedRegion = spy(this.parent); SplitTransaction st = prepareGOOD_SPLIT_ROW(spiedRegion); SplitTransaction spiedUponSt = spy(st); when(spiedRegion.createDaughterRegionFromSplits(spiedUponSt.getSecondDaughter())). thenThrow(new MockedFailedDaughterCreation()); boolean expectedException = false; Server mockServer = Mockito.mock(Server.class); when(mockServer.getConfiguration()).thenReturn(TEST_UTIL.getConfiguration()); try { spiedUponSt.execute(mockServer, null); } catch (MockedFailedDaughterCreation e) { expectedException = true; } assertTrue(expectedException); assertTrue(spiedUponSt.rollback(null, null)); int parentRowCount2 = countRows(this.parent); assertEquals(parentRowCount, parentRowCount2); assertTrue(!this.fs.exists(HRegion.getRegionDir(this.testdir, st.getFirstDaughter()))); assertTrue(!this.fs.exists(HRegion.getRegionDir(this.testdir, st.getSecondDaughter()))); assertTrue(!this.parent.lock.writeLock().isHeldByCurrentThread()); assertTrue(st.prepare()); PairOfSameType<HRegion> daughters = st.execute(mockServer, null); int daughtersRowCount = 0; for (HRegion openRegion: daughters) { try { int count = countRows(openRegion); assertTrue(count > 0 && count != rowcount); daughtersRowCount += count; } finally { HRegion.closeHRegion(openRegion); } } assertEquals(rowcount, daughtersRowCount); assertTrue(!this.parent.lock.writeLock().isHeldByCurrentThread()); assertTrue("Rollback hooks should be called.", wasRollBackHookCalled()); }
@SuppressWarnings("deprecation") public boolean rollback(final Server server, final RegionServerServices services) throws IOException { if (this.parent.getCoprocessorHost() != null) { this.parent.getCoprocessorHost().preRollBackSplit(); } boolean result = true; ListIterator<JournalEntry> iterator = this.journal.listIterator(this.journal.size()); while (iterator.hasPrevious()) { JournalEntry je = iterator.previous(); switch(je) { case SET_SPLITTING: if (useCoordinatedStateManager(server) && server instanceof HRegionServer) { ((BaseCoordinatedStateManager) server.getCoordinatedStateManager()) .getSplitTransactionCoordination().clean(this.parent.getRegionInfo()); } else if (services != null && !useZKForAssignment && !services.reportRegionTransition(TransitionCode.SPLIT_REVERTED, parent.getRegionInfo(), hri_a, hri_b)) { return false; } break; case CREATE_SPLIT_DIR: this.parent.writestate.writesEnabled = true; this.parent.getRegionFileSystem().cleanupSplitsDir(); break; case CLOSED_PARENT_REGION: try { this.parent.initialize(); } catch (IOException e) { LOG.error("Failed rollbacking CLOSED_PARENT_REGION of region " + this.parent.getRegionNameAsString(), e); throw new RuntimeException(e); } break; case STARTED_REGION_A_CREATION: this.parent.getRegionFileSystem().cleanupDaughterRegion(this.hri_a); break; case STARTED_REGION_B_CREATION: this.parent.getRegionFileSystem().cleanupDaughterRegion(this.hri_b); break; case OFFLINED_PARENT: if (services != null) services.addToOnlineRegions(this.parent); break; case PONR: return false; default: throw new RuntimeException("Unhandled journal entry: " + je); } } if (this.parent.getCoprocessorHost() != null) { this.parent.getCoprocessorHost().postRollBackSplit(); } return result; }
SplitTransaction { @SuppressWarnings("deprecation") public boolean rollback(final Server server, final RegionServerServices services) throws IOException { if (this.parent.getCoprocessorHost() != null) { this.parent.getCoprocessorHost().preRollBackSplit(); } boolean result = true; ListIterator<JournalEntry> iterator = this.journal.listIterator(this.journal.size()); while (iterator.hasPrevious()) { JournalEntry je = iterator.previous(); switch(je) { case SET_SPLITTING: if (useCoordinatedStateManager(server) && server instanceof HRegionServer) { ((BaseCoordinatedStateManager) server.getCoordinatedStateManager()) .getSplitTransactionCoordination().clean(this.parent.getRegionInfo()); } else if (services != null && !useZKForAssignment && !services.reportRegionTransition(TransitionCode.SPLIT_REVERTED, parent.getRegionInfo(), hri_a, hri_b)) { return false; } break; case CREATE_SPLIT_DIR: this.parent.writestate.writesEnabled = true; this.parent.getRegionFileSystem().cleanupSplitsDir(); break; case CLOSED_PARENT_REGION: try { this.parent.initialize(); } catch (IOException e) { LOG.error("Failed rollbacking CLOSED_PARENT_REGION of region " + this.parent.getRegionNameAsString(), e); throw new RuntimeException(e); } break; case STARTED_REGION_A_CREATION: this.parent.getRegionFileSystem().cleanupDaughterRegion(this.hri_a); break; case STARTED_REGION_B_CREATION: this.parent.getRegionFileSystem().cleanupDaughterRegion(this.hri_b); break; case OFFLINED_PARENT: if (services != null) services.addToOnlineRegions(this.parent); break; case PONR: return false; default: throw new RuntimeException("Unhandled journal entry: " + je); } } if (this.parent.getCoprocessorHost() != null) { this.parent.getCoprocessorHost().postRollBackSplit(); } return result; } }
SplitTransaction { @SuppressWarnings("deprecation") public boolean rollback(final Server server, final RegionServerServices services) throws IOException { if (this.parent.getCoprocessorHost() != null) { this.parent.getCoprocessorHost().preRollBackSplit(); } boolean result = true; ListIterator<JournalEntry> iterator = this.journal.listIterator(this.journal.size()); while (iterator.hasPrevious()) { JournalEntry je = iterator.previous(); switch(je) { case SET_SPLITTING: if (useCoordinatedStateManager(server) && server instanceof HRegionServer) { ((BaseCoordinatedStateManager) server.getCoordinatedStateManager()) .getSplitTransactionCoordination().clean(this.parent.getRegionInfo()); } else if (services != null && !useZKForAssignment && !services.reportRegionTransition(TransitionCode.SPLIT_REVERTED, parent.getRegionInfo(), hri_a, hri_b)) { return false; } break; case CREATE_SPLIT_DIR: this.parent.writestate.writesEnabled = true; this.parent.getRegionFileSystem().cleanupSplitsDir(); break; case CLOSED_PARENT_REGION: try { this.parent.initialize(); } catch (IOException e) { LOG.error("Failed rollbacking CLOSED_PARENT_REGION of region " + this.parent.getRegionNameAsString(), e); throw new RuntimeException(e); } break; case STARTED_REGION_A_CREATION: this.parent.getRegionFileSystem().cleanupDaughterRegion(this.hri_a); break; case STARTED_REGION_B_CREATION: this.parent.getRegionFileSystem().cleanupDaughterRegion(this.hri_b); break; case OFFLINED_PARENT: if (services != null) services.addToOnlineRegions(this.parent); break; case PONR: return false; default: throw new RuntimeException("Unhandled journal entry: " + je); } } if (this.parent.getCoprocessorHost() != null) { this.parent.getCoprocessorHost().postRollBackSplit(); } return result; } SplitTransaction(final HRegion r, final byte [] splitrow); }
SplitTransaction { @SuppressWarnings("deprecation") public boolean rollback(final Server server, final RegionServerServices services) throws IOException { if (this.parent.getCoprocessorHost() != null) { this.parent.getCoprocessorHost().preRollBackSplit(); } boolean result = true; ListIterator<JournalEntry> iterator = this.journal.listIterator(this.journal.size()); while (iterator.hasPrevious()) { JournalEntry je = iterator.previous(); switch(je) { case SET_SPLITTING: if (useCoordinatedStateManager(server) && server instanceof HRegionServer) { ((BaseCoordinatedStateManager) server.getCoordinatedStateManager()) .getSplitTransactionCoordination().clean(this.parent.getRegionInfo()); } else if (services != null && !useZKForAssignment && !services.reportRegionTransition(TransitionCode.SPLIT_REVERTED, parent.getRegionInfo(), hri_a, hri_b)) { return false; } break; case CREATE_SPLIT_DIR: this.parent.writestate.writesEnabled = true; this.parent.getRegionFileSystem().cleanupSplitsDir(); break; case CLOSED_PARENT_REGION: try { this.parent.initialize(); } catch (IOException e) { LOG.error("Failed rollbacking CLOSED_PARENT_REGION of region " + this.parent.getRegionNameAsString(), e); throw new RuntimeException(e); } break; case STARTED_REGION_A_CREATION: this.parent.getRegionFileSystem().cleanupDaughterRegion(this.hri_a); break; case STARTED_REGION_B_CREATION: this.parent.getRegionFileSystem().cleanupDaughterRegion(this.hri_b); break; case OFFLINED_PARENT: if (services != null) services.addToOnlineRegions(this.parent); break; case PONR: return false; default: throw new RuntimeException("Unhandled journal entry: " + je); } } if (this.parent.getCoprocessorHost() != null) { this.parent.getCoprocessorHost().postRollBackSplit(); } return result; } SplitTransaction(final HRegion r, final byte [] splitrow); boolean prepare(); PairOfSameType<HRegion> stepsBeforePONR(final Server server,
      final RegionServerServices services, boolean testing); PairOfSameType<HRegion> execute(final Server server,
      final RegionServerServices services); PairOfSameType<HRegion> stepsAfterPONR(final Server server,
      final RegionServerServices services, PairOfSameType<HRegion> regions); Put addLocation(final Put p, final ServerName sn, long openSeqNum); @SuppressWarnings("deprecation") boolean rollback(final Server server, final RegionServerServices services); }
SplitTransaction { @SuppressWarnings("deprecation") public boolean rollback(final Server server, final RegionServerServices services) throws IOException { if (this.parent.getCoprocessorHost() != null) { this.parent.getCoprocessorHost().preRollBackSplit(); } boolean result = true; ListIterator<JournalEntry> iterator = this.journal.listIterator(this.journal.size()); while (iterator.hasPrevious()) { JournalEntry je = iterator.previous(); switch(je) { case SET_SPLITTING: if (useCoordinatedStateManager(server) && server instanceof HRegionServer) { ((BaseCoordinatedStateManager) server.getCoordinatedStateManager()) .getSplitTransactionCoordination().clean(this.parent.getRegionInfo()); } else if (services != null && !useZKForAssignment && !services.reportRegionTransition(TransitionCode.SPLIT_REVERTED, parent.getRegionInfo(), hri_a, hri_b)) { return false; } break; case CREATE_SPLIT_DIR: this.parent.writestate.writesEnabled = true; this.parent.getRegionFileSystem().cleanupSplitsDir(); break; case CLOSED_PARENT_REGION: try { this.parent.initialize(); } catch (IOException e) { LOG.error("Failed rollbacking CLOSED_PARENT_REGION of region " + this.parent.getRegionNameAsString(), e); throw new RuntimeException(e); } break; case STARTED_REGION_A_CREATION: this.parent.getRegionFileSystem().cleanupDaughterRegion(this.hri_a); break; case STARTED_REGION_B_CREATION: this.parent.getRegionFileSystem().cleanupDaughterRegion(this.hri_b); break; case OFFLINED_PARENT: if (services != null) services.addToOnlineRegions(this.parent); break; case PONR: return false; default: throw new RuntimeException("Unhandled journal entry: " + je); } } if (this.parent.getCoprocessorHost() != null) { this.parent.getCoprocessorHost().postRollBackSplit(); } return result; } SplitTransaction(final HRegion r, final byte [] splitrow); boolean prepare(); PairOfSameType<HRegion> stepsBeforePONR(final Server server,
      final RegionServerServices services, boolean testing); PairOfSameType<HRegion> execute(final Server server,
      final RegionServerServices services); PairOfSameType<HRegion> stepsAfterPONR(final Server server,
      final RegionServerServices services, PairOfSameType<HRegion> regions); Put addLocation(final Put p, final ServerName sn, long openSeqNum); @SuppressWarnings("deprecation") boolean rollback(final Server server, final RegionServerServices services); public SplitTransactionCoordination.SplitTransactionDetails std; }