Search in sources :

Example 1 with ManagedCursorInfo

use of org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedCursorInfo 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 2 with ManagedCursorInfo

use of org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedCursorInfo in project pulsar by yahoo.

the class MetaStoreImplZookeeperTest method updatingCursorNode.

@Test(timeOut = 20000)
void updatingCursorNode() 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);
    ManagedCursorInfo info = ManagedCursorInfo.newBuilder().setCursorsLedgerId(1).build();
    store.asyncUpdateCursorInfo("my_test", "c1", info, null, new MetaStoreCallback<Void>() {

        public void operationFailed(MetaStoreException e) {
            fail("should have succeeded");
        }

        public void operationComplete(Void result, Stat version) {
            // Update again using the version
            zkc.failNow(Code.CONNECTIONLOSS);
            ManagedCursorInfo info = ManagedCursorInfo.newBuilder().setCursorsLedgerId(2).build();
            store.asyncUpdateCursorInfo("my_test", "c1", info, 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) ManagedCursorInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedCursorInfo) MetaStoreCallback(org.apache.bookkeeper.mledger.impl.MetaStore.MetaStoreCallback) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.testng.annotations.Test)

Example 3 with ManagedCursorInfo

use of org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedCursorInfo in project pulsar by yahoo.

the class MetaStoreImplZookeeperTest method readMalformedCursorNode.

@Test(timeOut = 20000)
void readMalformedCursorNode() throws Exception {
    MetaStore store = new MetaStoreImplZookeeper(zkc, executor);
    zkc.create("/managed-ledgers/my_test", "".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    zkc.create("/managed-ledgers/my_test/c1", "non-valid".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    final CountDownLatch latch = new CountDownLatch(1);
    store.asyncGetCursorInfo("my_test", "c1", new MetaStoreCallback<MLDataFormats.ManagedCursorInfo>() {

        public void operationFailed(MetaStoreException e) {
            // Ok
            latch.countDown();
        }

        public void operationComplete(ManagedCursorInfo result, Stat version) {
            fail("Operation should have failed");
        }
    });
    latch.await();
}
Also used : MetaStoreException(org.apache.bookkeeper.mledger.ManagedLedgerException.MetaStoreException) Stat(org.apache.bookkeeper.mledger.impl.MetaStore.Stat) ManagedCursorInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedCursorInfo) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.testng.annotations.Test)

Example 4 with ManagedCursorInfo

use of org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedCursorInfo in project incubator-pulsar by apache.

the class ManagedCursorTest method testOutOfOrderDeletePersistenceIntoZkWithClose.

/**
 * Close Cursor without MaxUnackedRangesToPersistInZK: It should store individually unack range into Zk
 *
 * @throws Exception
 */
@Test(timeOut = 20000)
public void testOutOfOrderDeletePersistenceIntoZkWithClose() throws Exception {
    final int totalAddEntries = 100;
    String ledgerName = "my_test_ledger_zk";
    String cursorName = "c1";
    ManagedLedgerConfig managedLedgerConfig = new ManagedLedgerConfig();
    ManagedLedgerImpl ledger = (ManagedLedgerImpl) factory.open(ledgerName, managedLedgerConfig);
    ManagedCursorImpl c1 = (ManagedCursorImpl) ledger.openCursor(cursorName);
    List<Position> addedPositions = new ArrayList<>();
    for (int i = 0; i < totalAddEntries; i++) {
        Position p = ledger.addEntry(("dummy-entry-" + i).getBytes(Encoding));
        addedPositions.add(p);
        if (i % 2 == 0) {
            // Acknowledge alternative message to create totalEntries/2 holes
            c1.delete(addedPositions.get(i));
        }
    }
    assertEquals(c1.getNumberOfEntriesInBacklog(), totalAddEntries / 2);
    // Close ledger to persist individual-deleted positions into cursor-ledger
    ledger.close();
    // verify cursor-ledgerId is updated as -1 into cursor-metaStore
    CountDownLatch latch = new CountDownLatch(1);
    AtomicInteger individualDeletedMessagesCount = new AtomicInteger(0);
    ledger.getStore().asyncGetCursorInfo(ledger.getName(), cursorName, new MetaStoreCallback<ManagedCursorInfo>() {

        @Override
        public void operationComplete(ManagedCursorInfo result, Stat stat) {
            individualDeletedMessagesCount.set(result.getIndividualDeletedMessagesCount());
            latch.countDown();
        }

        @Override
        public void operationFailed(MetaStoreException e) {
            latch.countDown();
        }
    });
    latch.await();
    assertEquals(individualDeletedMessagesCount.get(), totalAddEntries / 2 - 1);
    // Re-Open
    factory = new ManagedLedgerFactoryImpl(bkc, bkc.getZkHandle());
    ledger = (ManagedLedgerImpl) factory.open(ledgerName, managedLedgerConfig);
    c1 = (ManagedCursorImpl) ledger.openCursor(cursorName);
    // verify cursor has been recovered
    assertEquals(c1.getNumberOfEntriesInBacklog(), totalAddEntries / 2);
    // try to read entries which should only read non-deleted positions
    List<Entry> entries = c1.readEntries(totalAddEntries);
    assertEquals(entries.size(), totalAddEntries / 2);
}
Also used : Position(org.apache.bookkeeper.mledger.Position) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) MetaStoreException(org.apache.bookkeeper.mledger.ManagedLedgerException.MetaStoreException) Entry(org.apache.bookkeeper.mledger.Entry) LedgerEntry(org.apache.bookkeeper.client.LedgerEntry) Stat(org.apache.bookkeeper.mledger.impl.MetaStore.Stat) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ManagedCursorInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedCursorInfo) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) Test(org.testng.annotations.Test)

