org.apache.hadoop.hbase.zookeeper.ZKUtil.deleteNode()方法的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(11.0k)|赞(0)|评价(0)|浏览(136)

本文整理了Java中org.apache.hadoop.hbase.zookeeper.ZKUtil.deleteNode()方法的一些代码示例,展示了ZKUtil.deleteNode()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZKUtil.deleteNode()方法的具体详情如下:
包路径:org.apache.hadoop.hbase.zookeeper.ZKUtil
类名称:ZKUtil
方法名:deleteNode

ZKUtil.deleteNode介绍

[英]Delete the specified node. Sets no watches. Throws all exceptions.
[中]删除指定的节点。没有手表。抛出所有异常。

代码示例

代码示例来源:origin: apache/hbase

/**
 * Delete the specified node.  Sets no watches.  Throws all exceptions.
 */
public static void deleteNode(ZKWatcher zkw, String node)
 throws KeeperException {
 deleteNode(zkw, node, -1);
}

代码示例来源:origin: apache/hbase

/**
 * Create a bunch of znodes in a hierarchy, try deleting one that has childs (it will fail), then
 * delete it recursively, then delete the last znode
 */
@Test
public void testZNodeDeletes() throws Exception {
 ZKUtil.createWithParents(ZKW, "/l1/l2/l3/l4");
 try {
  ZKUtil.deleteNode(ZKW, "/l1/l2");
  fail("We should not be able to delete if znode has childs");
 } catch (KeeperException ex) {
  assertNotNull(ZKUtil.getDataNoWatch(ZKW, "/l1/l2/l3/l4", null));
 }
 ZKUtil.deleteNodeRecursively(ZKW, "/l1/l2");
 // make sure it really is deleted
 assertNull(ZKUtil.getDataNoWatch(ZKW, "/l1/l2/l3/l4", null));
 // do the same delete again and make sure it doesn't crash
 ZKUtil.deleteNodeRecursively(ZKW, "/l1/l2");
 ZKUtil.deleteNode(ZKW, "/l1");
 assertNull(ZKUtil.getDataNoWatch(ZKW, "/l1/l2", null));
}

代码示例来源:origin: apache/hbase

private void deleteMyEphemeralNode() throws KeeperException {
 ZKUtil.deleteNode(this.zooKeeper, getMyEphemeralNodePath());
}

代码示例来源:origin: apache/hbase

public static void deleteMetaLocation(ZKWatcher zookeeper, int replicaId)
 throws KeeperException {
 if (replicaId == RegionInfo.DEFAULT_REPLICA_ID) {
  LOG.info("Deleting hbase:meta region location in ZooKeeper");
 } else {
  LOG.info("Deleting hbase:meta for " + replicaId + " region location in ZooKeeper");
 }
 try {
  // Just delete the node.  Don't need any watches.
  ZKUtil.deleteNode(zookeeper, zookeeper.getZNodePaths().getZNodeForReplica(replicaId));
 } catch(KeeperException.NoNodeException nne) {
  // Has already been deleted
 }
}
/**

代码示例来源:origin: apache/hbase

/**
 * Sets the cluster as down by deleting the znode.
 * @throws KeeperException unexpected zk exception
 */
public void setClusterDown()
 throws KeeperException {
 try {
  ZKUtil.deleteNode(watcher, watcher.getZNodePaths().clusterStateZNode);
 } catch(KeeperException.NoNodeException nne) {
  LOG.warn("Attempted to set cluster as down but already down, cluster " +
    "state node (" + watcher.getZNodePaths().clusterStateZNode + ") not found");
 }
}

代码示例来源:origin: apache/hbase

private void cleanupHbckZnode() {
 try {
  if (zkw != null && hbckZodeCreated) {
   ZKUtil.deleteNode(zkw, hbckEphemeralNodePath);
   hbckZodeCreated = false;
  }
 } catch (KeeperException e) {
  // Ignore
  if (!e.code().equals(KeeperException.Code.NONODE)) {
   LOG.warn("Delete HBCK znode " + hbckEphemeralNodePath + " failed ", e);
  }
 }
}

代码示例来源:origin: apache/hbase

@Override
public void removeWAL(ServerName serverName, String queueId, String fileName)
  throws ReplicationException {
 String fileNode = getFileNode(serverName, queueId, fileName);
 try {
  ZKUtil.deleteNode(zookeeper, fileNode);
 } catch (NoNodeException e) {
  LOG.warn("{} already deleted when removing log", fileNode);
 } catch (KeeperException e) {
  throw new ReplicationException("Failed to remove wal from queue (serverName=" + serverName +
   ", queueId=" + queueId + ", fileName=" + fileName + ")", e);
 }
}

代码示例来源:origin: apache/hbase

