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

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

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

ZKUtil.createWithParents介绍

[英]Creates the specified node and all parent nodes required for it to exist. No watches are set and no errors are thrown if the node already exists. The nodes created are persistent and open access.
[中]创建指定节点及其存在所需的所有父节点。如果节点已经存在,则不会设置任何监视,也不会引发任何错误。创建的节点是持久的、开放访问的。

代码示例

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

/**
 * Creates the specified node and all parent nodes required for it to exist.
 *
 * No watches are set and no errors are thrown if the node already exists.
 *
 * The nodes created are persistent and open access.
 *
 * @param zkw zk reference
 * @param znode path of node
 * @throws KeeperException if unexpected zookeeper exception
 */
public static void createWithParents(ZKWatcher zkw, String znode)
 throws KeeperException {
 createWithParents(zkw, znode, new byte[0]);
}

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

@Override
public void addWAL(ServerName serverName, String queueId, String fileName)
  throws ReplicationException {
 try {
  ZKUtil.createWithParents(zookeeper, getFileNode(serverName, queueId, fileName));
 } catch (KeeperException e) {
  throw new ReplicationException("Failed to add wal to queue (serverName=" + serverName
    + ", queueId=" + queueId + ", fileName=" + fileName + ")", e);
 }
}

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

@Override
public void setLastSequenceIds(String peerId, Map<String, Long> lastSeqIds)
  throws ReplicationException {
 try {
  // No need CAS and retry here, because it'll call setLastSequenceIds() for disabled peers
  // only, so no conflict happen.
  List<ZKUtilOp> listOfOps = new ArrayList<>();
  for (Entry<String, Long> lastSeqEntry : lastSeqIds.entrySet()) {
   String path = getSerialReplicationRegionPeerNode(lastSeqEntry.getKey(), peerId);
   ZKUtil.createWithParents(zookeeper, path);
   listOfOps.add(ZKUtilOp.setData(path, ZKUtil.positionToByteArray(lastSeqEntry.getValue())));
  }
  if (!listOfOps.isEmpty()) {
   ZKUtil.multiOrSequential(zookeeper, listOfOps, true);
  }
 } catch (KeeperException e) {
  throw new ReplicationException("Failed to set last sequence ids, peerId=" + peerId
    + ", size of lastSeqIds=" + lastSeqIds.size(), e);
 }
}

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

/**
 * Set data into node creating node if it doesn't yet exist.
 * Does not set watch.
 *
 * @param zkw zk reference
 * @param znode path of node
 * @param data data to set for node
 * @throws KeeperException if a ZooKeeper operation fails
 */
public static void createSetData(final ZKWatcher zkw, final String znode, final byte [] data)
    throws KeeperException {
 if (checkExists(zkw, znode) == -1) {
  ZKUtil.createWithParents(zkw, znode, data);
 } else {
  ZKUtil.setData(zkw, znode, data);
 }
}

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

@Override
public void addPeerToHFileRefs(String peerId) throws ReplicationException {
 String peerNode = getHFileRefsPeerNode(peerId);
 try {
  if (ZKUtil.checkExists(zookeeper, peerNode) == -1) {
   LOG.info("Adding peer {} to hfile reference queue.", peerId);
   ZKUtil.createWithParents(zookeeper, peerNode);
  }
 } catch (KeeperException e) {
  throw new ReplicationException("Failed to add peer " + peerId + " to hfile reference queue.",
    e);
 }
}

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

public void start() throws KeeperException {
 watcher.registerListener(this);
 ZKUtil.createWithParents(watcher, labelZnode);
 ZKUtil.createWithParents(watcher, userAuthsZnode);
 byte[] data = ZKUtil.getDataAndWatch(watcher, labelZnode);
 if (data != null && data.length > 0) {
  refreshVisibilityLabelsCache(data);
 }
 data = ZKUtil.getDataAndWatch(watcher, userAuthsZnode);
 if (data != null && data.length > 0) {
  refreshUserAuthsCache(data);
 }
}

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

private void addLastSeqIdsToOps(String queueId, Map<String, Long> lastSeqIds,
  List<ZKUtilOp> listOfOps) throws KeeperException, ReplicationException {
 String peerId = new ReplicationQueueInfo(queueId).getPeerId();
 for (Entry<String, Long> lastSeqEntry : lastSeqIds.entrySet()) {
  String path = getSerialReplicationRegionPeerNode(lastSeqEntry.getKey(), peerId);
  Pair<Long, Integer> p = getLastSequenceIdWithVersion(lastSeqEntry.getKey(), peerId);
  byte[] data = ZKUtil.positionToByteArray(lastSeqEntry.getValue());
  if (p.getSecond() < 0) { // ZNode does not exist.
   ZKUtil.createWithParents(zookeeper,
    path.substring(0, path.lastIndexOf(ZNodePaths.ZNODE_PATH_SEPARATOR)));
   listOfOps.add(ZKUtilOp.createAndFailSilent(path, data));
   continue;
  }
  // Perform CAS in a specific version v0 (HBASE-20138)
  int v0 = p.getSecond();
  long lastPushedSeqId = p.getFirst();
  if (lastSeqEntry.getValue() <= lastPushedSeqId) {
   continue;
  }
  listOfOps.add(ZKUtilOp.setData(path, data, v0));
 }
}

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

