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
}
});
}
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
}
});
}
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);
}
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);
}
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) {
}
}));
}
}
Aggregations