Java 类org.apache.zookeeper.ZKUtil 实例源码

项目:hadoop-oss    文件:ActiveStandbyElector.java   
/**
 * Clear all of the state held within the parent ZNode.
 * This recursively deletes everything within the znode as well as the
 * parent znode itself. It should only be used when it's certain that
 * no electors are currently participating in the election.
 */
public synchronized void clearParentZNode()
    throws IOException, InterruptedException {
  Preconditions.checkState(!wantToBeInElection,
      "clearParentZNode() may not be called while in the election");

  try {
    LOG.info("Recursively deleting " + znodeWorkingDir + " from ZK...");

    zkDoWithRetries(new ZKAction<Void>() {
      @Override
      public Void run() throws KeeperException, InterruptedException {
        ZKUtil.deleteRecursive(zkClient, znodeWorkingDir);
        return null;
      }
    });
  } catch (KeeperException e) {
    throw new IOException("Couldn't clear parent znode " + znodeWorkingDir,
        e);
  }
  LOG.info("Successfully deleted " + znodeWorkingDir + " from ZK.");
}
项目:hadoop    文件:ActiveStandbyElector.java   
/**
 * Clear all of the state held within the parent ZNode.
 * This recursively deletes everything within the znode as well as the
 * parent znode itself. It should only be used when it's certain that
 * no electors are currently participating in the election.
 */
public synchronized void clearParentZNode()
    throws IOException, InterruptedException {
  Preconditions.checkState(!wantToBeInElection,
      "clearParentZNode() may not be called while in the election");

  try {
    LOG.info("Recursively deleting " + znodeWorkingDir + " from ZK...");

    zkDoWithRetries(new ZKAction<Void>() {
      @Override
      public Void run() throws KeeperException, InterruptedException {
        ZKUtil.deleteRecursive(zkClient, znodeWorkingDir);
        return null;
      }
    });
  } catch (KeeperException e) {
    throw new IOException("Couldn't clear parent znode " + znodeWorkingDir,
        e);
  }
  LOG.info("Successfully deleted " + znodeWorkingDir + " from ZK.");
}
项目:aliyun-oss-hadoop-fs    文件:ActiveStandbyElector.java   
/**
 * Clear all of the state held within the parent ZNode.
 * This recursively deletes everything within the znode as well as the
 * parent znode itself. It should only be used when it's certain that
 * no electors are currently participating in the election.
 */
public synchronized void clearParentZNode()
    throws IOException, InterruptedException {
  Preconditions.checkState(!wantToBeInElection,
      "clearParentZNode() may not be called while in the election");

  try {
    LOG.info("Recursively deleting " + znodeWorkingDir + " from ZK...");

    zkDoWithRetries(new ZKAction<Void>() {
      @Override
      public Void run() throws KeeperException, InterruptedException {
        ZKUtil.deleteRecursive(zkClient, znodeWorkingDir);
        return null;
      }
    });
  } catch (KeeperException e) {
    throw new IOException("Couldn't clear parent znode " + znodeWorkingDir,
        e);
  }
  LOG.info("Successfully deleted " + znodeWorkingDir + " from ZK.");
}
项目:big-c    文件:ActiveStandbyElector.java   
/**
 * Clear all of the state held within the parent ZNode.
 * This recursively deletes everything within the znode as well as the
 * parent znode itself. It should only be used when it's certain that
 * no electors are currently participating in the election.
 */
