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);
}
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);
}
}
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);
}
}
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);
}
}
Aggregations