Search in sources :

Example 31 with OpResult

use of org.apache.zookeeper.OpResult in project distributedlog by twitter.

the class TestZKVersionedSetOp method testAbortOpResult.

@Test(timeout = 60000)
public void testAbortOpResult() throws Exception {
    final AtomicReference<Throwable> exception = new AtomicReference<Throwable>();
    final CountDownLatch latch = new CountDownLatch(1);
    ZKVersionedSetOp versionedSetOp = new ZKVersionedSetOp(mock(Op.class), new Transaction.OpListener<Version>() {

        @Override
        public void onCommit(Version r) {
        // no-op
        }

        @Override
        public void onAbort(Throwable t) {
            exception.set(t);
            latch.countDown();
        }
    });
    KeeperException ke = KeeperException.create(KeeperException.Code.SESSIONEXPIRED);
    OpResult opResult = new OpResult.ErrorResult(KeeperException.Code.NONODE.intValue());
    versionedSetOp.abortOpResult(ke, opResult);
    latch.await();
    assertTrue(exception.get() instanceof KeeperException.NoNodeException);
}
Also used : Op(org.apache.zookeeper.Op) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) Transaction(com.twitter.distributedlog.util.Transaction) Version(org.apache.bookkeeper.versioning.Version) OpResult(org.apache.zookeeper.OpResult) KeeperException(org.apache.zookeeper.KeeperException) Test(org.junit.Test)

Example 32 with OpResult

use of org.apache.zookeeper.OpResult in project herddb by diennea.

the class BookKeeperDataStorageManager method writeZNodeEnforceOwnership.

private void writeZNodeEnforceOwnership(String tableSpace, String path, byte[] content, Stat stat) throws DataStorageManagerException {
    try {
        zkWrites.inc();
        Op opUpdateRoot = createUpdateTableSpaceRootOp(tableSpace);
        Op opCreate = Op.create(path, content, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        try {
            List<OpResult> multi = zk.ensureZooKeeper().multi(Arrays.asList(opUpdateRoot, opCreate));
            updateRootZkNodeVersion(tableSpace, multi.get(0));
        } catch (KeeperException.NodeExistsException ok) {
            LOGGER.log(Level.FINE, "Node exists {0}", ok.getPath());
        }
        opUpdateRoot = createUpdateTableSpaceRootOp(tableSpace);
        Op opUpdate = Op.setData(path, content, stat != null ? stat.getVersion() : -1);
        List<OpResult> multi = zk.ensureZooKeeper().multi(Arrays.asList(opUpdateRoot, opUpdate));
        updateRootZkNodeVersion(tableSpace, multi.get(0));
    } catch (IOException | KeeperException err) {
        throw new DataStorageManagerException(err);
    } catch (InterruptedException err) {
        Thread.currentThread().interrupt();
        throw new DataStorageManagerException(err);
    }
}
Also used : Op(org.apache.zookeeper.Op) DataStorageManagerException(herddb.storage.DataStorageManagerException) OpResult(org.apache.zookeeper.OpResult) IOException(java.io.IOException) KeeperException(org.apache.zookeeper.KeeperException)

Example 33 with OpResult

use of org.apache.zookeeper.OpResult in project herddb by diennea.

the class BookKeeperDataStorageManager method createZNode.

private void createZNode(String tableSpace, String path, byte[] content, boolean errorIfExists) throws DataStorageManagerException {
    try {
        zkWrites.inc();
        Op opUpdateRoot = createUpdateTableSpaceRootOp(tableSpace);
        Op opCreate = Op.create(path, content, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        List<OpResult> multi = zk.ensureZooKeeper().multi(Arrays.asList(opUpdateRoot, opCreate));
        updateRootZkNodeVersion(tableSpace, multi.get(0));
    } catch (KeeperException.NodeExistsException err) {
        if (errorIfExists) {
            throw new DataStorageManagerException(err);
        }
    } catch (IOException | KeeperException err) {
        throw new DataStorageManagerException(err);
    } catch (InterruptedException err) {
        Thread.currentThread().interrupt();
        throw new DataStorageManagerException(err);
    }
}
Also used : Op(org.apache.zookeeper.Op) DataStorageManagerException(herddb.storage.DataStorageManagerException) OpResult(org.apache.zookeeper.OpResult) IOException(java.io.IOException) KeeperException(org.apache.zookeeper.KeeperException)

Example 34 with OpResult

use of org.apache.zookeeper.OpResult in project herddb by diennea.

the class BookKeeperDataStorageManager method deleteZNodeEnforceOwnership.

private void deleteZNodeEnforceOwnership(String tableSpace, String path) throws DataStorageManagerException {
    try {
        zkWrites.inc();
        Op opUpdateRoot = createUpdateTableSpaceRootOp(tableSpace);
        Op opDelete = Op.delete(path, -1);
        List<OpResult> multi = zk.ensureZooKeeper().multi(Arrays.asList(opUpdateRoot, opDelete));
        updateRootZkNodeVersion(tableSpace, multi.get(0));
    } catch (IOException | KeeperException err) {
        throw new DataStorageManagerException(err);
    } catch (InterruptedException err) {
        Thread.currentThread().interrupt();
        throw new DataStorageManagerException(err);
    }
}
Also used : Op(org.apache.zookeeper.Op) DataStorageManagerException(herddb.storage.DataStorageManagerException) OpResult(org.apache.zookeeper.OpResult) IOException(java.io.IOException) KeeperException(org.apache.zookeeper.KeeperException)

Aggregations

OpResult (org.apache.zookeeper.OpResult)34 KeeperException (org.apache.zookeeper.KeeperException)21 Op (org.apache.zookeeper.Op)13 MultiCallback (org.apache.zookeeper.AsyncCallback.MultiCallback)10 ErrorResult (org.apache.zookeeper.OpResult.ErrorResult)8 List (java.util.List)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 ValueSource (org.junit.jupiter.params.provider.ValueSource)6 IOException (java.io.IOException)4 CreateResult (org.apache.zookeeper.OpResult.CreateResult)4 ACL (org.apache.zookeeper.data.ACL)4 Id (org.apache.zookeeper.data.Id)4 Test (org.junit.Test)4 DataStorageManagerException (herddb.storage.DataStorageManagerException)3 CheckResult (org.apache.zookeeper.OpResult.CheckResult)3 DeleteResult (org.apache.zookeeper.OpResult.DeleteResult)3 Stat (org.apache.zookeeper.data.Stat)3 LogExistsException (com.twitter.distributedlog.exceptions.LogExistsException)2 ZKException (com.twitter.distributedlog.exceptions.ZKException)2 ZKOp (com.twitter.distributedlog.zk.ZKOp)2