Search in sources :

Example 1 with ZKOp

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

the class BKLogWriteHandler method writeLogSegment.

// Transactional operations for logsegment
void writeLogSegment(final ZKTransaction txn, final List<ACL> acl, final String inprogressSegmentName, final LogSegmentMetadata metadata, final String path) {
    byte[] finalisedData = metadata.getFinalisedData().getBytes(UTF_8);
    Op zkOp = Op.create(path, finalisedData, acl, CreateMode.PERSISTENT);
    txn.addOp(new ZKOp(zkOp) {

        @Override
        protected void commitOpResult(OpResult opResult) {
            addLogSegmentToCache(inprogressSegmentName, metadata);
        }

        @Override
        protected void abortOpResult(Throwable t, OpResult opResult) {
        // no-op
        }
    });
}
Also used : Op(org.apache.zookeeper.Op) ZKVersionedSetOp(com.twitter.distributedlog.zk.ZKVersionedSetOp) ZKOp(com.twitter.distributedlog.zk.ZKOp) OpResult(org.apache.zookeeper.OpResult) ZKOp(com.twitter.distributedlog.zk.ZKOp)

Example 2 with ZKOp

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

the class BKLogWriteHandler method deleteLogSegment.

void deleteLogSegment(final ZKTransaction txn, final String logSegmentName, final String logSegmentPath) {
    Op zkOp = Op.delete(logSegmentPath, -1);
    txn.addOp(new ZKOp(zkOp) {

        @Override
        protected void commitOpResult(OpResult opResult) {
            removeLogSegmentFromCache(logSegmentName);
        }

        @Override
        protected void abortOpResult(Throwable t, OpResult opResult) {
        // no-op
        }
    });
}
Also used : Op(org.apache.zookeeper.Op) ZKVersionedSetOp(com.twitter.distributedlog.zk.ZKVersionedSetOp) ZKOp(com.twitter.distributedlog.zk.ZKOp) OpResult(org.apache.zookeeper.OpResult) ZKOp(com.twitter.distributedlog.zk.ZKOp)

Example 3 with ZKOp

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

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

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

Aggregations

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