Search in sources :

Example 6 with MetaStoreException

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);
    }
}
Also used : MetaStoreException(org.apache.bookkeeper.mledger.ManagedLedgerException.MetaStoreException) ManagedCursorInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedCursorInfo) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ParseException(com.google.protobuf.TextFormat.ParseException)

Example 7 with MetaStoreException

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);
}
Also used : MetaStoreException(org.apache.bookkeeper.mledger.ManagedLedgerException.MetaStoreException)

Example 8 with MetaStoreException

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);
}
Also used : MetaStoreException(org.apache.bookkeeper.mledger.ManagedLedgerException.MetaStoreException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) StringCallback(org.apache.zookeeper.AsyncCallback.StringCallback) ParseException(com.google.protobuf.TextFormat.ParseException) ManagedLedgerInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo)

Example 9 with MetaStoreException

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);
}
Also used : MetaStoreException(org.apache.bookkeeper.mledger.ManagedLedgerException.MetaStoreException)

Example 10 with MetaStoreException

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();
}
Also used : MetaStoreException(org.apache.bookkeeper.mledger.ManagedLedgerException.MetaStoreException) Stat(org.apache.bookkeeper.mledger.impl.MetaStore.Stat) MetaStoreCallback(org.apache.bookkeeper.mledger.impl.MetaStore.MetaStoreCallback) CountDownLatch(java.util.concurrent.CountDownLatch) ManagedLedgerInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo) Test(org.testng.annotations.Test)

Aggregations

MetaStoreException (org.apache.bookkeeper.mledger.ManagedLedgerException.MetaStoreException)19 Stat (org.apache.bookkeeper.mledger.impl.MetaStore.Stat)13 CountDownLatch (java.util.concurrent.CountDownLatch)9 ManagedLedgerInfo (org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo)9 Test (org.testng.annotations.Test)8 MetaStoreCallback (org.apache.bookkeeper.mledger.impl.MetaStore.MetaStoreCallback)6 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)5 LedgerInfo (org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo.LedgerInfo)5 BadVersionException (org.apache.bookkeeper.mledger.ManagedLedgerException.BadVersionException)4 ManagedCursorInfo (org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedCursorInfo)3 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)2 ParseException (com.google.protobuf.TextFormat.ParseException)2 OpenCallback (org.apache.bookkeeper.client.AsyncCallback.OpenCallback)2 ManagedLedger (org.apache.bookkeeper.mledger.ManagedLedger)2 ManagedLedgerConfig (org.apache.bookkeeper.mledger.ManagedLedgerConfig)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 BoundType (com.google.common.collect.BoundType)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Queues (com.google.common.collect.Queues)1