@Test(timeout = 300000) public void testRecoveryRegionRemovedFromZK() throws Exception { LOG.info("testRecoveryRegionRemovedFromZK"); conf.setBoolean(HConstants.DISTRIBUTED_LOG_REPLAY_KEY, false); String nodePath = ZKUtil.joinZNode(zkw.recoveringRegionsZNode, HRegionInfo.FIRST_META_REGIONINFO.getEncodedName()); ZKUtil.createSetData(zkw, nodePath, ZKUtil.positionToByteArray(0L)); slm = new SplitLogManager(zkw, conf, stopper, master, DUMMY_MASTER); slm.removeStaleRecoveringRegionsFromZK(null); List<String> recoveringRegions = zkw.getRecoverableZooKeeper().getChildren(zkw.recoveringRegionsZNode, false); assertTrue("Recovery regions isn't cleaned", recoveringRegions.isEmpty()); }
void removeStaleRecoveringRegionsFromZK(final Set<ServerName> failedServers) throws KeeperException, InterruptedIOException { Set<String> knownFailedServers = new HashSet<String>(); if (failedServers != null) { for (ServerName tmpServerName : failedServers) { knownFailedServers.add(tmpServerName.getServerName()); } } this.recoveringRegionLock.lock(); try { List<String> tasks = ZKUtil.listChildrenNoWatch(watcher, watcher.splitLogZNode); if (tasks != null) { for (String t : tasks) { byte[] data; try { data = ZKUtil.getData(this.watcher, ZKUtil.joinZNode(watcher.splitLogZNode, t)); } catch (InterruptedException e) { throw new InterruptedIOException(); } if (data != null) { SplitLogTask slt = null; try { slt = SplitLogTask.parseFrom(data); } catch (DeserializationException e) { LOG.warn("Failed parse data for znode " + t, e); } if (slt != null && slt.isDone()) { continue; } } t = ZKSplitLog.getFileName(t); ServerName serverName = HLogUtil.getServerNameFromHLogDirectoryName(new Path(t)); if (serverName != null) { knownFailedServers.add(serverName.getServerName()); } else { LOG.warn("Found invalid WAL log file name:" + t); } } } List<String> regions = ZKUtil.listChildrenNoWatch(watcher, watcher.recoveringRegionsZNode); if (regions != null) { for (String region : regions) { String nodePath = ZKUtil.joinZNode(watcher.recoveringRegionsZNode, region); List<String> regionFailedServers = ZKUtil.listChildrenNoWatch(watcher, nodePath); if (regionFailedServers == null || regionFailedServers.isEmpty()) { ZKUtil.deleteNode(watcher, nodePath); continue; } boolean needMoreRecovery = false; for (String tmpFailedServer : regionFailedServers) { if (knownFailedServers.contains(tmpFailedServer)) { needMoreRecovery = true; break; } } if (!needMoreRecovery) { ZKUtil.deleteNodeRecursively(watcher, nodePath); } } } } finally { this.recoveringRegionLock.unlock(); } }
SplitLogManager extends ZooKeeperListener { void removeStaleRecoveringRegionsFromZK(final Set<ServerName> failedServers) throws KeeperException, InterruptedIOException { Set<String> knownFailedServers = new HashSet<String>(); if (failedServers != null) { for (ServerName tmpServerName : failedServers) { knownFailedServers.add(tmpServerName.getServerName()); } } this.recoveringRegionLock.lock(); try { List<String> tasks = ZKUtil.listChildrenNoWatch(watcher, watcher.splitLogZNode); if (tasks != null) { for (String t : tasks) { byte[] data; try { data = ZKUtil.getData(this.watcher, ZKUtil.joinZNode(watcher.splitLogZNode, t)); } catch (InterruptedException e) { throw new InterruptedIOException(); } if (data != null) { SplitLogTask slt = null; try { slt = SplitLogTask.parseFrom(data); } catch (DeserializationException e) { LOG.warn("Failed parse data for znode " + t, e); } if (slt != null && slt.isDone()) { continue; } } t = ZKSplitLog.getFileName(t); ServerName serverName = HLogUtil.getServerNameFromHLogDirectoryName(new Path(t)); if (serverName != null) { knownFailedServers.add(serverName.getServerName()); } else { LOG.warn("Found invalid WAL log file name:" + t); } } } List<String> regions = ZKUtil.listChildrenNoWatch(watcher, watcher.recoveringRegionsZNode); if (regions != null) { for (String region : regions) { String nodePath = ZKUtil.joinZNode(watcher.recoveringRegionsZNode, region); List<String> regionFailedServers = ZKUtil.listChildrenNoWatch(watcher, nodePath); if (regionFailedServers == null || regionFailedServers.isEmpty()) { ZKUtil.deleteNode(watcher, nodePath); continue; } boolean needMoreRecovery = false; for (String tmpFailedServer : regionFailedServers) { if (knownFailedServers.contains(tmpFailedServer)) { needMoreRecovery = true; break; } } if (!needMoreRecovery) { ZKUtil.deleteNodeRecursively(watcher, nodePath); } } } } finally { this.recoveringRegionLock.unlock(); } } }
SplitLogManager extends ZooKeeperListener { void removeStaleRecoveringRegionsFromZK(final Set<ServerName> failedServers) throws KeeperException, InterruptedIOException { Set<String> knownFailedServers = new HashSet<String>(); if (failedServers != null) { for (ServerName tmpServerName : failedServers) { knownFailedServers.add(tmpServerName.getServerName()); } } this.recoveringRegionLock.lock(); try { List<String> tasks = ZKUtil.listChildrenNoWatch(watcher, watcher.splitLogZNode); if (tasks != null) { for (String t : tasks) { byte[] data; try { data = ZKUtil.getData(this.watcher, ZKUtil.joinZNode(watcher.splitLogZNode, t)); } catch (InterruptedException e) { throw new InterruptedIOException(); } if (data != null) { SplitLogTask slt = null; try { slt = SplitLogTask.parseFrom(data); } catch (DeserializationException e) { LOG.warn("Failed parse data for znode " + t, e); } if (slt != null && slt.isDone()) { continue; } } t = ZKSplitLog.getFileName(t); ServerName serverName = HLogUtil.getServerNameFromHLogDirectoryName(new Path(t)); if (serverName != null) { knownFailedServers.add(serverName.getServerName()); } else { LOG.warn("Found invalid WAL log file name:" + t); } } } List<String> regions = ZKUtil.listChildrenNoWatch(watcher, watcher.recoveringRegionsZNode); if (regions != null) { for (String region : regions) { String nodePath = ZKUtil.joinZNode(watcher.recoveringRegionsZNode, region); List<String> regionFailedServers = ZKUtil.listChildrenNoWatch(watcher, nodePath); if (regionFailedServers == null || regionFailedServers.isEmpty()) { ZKUtil.deleteNode(watcher, nodePath); continue; } boolean needMoreRecovery = false; for (String tmpFailedServer : regionFailedServers) { if (knownFailedServers.contains(tmpFailedServer)) { needMoreRecovery = true; break; } } if (!needMoreRecovery) { ZKUtil.deleteNodeRecursively(watcher, nodePath); } } } } finally { this.recoveringRegionLock.unlock(); } } SplitLogManager(ZooKeeperWatcher zkw, final Configuration conf,
      Stoppable stopper, MasterServices master, ServerName serverName);  SplitLogManager(ZooKeeperWatcher zkw, Configuration conf, Stoppable stopper,
      MasterServices master, ServerName serverName, TaskFinisher tf); }
