@Test public void testFailedFlushAborts() throws IOException, NodeExistsException, KeeperException { final Server server = new MockServer(HTU, false); final RegionServerServices rss = HTU.createMockRegionServerService(); HTableDescriptor htd = TEST_HTD; final HRegionInfo hri = new HRegionInfo(htd.getTableName(), HConstants.EMPTY_END_ROW, HConstants.EMPTY_END_ROW); HRegion region = HTU.createLocalHRegion(hri, htd); try { assertNotNull(region); HRegion spy = Mockito.spy(region); final boolean abort = false; Mockito.when(spy.close(abort)). thenThrow(new IOException("Mocked failed close!")); rss.addToOnlineRegions(spy); assertFalse(server.isStopped()); ZkCoordinatedStateManager consensusProvider = new ZkCoordinatedStateManager(); consensusProvider.initialize(server); consensusProvider.start(); ZkCloseRegionCoordination.ZkCloseRegionDetails zkCrd = new ZkCloseRegionCoordination.ZkCloseRegionDetails(); zkCrd.setPublishStatusInZk(false); zkCrd.setExpectedVersion(-1); CloseRegionHandler handler = new CloseRegionHandler(server, rss, hri, false, consensusProvider.getCloseRegionCoordination(), zkCrd); boolean throwable = false; try { handler.process(); } catch (Throwable t) { throwable = true; } finally { assertTrue(throwable); assertTrue(server.isStopped()); } } finally { HRegion.closeHRegion(region); } }
@Override public void process() { try { String name = regionInfo.getRegionNameAsString(); LOG.debug("Processing close of " + name); String encodedRegionName = regionInfo.getEncodedName(); HRegion region = this.rsServices.getFromOnlineRegions(encodedRegionName); if (region == null) { LOG.warn("Received CLOSE for region " + name + " but currently not serving - ignoring"); return; } try { if (useZKForAssignment && closeRegionCoordination.checkClosingState( regionInfo, closeRegionDetails)) { return; } if (region.close(abort) == null) { LOG.warn("Can't close region: was already closed during close(): " + regionInfo.getRegionNameAsString()); return; } } catch (IOException ioe) { server.abort("Unrecoverable exception while closing region " + regionInfo.getRegionNameAsString() + ", still finishing close", ioe); throw new RuntimeException(ioe); } this.rsServices.removeFromOnlineRegions(region, destination); if (!useZKForAssignment) { rsServices.reportRegionTransition(TransitionCode.CLOSED, regionInfo); } else { closeRegionCoordination.setClosedState(region, this.server.getServerName(), closeRegionDetails); } LOG.debug("Closed " + region.getRegionNameAsString()); } finally { this.rsServices.getRegionsInTransitionInRS(). remove(this.regionInfo.getEncodedNameAsBytes()); } }
CloseRegionHandler extends EventHandler { @Override public void process() { try { String name = regionInfo.getRegionNameAsString(); LOG.debug("Processing close of " + name); String encodedRegionName = regionInfo.getEncodedName(); HRegion region = this.rsServices.getFromOnlineRegions(encodedRegionName); if (region == null) { LOG.warn("Received CLOSE for region " + name + " but currently not serving - ignoring"); return; } try { if (useZKForAssignment && closeRegionCoordination.checkClosingState( regionInfo, closeRegionDetails)) { return; } if (region.close(abort) == null) { LOG.warn("Can't close region: was already closed during close(): " + regionInfo.getRegionNameAsString()); return; } } catch (IOException ioe) { server.abort("Unrecoverable exception while closing region " + regionInfo.getRegionNameAsString() + ", still finishing close", ioe); throw new RuntimeException(ioe); } this.rsServices.removeFromOnlineRegions(region, destination); if (!useZKForAssignment) { rsServices.reportRegionTransition(TransitionCode.CLOSED, regionInfo); } else { closeRegionCoordination.setClosedState(region, this.server.getServerName(), closeRegionDetails); } LOG.debug("Closed " + region.getRegionNameAsString()); } finally { this.rsServices.getRegionsInTransitionInRS(). remove(this.regionInfo.getEncodedNameAsBytes()); } } }
CloseRegionHandler extends EventHandler { @Override public void process() { try { String name = regionInfo.getRegionNameAsString(); LOG.debug("Processing close of " + name); String encodedRegionName = regionInfo.getEncodedName(); HRegion region = this.rsServices.getFromOnlineRegions(encodedRegionName); if (region == null) { LOG.warn("Received CLOSE for region " + name + " but currently not serving - ignoring"); return; } try { if (useZKForAssignment && closeRegionCoordination.checkClosingState( regionInfo, closeRegionDetails)) { return; } if (region.close(abort) == null) { LOG.warn("Can't close region: was already closed during close(): " + regionInfo.getRegionNameAsString()); return; } } catch (IOException ioe) { server.abort("Unrecoverable exception while closing region " + regionInfo.getRegionNameAsString() + ", still finishing close", ioe); throw new RuntimeException(ioe); } this.rsServices.removeFromOnlineRegions(region, destination); if (!useZKForAssignment) { rsServices.reportRegionTransition(TransitionCode.CLOSED, regionInfo); } else { closeRegionCoordination.setClosedState(region, this.server.getServerName(), closeRegionDetails); } LOG.debug("Closed " + region.getRegionNameAsString()); } finally { this.rsServices.getRegionsInTransitionInRS(). remove(this.regionInfo.getEncodedNameAsBytes()); } } CloseRegionHandler(final Server server,
      final RegionServerServices rsServices,
      final HRegionInfo regionInfo, final boolean abort,
      CloseRegionCoordination closeRegionCoordination,
      CloseRegionCoordination.CloseRegionDetails crd);  CloseRegionHandler(final Server server,
      final RegionServerServices rsServices,
      final HRegionInfo regionInfo, final boolean abort,
      CloseRegionCoordination closeRegionCoordination,
      CloseRegionCoordination.CloseRegionDetails crd,
      ServerName destination);  CloseRegionHandler(final Server server,
      final RegionServerServices rsServices, HRegionInfo regionInfo,
      boolean abort, CloseRegionCoordination closeRegionCoordination,
      CloseRegionCoordination.CloseRegionDetails crd, EventType eventType); protected  CloseRegionHandler(final Server server,
      final RegionServerServices rsServices, HRegionInfo regionInfo,
      boolean abort, CloseRegionCoordination closeRegionCoordination,
      CloseRegionCoordination.CloseRegionDetails crd,
      EventType eventType, ServerName destination); }
