@Test public void testZKClosingNodeVersionMismatch() throws IOException, NodeExistsException, KeeperException, DeserializationException { final Server server = new MockServer(HTU); final RegionServerServices rss = HTU.createMockRegionServerService(); HTableDescriptor htd = TEST_HTD; final HRegionInfo hri = TEST_HRI; OpenRegion(server, rss, htd, hri); int versionOfClosingNode = ZKAssign.createNodeClosing(server.getZooKeeper(), hri, server.getServerName()); CloseRegionHandler handler = new CloseRegionHandler(server, rss, hri, false, true, versionOfClosingNode+1); handler.process(); RegionTransition rt = RegionTransition.parseFrom(ZKAssign.getData(server.getZooKeeper(), hri.getEncodedName())); assertTrue(rt.getEventType().equals(EventType.M_ZK_REGION_CLOSING )); }
@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();  }