Ejemplo n.º 1
0
 /** Load all hlogs in all replication queues from ZK */
 private Set<String> loadHLogsFromQueues() {
   List<String> rss = zkHelper.getListOfReplicators();
   if (rss == null) {
     LOG.debug("Didn't find any region server that replicates, won't prevent any deletions.");
     return ImmutableSet.of();
   }
   Set<String> hlogs = Sets.newHashSet();
   for (String rs : rss) {
     List<String> listOfPeers = zkHelper.getListPeersForRS(rs);
     // if rs just died, this will be null
     if (listOfPeers == null) {
       continue;
     }
     for (String id : listOfPeers) {
       List<String> peersHlogs = zkHelper.getListHLogsForPeerForRS(rs, id);
       if (peersHlogs != null) {
         hlogs.addAll(peersHlogs);
       }
     }
   }
   return hlogs;
 }
Ejemplo n.º 2
0
  @Override
  public Iterable<FileStatus> getDeletableFiles(Iterable<FileStatus> files) {
    try {
      if (!zkHelper.getReplication()) {
        return ImmutableList.of();
      }
    } catch (KeeperException e) {
      abort("Cannot get the state of replication", e);
      return ImmutableList.of();
    }

    // all members of this class are null if replication is disabled,
    // so we cannot filter the files
    if (this.getConf() == null) {
      return files;
    }

    final Set<String> hlogs = loadHLogsFromQueues();
    return Iterables.filter(
        files,
        new Predicate<FileStatus>() {
          @Override
          public boolean apply(FileStatus file) {
            String hlog = file.getPath().getName();
            boolean logInReplicationQueue = hlogs.contains(hlog);
            if (LOG.isDebugEnabled()) {
              if (logInReplicationQueue) {
                LOG.debug("Found log in ZK, keeping: " + hlog);
              } else {
                LOG.debug("Didn't find this log in ZK, deleting: " + hlog);
              }
            }
            return !logInReplicationQueue;
          }
        });
  }