gpt4 book ai didi

org.apache.ignite.spi.discovery.zk.internal.ZookeeperClient类的使用及代码示例

转载 作者:知者 更新时间:2024-03-13 09:49:44 26 4
gpt4 key购买 nike

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

ZookeeperClient介绍

[英]Zookeeper Client.
[中]动物园管理员客户。

代码示例

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

ZookeeperClient client = rtState.zkClient;
if (!client.exists(zkPaths.clusterDir)) {
  createRootPathParents(zkPaths.clusterDir, client);
  client.createIfNeeded(zkPaths.clusterDir, null, PERSISTENT);
List<String> createdDirs = client.getChildren(zkPaths.clusterDir);
  client.createAll(dirs, PERSISTENT);

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

/**
 * @param startInternalOrder Starting internal order for cluster (znodes having lower order belong
 *      to clients from previous cluster and should be removed).
 * @throws Exception If failed.
 */
private void cleanupPreviousClusterData(long startInternalOrder) throws Exception {
  long start = System.currentTimeMillis();
  ZookeeperClient client = rtState.zkClient;
  List<String> batch = new LinkedList<>();
  List<String> evtChildren = client.getChildrenPaths(zkPaths.evtsPath);
  for (String evtPath : evtChildren)
    batch.addAll(client.getChildrenPaths(evtPath));
  batch.addAll(evtChildren);
  batch.addAll(client.getChildrenPaths(zkPaths.customEvtsDir));
  batch.addAll(client.getChildrenPaths(zkPaths.customEvtsPartsDir));
  batch.addAll(client.getChildrenPaths(zkPaths.customEvtsAcksDir));
  client.deleteAll(batch, -1);
  if (startInternalOrder > 0) {
    for (String alive : client.getChildren(zkPaths.aliveNodesDir)) {
      if (ZkIgnitePaths.aliveInternalId(alive) < startInternalOrder)
        client.deleteIfExists(zkPaths.aliveNodesDir + "/" + alive, -1);
    }
  }
  long time = System.currentTimeMillis() - start;
  if (time > 0) {
    if (log.isInfoEnabled())
      log.info("Previous cluster data cleanup time: " + time);
  }
}

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

/** {@inheritDoc} */
  @Override public void execute() {
    getChildrenAsync(path, watcher, cb);
  }
}

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

/**
 * @param internalId Node internal ID.
 * @throws Exception If failed.
 */
private void deleteAliveNode(long internalId) throws Exception {
  for (String child : rtState.zkClient.getChildren(zkPaths.aliveNodesDir)) {
    if (ZkIgnitePaths.aliveInternalId(child) == internalId) {
      // Need use sync delete to do not process again join of this node again.
      rtState.zkClient.deleteIfExists(zkPaths.aliveNodesDir + "/" + child, -1);
      return;
    }
  }
}

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

/**
 * @param path Path to save.
 * @param bytes Bytes to save.
 * @param overhead Extra overhead.
 * @return Parts count.
 * @throws Exception If failed.
 */
private int saveData(String path, byte[] bytes, int overhead) throws Exception {
  int dataForJoinedPartCnt = 1;
  if (rtState.zkClient.needSplitNodeData(path, bytes, overhead)) {
    dataForJoinedPartCnt = saveMultipleParts(rtState.zkClient,
      path,
      rtState.zkClient.splitNodeData(path, bytes, overhead));
  }
  else {
    rtState.zkClient.createIfNeeded(multipartPathName(path, 0),
      bytes,
      PERSISTENT);
  }
  return dataForJoinedPartCnt;
}

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

/**
 * @param internalIds Nodes internal IDs.
 * @throws Exception If failed.
 */
private void deleteAliveNodes(@Nullable GridLongList internalIds) throws Exception {
  if (internalIds == null)
    return;
  List<String> alives = rtState.zkClient.getChildren(zkPaths.aliveNodesDir);
  for (int i = 0; i < alives.size(); i++) {
    String alive = alives.get(i);
    if (internalIds.contains(ZkIgnitePaths.aliveInternalId(alive)))
      rtState.zkClient.deleteIfExistsAsync(zkPaths.aliveNodesDir + "/" + alive);
  }
}

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