SplitLogManager extends ZooKeeperListener { void removeStaleRecoveringRegionsFromZK(final Set<ServerName> failedServers) throws KeeperException, InterruptedIOException { Set<String> knownFailedServers = new HashSet<String>(); if (failedServers != null) { for (ServerName tmpServerName : failedServers) { knownFailedServers.add(tmpServerName.getServerName()); } } this.recoveringRegionLock.lock(); try { List<String> tasks = ZKUtil.listChildrenNoWatch(watcher, watcher.splitLogZNode); if (tasks != null) { for (String t : tasks) { byte[] data; try { data = ZKUtil.getData(this.watcher, ZKUtil.joinZNode(watcher.splitLogZNode, t)); } catch (InterruptedException e) { throw new InterruptedIOException(); } if (data != null) { SplitLogTask slt = null; try { slt = SplitLogTask.parseFrom(data); } catch (DeserializationException e) { LOG.warn("Failed parse data for znode " + t, e); } if (slt != null && slt.isDone()) { continue; } } t = ZKSplitLog.getFileName(t); ServerName serverName = HLogUtil.getServerNameFromHLogDirectoryName(new Path(t)); if (serverName != null) { knownFailedServers.add(serverName.getServerName()); } else { LOG.warn("Found invalid WAL log file name:" + t); } } } List<String> regions = ZKUtil.listChildrenNoWatch(watcher, watcher.recoveringRegionsZNode); if (regions != null) { for (String region : regions) { String nodePath = ZKUtil.joinZNode(watcher.recoveringRegionsZNode, region); List<String> regionFailedServers = ZKUtil.listChildrenNoWatch(watcher, nodePath); if (regionFailedServers == null || regionFailedServers.isEmpty()) { ZKUtil.deleteNode(watcher, nodePath); continue; } boolean needMoreRecovery = false; for (String tmpFailedServer : regionFailedServers) { if (knownFailedServers.contains(tmpFailedServer)) { needMoreRecovery = true; break; } } if (!needMoreRecovery) { ZKUtil.deleteNodeRecursively(watcher, nodePath); } } } } finally { this.recoveringRegionLock.unlock(); } } SplitLogManager(ZooKeeperWatcher zkw, final Configuration conf,
      Stoppable stopper, MasterServices master, ServerName serverName);  SplitLogManager(ZooKeeperWatcher zkw, Configuration conf, Stoppable stopper,
      MasterServices master, ServerName serverName, TaskFinisher tf); long splitLogDistributed(final Path logDir); long splitLogDistributed(final List<Path> logDirs); long splitLogDistributed(final Set<ServerName> serverNames, final List<Path> logDirs,
      PathFilter filter); static void deleteRecoveringRegionZNodes(ZooKeeperWatcher watcher, List<String> regions); @Override void nodeDataChanged(String path); void stop(); static long parseLastFlushedSequenceIdFrom(final byte[] bytes); static boolean isRegionMarkedRecoveringInZK(ZooKeeperWatcher zkw, String regionEncodedName); static RegionStoreSequenceIds getRegionFlushedSequenceId(ZooKeeperWatcher zkw,
      String serverName, String encodedRegionName); void setRecoveryMode(boolean isForInitialization); RecoveryMode getRecoveryMode(); }
