@Test public void testCloseRegion() throws IOException, NodeExistsException, KeeperException, DeserializationException { final Server server = new MockServer(HTU); final RegionServerServices rss = HTU.createMockRegionServerService(); HTableDescriptor htd = TEST_HTD; HRegionInfo hri = TEST_HRI; ZkCoordinatedStateManager coordinationProvider = new ZkCoordinatedStateManager(); coordinationProvider.initialize(server); coordinationProvider.start(); OpenRegion(server, rss, htd, hri, coordinationProvider.getOpenRegionCoordination()); int versionOfClosingNode = ZKAssign.createNodeClosing(server.getZooKeeper(), hri, server.getServerName()); ZkCloseRegionCoordination.ZkCloseRegionDetails zkCrd = new ZkCloseRegionCoordination.ZkCloseRegionDetails(); zkCrd.setPublishStatusInZk(true); zkCrd.setExpectedVersion(versionOfClosingNode); CloseRegionHandler handler = new CloseRegionHandler(server, rss, hri, false, coordinationProvider.getCloseRegionCoordination(), zkCrd); handler.process(); RegionTransition rt = RegionTransition.parseFrom( ZKAssign.getData(server.getZooKeeper(), hri.getEncodedName())); assertTrue(rt.getEventType().equals(EventType.RS_ZK_REGION_CLOSED)); }
@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();  }