use of org.apache.bookkeeper.versioning.LongVersion in project bookkeeper by apache.
the class ZKSubscriptionsStore method deleteSubscriber.
@Override
public CompletableFuture<Boolean> deleteSubscriber(String subscriberId) {
subscribers.remove(subscriberId);
String path = getSubscriberZKPath(subscriberId);
return Utils.zkDeleteIfNotExist(zkc, path, new LongVersion(-1L));
}
use of org.apache.bookkeeper.versioning.LongVersion in project bookkeeper by apache.
the class ZKLogStreamMetadataStore method executeCreateMissingPathTxn.
private static void executeCreateMissingPathTxn(ZooKeeper zk, List<Op> zkOps, List<byte[]> pathsToCreate, List<Versioned<byte[]>> metadatas, String logRootPath, CompletableFuture<List<Versioned<byte[]>>> promise) {
zk.multi(zkOps, new AsyncCallback.MultiCallback() {
@Override
public void processResult(int rc, String path, Object ctx, List<OpResult> resultList) {
if (KeeperException.Code.OK.intValue() == rc) {
List<Versioned<byte[]>> finalMetadatas = Lists.newArrayListWithExpectedSize(metadatas.size());
for (int i = 0; i < pathsToCreate.size(); i++) {
byte[] dataCreated = pathsToCreate.get(i);
if (null == dataCreated) {
finalMetadatas.add(metadatas.get(i));
} else {
finalMetadatas.add(new Versioned<byte[]>(dataCreated, new LongVersion(0)));
}
}
promise.complete(finalMetadatas);
} else if (KeeperException.Code.NODEEXISTS.intValue() == rc) {
promise.completeExceptionally(new LogExistsException("Someone just created log " + logRootPath));
} else {
if (LOG.isDebugEnabled()) {
StringBuilder builder = new StringBuilder();
for (OpResult result : resultList) {
if (result instanceof OpResult.ErrorResult) {
OpResult.ErrorResult errorResult = (OpResult.ErrorResult) result;
builder.append(errorResult.getErr()).append(",");
} else {
builder.append(0).append(",");
}
}
String resultCodeList = builder.substring(0, builder.length() - 1);
LOG.debug("Failed to create log, full rc list = {}", resultCodeList);
}
promise.completeExceptionally(new ZKException("Failed to create log " + logRootPath, KeeperException.Code.get(rc)));
}
}
}, null);
}
use of org.apache.bookkeeper.versioning.LongVersion in project bookkeeper by apache.
the class Utils method zkGetData.
/**
* Retrieve data from zookeeper <code>path</code>.
*
* @param path
* zookeeper path to retrieve data
* @param watch
* whether to watch the path
* @return future representing the versioned value. null version or null value means path doesn't exist.
*/
public static CompletableFuture<Versioned<byte[]>> zkGetData(ZooKeeper zk, String path, boolean watch) {
final CompletableFuture<Versioned<byte[]>> promise = new CompletableFuture<Versioned<byte[]>>();
zk.getData(path, watch, new AsyncCallback.DataCallback() {
@Override
public void processResult(int rc, String path, Object ctx, byte[] data, Stat stat) {
if (KeeperException.Code.OK.intValue() == rc) {
if (null == stat) {
promise.complete(new Versioned<byte[]>(null, null));
} else {
promise.complete(new Versioned<byte[]>(data, new LongVersion(stat.getVersion())));
}
} else if (KeeperException.Code.NONODE.intValue() == rc) {
promise.complete(new Versioned<byte[]>(null, null));
} else {
promise.completeExceptionally(KeeperException.create(KeeperException.Code.get(rc)));
}
}
}, null);
return promise;
}
use of org.apache.bookkeeper.versioning.LongVersion in project bookkeeper by apache.
the class SimpleLedgerAllocator method createAllocationData.
private static CompletableFuture<Versioned<byte[]>> createAllocationData(final String allocatePath, final ZooKeeperClient zkc) {
try {
final CompletableFuture<Versioned<byte[]>> promise = new CompletableFuture<Versioned<byte[]>>();
zkc.get().create(allocatePath, DistributedLogConstants.EMPTY_BYTES, zkc.getDefaultACL(), CreateMode.PERSISTENT, new org.apache.zookeeper.AsyncCallback.Create2Callback() {
@Override
public void processResult(int rc, String path, Object ctx, String name, Stat stat) {
if (KeeperException.Code.OK.intValue() == rc) {
promise.complete(new Versioned<byte[]>(DistributedLogConstants.EMPTY_BYTES, new LongVersion(stat.getVersion())));
} else if (KeeperException.Code.NODEEXISTS.intValue() == rc) {
FutureUtils.proxyTo(Utils.zkGetData(zkc, allocatePath, false), promise);
} else {
promise.completeExceptionally(Utils.zkException(KeeperException.create(KeeperException.Code.get(rc)), allocatePath));
}
}
}, null);
return promise;
} catch (ZooKeeperClient.ZooKeeperConnectionException e) {
return FutureUtils.exception(Utils.zkException(e, allocatePath));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return FutureUtils.exception(Utils.zkException(e, allocatePath));
}
}
use of org.apache.bookkeeper.versioning.LongVersion in project bookkeeper by apache.
the class ZKLogSegmentMetadataStore method storeMaxLogSegmentSequenceNumber.
// max sequence number and max transaction id
@Override
public void storeMaxLogSegmentSequenceNumber(Transaction<Object> txn, LogMetadata logMetadata, Versioned<Long> lssn, Transaction.OpListener<Version> listener) {
Version version = lssn.getVersion();
assert (version instanceof LongVersion);
LongVersion zkVersion = (LongVersion) version;
byte[] data = DLUtils.serializeLogSegmentSequenceNumber(lssn.getValue());
Op setDataOp = Op.setData(logMetadata.getLogSegmentsPath(), data, (int) zkVersion.getLongVersion());
ZKOp zkOp = new ZKVersionedSetOp(setDataOp, listener);
txn.addOp(zkOp);
}
Aggregations