use of org.apache.bookkeeper.mledger.ManagedLedgerException.MetaStoreException in project pulsar by yahoo.
the class MetaStoreImplZookeeper method asyncGetCursorInfo.
@Override
public void asyncGetCursorInfo(String ledgerName, String consumerName, final MetaStoreCallback<ManagedCursorInfo> callback) {
String path = prefix + ledgerName + "/" + consumerName;
if (log.isDebugEnabled()) {
log.debug("Reading from {}", path);
}
zk.getData(path, false, (rc, path1, ctx, data, stat) -> executor.submit(safeRun(() -> {
if (rc != Code.OK.intValue()) {
callback.operationFailed(new MetaStoreException(KeeperException.create(Code.get(rc))));
} else {
try {
ManagedCursorInfo info = parseManagedCursorInfo(data);
callback.operationComplete(info, new ZKStat(stat));
} catch (ParseException | InvalidProtocolBufferException e) {
callback.operationFailed(new MetaStoreException(e));
}
}
})), null);
if (log.isDebugEnabled()) {
log.debug("Reading from {} ok", path);
}
}
use of org.apache.bookkeeper.mledger.ManagedLedgerException.MetaStoreException in project pulsar by yahoo.
the class MetaStoreImplZookeeper method asyncRemoveCursor.
@Override
public void asyncRemoveCursor(final String ledgerName, final String consumerName, final MetaStoreCallback<Void> callback) {
log.info("[{}] Remove consumer={}", ledgerName, consumerName);
zk.delete(prefix + ledgerName + "/" + consumerName, -1, (rc, path, ctx) -> executor.submit(safeRun(() -> {
if (log.isDebugEnabled()) {
log.debug("[{}] [{}] zk delete done. rc={}", ledgerName, consumerName, Code.get(rc));
}
if (rc == Code.OK.intValue()) {
callback.operationComplete(null, null);
} else {
callback.operationFailed(new MetaStoreException(KeeperException.create(Code.get(rc))));
}
})), null);
}
use of org.apache.bookkeeper.mledger.ManagedLedgerException.MetaStoreException in project pulsar by yahoo.
the class MetaStoreImplZookeeper method getManagedLedgerInfo.
@Override
public void getManagedLedgerInfo(final String ledgerName, final MetaStoreCallback<ManagedLedgerInfo> callback) {
// Try to get the content or create an empty node
zk.getData(prefix + ledgerName, false, (rc, path, ctx, readData, stat) -> executor.submit(safeRun(() -> {
if (rc == Code.OK.intValue()) {
try {
ManagedLedgerInfo info = parseManagedLedgerInfo(readData);
info = updateMLInfoTimestamp(info);
callback.operationComplete(info, new ZKStat(stat));
} catch (ParseException | InvalidProtocolBufferException e) {
callback.operationFailed(new MetaStoreException(e));
}
} else if (rc == Code.NONODE.intValue()) {
log.info("Creating '{}{}'", prefix, ledgerName);
StringCallback createcb = (rc1, path1, ctx1, name) -> {
if (rc1 == Code.OK.intValue()) {
ManagedLedgerInfo info = ManagedLedgerInfo.getDefaultInstance();
callback.operationComplete(info, new ZKStat());
} else {
callback.operationFailed(new MetaStoreException(KeeperException.create(Code.get(rc1))));
}
};
ZkUtils.asyncCreateFullPathOptimistic(zk, prefix + ledgerName, new byte[0], Acl, CreateMode.PERSISTENT, createcb, null);
} else {
callback.operationFailed(new MetaStoreException(KeeperException.create(Code.get(rc))));
}
})), null);
}
use of org.apache.bookkeeper.mledger.ManagedLedgerException.MetaStoreException in project pulsar by yahoo.
the class MetaStoreImplZookeeper method removeManagedLedger.
@Override
public void removeManagedLedger(String ledgerName, MetaStoreCallback<Void> callback) {
log.info("[{}] Remove ManagedLedger", ledgerName);
zk.delete(prefix + ledgerName, -1, (rc, path, ctx) -> executor.submit(safeRun(() -> {
if (log.isDebugEnabled()) {
log.debug("[{}] zk delete done. rc={}", ledgerName, Code.get(rc));
}
if (rc == Code.OK.intValue()) {
callback.operationComplete(null, null);
} else {
callback.operationFailed(new MetaStoreException(KeeperException.create(Code.get(rc))));
}
})), null);
}
use of org.apache.bookkeeper.mledger.ManagedLedgerException.MetaStoreException in project pulsar by yahoo.
the class MetaStoreImplZookeeperTest method updatingMLNode.
@Test(timeOut = 20000)
void updatingMLNode() throws Exception {
final MetaStore store = new MetaStoreImplZookeeper(zkc, executor);
zkc.create("/managed-ledgers/my_test", "".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
final CountDownLatch latch = new CountDownLatch(1);
store.getManagedLedgerInfo("my_test", new MetaStoreCallback<ManagedLedgerInfo>() {
public void operationFailed(MetaStoreException e) {
fail("should have succeeded");
}
public void operationComplete(ManagedLedgerInfo mlInfo, Stat version) {
// Update again using the version
zkc.failNow(Code.BADVERSION);
store.asyncUpdateLedgerIds("my_test", mlInfo, version, new MetaStoreCallback<Void>() {
public void operationFailed(MetaStoreException e) {
// ok
latch.countDown();
}
@Override
public void operationComplete(Void result, Stat version) {
fail("should have failed");
}
});
}
});
latch.await();
}
Aggregations