Example 5 with ManagedCursorInfo

use of org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedCursorInfo in project incubator-pulsar by apache.

the class MetaStoreImplZookeeperTest method readMalformedCursorNode.

@Test(timeOut = 20000)
void readMalformedCursorNode() throws Exception {
    MetaStore store = new MetaStoreImplZookeeper(zkc, executor);
    zkc.create("/managed-ledgers/my_test", "".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    zkc.create("/managed-ledgers/my_test/c1", "non-valid".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    final CountDownLatch latch = new CountDownLatch(1);
    store.asyncGetCursorInfo("my_test", "c1", new MetaStoreCallback<MLDataFormats.ManagedCursorInfo>() {

        public void operationFailed(MetaStoreException e) {
            // Ok
            latch.countDown();
        }

        public void operationComplete(ManagedCursorInfo result, Stat version) {
            fail("Operation should have failed");
        }
    });
    latch.await();
}
Also used : MetaStoreException(org.apache.bookkeeper.mledger.ManagedLedgerException.MetaStoreException) Stat(org.apache.bookkeeper.mledger.impl.MetaStore.Stat) ManagedCursorInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedCursorInfo) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.testng.annotations.Test)

Aggregations

MetaStoreException (org.apache.bookkeeper.mledger.ManagedLedgerException.MetaStoreException)9 ManagedCursorInfo (org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedCursorInfo)9 Stat (org.apache.bookkeeper.mledger.impl.MetaStore.Stat)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 Test (org.testng.annotations.Test)6 ArrayList (java.util.ArrayList)3 MetaStoreCallback (org.apache.bookkeeper.mledger.impl.MetaStore.MetaStoreCallback)3 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)2 ParseException (com.google.protobuf.TextFormat.ParseException)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 LedgerEntry (org.apache.bookkeeper.client.LedgerEntry)2 Entry (org.apache.bookkeeper.mledger.Entry)2 ManagedLedgerConfig (org.apache.bookkeeper.mledger.ManagedLedgerConfig)2 Position (org.apache.bookkeeper.mledger.Position)2 List (java.util.List)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 BKException (org.apache.bookkeeper.client.BKException)1 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)1 ManagedLedgerInfo (org.apache.bookkeeper.mledger.ManagedLedgerInfo)1