if (zkClient.needSplitNodeData(joinDataPath, joinDataBytes, OVERHEAD)) {
  List<byte[]> parts = zkClient.splitNodeData(joinDataPath, joinDataBytes, OVERHEAD);
  joinDataPath = zkClient.createIfNeeded(
    joinDataPath,
    marshalZip(new ZkJoiningNodeData(parts.size())),
  joinDataPath = zkClient.createIfNeeded(
    joinDataPath,
    joinDataBytes,
rtState.locNodeZkPath = zkClient.createSequential(
  prefix,
  zkPaths.aliveNodesDir,
  log.info("Node started join [nodeId=" + locNode.id() +
    ", instanceName=" + locNode.attribute(ATTR_IGNITE_INSTANCE_NAME) +
    ", zkSessionId=0x" + Long.toHexString(rtState.zkClient.zk().getSessionId()) +
    ", joinDataSize=" + joinDataBytes.length +
    (rtState.joinDataPartCnt > 1 ? (", joinDataPartCnt=" + rtState.joinDataPartCnt) : "") +
  zkClient.getChildrenAsync(zkPaths.aliveNodesDir, null, new CheckCoordinatorCallback(rtState));
zkClient.getDataAsync(zkPaths.evtsPath, rtState.watcher, rtState.watcher);

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

/**
 * @throws Exception If failed.
 */
@Test
public void testDeleteAllNoNode() throws Exception {
  startZK(1);
  ZookeeperClient client = createClient(SES_TIMEOUT);
  client.createIfNeeded("/apacheIgnite", null, CreateMode.PERSISTENT);
  client.createIfNeeded("/apacheIgnite/1", null, CreateMode.PERSISTENT);
  client.createIfNeeded("/apacheIgnite/2", null, CreateMode.PERSISTENT);
  client.deleteAll(Arrays.asList("/apacheIgnite/1", "/apacheIgnite/2", "/apacheIgnite/3"), -1);
  assertTrue(client.getChildren("/apacheIgnite").isEmpty());
}

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

/**
 * @throws Exception If failed.
 */
@Test
public void testCreateAllNodeExists() throws Exception {
  startZK(1);
  ZookeeperClient client = createClient(SES_TIMEOUT);
  client.createIfNeeded("/apacheIgnite", null, CreateMode.PERSISTENT);
  client.createIfNeeded("/apacheIgnite/1", null, CreateMode.PERSISTENT);
  List<String> paths = new ArrayList<>();
  paths.add("/apacheIgnite/1");
  paths.add("/apacheIgnite/2");
  paths.add("/apacheIgnite/3");
  client.createAll(paths, CreateMode.PERSISTENT);
  assertEquals(3, client.getChildren("/apacheIgnite").size());
}

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

/**
 * @param futResPath Result path.
 * @param client Client.
 * @param data Result data.
 * @throws Exception If failed.
 */
static void saveResult(String futResPath, ZookeeperClient client, byte[] data) throws Exception {
  client.createIfNeeded(futResPath, data, CreateMode.PERSISTENT);
}

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

/**
 * @throws Exception If failed.
 */
@Test
public void testSaveLargeValue() throws Exception {
  startZK(1);
  final ZookeeperClient client = createClient(SES_TIMEOUT);
  byte[] data = new byte[1024 * 1024];
  String basePath = "/ignite";
  assertTrue(client.needSplitNodeData(basePath, data, 2));
  List<byte[]> parts = client.splitNodeData(basePath, data, 2);
  assertTrue(parts.size() > 1);
  ZooKeeper zk = client.zk();
  for (int i = 0; i < parts.size(); i++) {
    byte[] part = parts.get(i);
    assertTrue(part.length > 0);
    String path0 = basePath + ":" + i;
    zk.create(path0, part, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
  }
}

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

/**
 * @throws Exception If failed.
 */
@Test
public void testConnectionLoss4() throws Exception {
  startZK(1);
  CallbackFuture cb = new CallbackFuture();
  final ZookeeperClient client = new ZookeeperClient(log, zkCluster.getConnectString(), 3000, cb);
  client.createIfNeeded("/apacheIgnite1", null, CreateMode.PERSISTENT);
  final CountDownLatch l = new CountDownLatch(1);
  client.getChildrenAsync("/apacheIgnite1", null, new AsyncCallback.Children2Callback() {
    @Override public void processResult(int rc, String path, Object ctx, List<String> children, Stat stat) {
      closeZK();
      try {
        client.createIfNeeded("/apacheIgnite2", null, CreateMode.PERSISTENT);
      }
      catch (ZookeeperClientFailedException e) {
        info("Expected error: " + e);
        l.countDown();
      }
      catch (Exception e) {
        fail("Unexpected error: " + e);
      }
    }
  });
  assertTrue(l.await(10, TimeUnit.SECONDS));
  cb.get();
}

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

rtState.zkClient = new ZookeeperClient(
  igniteInstanceName,
  log,
if (rtState.zkClient.pingerEnabled() && !locNode.isClient() && !locNode.isDaemon()) {
  ZkPinger pinger = new ZkPinger(log, rtState.zkClient.zk(), zkPaths);
  rtState.zkClient.attachPinger(pinger);

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

/**
 * @param zkClient Client.
 * @param msgBytes Marshalled message.
 * @throws ZookeeperClientFailedException If connection to zk was lost.
 * @throws InterruptedException If interrupted.
 */
private void saveCustomMessage(ZookeeperClient zkClient, byte[] msgBytes)
  throws ZookeeperClientFailedException, InterruptedException
{
  String prefix = UUID.randomUUID().toString();
  int partCnt = 1;
  int overhead = 10;
  UUID locId = locNode.id();
  String path = zkPaths.createCustomEventPath(prefix, locId, partCnt);
  if (zkClient.needSplitNodeData(path, msgBytes, overhead)) {
    List<byte[]> parts = zkClient.splitNodeData(path, msgBytes, overhead);
    String partsBasePath = zkPaths.customEventPartsBasePath(prefix, locId);
    saveMultipleParts(zkClient, partsBasePath, parts);
    msgBytes = null;
    partCnt = parts.size();
  }
  zkClient.createSequential(prefix,
    zkPaths.customEvtsDir,
    zkPaths.createCustomEventPath(prefix, locId, partCnt),
    msgBytes,
    CreateMode.PERSISTENT_SEQUENTIAL);
}

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

client.createIfNeeded("/apacheIgnite1", null, CreateMode.PERSISTENT);
client.getChildrenAsync("/apacheIgnite1", null, new AsyncCallback.Children2Callback() {
  @Override public void processResult(int rc, String path, Object ctx, List<String> children, Stat stat) {
    try {

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

/**
 * @param client Client.
 * @param paths Paths utils.
 * @param futId Future ID.
 * @param log Ignite Logger.
 * @throws Exception If failed.
 */
static void deleteFutureData(ZookeeperClient client,
  ZkIgnitePaths paths,
  UUID futId,
  IgniteLogger log
) throws Exception {
  List<String> batch = new LinkedList<>();
  String evtDir = paths.distributedFutureBasePath(futId);
  if (client.exists(evtDir)) {
    batch.addAll(client.getChildrenPaths(evtDir));
    batch.add(evtDir);
  }
  batch.add(paths.distributedFutureResultPath(futId));
  client.deleteAll(batch, -1);
}

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

int size = requestOverhead(path) + 48 /* overhead */;
      createIfNeeded(op.getPath(), null, createMode);
    onZookeeperError(connStartTime, e);

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

/**
 * @throws Exception If failed.
 */
@Test
public void testConnectionLoss1() throws Exception {
  ZookeeperClient client = new ZookeeperClient(log, "localhost:2200", 3000, null);
  try {
    client.createIfNeeded("/apacheIgnite", null, CreateMode.PERSISTENT);
    fail();
  }
  catch (ZookeeperClientFailedException e) {
    info("Expected error: " + e);
  }
}

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

aliveNodes = rtState.zkClient.getChildren(zkPaths.aliveNodesDir);
    rtState.zkClient.getChildrenAsync(zkPaths.aliveNodesDir, rtState.watcher, rtState.watcher);
rtState.zkClient.getChildrenAsync(zkPaths.aliveNodesDir, rtState.watcher, rtState.watcher);

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

/**
 * @throws Exception If failed.
 */
@Test
public void testClose() throws Exception {
  startZK(1);
  final ZookeeperClient client = createClient(SES_TIMEOUT);
  client.createIfNeeded("/apacheIgnite1", null, CreateMode.PERSISTENT);
  client.zk().close();
  GridTestUtils.assertThrows(log, new Callable<Void>() {
    @Override public Void call() throws Exception {
      client.createIfNeeded("/apacheIgnite2", null, CreateMode.PERSISTENT);
      return null;
    }
  }, ZookeeperClientFailedException.class, null);
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com