/** * Delete a config in ZooKeeper * * @param configName the config to delete * @throws IOException if an I/O error occurs */ public void deleteConfigDir(String configName) throws IOException { try { zkClient.clean(ZkConfigManager.CONFIGS_ZKNODE + "/" + configName); } catch (KeeperException | InterruptedException e) { throw new IOException("Error checking whether config exists", SolrZkClient.checkInterrupted(e)); } }
public void clean(String path) throws InterruptedException, KeeperException { List<String> children; try { children = getChildren(path, null, true); } catch (NoNodeException r) { return; } for (String string : children) { // we can't clean the built-in zookeeper node if (path.equals("/") && string.equals("zookeeper")) continue; if (path.equals("/")) { clean(path + string); } else { clean(path + "/" + string); } } try { if (!path.equals("/")) { try { delete(path, -1, true); } catch (NotEmptyException e) { clean(path); } } } catch (NoNodeException r) { return; } }
static void tryCleanPath(String zkHost, String path) throws Exception { SolrZkClient zkClient = new SolrZkClient(zkHost, TIMEOUT); if (zkClient.exists(path, true)) { zkClient.clean(path); } zkClient.close(); } }