if (znode.endsWith(suffix)) {
 sb.append(ZNodePaths.ZNODE_PATH_SEPARATOR).append(znode);
 ZKUtil.deleteNode(zookeeper, sb.toString());
 sb.setLength(levelTwoLength);

代码示例来源:origin: apache/hbase

/***
  * Delete the acl notify node of namespace
  */
 public void deleteNamespaceACLNode(final String namespace) {
  String zkNode = ZNodePaths.joinZNode(watcher.getZNodePaths().baseZNode, ACL_NODE);
  zkNode = ZNodePaths.joinZNode(zkNode, AccessControlLists.NAMESPACE_PREFIX + namespace);

  try {
   ZKUtil.deleteNode(watcher, zkNode);
  } catch (KeeperException.NoNodeException e) {
   LOG.warn("No acl notify node of namespace '" + namespace + "'");
  } catch (KeeperException e) {
   LOG.error("Failed deleting acl node of namespace '" + namespace + "'", e);
   watcher.abort("Failed deleting node " + zkNode, e);
  }
 }
}

代码示例来源:origin: apache/hbase

/***
 * Delete the acl notify node of table
 * @param tableName
 */
public void deleteTableACLNode(final TableName tableName) {
 String zkNode = ZNodePaths.joinZNode(watcher.getZNodePaths().baseZNode, ACL_NODE);
 zkNode = ZNodePaths.joinZNode(zkNode, tableName.getNameAsString());
 try {
  ZKUtil.deleteNode(watcher, zkNode);
 } catch (KeeperException.NoNodeException e) {
  LOG.warn("No acl notify node of table '" + tableName + "'");
 } catch (KeeperException e) {
  LOG.error("Failed deleting acl node of table '" + tableName + "'", e);
  watcher.abort("Failed deleting node " + zkNode, e);
 }
}

代码示例来源:origin: apache/hbase

public void removeKeyFromZK(AuthenticationKey key) {
 String keyZNode = getKeyNode(key.getKeyId());
 try {
  ZKUtil.deleteNode(watcher, keyZNode);
 } catch (KeeperException.NoNodeException nne) {
  LOG.error("Non-existent znode "+keyZNode+" for key "+key.getKeyId(), nne);
 } catch (KeeperException ke) {
  LOG.error(HBaseMarkers.FATAL, "Failed removing znode "+keyZNode+" for key "+
    key.getKeyId(), ke);
  watcher.abort("Unhandled zookeeper error removing znode "+keyZNode+
    " for key "+key.getKeyId(), ke);
 }
}

代码示例来源:origin: apache/hbase

/**
  * delete the master znode if its content is same as the parameter
  * @param zkw must not be null
  * @param content must not be null
  */
 public static boolean deleteIfEquals(ZKWatcher zkw, final String content) {
  if (content == null){
   throw new IllegalArgumentException("Content must not be null");
  }

  try {
   Stat stat = new Stat();
   byte[] data = ZKUtil.getDataNoWatch(zkw, zkw.getZNodePaths().masterAddressZNode, stat);
   ServerName sn = ProtobufUtil.parseServerNameFrom(data);
   if (sn != null && content.equals(sn.toString())) {
    return (ZKUtil.deleteNode(zkw, zkw.getZNodePaths().masterAddressZNode, stat.getVersion()));
   }
  } catch (KeeperException e) {
   LOG.warn("Can't get or delete the master znode", e);
  } catch (DeserializationException e) {
   LOG.warn("Can't get or delete the master znode", e);
  }

  return false;
 }
}

代码示例来源:origin: apache/hbase

public void stop() {
  try {
   synchronized (clusterHasActiveMaster) {
    // Master is already stopped, wake up the manager
    // thread so that it can shutdown soon.
    clusterHasActiveMaster.notifyAll();
   }
   // If our address is in ZK, delete it on our way out
   ServerName activeMaster = null;
   try {
    activeMaster = MasterAddressTracker.getMasterAddress(this.watcher);
   } catch (IOException e) {
    LOG.warn("Failed get of master address: " + e.toString());
   }
   if (activeMaster != null &&  activeMaster.equals(this.sn)) {
    ZKUtil.deleteNode(watcher, watcher.getZNodePaths().masterAddressZNode);
    // We may have failed to delete the znode at the previous step, but
    //  we delete the file anyway: a second attempt to delete the znode is likely to fail again.
    ZNodeClearer.deleteMyEphemeralNodeOnDisk();
   }
  } catch (KeeperException e) {
   LOG.debug(this.watcher.prefix("Failed delete of our master address node; " +
     e.getMessage()));
  }
 }
}

代码示例来源:origin: apache/hbase

private void unassignMetaReplica(HbckInfo hi) throws IOException, InterruptedException,
KeeperException {
 undeployRegions(hi);
 ZKUtil.deleteNode(zkw, zkw.getZNodePaths().getZNodeForReplica(hi.metaEntry.getReplicaId()));
}

代码示例来源:origin: apache/hbase

