Search in sources :

Example 1 with Version

use of org.apache.bookkeeper.versioning.Version in project distributedlog by twitter.

the class ZKLogSegmentMetadataStore method storeMaxTxnId.

@Override
public void storeMaxTxnId(Transaction<Object> txn, String path, Versioned<Long> transactionId, Transaction.OpListener<Version> listener) {
    Version version = transactionId.getVersion();
    assert (version instanceof ZkVersion);
    ZkVersion zkVersion = (ZkVersion) version;
    byte[] data = DLUtils.serializeTransactionId(transactionId.getValue());
    Op setDataOp = Op.setData(path, data, zkVersion.getZnodeVersion());
    ZKOp zkOp = new ZKVersionedSetOp(setDataOp, listener);
    txn.addOp(zkOp);
}
Also used : Op(org.apache.zookeeper.Op) ZKOp(com.twitter.distributedlog.zk.ZKOp) DefaultZKOp(com.twitter.distributedlog.zk.DefaultZKOp) ZKVersionedSetOp(com.twitter.distributedlog.zk.ZKVersionedSetOp) ZkVersion(org.apache.bookkeeper.meta.ZkVersion) Version(org.apache.bookkeeper.versioning.Version) ZKOp(com.twitter.distributedlog.zk.ZKOp) DefaultZKOp(com.twitter.distributedlog.zk.DefaultZKOp) ZkVersion(org.apache.bookkeeper.meta.ZkVersion) ZKVersionedSetOp(com.twitter.distributedlog.zk.ZKVersionedSetOp)

Example 2 with Version

use of org.apache.bookkeeper.versioning.Version in project distributedlog by twitter.

the class ZKLogSegmentMetadataStore method storeMaxLogSegmentSequenceNumber.

// max sequence number and max transaction id
@Override
public void storeMaxLogSegmentSequenceNumber(Transaction<Object> txn, String path, Versioned<Long> lssn, Transaction.OpListener<Version> listener) {
    Version version = lssn.getVersion();
    assert (version instanceof ZkVersion);
    ZkVersion zkVersion = (ZkVersion) version;
    byte[] data = DLUtils.serializeLogSegmentSequenceNumber(lssn.getValue());
    Op setDataOp = Op.setData(path, data, zkVersion.getZnodeVersion());
    ZKOp zkOp = new ZKVersionedSetOp(setDataOp, listener);
    txn.addOp(zkOp);
}
Also used : Op(org.apache.zookeeper.Op) ZKOp(com.twitter.distributedlog.zk.ZKOp) DefaultZKOp(com.twitter.distributedlog.zk.DefaultZKOp) ZKVersionedSetOp(com.twitter.distributedlog.zk.ZKVersionedSetOp) ZkVersion(org.apache.bookkeeper.meta.ZkVersion) Version(org.apache.bookkeeper.versioning.Version) ZKOp(com.twitter.distributedlog.zk.ZKOp) DefaultZKOp(com.twitter.distributedlog.zk.DefaultZKOp) ZkVersion(org.apache.bookkeeper.meta.ZkVersion) ZKVersionedSetOp(com.twitter.distributedlog.zk.ZKVersionedSetOp)

Example 3 with Version

use of org.apache.bookkeeper.versioning.Version in project distributedlog by twitter.

the class TestZKVersionedSetOp method testAbortNullOpResult.

@Test(timeout = 60000)
public void testAbortNullOpResult() 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);
    versionedSetOp.abortOpResult(ke, null);
    latch.await();
    assertTrue(ke == exception.get());
}
Also used : Op(org.apache.zookeeper.Op) Transaction(com.twitter.distributedlog.util.Transaction) Version(org.apache.bookkeeper.versioning.Version) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) KeeperException(org.apache.zookeeper.KeeperException) Test(org.junit.Test)

Example 4 with Version

use of org.apache.bookkeeper.versioning.Version in project distributedlog by twitter.

the class TestZKLogSegmentMetadataStore method testStoreMaxTxnIdBadVersion.