public synchronized void clearParentZNode()
    throws IOException, InterruptedException {
  Preconditions.checkState(!wantToBeInElection,
      "clearParentZNode() may not be called while in the election");

  try {
    LOG.info("Recursively deleting " + znodeWorkingDir + " from ZK...");

    zkDoWithRetries(new ZKAction<Void>() {
      @Override
      public Void run() throws KeeperException, InterruptedException {
        ZKUtil.deleteRecursive(zkClient, znodeWorkingDir);
        return null;
      }
    });
  } catch (KeeperException e) {
    throw new IOException("Couldn't clear parent znode " + znodeWorkingDir,
        e);
  }
  LOG.info("Successfully deleted " + znodeWorkingDir + " from ZK.");
}
项目:distributedlog    文件:BKLogWriteHandler.java   
public void deleteLog() throws IOException {
    lock.checkOwnershipAndReacquire();
    FutureUtils.result(purgeLogSegmentsOlderThanTxnId(-1));

    try {
        Utils.closeQuietly(lock);
        zooKeeperClient.get().exists(logMetadata.getLogSegmentsPath(), false);
        zooKeeperClient.get().exists(logMetadata.getMaxTxIdPath(), false);
        if (logMetadata.getLogRootPath().toLowerCase().contains("distributedlog")) {
            ZKUtil.deleteRecursive(zooKeeperClient.get(), logMetadata.getLogRootPath());
        } else {
            LOG.warn("Skip deletion of unrecognized ZK Path {}", logMetadata.getLogRootPath());
        }
    } catch (InterruptedException ie) {
        LOG.error("Interrupted while deleting log znodes", ie);
        throw new DLInterruptedException("Interrupted while deleting " + logMetadata.getLogRootPath(), ie);
    } catch (KeeperException ke) {
        LOG.error("Error deleting" + logMetadata.getLogRootPath() + " in zookeeper", ke);
    }
}
项目:hadoop-2.6.0-cdh5.4.3    文件:ActiveStandbyElector.java   
/**
 * Clear all of the state held within the parent ZNode.
 * This recursively deletes everything within the znode as well as the
 * parent znode itself. It should only be used when it's certain that
 * no electors are currently participating in the election.
 */
public synchronized void clearParentZNode()
    throws IOException, InterruptedException {
  Preconditions.checkState(!wantToBeInElection,
      "clearParentZNode() may not be called while in the election");

  try {
    LOG.info("Recursively deleting " + znodeWorkingDir + " from ZK...");

    zkDoWithRetries(new ZKAction<Void>() {
      @Override
      public Void run() throws KeeperException, InterruptedException {
        ZKUtil.deleteRecursive(zkClient, znodeWorkingDir);
        return null;
      }
    });
  } catch (KeeperException e) {
    throw new IOException("Couldn't clear parent znode " + znodeWorkingDir,
        e);
  }
  LOG.info("Successfully deleted " + znodeWorkingDir + " from ZK.");
}
项目:hadoop-plus    文件:ActiveStandbyElector.java   
/**
 * Clear all of the state held within the parent ZNode.
 * This recursively deletes everything within the znode as well as the
 * parent znode itself. It should only be used when it's certain that
 * no electors are currently participating in the election.
 */
public synchronized void clearParentZNode()
    throws IOException, InterruptedException {
  Preconditions.checkState(!wantToBeInElection,
      "clearParentZNode() may not be called while in the election");

  try {
    LOG.info("Recursively deleting " + znodeWorkingDir + " from ZK...");

    zkDoWithRetries(new ZKAction<Void>() {
      @Override
      public Void run() throws KeeperException, InterruptedException {
        ZKUtil.deleteRecursive(zkClient, znodeWorkingDir);
        return null;
      }
    });
  } catch (KeeperException e) {
    throw new IOException("Couldn't clear parent znode " + znodeWorkingDir,
        e);
  }
  LOG.info("Successfully deleted " + znodeWorkingDir + " from ZK.");
}
项目:hops    文件:ActiveStandbyElector.java   
/**
 * Clear all of the state held within the parent ZNode.
 * This recursively deletes everything within the znode as well as the
 * parent znode itself. It should only be used when it's certain that
 * no electors are currently participating in the election.
 */
