Search in sources :

Example 11 with Version

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

the class BKLogWriteHandler method storeMaxTxId.

// Transactional operations for MaxTxId
void storeMaxTxId(final ZKTransaction txn, final MaxTxId maxTxId, final long txId) {
    byte[] data = maxTxId.couldStore(txId);
    if (null != data) {
        Op zkOp = Op.setData(maxTxId.getZkPath(), data, -1);
        txn.addOp(new ZKVersionedSetOp(zkOp, new Transaction.OpListener<Version>() {

            @Override
            public void onCommit(Version version) {
                maxTxId.setMaxTxId(txId);
            }

            @Override
            public void onAbort(Throwable t) {
            }
        }));
    }
}
Also used : Op(org.apache.zookeeper.Op) ZKVersionedSetOp(com.twitter.distributedlog.zk.ZKVersionedSetOp) ZKOp(com.twitter.distributedlog.zk.ZKOp) ZkVersion(org.apache.bookkeeper.meta.ZkVersion) Version(org.apache.bookkeeper.versioning.Version) ZKVersionedSetOp(com.twitter.distributedlog.zk.ZKVersionedSetOp)

Example 12 with Version

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

the class BKLogWriteHandler method storeMaxSequenceNumber.

// Transactional operations for MaxLogSegmentSequenceNo
void storeMaxSequenceNumber(final Transaction txn, final MaxLogSegmentSequenceNo maxSeqNo, final long seqNo, final boolean isInprogress) {
    byte[] data = DLUtils.serializeLogSegmentSequenceNumber(seqNo);
    Op zkOp = Op.setData(logMetadata.getLogSegmentsPath(), data, maxSeqNo.getZkVersion());
    txn.addOp(new ZKVersionedSetOp(zkOp, new Transaction.OpListener<Version>() {

        @Override
        public void onCommit(Version version) {
            if (validateLogSegmentSequenceNumber) {
                synchronized (inprogressLSSNs) {
                    if (isInprogress) {
                        inprogressLSSNs.add(seqNo);
                    } else {
                        inprogressLSSNs.removeFirst();
                    }
                }
            }
            maxSeqNo.update((ZkVersion) version, seqNo);
        }

        @Override
        public void onAbort(Throwable t) {
        // no-op
        }
    }));
}
Also used : Op(org.apache.zookeeper.Op) ZKVersionedSetOp(com.twitter.distributedlog.zk.ZKVersionedSetOp) ZKOp(com.twitter.distributedlog.zk.ZKOp) ZkVersion(org.apache.bookkeeper.meta.ZkVersion) Version(org.apache.bookkeeper.versioning.Version) ZKVersionedSetOp(com.twitter.distributedlog.zk.ZKVersionedSetOp)

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