void createLogInNamespaceSync(URI uri, String logName) throws InterruptedException, IOException, KeeperException { Transaction txn = zkc.get().transaction();
@Test public void testChRootTransaction() throws Exception { // creating the subtree for chRoot clients. String chRoot = createNameSpace(); // checking the child version using chRoot client. zk_chroot = createClient(this.hostPort + chRoot); String childPath = "/myid"; Transaction transaction = zk_chroot.transaction(); transaction.create(childPath, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); transaction.check(childPath, 0); transaction.setData(childPath, childPath.getBytes(), 0); commit(transaction); Assert.assertNotNull("zNode is not created under chroot:" + chRoot, zk .exists(chRoot + childPath, false)); Assert.assertNotNull("zNode is not created under chroot:" + chRoot, zk_chroot.exists(childPath, false)); Assert.assertNull("zNode is created directly under '/', ignored configured chroot", zk.exists(childPath, false)); Assert.assertArrayEquals("zNode data not matching", childPath .getBytes(), zk_chroot.getData(childPath, false, null)); transaction = zk_chroot.transaction(); // Deleting child using chRoot client. transaction.delete(childPath, 1); commit(transaction); Assert.assertNull("chroot:" + chRoot + " exists after delete", zk .exists(chRoot + "/myid", false)); Assert.assertNull("chroot:" + chRoot + " exists after delete", zk_chroot.exists("/myid", false)); }
Transaction transaction = zk.transaction(); transaction.setData(node1, "no way".getBytes(), -1); transaction.create(node2, data.getBytes(),
@Test public void testTransactionBuilder() throws Exception { List<OpResult> results = commit(zk.transaction() .create("/t1", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT) .create("/t1/child", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT) results = commit(zk.transaction() .check("/t1", 0) .check("/t1/child", 0) results = commit(zk.transaction() .check("/t1", 0) .check("/t1/child", 0) results = commit(zk.transaction() .check("/t1", 0) .setData("/t1", new byte[0], 0)); results = commit(zk.transaction() .check("/t1", 1) .setData("/t1", new byte[0], 2)); results = commit(zk.transaction() .check("/t1", 1) .check("/t1/child", 0) results = commit(zk.transaction() .delete("/t2", -1) .delete("/t1/child", -1));
private static void createLog(ZooKeeperClient zk, URI uri, String logName, String logIdentifier) throws Exception { final String logRootPath = getLogRootPath(uri, logName, logIdentifier); final String logSegmentsPath = logRootPath + LOGSEGMENTS_PATH; final String maxTxIdPath = logRootPath + MAX_TXID_PATH; final String lockPath = logRootPath + LOCK_PATH; final String readLockPath = logRootPath + READ_LOCK_PATH; final String versionPath = logRootPath + VERSION_PATH; final String allocationPath = logRootPath + ALLOCATION_PATH; Utils.zkCreateFullPathOptimistic(zk, logRootPath, new byte[0], zk.getDefaultACL(), CreateMode.PERSISTENT); Transaction txn = zk.get().transaction(); txn.create(logSegmentsPath, DLUtils.serializeLogSegmentSequenceNumber( DistributedLogConstants.UNASSIGNED_LOGSEGMENT_SEQNO), zk.getDefaultACL(), CreateMode.PERSISTENT); txn.create(maxTxIdPath, DLUtils.serializeTransactionId(0L), zk.getDefaultACL(), CreateMode.PERSISTENT); txn.create(lockPath, DistributedLogConstants.EMPTY_BYTES, zk.getDefaultACL(), CreateMode.PERSISTENT); txn.create(readLockPath, DistributedLogConstants.EMPTY_BYTES, zk.getDefaultACL(), CreateMode.PERSISTENT); txn.create(versionPath, ZKLogMetadataForWriter.intToBytes(LAYOUT_VERSION), zk.getDefaultACL(), CreateMode.PERSISTENT); txn.create(allocationPath, DistributedLogConstants.EMPTY_BYTES, zk.getDefaultACL(), CreateMode.PERSISTENT); txn.commit(); }
/** * * @param zk * Zookeeper server to commit transactions to. * @param transactionSize * Number of operations to perform before commiting, <em>n.b you will * have to perform you last {@link #commit()} manually </em> */ protected AutoCommitTransactionWrapper(ZooKeeper zk, int transactionSize) { super(zk); transaction = zk.transaction(); this.zk = zk; this.transactionSize = transactionSize; }
@Override @Deprecated public Transaction transaction() { // since there is no reference about which client that the transaction could use // so just use ZooKeeper instance directly. // you'd better to use {@link #multi}. ZooKeeper zkHandle = zk.get(); if (null == zkHandle) { return super.transaction(); } return zkHandle.transaction(); }
@Override @Deprecated public Transaction transaction() { // since there is no reference about which client that the transaction could use // so just use ZooKeeper instance directly. // you'd better to use {@link #multi}. ZooKeeper zkHandle = zk.get(); if (null == zkHandle) { return super.transaction(); } return zkHandle.transaction(); }
private void maybeCommitTransaction() { if (opsSinceCommit >= (transactionSize - 1)) { try { Writer.logger.info("Committing transaction"); transaction.commit(); opsSinceCommit = 0; transaction = zk.transaction(); } catch (InterruptedException | KeeperException e) { throw new RuntimeException(e); } } else { opsSinceCommit++; } }
Transaction txn = zooKeeper.transaction(); for (int i = 2; i < args.length; i++) { String childPath = ZKPaths.makePath(parentPath, args[i]);
Transaction tx = zk.transaction(); List<String> children = zk.getChildren(serverLoadPath, false); HashSet<String> servers = new HashSet<String>(children);
void createLogInNamespaceSync(URI uri, String logName) throws InterruptedException, IOException, KeeperException { Transaction txn = zkc.get().transaction();