@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()); CloseRegionHandler handler = new CloseRegionHandler(server, rss, hri, false, false, -1); 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"); if (zk){ LOG.error("The znode is not modified as we are not serving " + name); } return; } try { if (zk && !ZKAssign.checkClosingState(server.getZooKeeper(), regionInfo, expectedVersion)){ return; } if (region.close(abort) == null) { LOG.warn("Can't close region: was already closed during close(): " + regionInfo.getRegionNameAsString()); return; } } catch (KeeperException ke) { server.abort("Unrecoverable exception while checking state with zk " + regionInfo.getRegionNameAsString() + ", still finishing close", ke); throw new RuntimeException(ke); } 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 (this.zk) { if (setClosedState(this.expectedVersion, region)) { LOG.debug("Set closed state in zk for " + name + " on " + this.server.getServerName()); } else { LOG.debug("Set closed state in zk UNSUCCESSFUL for " + name + " on " + this.server.getServerName()); } } 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"); if (zk){ LOG.error("The znode is not modified as we are not serving " + name); } return; } try { if (zk && !ZKAssign.checkClosingState(server.getZooKeeper(), regionInfo, expectedVersion)){ return; } if (region.close(abort) == null) { LOG.warn("Can't close region: was already closed during close(): " + regionInfo.getRegionNameAsString()); return; } } catch (KeeperException ke) { server.abort("Unrecoverable exception while checking state with zk " + regionInfo.getRegionNameAsString() + ", still finishing close", ke); throw new RuntimeException(ke); } 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 (this.zk) { if (setClosedState(this.expectedVersion, region)) { LOG.debug("Set closed state in zk for " + name + " on " + this.server.getServerName()); } else { LOG.debug("Set closed state in zk UNSUCCESSFUL for " + name + " on " + this.server.getServerName()); } } 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"); if (zk){ LOG.error("The znode is not modified as we are not serving " + name); } return; } try { if (zk && !ZKAssign.checkClosingState(server.getZooKeeper(), regionInfo, expectedVersion)){ return; } if (region.close(abort) == null) { LOG.warn("Can't close region: was already closed during close(): " + regionInfo.getRegionNameAsString()); return; } } catch (KeeperException ke) { server.abort("Unrecoverable exception while checking state with zk " + regionInfo.getRegionNameAsString() + ", still finishing close", ke); throw new RuntimeException(ke); } 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 (this.zk) { if (setClosedState(this.expectedVersion, region)) { LOG.debug("Set closed state in zk for " + name + " on " + this.server.getServerName()); } else { LOG.debug("Set closed state in zk UNSUCCESSFUL for " + name + " on " + this.server.getServerName()); } } LOG.debug("Closed " + region.getRegionNameAsString()); } finally { this.rsServices.getRegionsInTransitionInRS(). remove(this.regionInfo.getEncodedNameAsBytes()); } } CloseRegionHandler(final Server server,
      final RegionServerServices rsServices, HRegionInfo regionInfo);  CloseRegionHandler(final Server server,
      final RegionServerServices rsServices,
      final HRegionInfo regionInfo, final boolean abort, final boolean zk,
      final int versionOfClosingNode);  CloseRegionHandler(final Server server,
      final RegionServerServices rsServices,
      final HRegionInfo regionInfo, final boolean abort, final boolean zk,
      final int versionOfClosingNode, ServerName destination);  CloseRegionHandler(final Server server,
      final RegionServerServices rsServices, HRegionInfo regionInfo,
      boolean abort, final boolean zk, final int versionOfClosingNode,
      EventType eventType); protected  CloseRegionHandler(final Server server,
      final RegionServerServices rsServices, HRegionInfo regionInfo,
      boolean abort, final boolean zk, final int versionOfClosingNode,
      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"); if (zk){ LOG.error("The znode is not modified as we are not serving " + name); } return; } try { if (zk && !ZKAssign.checkClosingState(server.getZooKeeper(), regionInfo, expectedVersion)){ return; } if (region.close(abort) == null) { LOG.warn("Can't close region: was already closed during close(): " + regionInfo.getRegionNameAsString()); return; } } catch (KeeperException ke) { server.abort("Unrecoverable exception while checking state with zk " + regionInfo.getRegionNameAsString() + ", still finishing close", ke); throw new RuntimeException(ke); } 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 (this.zk) { if (setClosedState(this.expectedVersion, region)) { LOG.debug("Set closed state in zk for " + name + " on " + this.server.getServerName()); } else { LOG.debug("Set closed state in zk UNSUCCESSFUL for " + name + " on " + this.server.getServerName()); } } LOG.debug("Closed " + region.getRegionNameAsString()); } finally { this.rsServices.getRegionsInTransitionInRS(). remove(this.regionInfo.getEncodedNameAsBytes()); } } CloseRegionHandler(final Server server,
      final RegionServerServices rsServices, HRegionInfo regionInfo);  CloseRegionHandler(final Server server,
      final RegionServerServices rsServices,
      final HRegionInfo regionInfo, final boolean abort, final boolean zk,
      final int versionOfClosingNode);  CloseRegionHandler(final Server server,
      final RegionServerServices rsServices,
      final HRegionInfo regionInfo, final boolean abort, final boolean zk,
      final int versionOfClosingNode, ServerName destination);  CloseRegionHandler(final Server server,
      final RegionServerServices rsServices, HRegionInfo regionInfo,
      boolean abort, final boolean zk, final int versionOfClosingNode,
      EventType eventType); protected  CloseRegionHandler(final Server server,
      final RegionServerServices rsServices, HRegionInfo regionInfo,
      boolean abort, final boolean zk, final int versionOfClosingNode,
      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"); if (zk){ LOG.error("The znode is not modified as we are not serving " + name); } return; } try { if (zk && !ZKAssign.checkClosingState(server.getZooKeeper(), regionInfo, expectedVersion)){ return; } if (region.close(abort) == null) { LOG.warn("Can't close region: was already closed during close(): " + regionInfo.getRegionNameAsString()); return; } } catch (KeeperException ke) { server.abort("Unrecoverable exception while checking state with zk " + regionInfo.getRegionNameAsString() + ", still finishing close", ke); throw new RuntimeException(ke); } 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 (this.zk) { if (setClosedState(this.expectedVersion, region)) { LOG.debug("Set closed state in zk for " + name + " on " + this.server.getServerName()); } else { LOG.debug("Set closed state in zk UNSUCCESSFUL for " + name + " on " + this.server.getServerName()); } } LOG.debug("Closed " + region.getRegionNameAsString()); } finally { this.rsServices.getRegionsInTransitionInRS(). remove(this.regionInfo.getEncodedNameAsBytes()); } } CloseRegionHandler(final Server server,
      final RegionServerServices rsServices, HRegionInfo regionInfo);  CloseRegionHandler(final Server server,
      final RegionServerServices rsServices,
      final HRegionInfo regionInfo, final boolean abort, final boolean zk,
      final int versionOfClosingNode);  CloseRegionHandler(final Server server,
      final RegionServerServices rsServices,
      final HRegionInfo regionInfo, final boolean abort, final boolean zk,
      final int versionOfClosingNode, ServerName destination);  CloseRegionHandler(final Server server,
      final RegionServerServices rsServices, HRegionInfo regionInfo,
      boolean abort, final boolean zk, final int versionOfClosingNode,
      EventType eventType); protected  CloseRegionHandler(final Server server,
      final RegionServerServices rsServices, HRegionInfo regionInfo,
      boolean abort, final boolean zk, final int versionOfClosingNode,
      EventType eventType, ServerName destination); HRegionInfo getRegionInfo(); @Override void process();  }