public synchronized void clearParentZNode()
    throws IOException, InterruptedException {
  Preconditions.checkState(!wantToBeInElection,
      "clearParentZNode() may not be called while in the election");

  try {
    LOG.info("Recursively deleting " + znodeWorkingDir + " from ZK...");

    zkDoWithRetries(new ZKAction<Void>() {
      @Override
      public Void run() throws KeeperException, InterruptedException {
        ZKUtil.deleteRecursive(zkClient, znodeWorkingDir);
        return null;
      }
    });
  } catch (KeeperException e) {
    throw new IOException("Couldn't clear parent znode " + znodeWorkingDir,
        e);
  }
  LOG.info("Successfully deleted " + znodeWorkingDir + " from ZK.");
}
项目:hadoop-TCP    文件:ActiveStandbyElector.java   
/**
 * Clear all of the state held within the parent ZNode.
 * This recursively deletes everything within the znode as well as the
 * parent znode itself. It should only be used when it's certain that
 * no electors are currently participating in the election.
 */
public synchronized void clearParentZNode()
    throws IOException, InterruptedException {
  Preconditions.checkState(!wantToBeInElection,
      "clearParentZNode() may not be called while in the election");

  try {
    LOG.info("Recursively deleting " + znodeWorkingDir + " from ZK...");

    zkDoWithRetries(new ZKAction<Void>() {
      @Override
      public Void run() throws KeeperException, InterruptedException {
        ZKUtil.deleteRecursive(zkClient, znodeWorkingDir);
        return null;
      }
    });
  } catch (KeeperException e) {
    throw new IOException("Couldn't clear parent znode " + znodeWorkingDir,
        e);
  }
  LOG.info("Successfully deleted " + znodeWorkingDir + " from ZK.");
}
项目:hardfs    文件:ActiveStandbyElector.java   
/**
 * Clear all of the state held within the parent ZNode.
 * This recursively deletes everything within the znode as well as the
 * parent znode itself. It should only be used when it's certain that
 * no electors are currently participating in the election.
 */
public synchronized void clearParentZNode()
    throws IOException, InterruptedException {
  Preconditions.checkState(!wantToBeInElection,
      "clearParentZNode() may not be called while in the election");

  try {
    LOG.info("Recursively deleting " + znodeWorkingDir + " from ZK...");

    zkDoWithRetries(new ZKAction<Void>() {
      @Override
      public Void run() throws KeeperException, InterruptedException {
        ZKUtil.deleteRecursive(zkClient, znodeWorkingDir);
        return null;
      }
    });
  } catch (KeeperException e) {
    throw new IOException("Couldn't clear parent znode " + znodeWorkingDir,
        e);
  }
  LOG.info("Successfully deleted " + znodeWorkingDir + " from ZK.");
}
项目:hadoop-on-lustre2    文件:ActiveStandbyElector.java   
/**
 * Clear all of the state held within the parent ZNode.
 * This recursively deletes everything within the znode as well as the
 * parent znode itself. It should only be used when it's certain that
 * no electors are currently participating in the election.
 */
public synchronized void clearParentZNode()
    throws IOException, InterruptedException {
  Preconditions.checkState(!wantToBeInElection,
      "clearParentZNode() may not be called while in the election");

  try {
    LOG.info("Recursively deleting " + znodeWorkingDir + " from ZK...");

    zkDoWithRetries(new ZKAction<Void>() {
      @Override
      public Void run() throws KeeperException, InterruptedException {
        ZKUtil.deleteRecursive(zkClient, znodeWorkingDir);
        return null;
      }
    });
  } catch (KeeperException e) {
    throw new IOException("Couldn't clear parent znode " + znodeWorkingDir,
        e);
  }
  LOG.info("Successfully deleted " + znodeWorkingDir + " from ZK.");
}
项目:dxram    文件:ZooKeeperHandler.java   
/**
 * Disconnects from ZooKeeper
 *
 * @param p_delete
 *     if true alle ZooKeeper nodes are deleted
 * @throws ZooKeeperException
 *     if ZooKeeper could not accessed
 */
