use of org.apache.bookkeeper.versioning.LongVersion in project bookkeeper by apache.
the class ZKLogSegmentMetadataStore method storeMaxTxnId.
@Override
public void storeMaxTxnId(Transaction<Object> txn, LogMetadataForWriter logMetadata, Versioned<Long> transactionId, Transaction.OpListener<Version> listener) {
Version version = transactionId.getVersion();
assert (version instanceof LongVersion);
LongVersion zkVersion = (LongVersion) version;
byte[] data = DLUtils.serializeTransactionId(transactionId.getValue());
Op setDataOp = Op.setData(logMetadata.getMaxTxIdPath(), data, (int) zkVersion.getLongVersion());
ZKOp zkOp = new ZKVersionedSetOp(setDataOp, listener);
txn.addOp(zkOp);
}
use of org.apache.bookkeeper.versioning.LongVersion in project bookkeeper by apache.
the class ZKLogSegmentMetadataStore method processResult.
@Override
@SuppressWarnings("unchecked")
public void processResult(int rc, String path, Object ctx, List<String> children, Stat stat) {
CompletableFuture<Versioned<List<String>>> result = ((CompletableFuture<Versioned<List<String>>>) ctx);
if (KeeperException.Code.OK.intValue() == rc) {
/**
* cversion: the number of changes to the children of this znode *
*/
LongVersion zkVersion = new LongVersion(stat.getCversion());
result.complete(new Versioned(children, zkVersion));
} else if (KeeperException.Code.NONODE.intValue() == rc) {
result.completeExceptionally(new LogNotFoundException("Log " + path + " not found"));
} else {
result.completeExceptionally(new ZKException("Failed to get log segments from " + path, KeeperException.Code.get(rc)));
}
}
use of org.apache.bookkeeper.versioning.LongVersion in project bookkeeper by apache.
the class TestLogSegmentsZK method getMaxLogSegmentSequenceNo.
private static MaxLogSegmentSequenceNo getMaxLogSegmentSequenceNo(ZooKeeperClient zkc, URI uri, String streamName, DistributedLogConfiguration conf) throws Exception {
Stat stat = new Stat();
String logSegmentsPath = LogMetadata.getLogSegmentsPath(uri, streamName, conf.getUnpartitionedStreamName());
byte[] data = zkc.get().getData(logSegmentsPath, false, stat);
Versioned<byte[]> maxLSSNData = new Versioned<byte[]>(data, new LongVersion(stat.getVersion()));
return new MaxLogSegmentSequenceNo(maxLSSNData);
}
use of org.apache.bookkeeper.versioning.LongVersion in project bookkeeper by apache.
the class AbstractZkLedgerManager method createLedgerMetadata.
@Override
public void createLedgerMetadata(final long ledgerId, final LedgerMetadata metadata, final GenericCallback<Void> ledgerCb) {
String ledgerPath = getLedgerPath(ledgerId);
StringCallback scb = new StringCallback() {
@Override
public void processResult(int rc, String path, Object ctx, String name) {
if (rc == Code.OK.intValue()) {
// update version
metadata.setVersion(new LongVersion(0));
ledgerCb.operationComplete(BKException.Code.OK, null);
} else if (rc == Code.NODEEXISTS.intValue()) {
LOG.warn("Failed to create ledger metadata for {} which already exist", ledgerId);
ledgerCb.operationComplete(BKException.Code.LedgerExistException, null);
} else {
LOG.error("Could not create node for ledger {}", ledgerId, KeeperException.create(Code.get(rc), path));
ledgerCb.operationComplete(BKException.Code.ZKException, null);
}
}
};
List<ACL> zkAcls = ZkUtils.getACLs(conf);
ZkUtils.asyncCreateFullPathOptimistic(zk, ledgerPath, metadata.serialize(), zkAcls, CreateMode.PERSISTENT, scb, null);
}
use of org.apache.bookkeeper.versioning.LongVersion in project bookkeeper by apache.
the class AbstractZkLedgerManager method removeLedgerMetadata.
/**
* Removes ledger metadata from ZooKeeper and deletes its parent znodes
* recursively if they dont have anymore children.
*
* @param ledgerId
* ledger identifier
* @param version
* local version of metadata znode
* @param cb
* callback object
*/
@Override
public void removeLedgerMetadata(final long ledgerId, final Version version, final GenericCallback<Void> cb) {
int znodeVersion = -1;
if (Version.NEW == version) {
LOG.error("Request to delete ledger {} metadata with version set to the initial one", ledgerId);
cb.operationComplete(BKException.Code.MetadataVersionException, (Void) null);
return;
} else if (Version.ANY != version) {
if (!(version instanceof LongVersion)) {
LOG.info("Not an instance of ZKVersion: {}", ledgerId);
cb.operationComplete(BKException.Code.MetadataVersionException, (Void) null);
return;
} else {
znodeVersion = (int) ((LongVersion) version).getLongVersion();
}
}
VoidCallback callbackForDelete = new VoidCallback() {
@Override
public void processResult(int rc, String path, Object ctx) {
int bkRc;
if (rc == KeeperException.Code.NONODE.intValue()) {
LOG.warn("Ledger node does not exist in ZooKeeper: ledgerId={}", ledgerId);
bkRc = BKException.Code.NoSuchLedgerExistsException;
} else if (rc == KeeperException.Code.OK.intValue()) {
// removed listener on ledgerId
Set<LedgerMetadataListener> listenerSet = listeners.remove(ledgerId);
if (null != listenerSet) {
if (LOG.isDebugEnabled()) {
LOG.debug("Remove registered ledger metadata listeners on ledger {} after ledger is deleted.", ledgerId, listenerSet);
}
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("No ledger metadata listeners to remove from ledger {} when it's being deleted.", ledgerId);
}
}
bkRc = BKException.Code.OK;
} else {
bkRc = BKException.Code.ZKException;
}
cb.operationComplete(bkRc, (Void) null);
}
};
String ledgerZnodePath = getLedgerPath(ledgerId);
if (this instanceof HierarchicalLedgerManager || this instanceof LongHierarchicalLedgerManager) {
/*
* do recursive deletes only for HierarchicalLedgerManager and
* LongHierarchicalLedgerManager
*/
ZkUtils.asyncDeleteFullPathOptimistic(zk, ledgerZnodePath, znodeVersion, callbackForDelete, ledgerZnodePath);
} else {
zk.delete(ledgerZnodePath, znodeVersion, callbackForDelete, null);
}
}
Aggregations