SplitLogManager extends ZooKeeperListener { void removeStaleRecoveringRegionsFromZK(final Set<ServerName> failedServers) throws KeeperException, InterruptedIOException { Set<String> knownFailedServers = new HashSet<String>(); if (failedServers != null) { for (ServerName tmpServerName : failedServers) { knownFailedServers.add(tmpServerName.getServerName()); } } this.recoveringRegionLock.lock(); try { List<String> tasks = ZKUtil.listChildrenNoWatch(watcher, watcher.splitLogZNode); if (tasks != null) { for (String t : tasks) { byte[] data; try { data = ZKUtil.getData(this.watcher, ZKUtil.joinZNode(watcher.splitLogZNode, t)); } catch (InterruptedException e) { throw new InterruptedIOException(); } if (data != null) { SplitLogTask slt = null; try { slt = SplitLogTask.parseFrom(data); } catch (DeserializationException e) { LOG.warn("Failed parse data for znode " + t, e); } if (slt != null && slt.isDone()) { continue; } } t = ZKSplitLog.getFileName(t); ServerName serverName = HLogUtil.getServerNameFromHLogDirectoryName(new Path(t)); if (serverName != null) { knownFailedServers.add(serverName.getServerName()); } else { LOG.warn("Found invalid WAL log file name:" + t); } } } List<String> regions = ZKUtil.listChildrenNoWatch(watcher, watcher.recoveringRegionsZNode); if (regions != null) { for (String region : regions) { String nodePath = ZKUtil.joinZNode(watcher.recoveringRegionsZNode, region); List<String> regionFailedServers = ZKUtil.listChildrenNoWatch(watcher, nodePath); if (regionFailedServers == null || regionFailedServers.isEmpty()) { ZKUtil.deleteNode(watcher, nodePath); continue; } boolean needMoreRecovery = false; for (String tmpFailedServer : regionFailedServers) { if (knownFailedServers.contains(tmpFailedServer)) { needMoreRecovery = true; break; } } if (!needMoreRecovery) { ZKUtil.deleteNodeRecursively(watcher, nodePath); } } } } finally { this.recoveringRegionLock.unlock(); } } SplitLogManager(ZooKeeperWatcher zkw, final Configuration conf,
      Stoppable stopper, MasterServices master, ServerName serverName);  SplitLogManager(ZooKeeperWatcher zkw, Configuration conf, Stoppable stopper,
      MasterServices master, ServerName serverName, TaskFinisher tf); long splitLogDistributed(final Path logDir); long splitLogDistributed(final List<Path> logDirs); long splitLogDistributed(final Set<ServerName> serverNames, final List<Path> logDirs,
      PathFilter filter); static void deleteRecoveringRegionZNodes(ZooKeeperWatcher watcher, List<String> regions); @Override void nodeDataChanged(String path); void stop(); static long parseLastFlushedSequenceIdFrom(final byte[] bytes); static boolean isRegionMarkedRecoveringInZK(ZooKeeperWatcher zkw, String regionEncodedName); static RegionStoreSequenceIds getRegionFlushedSequenceId(ZooKeeperWatcher zkw,
      String serverName, String encodedRegionName); void setRecoveryMode(boolean isForInitialization); RecoveryMode getRecoveryMode(); static final int DEFAULT_TIMEOUT; static final int DEFAULT_ZK_RETRIES; static final int DEFAULT_MAX_RESUBMIT; static final int DEFAULT_UNASSIGNED_TIMEOUT; public boolean ignoreZKDeleteForTesting; }