public synchronized void close(final boolean p_delete) throws ZooKeeperException {
    if (m_zookeeper != null) {
        try {
            if (p_delete) {
                ZKUtil.deleteRecursive(m_zookeeper, m_path);
            }
            m_zookeeper.close();
        } catch (final InterruptedException | KeeperException e) {
            throw new ZooKeeperException("Could not access ZooKeeper", e);
        }
        m_zookeeper = null;
    }
}
项目:SecureKeeper    文件:DeleteAllCommand.java   
@Override
public boolean exec() throws KeeperException,
        InterruptedException {
    printDeprecatedWarning();

    String path = args[1];
    ZKUtil.deleteRecursive(zk, path);
    return false;
}
项目:SecureKeeper    文件:DeleteAllCommand.java   
@Override
public boolean exec() throws KeeperException,
        InterruptedException {
    printDeprecatedWarning();

    String path = args[1];
    ZKUtil.deleteRecursive(zk, path);
    return false;
}
项目:distributedlog    文件:BKDistributedLogManager.java   
/**
 * Delete all the partitions of the specified log
 *
 * @throws IOException if the deletion fails
 */
@Override
public void delete() throws IOException {
    BKLogWriteHandler ledgerHandler = createWriteHandler(true);
    try {
        ledgerHandler.deleteLog();
    } finally {
        Utils.closeQuietly(ledgerHandler);
    }

    // Delete the ZK path associated with the log stream
    String zkPath = getZKPath();
    // Safety check when we are using the shared zookeeper
    if (zkPath.toLowerCase().contains("distributedlog")) {
        try {
            LOG.info("Delete the path associated with the log {}, ZK Path {}", name, zkPath);
            ZKUtil.deleteRecursive(writerZKC.get(), zkPath);
        } catch (InterruptedException ie) {
            LOG.error("Interrupted while accessing ZK", ie);
            throw new DLInterruptedException("Error initializing zk", ie);
        } catch (KeeperException ke) {
            LOG.error("Error accessing entry in zookeeper", ke);
            throw new IOException("Error initializing zk", ke);
        }
    } else {
        LOG.warn("Skip deletion of unrecognized ZK Path {}", zkPath);
    }
}
项目:Scribengin    文件:RegistryImpl.java   
@Override
public void rdelete(String path) throws RegistryException {
  checkConnected();
  try {
    PathUtils.validatePath(path);
    List<String> tree = ZKUtil.listSubTreeBFS(zkClient, realPath(path));
    for (int i = tree.size() - 1; i >= 0 ; --i) {
      //Delete the leaves first and eventually get rid of the root
      zkClient.delete(tree.get(i), -1); //Delete all versions of the node with -1.
    }
  } catch (InterruptedException | KeeperException e) {
    throw new RegistryException(ErrorCode.Unknown, e) ;
  }
}
项目:Scribengin    文件:RegistryImpl.java   
public List<String> findDencendantRealPaths(String path) throws RegistryException {
  checkConnected();
  try {
    PathUtils.validatePath(realPath(path));
    return ZKUtil.listSubTreeBFS(zkClient, realPath(path));
  } catch (InterruptedException | KeeperException e) {
    throw new RegistryException(ErrorCode.Unknown, e) ;
  }
}
项目:Scribengin    文件:RegistryImpl.java   
public void rcopy(String path, String toPath) throws RegistryException {
  try {
    PathUtils.validatePath(path);
    List<String> tree = ZKUtil.listSubTreeBFS(zkClient, realPath(path));
    for (int i = 0; i < tree.size(); i++) {
      String selPath = tree.get(i);
      String selToPath = selPath.replace(path, toPath);
      byte[] data = zkClient.getData(selPath, false, new Stat()) ;
      zkClient.create(selToPath, data, DEFAULT_ACL, toCreateMode(NodeCreateMode.PERSISTENT)) ;
    }
  } catch (InterruptedException | KeeperException e) {
    throw new RegistryException(ErrorCode.Unknown, e) ;
  }
}
项目:resa    文件:MigrateSimulateForCH.java   
@Test
public void deleteZkNode() throws Exception {
    ZKUtil.deleteRecursive(zk.getZookeeperClient().getZooKeeper(), "/resa");
}