/***
 * Write a table's access controls to the permissions mirror in zookeeper
 * @param entry
 * @param permsData
 */
public void writeToZookeeper(byte[] entry, byte[] permsData) {
 String entryName = Bytes.toString(entry);
 String zkNode = ZNodePaths.joinZNode(watcher.getZNodePaths().baseZNode, ACL_NODE);
 zkNode = ZNodePaths.joinZNode(zkNode, entryName);
 try {
  ZKUtil.createWithParents(watcher, zkNode);
  ZKUtil.updateExistingNodeData(watcher, zkNode, permsData, -1);
 } catch (KeeperException e) {
  LOG.error("Failed updating permissions for entry '" +
    entryName + "'", e);
  watcher.abort("Failed writing node "+zkNode+" to zookeeper", e);
 }
}

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

public void start() throws KeeperException {
 watcher.registerListener(this);
 // make sure the base node exists
 ZKUtil.createWithParents(watcher, keysParentZNode);
 if (ZKUtil.watchAndCheckExists(watcher, keysParentZNode)) {
  List<ZKUtil.NodeAndData> nodes =
    ZKUtil.getChildDataAndWatchForNewChildren(watcher, keysParentZNode);
  refreshNodes(nodes);
 }
}

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

public void start() {
 try {
  watcher.registerListener(this);
  String parent = ZKUtil.getParent(leaderZNode);
  if (ZKUtil.checkExists(watcher, parent) < 0) {
   ZKUtil.createWithParents(watcher, parent);
  }
 } catch (KeeperException ke) {
  watcher.abort("Unhandled zk exception when starting", ke);
  candidate.stop("Unhandled zk exception starting up: "+ke.getMessage());
 }
}

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

@Before
public void setUp() throws Exception {
 Configuration conf = testUtil.getConfiguration();
 conf.set(HConstants.MASTER_PORT, "0");
 conf.setInt(HConstants.ZK_SESSION_TIMEOUT, 2000);
 testUtil.startMiniZKCluster();
 ZKWatcher watcher = testUtil.getZooKeeperWatcher();
 ZKUtil.createWithParents(watcher, watcher.getZNodePaths().masterAddressZNode,
     Bytes.toBytes("fake:123"));
 master = new HMaster(conf);
 rpcClient = RpcClientFactory.createClient(conf, HConstants.CLUSTER_ID_DEFAULT);
}

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

private static String initPeerClusterState(String baseZKNode)
  throws IOException, KeeperException {
 // Add a dummy region server and set up the cluster id
 Configuration testConf = new Configuration(conf);
 testConf.set(HConstants.ZOOKEEPER_ZNODE_PARENT, baseZKNode);
 ZKWatcher zkw1 = new ZKWatcher(testConf, "test1", null);
 String fakeRs = ZNodePaths.joinZNode(zkw1.getZNodePaths().rsZNode,
     "hostname1.example.org:1234");
 ZKUtil.createWithParents(zkw1, fakeRs);
 ZKClusterId.setClusterId(zkw1, new ClusterId());
 return ZKConfig.getZooKeeperClusterKey(testConf);
}

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

@Override
 protected Pair<Long, Integer> getLastSequenceIdWithVersion(String encodedRegionName,
   String peerId) throws KeeperException {
  Pair<Long, Integer> oldPair = super.getLastSequenceIdWithVersion(encodedRegionName, peerId);
  if (getLastSeqIdOpIndex < 100) {
   // Let the ZNode version increase.
   String path = getSerialReplicationRegionPeerNode(encodedRegionName, peerId);
   ZKUtil.createWithParents(zookeeper, path);
   ZKUtil.setData(zookeeper, path, ZKUtil.positionToByteArray(100L));
  }
  getLastSeqIdOpIndex++;
  return oldPair;
 }
};

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

private void createBaseZNodes() throws ZooKeeperConnectionException {
 try {
  // Create all the necessary "directories" of znodes
  ZKUtil.createWithParents(this, znodePaths.baseZNode);
  ZKUtil.createAndFailSilent(this, znodePaths.rsZNode);
  ZKUtil.createAndFailSilent(this, znodePaths.drainingZNode);
  ZKUtil.createAndFailSilent(this, znodePaths.tableZNode);
  ZKUtil.createAndFailSilent(this, znodePaths.splitLogZNode);
  ZKUtil.createAndFailSilent(this, znodePaths.backupMasterAddressesZNode);
  ZKUtil.createAndFailSilent(this, znodePaths.tableLockZNode);
  ZKUtil.createAndFailSilent(this, znodePaths.masterMaintZNode);
 } catch (KeeperException e) {
  throw new ZooKeeperConnectionException(
    prefix("Unexpected KeeperException creating base node"), e);
 }
}

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

