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

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

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

ZKUtil.createAndFailSilent介绍

[英]Creates the specified node, iff the node does not exist. Does not set a watch and fails silently if the node already exists. The node created is persistent and open access.
[中]创建指定的节点(如果该节点不存在)。如果节点已经存在,则不设置监视并静默失败。创建的节点是持久的、开放访问的。

代码示例

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

  1. /**
  2. * Creates the specified node, iff the node does not exist. Does not set a
  3. * watch and fails silently if the node already exists.
  4. *
  5. * The node created is persistent and open access.
  6. *
  7. * @param zkw zk reference
  8. * @param znode path of node
  9. * @throws KeeperException if unexpected zookeeper exception
  10. */
  11. public static void createAndFailSilent(ZKWatcher zkw,
  12. String znode) throws KeeperException {
  13. createAndFailSilent(zkw, znode, new byte[0]);
  14. }

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

  1. private void createBaseZNodes() throws ZooKeeperConnectionException {
  2. try {
  3. // Create all the necessary "directories" of znodes
  4. ZKUtil.createWithParents(this, znodePaths.baseZNode);
  5. ZKUtil.createAndFailSilent(this, znodePaths.rsZNode);
  6. ZKUtil.createAndFailSilent(this, znodePaths.drainingZNode);
  7. ZKUtil.createAndFailSilent(this, znodePaths.tableZNode);
  8. ZKUtil.createAndFailSilent(this, znodePaths.splitLogZNode);
  9. ZKUtil.createAndFailSilent(this, znodePaths.backupMasterAddressesZNode);
  10. ZKUtil.createAndFailSilent(this, znodePaths.tableLockZNode);
  11. ZKUtil.createAndFailSilent(this, znodePaths.masterMaintZNode);
  12. } catch (KeeperException e) {
  13. throw new ZooKeeperConnectionException(
  14. prefix("Unexpected KeeperException creating base node"), e);
  15. }
  16. }

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

  1. /**
  2. * Creates the specified node containing specified data, iff the node does not exist. Does
  3. * not set a watch and fails silently if the node already exists.
  4. *
  5. * The node created is persistent and open access.
  6. *
  7. * @param zkw zk reference
  8. * @param znode path of node
  9. * @param data a byte array data to store in the znode
  10. * @throws KeeperException if unexpected zookeeper exception
  11. */
  12. public static void createAndFailSilent(ZKWatcher zkw,
  13. String znode, byte[] data)
  14. throws KeeperException {
  15. createAndFailSilent(zkw,
  16. (CreateAndFailSilent)ZKUtilOp.createAndFailSilent(znode, data));
  17. }

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

  1. private static void processSequentially(ZKWatcher zkw, List<ZKUtilOp> ops)
  2. throws KeeperException, NoNodeException {
  3. for (ZKUtilOp op : ops) {
  4. if (op instanceof CreateAndFailSilent) {
  5. createAndFailSilent(zkw, (CreateAndFailSilent) op);
  6. } else if (op instanceof DeleteNodeFailSilent) {
  7. deleteNodeFailSilent(zkw, (DeleteNodeFailSilent) op);
  8. } else if (op instanceof SetData) {
  9. setData(zkw, (SetData) op);
  10. } else {
  11. throw new UnsupportedOperationException("Unexpected ZKUtilOp type: "
  12. + op.getClass().getName());
  13. }
  14. }
  15. }

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

  1. /**
  2. * Perform a best effort enable of hfile retention, which relies on zookeeper communicating the //
  3. * * change back to the hfile cleaner.
  4. * <p>
  5. * No attempt is made to make sure that backups are successfully created - it is inherently an
  6. * <b>asynchronous operation</b>.
  7. * @param zooKeeper watcher connection to zk cluster
  8. * @param table table name on which to enable archiving
  9. * @throws KeeperException
  10. */
  11. private void enable(ZKWatcher zooKeeper, byte[] table)
  12. throws KeeperException {
  13. LOG.debug("Ensuring archiving znode exists");
  14. ZKUtil.createAndFailSilent(zooKeeper, archiveZnode);
  15. // then add the table to the list of znodes to archive
  16. String tableNode = this.getTableNode(table);
  17. LOG.debug("Creating: " + tableNode + ", data: []");
  18. ZKUtil.createSetData(zooKeeper, tableNode, new byte[0]);
  19. }

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

  1. public void clearZNodes(String procedureName) throws KeeperException {
  2. LOG.info("Clearing all znodes for procedure " + procedureName + "including nodes "
  3. + acquiredZnode + " " + reachedZnode + " " + abortZnode);
  4. // Make sure we trigger the watches on these nodes by creating them. (HBASE-13885)
  5. String acquiredBarrierNode = getAcquiredBarrierNode(procedureName);
  6. String reachedBarrierNode = getReachedBarrierNode(procedureName);
  7. String abortZNode = getAbortZNode(procedureName);
  8. ZKUtil.createAndFailSilent(watcher, acquiredBarrierNode);
  9. ZKUtil.createAndFailSilent(watcher, abortZNode);
  10. ZKUtil.deleteNodeRecursivelyMultiOrSequential(watcher, true, acquiredBarrierNode,
  11. reachedBarrierNode, abortZNode);
  12. if (LOG.isTraceEnabled()) {
  13. logZKTree(this.baseZNode);
  14. }
  15. }
  16. }

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

  1. public SplitOrMergeTracker(ZKWatcher watcher, Configuration conf,
  2. Abortable abortable) {
  3. try {
  4. if (ZKUtil.checkExists(watcher, watcher.getZNodePaths().switchZNode) < 0) {
  5. ZKUtil.createAndFailSilent(watcher, watcher.getZNodePaths().switchZNode);
  6. }
  7. } catch (KeeperException e) {
  8. throw new RuntimeException(e);
  9. }
  10. splitZnode = ZNodePaths.joinZNode(watcher.getZNodePaths().switchZNode,
  11. conf.get("zookeeper.znode.switch.split", "split"));
  12. mergeZnode = ZNodePaths.joinZNode(watcher.getZNodePaths().switchZNode,
  13. conf.get("zookeeper.znode.switch.merge", "merge"));
  14. splitStateTracker = new SwitchStateTracker(watcher, splitZnode, abortable);
  15. mergeStateTracker = new SwitchStateTracker(watcher, mergeZnode, abortable);
  16. }

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

  1. ZKUtil.createAndFailSilent(watcher, groupBasePath, ProtobufMagic.PB_MAGIC);
  2. RSGroupProtos.RSGroupInfo proto = RSGroupProtobufUtil.toProtoGroupInfo(RSGroupInfo);
  3. LOG.debug("Updating znode: " + znode);
  4. ZKUtil.createAndFailSilent(watcher, znode);
  5. zkOps.add(ZKUtil.ZKUtilOp.deleteNodeFailSilent(znode));
  6. zkOps.add(ZKUtil.ZKUtilOp.createAndFailSilent(znode,

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

  1. /**
  2. * Top-level watcher/controller for procedures across the cluster.
  3. * <p>
  4. * On instantiation, this ensures the procedure znodes exist. This however requires the passed in
  5. * watcher has been started.
  6. * @param watcher watcher for the cluster ZK. Owned by <tt>this</tt> and closed via
  7. * {@link #close()}
  8. * @param procDescription name of the znode describing the procedure to run
  9. * @throws KeeperException when the procedure znodes cannot be created
  10. */
  11. public ZKProcedureUtil(ZKWatcher watcher, String procDescription)
  12. throws KeeperException {
  13. super(watcher);
  14. // make sure we are listening for events
  15. watcher.registerListener(this);
  16. // setup paths for the zknodes used in procedures
  17. this.baseZNode = ZNodePaths.joinZNode(watcher.getZNodePaths().baseZNode, procDescription);
  18. acquiredZnode = ZNodePaths.joinZNode(baseZNode, ACQUIRED_BARRIER_ZNODE_DEFAULT);
  19. reachedZnode = ZNodePaths.joinZNode(baseZNode, REACHED_BARRIER_ZNODE_DEFAULT);
  20. abortZnode = ZNodePaths.joinZNode(baseZNode, ABORT_ZNODE_DEFAULT);
  21. // first make sure all the ZK nodes exist
  22. // make sure all the parents exist (sometimes not the case in tests)
  23. ZKUtil.createWithParents(watcher, acquiredZnode);
  24. // regular create because all the parents exist
  25. ZKUtil.createAndFailSilent(watcher, reachedZnode);
  26. ZKUtil.createAndFailSilent(watcher, abortZnode);
  27. }

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

  1. /**
  2. * This is the abort message being sent by the coordinator to member
  3. *
  4. * TODO this code isn't actually used but can be used to issue a cancellation from the
  5. * coordinator.
  6. */
  7. @Override
  8. final public void sendAbortToMembers(Procedure proc, ForeignException ee) {
  9. String procName = proc.getName();
  10. LOG.debug("Aborting procedure '" + procName + "' in zk");
  11. String procAbortNode = zkProc.getAbortZNode(procName);
  12. try {
  13. LOG.debug("Creating abort znode:" + procAbortNode);
  14. String source = (ee.getSource() == null) ? coordName : ee.getSource();
  15. byte[] errorInfo = ProtobufUtil.prependPBMagic(ForeignException.serialize(source, ee));
  16. // first create the znode for the procedure
  17. ZKUtil.createAndFailSilent(zkProc.getWatcher(), procAbortNode, errorInfo);
  18. LOG.debug("Finished creating abort node:" + procAbortNode);
  19. } catch (KeeperException e) {
  20. // possible that we get this error for the procedure if we already reset the zk state, but in
  21. // that case we should still get an error for that procedure anyways
  22. zkProc.logZKTree(zkProc.baseZNode);
  23. coordinator.rpcConnectionFailure("Failed to post zk node:" + procAbortNode
  24. + " to abort procedure '" + procName + "'", new IOException(e));
  25. }
  26. }

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

  1. /**
  2. * This acts as the ack for a completed procedure
  3. */
  4. @Override
  5. public void sendMemberCompleted(Subprocedure sub, byte[] data) throws IOException {
  6. String procName = sub.getName();
  7. LOG.debug("Marking procedure '" + procName + "' completed for member '" + memberName
  8. + "' in zk");
  9. String joinPath =
  10. ZNodePaths.joinZNode(zkController.getReachedBarrierNode(procName), memberName);
  11. // ProtobufUtil.prependPBMagic does not take care of null
  12. if (data == null) {
  13. data = new byte[0];
  14. }
  15. try {
  16. ZKUtil.createAndFailSilent(zkController.getWatcher(), joinPath,
  17. ProtobufUtil.prependPBMagic(data));
  18. } catch (KeeperException e) {
  19. member.controllerConnectionFailure("Failed to post zk node:" + joinPath
  20. + " to join procedure barrier.", e, procName);
  21. }
  22. }

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

  1. /**
  2. * This should be called by the member and should write a serialized root cause exception as
  3. * to the abort znode.
  4. */
  5. @Override
  6. public void sendMemberAborted(Subprocedure sub, ForeignException ee) {
  7. if (sub == null) {
  8. LOG.error("Failed due to null subprocedure", ee);
  9. return;
  10. }
  11. String procName = sub.getName();
  12. LOG.debug("Aborting procedure (" + procName + ") in zk");
  13. String procAbortZNode = zkController.getAbortZNode(procName);
  14. try {
  15. String source = (ee.getSource() == null) ? memberName: ee.getSource();
  16. byte[] errorInfo = ProtobufUtil.prependPBMagic(ForeignException.serialize(source, ee));
  17. ZKUtil.createAndFailSilent(zkController.getWatcher(), procAbortZNode, errorInfo);
  18. LOG.debug("Finished creating abort znode:" + procAbortZNode);
  19. } catch (KeeperException e) {
  20. // possible that we get this error for the procedure if we already reset the zk state, but in
  21. // that case we should still get an error for that procedure anyways
  22. zkController.logZKTree(zkController.getBaseZnode());
  23. member.controllerConnectionFailure("Failed to post zk node:" + procAbortZNode
  24. + " to abort procedure", e, procName);
  25. }
  26. }

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

  1. /**
  2. * This attempts to create an acquired state znode for the procedure (snapshot name).
  3. *
  4. * It then looks for the reached znode to trigger in-barrier execution. If not present we
  5. * have a watcher, if present then trigger the in-barrier action.
  6. */
  7. @Override
  8. public void sendMemberAcquired(Subprocedure sub) throws IOException {
  9. String procName = sub.getName();
  10. try {
  11. LOG.debug("Member: '" + memberName + "' joining acquired barrier for procedure (" + procName
  12. + ") in zk");
  13. String acquiredZNode = ZNodePaths.joinZNode(ZKProcedureUtil.getAcquireBarrierNode(
  14. zkController, procName), memberName);
  15. ZKUtil.createAndFailSilent(zkController.getWatcher(), acquiredZNode);
  16. // watch for the complete node for this snapshot
  17. String reachedBarrier = zkController.getReachedBarrierNode(procName);
  18. LOG.debug("Watch for global barrier reached:" + reachedBarrier);
  19. if (ZKUtil.watchAndCheckExists(zkController.getWatcher(), reachedBarrier)) {
  20. receivedReachedGlobalBarrier(reachedBarrier);
  21. }
  22. } catch (KeeperException e) {
  23. member.controllerConnectionFailure("Failed to acquire barrier for procedure: "
  24. + procName + " and member: " + memberName, e, procName);
  25. }
  26. }

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

  1. try {
  2. String node = ZNodePaths.joinZNode(parentZnode, server.getServerName());
  3. ZKUtil.createAndFailSilent(getZooKeeper(), node);
  4. } catch (KeeperException ke) {
  5. throw new HBaseIOException(

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

  1. @Before
  2. public void setup() throws Exception {
  3. TEST_UTIL.startMiniZKCluster();
  4. Configuration conf = TEST_UTIL.getConfiguration();
  5. zkw = new ZKWatcher(TEST_UTIL.getConfiguration(),
  6. "split-log-worker-tests", null);
  7. ds = new DummyServer(zkw, conf);
  8. ZKUtil.deleteChildrenRecursively(zkw, zkw.getZNodePaths().baseZNode);
  9. ZKUtil.createAndFailSilent(zkw, zkw.getZNodePaths().baseZNode);
  10. assertThat(ZKUtil.checkExists(zkw, zkw.getZNodePaths().baseZNode), not(is(-1)));
  11. LOG.debug(zkw.getZNodePaths().baseZNode + " created");
  12. ZKUtil.createAndFailSilent(zkw, zkw.getZNodePaths().splitLogZNode);
  13. assertThat(ZKUtil.checkExists(zkw, zkw.getZNodePaths().splitLogZNode), not(is(-1)));
  14. LOG.debug(zkw.getZNodePaths().splitLogZNode + " created");
  15. ZKUtil.createAndFailSilent(zkw, zkw.getZNodePaths().rsZNode);
  16. assertThat(ZKUtil.checkExists(zkw, zkw.getZNodePaths().rsZNode), not(is(-1)));
  17. SplitLogCounters.resetCounters();
  18. executorService = new ExecutorService("TestSplitLogWorker");
  19. executorService.startExecutorService(ExecutorType.RS_LOG_REPLAY_OPS, 10);
  20. }

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

  1. @Before
  2. public void setup() throws Exception {
  3. TEST_UTIL = new HBaseTestingUtility();
  4. TEST_UTIL.startMiniZKCluster();
  5. conf = TEST_UTIL.getConfiguration();
  6. // Use a different ZK wrapper instance for each tests.
  7. zkw =
  8. new ZKWatcher(conf, "split-log-manager-tests" + TEST_UTIL.getRandomUUID().toString(), null);
  9. master = new DummyMasterServices(zkw, conf);
  10. ZKUtil.deleteChildrenRecursively(zkw, zkw.getZNodePaths().baseZNode);
  11. ZKUtil.createAndFailSilent(zkw, zkw.getZNodePaths().baseZNode);
  12. assertTrue(ZKUtil.checkExists(zkw, zkw.getZNodePaths().baseZNode) != -1);
  13. LOG.debug(zkw.getZNodePaths().baseZNode + " created");
  14. ZKUtil.createAndFailSilent(zkw, zkw.getZNodePaths().splitLogZNode);
  15. assertTrue(ZKUtil.checkExists(zkw, zkw.getZNodePaths().splitLogZNode) != -1);
  16. LOG.debug(zkw.getZNodePaths().splitLogZNode + " created");
  17. resetCounters();
  18. // By default, we let the test manage the error as before, so the server
  19. // does not appear as dead from the master point of view, only from the split log pov.
  20. Mockito.when(sm.isServerOnline(Mockito.any())).thenReturn(true);
  21. to = 12000;
  22. conf.setInt(HConstants.HBASE_SPLITLOG_MANAGER_TIMEOUT, to);
  23. conf.setInt("hbase.splitlog.manager.unassigned.timeout", 2 * to);
  24. conf.setInt("hbase.splitlog.manager.timeoutmonitor.period", 100);
  25. to = to + 16 * 100;
  26. }

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

  1. ZKUtil.createAndFailSilent(watcher, commit);
  2. LOG.debug("Commit node:" + commit + ", exists:" + ZKUtil.checkExists(watcher, commit));
  3. committed.await();

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

  1. private void updateZooKeeper(TableState tableState) throws IOException {
  2. if (tableState == null) {
  3. return;
  4. }
  5. String znode = ZNodePaths.joinZNode(this.master.getZooKeeper().getZNodePaths().tableZNode,
  6. tableState.getTableName().getNameAsString());
  7. try {
  8. // Make sure znode exists.
  9. if (ZKUtil.checkExists(this.master.getZooKeeper(), znode) == -1) {
  10. ZKUtil.createAndFailSilent(this.master.getZooKeeper(), znode);
  11. }
  12. // Now set newState
  13. ZooKeeperProtos.DeprecatedTableState.Builder builder =
  14. ZooKeeperProtos.DeprecatedTableState.newBuilder();
  15. builder.setState(
  16. ZooKeeperProtos.DeprecatedTableState.State.valueOf(tableState.getState().toString()));
  17. byte[] data = ProtobufUtil.prependPBMagic(builder.build().toByteArray());
  18. ZKUtil.setData(this.master.getZooKeeper(), znode, data);
  19. } catch (KeeperException e) {
  20. // Only hbase1 clients suffer if this fails.
  21. LOG.warn("Failed setting table state to zookeeper mirrored for hbase-1.x clients", e);
  22. }
  23. }

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

  1. /**
  2. * create an address tracker instance
  3. * @param sn if not-null set the active master
  4. * @param infoPort if there is an active master, set its info port.
  5. */
  6. private MasterAddressTracker setupMasterTracker(final ServerName sn, final int infoPort)
  7. throws Exception {
  8. ZKWatcher zk = new ZKWatcher(TEST_UTIL.getConfiguration(),
  9. name.getMethodName(), null);
  10. ZKUtil.createAndFailSilent(zk, zk.getZNodePaths().baseZNode);
  11. // Should not have a master yet
  12. MasterAddressTracker addressTracker = new MasterAddressTracker(zk, null);
  13. addressTracker.start();
  14. assertFalse(addressTracker.hasMaster());
  15. zk.registerListener(addressTracker);
  16. // Use a listener to capture when the node is actually created
  17. NodeCreationListener listener = new NodeCreationListener(zk,
  18. zk.getZNodePaths().masterAddressZNode);
  19. zk.registerListener(listener);
  20. if (sn != null) {
  21. LOG.info("Creating master node");
  22. MasterAddressTracker.setMasterAddress(zk, zk.getZNodePaths().masterAddressZNode,
  23. sn, infoPort);
  24. // Wait for the node to be created
  25. LOG.info("Waiting for master address manager to be notified");
  26. listener.waitForCreation();
  27. LOG.info("Master node created");
  28. }
  29. return addressTracker;
  30. }

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

  1. @Test
  2. public void testCleanZNode() throws Exception {
  3. ZKWatcher zkw = new ZKWatcher(TEST_UTIL.getConfiguration(),
  4. "testNodeTracker", new TestZKNodeTracker.StubAbortable());
  5. final ServerName sn = ServerName.valueOf("127.0.0.1:52", 45L);
  6. ZKUtil.createAndFailSilent(zkw,
  7. TEST_UTIL.getConfiguration().get(HConstants.ZOOKEEPER_ZNODE_PARENT,
  8. HConstants.DEFAULT_ZOOKEEPER_ZNODE_PARENT));
  9. final String nodeName = zkw.getZNodePaths().masterAddressZNode;
  10. // Check that we manage the case when there is no data
  11. ZKUtil.createAndFailSilent(zkw, nodeName);
  12. MasterAddressTracker.deleteIfEquals(zkw, sn.toString());
  13. assertNotNull(ZKUtil.getData(zkw, nodeName));
  14. // Check that we don't delete if we're not supposed to
  15. ZKUtil.setData(zkw, nodeName, MasterAddressTracker.toByteArray(sn, 0));
  16. MasterAddressTracker.deleteIfEquals(zkw, ServerName.valueOf("127.0.0.2:52", 45L).toString());
  17. assertNotNull(ZKUtil.getData(zkw, nodeName));
  18. // Check that we delete when we're supposed to
  19. ZKUtil.setData(zkw, nodeName,MasterAddressTracker.toByteArray(sn, 0));
  20. MasterAddressTracker.deleteIfEquals(zkw, sn.toString());
  21. assertNull(ZKUtil.getData(zkw, nodeName));
  22. // Check that we support the case when the znode does not exist
  23. MasterAddressTracker.deleteIfEquals(zkw, sn.toString()); // must not throw an exception
  24. }

相关文章