Search in sources :

Example 1 with ZKVersionedSetOp

use of com.twitter.distributedlog.zk.ZKVersionedSetOp 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 ZKVersionedSetOp

use of com.twitter.distributedlog.zk.ZKVersionedSetOp 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 ZKVersionedSetOp

use of com.twitter.distributedlog.zk.ZKVersionedSetOp in project distributedlog by twitter.

the class SimpleLedgerAllocator method completeAllocation.

private synchronized void completeAllocation(LedgerHandle lh) {
    allocatedLh = lh;
    if (null == tryObtainTxn) {
        return;
    }
    org.apache.zookeeper.Op zkSetDataOp = org.apache.zookeeper.Op.setData(allocatePath, DistributedLogConstants.EMPTY_BYTES, version.getZnodeVersion());
    ZKVersionedSetOp commitOp = new ZKVersionedSetOp(zkSetDataOp, this);
    tryObtainTxn.addOp(commitOp);
    setPhase(Phase.HANDING_OVER);
    FutureUtils.setValue(allocatePromise, lh);
}
Also used : ZKVersionedSetOp(com.twitter.distributedlog.zk.ZKVersionedSetOp)

Example 4 with ZKVersionedSetOp

use of com.twitter.distributedlog.zk.ZKVersionedSetOp 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 5 with ZKVersionedSetOp

use of com.twitter.distributedlog.zk.ZKVersionedSetOp 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

ZKVersionedSetOp (com.twitter.distributedlog.zk.ZKVersionedSetOp)5 ZKOp (com.twitter.distributedlog.zk.ZKOp)4 ZkVersion (org.apache.bookkeeper.meta.ZkVersion)4 Version (org.apache.bookkeeper.versioning.Version)4 Op (org.apache.zookeeper.Op)4 DefaultZKOp (com.twitter.distributedlog.zk.DefaultZKOp)2