CloseRegionHandler extends EventHandler { @Override public void process() { try { String name = regionInfo.getRegionNameAsString(); LOG.debug("Processing close of " + name); String encodedRegionName = regionInfo.getEncodedName(); HRegion region = this.rsServices.getFromOnlineRegions(encodedRegionName); if (region == null) { LOG.warn("Received CLOSE for region " + name + " but currently not serving - ignoring"); return; } try { if (useZKForAssignment && closeRegionCoordination.checkClosingState( regionInfo, closeRegionDetails)) { return; } if (region.close(abort) == null) { LOG.warn("Can't close region: was already closed during close(): " + regionInfo.getRegionNameAsString()); return; } } catch (IOException ioe) { server.abort("Unrecoverable exception while closing region " + regionInfo.getRegionNameAsString() + ", still finishing close", ioe); throw new RuntimeException(ioe); } this.rsServices.removeFromOnlineRegions(region, destination); if (!useZKForAssignment) { rsServices.reportRegionTransition(TransitionCode.CLOSED, regionInfo); } else { closeRegionCoordination.setClosedState(region, this.server.getServerName(), closeRegionDetails); } LOG.debug("Closed " + region.getRegionNameAsString()); } finally { this.rsServices.getRegionsInTransitionInRS(). remove(this.regionInfo.getEncodedNameAsBytes()); } } CloseRegionHandler(final Server server,
      final RegionServerServices rsServices,
      final HRegionInfo regionInfo, final boolean abort,
      CloseRegionCoordination closeRegionCoordination,
      CloseRegionCoordination.CloseRegionDetails crd);  CloseRegionHandler(final Server server,
      final RegionServerServices rsServices,
      final HRegionInfo regionInfo, final boolean abort,
      CloseRegionCoordination closeRegionCoordination,
      CloseRegionCoordination.CloseRegionDetails crd,
      ServerName destination);  CloseRegionHandler(final Server server,
      final RegionServerServices rsServices, HRegionInfo regionInfo,
      boolean abort, CloseRegionCoordination closeRegionCoordination,
      CloseRegionCoordination.CloseRegionDetails crd, EventType eventType); protected  CloseRegionHandler(final Server server,
      final RegionServerServices rsServices, HRegionInfo regionInfo,
      boolean abort, CloseRegionCoordination closeRegionCoordination,
      CloseRegionCoordination.CloseRegionDetails crd,
      EventType eventType, ServerName destination); HRegionInfo getRegionInfo(); @Override void process(); }
CloseRegionHandler extends EventHandler { @Override public void process() { try { String name = regionInfo.getRegionNameAsString(); LOG.debug("Processing close of " + name); String encodedRegionName = regionInfo.getEncodedName(); HRegion region = this.rsServices.getFromOnlineRegions(encodedRegionName); if (region == null) { LOG.warn("Received CLOSE for region " + name + " but currently not serving - ignoring"); return; } try { if (useZKForAssignment && closeRegionCoordination.checkClosingState( regionInfo, closeRegionDetails)) { return; } if (region.close(abort) == null) { LOG.warn("Can't close region: was already closed during close(): " + regionInfo.getRegionNameAsString()); return; } } catch (IOException ioe) { server.abort("Unrecoverable exception while closing region " + regionInfo.getRegionNameAsString() + ", still finishing close", ioe); throw new RuntimeException(ioe); } this.rsServices.removeFromOnlineRegions(region, destination); if (!useZKForAssignment) { rsServices.reportRegionTransition(TransitionCode.CLOSED, regionInfo); } else { closeRegionCoordination.setClosedState(region, this.server.getServerName(), closeRegionDetails); } LOG.debug("Closed " + region.getRegionNameAsString()); } finally { this.rsServices.getRegionsInTransitionInRS(). remove(this.regionInfo.getEncodedNameAsBytes()); } } CloseRegionHandler(final Server server,
      final RegionServerServices rsServices,
      final HRegionInfo regionInfo, final boolean abort,
      CloseRegionCoordination closeRegionCoordination,
      CloseRegionCoordination.CloseRegionDetails crd);  CloseRegionHandler(final Server server,
      final RegionServerServices rsServices,
      final HRegionInfo regionInfo, final boolean abort,
      CloseRegionCoordination closeRegionCoordination,
      CloseRegionCoordination.CloseRegionDetails crd,
      ServerName destination);  CloseRegionHandler(final Server server,
      final RegionServerServices rsServices, HRegionInfo regionInfo,
      boolean abort, CloseRegionCoordination closeRegionCoordination,
      CloseRegionCoordination.CloseRegionDetails crd, EventType eventType); protected  CloseRegionHandler(final Server server,
      final RegionServerServices rsServices, HRegionInfo regionInfo,
      boolean abort, CloseRegionCoordination closeRegionCoordination,
      CloseRegionCoordination.CloseRegionDetails crd,
      EventType eventType, ServerName destination); HRegionInfo getRegionInfo(); @Override void process();  }