@Override
public void addPeer(String peerId, ReplicationPeerConfig peerConfig, boolean enabled,
  SyncReplicationState syncReplicationState) throws ReplicationException {
 List<ZKUtilOp> multiOps = Arrays.asList(
  ZKUtilOp.createAndFailSilent(getPeerNode(peerId),
   ReplicationPeerConfigUtil.toByteArray(peerConfig)),
  ZKUtilOp.createAndFailSilent(getPeerStateNode(peerId),
   enabled ? ENABLED_ZNODE_BYTES : DISABLED_ZNODE_BYTES),
  ZKUtilOp.createAndFailSilent(getSyncReplicationStateNode(peerId),
   SyncReplicationState.toByteArray(syncReplicationState)),
  ZKUtilOp.createAndFailSilent(getNewSyncReplicationStateNode(peerId), NONE_STATE_ZNODE_BYTES));
 try {
  ZKUtil.createWithParents(zookeeper, peersZNode);
  ZKUtil.multiOrSequential(zookeeper, multiOps, false);
 } catch (KeeperException e) {
  throw new ReplicationException(
   "Could not add peer with id=" + peerId + ", peerConfig=>" + peerConfig + ", state=" +
    (enabled ? "ENABLED" : "DISABLED") + ", syncReplicationState=" + syncReplicationState,
   e);
 }
}

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

/**
 * Create a znode with data
 */
@Test
public void testCreateWithParents() throws KeeperException, InterruptedException {
 byte[] expectedData = new byte[] { 1, 2, 3 };
 ZKUtil.createWithParents(ZKW, "/l1/l2/l3/l4/testCreateWithParents", expectedData);
 byte[] data = ZKUtil.getData(ZKW, "/l1/l2/l3/l4/testCreateWithParents");
 assertTrue(Bytes.equals(expectedData, data));
 ZKUtil.deleteNodeRecursively(ZKW, "/l1");
 ZKUtil.createWithParents(ZKW, "/testCreateWithParents", expectedData);
 data = ZKUtil.getData(ZKW, "/testCreateWithParents");
 assertTrue(Bytes.equals(expectedData, data));
 ZKUtil.deleteNodeRecursively(ZKW, "/testCreateWithParents");
}

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

/**
 * Finally, we check the ACLs of a node outside of the /hbase hierarchy and
 * verify that its ACL is simply 'hbase:Perms.ALL'.
 */
@Test
public void testOutsideHBaseNodeACL() throws Exception {
 if (!secureZKAvailable) {
  return;
 }
 ZKUtil.createWithParents(zkw, "/testACLNode");
 List<ACL> acls = zkw.getRecoverableZooKeeper().getZooKeeper()
   .getACL("/testACLNode", new Stat());
 assertEquals(1, acls.size());
 assertEquals("sasl", acls.get(0).getId().getScheme());
 assertEquals("hbase", acls.get(0).getId().getId());
 assertEquals(ZooDefs.Perms.ALL, acls.get(0).getPerms());
}

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

@BeforeClass
public static void setUpBeforeClass() throws Exception {
 utility = new HBaseTestingUtility();
 utility.startMiniZKCluster();
 conf = utility.getConfiguration();
 ZKWatcher zk = HBaseTestingUtility.getZooKeeperWatcher(utility);
 ZKUtil.createWithParents(zk, zk.getZNodePaths().rsZNode);
}

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

@Test
public void testSetDataWithVersion() throws Exception {
 ZKUtil.createWithParents(ZKW, "/s1/s2/s3");
 int v0 = getZNodeDataVersion("/s1/s2/s3");
 assertEquals(0, v0);
 ZKUtil.setData(ZKW, "/s1/s2/s3", Bytes.toBytes(12L));
 int v1 = getZNodeDataVersion("/s1/s2/s3");
 assertEquals(1, v1);
 ZKUtil.multiOrSequential(ZKW,
  ImmutableList.of(ZKUtilOp.setData("/s1/s2/s3", Bytes.toBytes(13L), v1)), false);
 int v2 = getZNodeDataVersion("/s1/s2/s3");
 assertEquals(2, v2);
}

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

/**
 * Setup the config for the cluster
 */
@BeforeClass
public static void setupCluster() throws Exception {
 setupConf(UTIL.getConfiguration());
 UTIL.startMiniZKCluster();
 CONNECTION = (ClusterConnection)ConnectionFactory.createConnection(UTIL.getConfiguration());
 archivingClient = new ZKTableArchiveClient(UTIL.getConfiguration(), CONNECTION);
 // make hfile archiving node so we can archive files
 ZKWatcher watcher = UTIL.getZooKeeperWatcher();
 String archivingZNode = ZKTableArchiveClient.getArchiveZNode(UTIL.getConfiguration(), watcher);
 ZKUtil.createWithParents(watcher, archivingZNode);
 rss = mock(RegionServerServices.class);
}

相关文章

微信公众号

最新文章

更多