Search in sources :

Example 11 with LedgerInfo

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

the class ManagedLedgerTest method cursorReadsWithDiscardedEmptyLedgersStillListed.

@Test
public void cursorReadsWithDiscardedEmptyLedgersStillListed() throws Exception {
    ManagedLedgerImpl ledger = (ManagedLedgerImpl) factory.open("my_test_ledger");
    ManagedCursor c1 = ledger.openCursor("c1");
    ledger.addEntry("entry-1".getBytes());
    ledger.close();
    ledger = (ManagedLedgerImpl) factory.open("my_test_ledger");
    c1 = ledger.openCursor("c1");
    ledger.addEntry("entry-2".getBytes());
    final LedgerInfo l1info = ledger.getLedgersInfoAsList().get(0);
    final LedgerInfo l2info = ledger.getLedgersInfoAsList().get(1);
    ledger.close();
    // Add the deleted ledger back in the meta-data to simulate an empty ledger that was deleted but not removed
    // from the list of ledgers
    final CountDownLatch counter = new CountDownLatch(1);
    final MetaStore store = factory.getMetaStore();
    store.getManagedLedgerInfo("my_test_ledger", new MetaStoreCallback<ManagedLedgerInfo>() {

        @Override
        public void operationComplete(ManagedLedgerInfo result, Stat version) {
            // Update the list
            ManagedLedgerInfo.Builder info = ManagedLedgerInfo.newBuilder(result);
            info.clearLedgerInfo();
            info.addLedgerInfo(LedgerInfo.newBuilder().setLedgerId(l1info.getLedgerId()).build());
            info.addLedgerInfo(l2info);
            store.asyncUpdateLedgerIds("my_test_ledger", info.build(), version, new MetaStoreCallback<Void>() {

                @Override
                public void operationComplete(Void result, Stat version) {
                    counter.countDown();
                }

                @Override
                public void operationFailed(MetaStoreException e) {
                    counter.countDown();
                }
            });
        }

        @Override
        public void operationFailed(MetaStoreException e) {
            counter.countDown();
        }
    });
    // Wait for the change to be effective
    counter.await();
    // Delete the ledger and mantain it in the ledgers list
    bkc.deleteLedger(l1info.getLedgerId());
    // re-open
    ledger = (ManagedLedgerImpl) factory.open("my_test_ledger");
    c1 = ledger.openCursor("c1");
    assertEquals(c1.getNumberOfEntries(), 1);
    assertEquals(c1.hasMoreEntries(), true);
    assertEquals(ledger.getLedgersInfoAsList().size(), 2);
    List<Entry> entries = c1.readEntries(10);
    assertEquals(entries.size(), 1);
    entries.forEach(e -> e.release());
    assertEquals(c1.hasMoreEntries(), false);
    entries = c1.readEntries(1);
    assertEquals(entries.size(), 0);
    entries.forEach(e -> e.release());
}
Also used : MetaStoreCallback(org.apache.bookkeeper.mledger.impl.MetaStore.MetaStoreCallback) CountDownLatch(java.util.concurrent.CountDownLatch) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) ManagedLedgerInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo) ManagedLedgerInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo) LedgerInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo.LedgerInfo) MetaStoreException(org.apache.bookkeeper.mledger.ManagedLedgerException.MetaStoreException) Entry(org.apache.bookkeeper.mledger.Entry) Stat(org.apache.bookkeeper.mledger.impl.MetaStore.Stat) Test(org.testng.annotations.Test)

Aggregations

ManagedLedgerInfo (org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo)11 LedgerInfo (org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo.LedgerInfo)11 MetaStoreException (org.apache.bookkeeper.mledger.ManagedLedgerException.MetaStoreException)7 Stat (org.apache.bookkeeper.mledger.impl.MetaStore.Stat)7 CountDownLatch (java.util.concurrent.CountDownLatch)5 MetaStoreCallback (org.apache.bookkeeper.mledger.impl.MetaStore.MetaStoreCallback)5 OpenCallback (org.apache.bookkeeper.client.AsyncCallback.OpenCallback)4 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)4 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)3 BoundType (com.google.common.collect.BoundType)3 Lists (com.google.common.collect.Lists)3 Maps (com.google.common.collect.Maps)3 Queues (com.google.common.collect.Queues)3 Range (com.google.common.collect.Range)3 RateLimiter (com.google.common.util.concurrent.RateLimiter)3 Commands (com.yahoo.pulsar.common.api.Commands)3 MessageMetadata (com.yahoo.pulsar.common.api.proto.PulsarApi.MessageMetadata)3 ConcurrentLongHashMap (com.yahoo.pulsar.common.util.collections.ConcurrentLongHashMap)3 ByteBuf (io.netty.buffer.ByteBuf)3 Unpooled (io.netty.buffer.Unpooled)3