@Test(timeout = 60000)
public void testStoreMaxTxnIdBadVersion() throws Exception {
    Transaction<Object> updateTxn = lsmStore.transaction();
    Versioned<Long> value = new Versioned<Long>(999L, new ZkVersion(10));
    final Promise<Version> result = new Promise<Version>();
    lsmStore.storeMaxTxnId(updateTxn, rootZkPath, value, new Transaction.OpListener<Version>() {

        @Override
        public void onCommit(Version r) {
            result.setValue(r);
        }

        @Override
        public void onAbort(Throwable t) {
            result.setException(t);
        }
    });
    try {
        FutureUtils.result(updateTxn.execute());
        fail("Should fail on storing log record transaction id if providing bad version");
    } catch (ZKException zke) {
        assertEquals(KeeperException.Code.BADVERSION, zke.getKeeperExceptionCode());
    }
    try {
        Await.result(result);
        fail("Should fail on storing log record transaction id if providing bad version");
    } catch (KeeperException ke) {
        assertEquals(KeeperException.Code.BADVERSION, ke.code());
    }
    Stat stat = new Stat();
    byte[] data = zkc.get().getData(rootZkPath, false, stat);
    assertEquals(0, stat.getVersion());
    assertEquals(0, data.length);
}
Also used : Versioned(org.apache.bookkeeper.versioning.Versioned) Promise(com.twitter.util.Promise) ZKException(com.twitter.distributedlog.exceptions.ZKException) Stat(org.apache.zookeeper.data.Stat) Transaction(com.twitter.distributedlog.util.Transaction) ZkVersion(org.apache.bookkeeper.meta.ZkVersion) Version(org.apache.bookkeeper.versioning.Version) ZkVersion(org.apache.bookkeeper.meta.ZkVersion) KeeperException(org.apache.zookeeper.KeeperException) Test(org.junit.Test)

Example 5 with Version

use of org.apache.bookkeeper.versioning.Version in project distributedlog by twitter.

the class TestZKLogSegmentMetadataStore method testStoreMaxLogSegmentSequenceNumberOnNonExistentPath.

@Test(timeout = 60000)
public void testStoreMaxLogSegmentSequenceNumberOnNonExistentPath() throws Exception {
    Transaction<Object> updateTxn = lsmStore.transaction();
    Versioned<Long> value = new Versioned<Long>(999L, new ZkVersion(10));
    final Promise<Version> result = new Promise<Version>();
    String nonExistentPath = rootZkPath + "/non-existent";
    lsmStore.storeMaxLogSegmentSequenceNumber(updateTxn, nonExistentPath, value, new Transaction.OpListener<Version>() {

        @Override
        public void onCommit(Version r) {
            result.setValue(r);
        }

        @Override
        public void onAbort(Throwable t) {
            result.setException(t);
        }
    });
    try {
        FutureUtils.result(updateTxn.execute());
        fail("Should fail on storing log segment sequence number if path doesn't exist");
    } catch (ZKException zke) {
        assertEquals(KeeperException.Code.NONODE, zke.getKeeperExceptionCode());
    }
    try {
        Await.result(result);
        fail("Should fail on storing log segment sequence number if path doesn't exist");
    } catch (KeeperException ke) {
        assertEquals(KeeperException.Code.NONODE, ke.code());
    }
}
Also used : Versioned(org.apache.bookkeeper.versioning.Versioned) Promise(com.twitter.util.Promise) ZKException(com.twitter.distributedlog.exceptions.ZKException) Transaction(com.twitter.distributedlog.util.Transaction) ZkVersion(org.apache.bookkeeper.meta.ZkVersion) Version(org.apache.bookkeeper.versioning.Version) ZkVersion(org.apache.bookkeeper.meta.ZkVersion) KeeperException(org.apache.zookeeper.KeeperException) Test(org.junit.Test)

Aggregations

Version (org.apache.bookkeeper.versioning.Version)12 ZkVersion (org.apache.bookkeeper.meta.ZkVersion)10 Transaction (com.twitter.distributedlog.util.Transaction)8 Test (org.junit.Test)8 Promise (com.twitter.util.Promise)6 Versioned (org.apache.bookkeeper.versioning.Versioned)6 KeeperException (org.apache.zookeeper.KeeperException)6 Op (org.apache.zookeeper.Op)6 ZKException (com.twitter.distributedlog.exceptions.ZKException)4 ZKOp (com.twitter.distributedlog.zk.ZKOp)4 ZKVersionedSetOp (com.twitter.distributedlog.zk.ZKVersionedSetOp)4 Stat (org.apache.zookeeper.data.Stat)4 DefaultZKOp (com.twitter.distributedlog.zk.DefaultZKOp)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 OpResult (org.apache.zookeeper.OpResult)1