private void unassignExcessMetaReplica(int numMetaReplicasConfigured) {
  final ZKWatcher zooKeeper = master.getZooKeeper();
  // unassign the unneeded replicas (for e.g., if the previous master was configured
  // with a replication of 3 and now it is 2, we need to unassign the 1 unneeded replica)
  try {
   List<String> metaReplicaZnodes = zooKeeper.getMetaReplicaNodes();
   for (String metaReplicaZnode : metaReplicaZnodes) {
    int replicaId = zooKeeper.getZNodePaths().getMetaReplicaIdFromZnode(metaReplicaZnode);
    if (replicaId >= numMetaReplicasConfigured) {
     RegionState r = MetaTableLocator.getMetaRegionState(zooKeeper, replicaId);
     LOG.info("Closing excess replica of meta region " + r.getRegion());
     // send a close and wait for a max of 30 seconds
     ServerManager.closeRegionSilentlyAndWait(master.getClusterConnection(),
       r.getServerName(), r.getRegion(), 30000);
     ZKUtil.deleteNode(zooKeeper, zooKeeper.getZNodePaths().getZNodeForReplica(replicaId));
    }
   }
  } catch (Exception ex) {
   // ignore the exception since we don't want the master to be wedged due to potential
   // issues in the cleanup of the extra regions. We can do that cleanup via hbck or manually
   LOG.warn("Ignoring exception " + ex);
  }
 }
}

代码示例来源:origin: apache/hbase

@Test
public void testRegionServerRemovedEvent() throws Exception {
 ZKUtil.createAndWatch(zkw,
  ZNodePaths.joinZNode(zkw.getZNodePaths().rsZNode, "hostname2.example.org:1234"),
  HConstants.EMPTY_BYTE_ARRAY);
 rt.registerListener(new DummyReplicationListener());
 // delete one
 ZKUtil.deleteNode(zkw,
  ZNodePaths.joinZNode(zkw.getZNodePaths().rsZNode, "hostname2.example.org:1234"));
 // wait for event
 while (rsRemovedCount.get() < 1) {
  Thread.sleep(5);
 }
 assertEquals("hostname2.example.org:1234", rsRemovedData);
}

代码示例来源:origin: apache/hbase

@Test
public void testGetListOfRegionServers() throws Exception {
 // 0 region servers
 assertEquals(0, rt.getListOfRegionServers().size());
 // 1 region server
 ZKUtil.createWithParents(zkw,
  ZNodePaths.joinZNode(zkw.getZNodePaths().rsZNode, "hostname1.example.org:1234"));
 assertEquals(1, rt.getListOfRegionServers().size());
 // 2 region servers
 ZKUtil.createWithParents(zkw,
  ZNodePaths.joinZNode(zkw.getZNodePaths().rsZNode, "hostname2.example.org:1234"));
 assertEquals(2, rt.getListOfRegionServers().size());
 // 1 region server
 ZKUtil.deleteNode(zkw,
  ZNodePaths.joinZNode(zkw.getZNodePaths().rsZNode, "hostname2.example.org:1234"));
 assertEquals(1, rt.getListOfRegionServers().size());
 // 0 region server
 ZKUtil.deleteNode(zkw,
  ZNodePaths.joinZNode(zkw.getZNodePaths().rsZNode, "hostname1.example.org:1234"));
 assertEquals(0, rt.getListOfRegionServers().size());
}

代码示例来源:origin: apache/hbase

"testActiveMasterManagerFromZK", null, true);
try {
 ZKUtil.deleteNode(zk, zk.getZNodePaths().masterAddressZNode);
 ZKUtil.deleteNode(zk, zk.getZNodePaths().clusterStateZNode);
} catch(KeeperException.NoNodeException nne) {}

代码示例来源:origin: apache/hbase

ZKUtil.deleteNode(UTIL.getZooKeeperWatcher(), STORAGE.getSyncReplicationStateNode(peerId));
ZKUtil.deleteNode(UTIL.getZooKeeperWatcher(), STORAGE.getNewSyncReplicationStateNode(peerId));

代码示例来源:origin: apache/hbase

@Ignore @Test // The close silently doesn't work any more since HBASE-14614. Fix.
public void testHBaseFsckWithFewerMetaReplicaZnodes() throws Exception {
 ClusterConnection c = (ClusterConnection)ConnectionFactory.createConnection(
   TEST_UTIL.getConfiguration());
 RegionLocations rl = c.locateRegion(TableName.META_TABLE_NAME, HConstants.EMPTY_START_ROW,
   false, false);
 HBaseFsckRepair.closeRegionSilentlyAndWait(c,
   rl.getRegionLocation(2).getServerName(), rl.getRegionLocation(2).getRegionInfo());
 ZKWatcher zkw = TEST_UTIL.getZooKeeperWatcher();
 ZKUtil.deleteNode(zkw, zkw.getZNodePaths().getZNodeForReplica(2));
 // check that problem exists
 HBaseFsck hbck = doFsck(TEST_UTIL.getConfiguration(), false);
 assertErrors(hbck, new ERROR_CODE[]{ERROR_CODE.UNKNOWN,ERROR_CODE.NO_META_REGION});
 // fix the problem
 hbck = doFsck(TEST_UTIL.getConfiguration(), true);
 // run hbck again to make sure we don't see any errors
 hbck = doFsck(TEST_UTIL.getConfiguration(), false);
 assertErrors(hbck, new ERROR_CODE[]{});
}

相关文章

微信公众号

最新文章

更多