Search in sources :

Example 26 with ZkVersion

use of org.apache.bookkeeper.meta.ZkVersion in project distributedlog by twitter.

the class SimpleLedgerAllocator method createAllocationData.

private static Future<Versioned<byte[]>> createAllocationData(final String allocatePath, final ZooKeeperClient zkc) {
    try {
        final Promise<Versioned<byte[]>> promise = new Promise<Versioned<byte[]>>();
        zkc.get().create(allocatePath, DistributedLogConstants.EMPTY_BYTES, zkc.getDefaultACL(), CreateMode.PERSISTENT, new org.apache.zookeeper.AsyncCallback.Create2Callback() {

            @Override
            public void processResult(int rc, String path, Object ctx, String name, Stat stat) {
                if (KeeperException.Code.OK.intValue() == rc) {
                    promise.setValue(new Versioned<byte[]>(DistributedLogConstants.EMPTY_BYTES, new ZkVersion(stat.getVersion())));
                } else if (KeeperException.Code.NODEEXISTS.intValue() == rc) {
                    Utils.zkGetData(zkc, allocatePath, false).proxyTo(promise);
                } else {
                    promise.setException(FutureUtils.zkException(KeeperException.create(KeeperException.Code.get(rc)), allocatePath));
                }
            }
        }, null);
        return promise;
    } catch (ZooKeeperClient.ZooKeeperConnectionException e) {
        return Future.exception(FutureUtils.zkException(e, allocatePath));
    } catch (InterruptedException e) {
        return Future.exception(FutureUtils.zkException(e, allocatePath));
    }
}
Also used : Versioned(org.apache.bookkeeper.versioning.Versioned) Promise(com.twitter.util.Promise) Stat(org.apache.zookeeper.data.Stat) ZooKeeperClient(com.twitter.distributedlog.ZooKeeperClient) ZkVersion(org.apache.bookkeeper.meta.ZkVersion)

Aggregations

ZkVersion (org.apache.bookkeeper.meta.ZkVersion)26 Versioned (org.apache.bookkeeper.versioning.Versioned)21 Test (org.junit.Test)16 Stat (org.apache.zookeeper.data.Stat)11 Promise (com.twitter.util.Promise)9 Version (org.apache.bookkeeper.versioning.Version)9 URI (java.net.URI)8 ZKException (com.twitter.distributedlog.exceptions.ZKException)7 Transaction (com.twitter.distributedlog.util.Transaction)6 AsyncCallback (org.apache.zookeeper.AsyncCallback)4 KeeperException (org.apache.zookeeper.KeeperException)4 Op (org.apache.zookeeper.Op)4 ZKOp (com.twitter.distributedlog.zk.ZKOp)3 ZKVersionedSetOp (com.twitter.distributedlog.zk.ZKVersionedSetOp)3 DefaultZKOp (com.twitter.distributedlog.zk.DefaultZKOp)2 ZKTransaction (com.twitter.distributedlog.zk.ZKTransaction)2 LedgerEntry (org.apache.bookkeeper.client.LedgerEntry)2 LedgerHandle (org.apache.bookkeeper.client.LedgerHandle)2 OpResult (org.apache.zookeeper.OpResult)2 ZooKeeperClient (com.twitter.distributedlog.ZooKeeperClient)1