Search in sources :

Example 6 with MetaStoreCallback

use of org.apache.bookkeeper.mledger.impl.MetaStore.MetaStoreCallback 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

MetaStoreException (org.apache.bookkeeper.mledger.ManagedLedgerException.MetaStoreException)6 MetaStoreCallback (org.apache.bookkeeper.mledger.impl.MetaStore.MetaStoreCallback)6 Stat (org.apache.bookkeeper.mledger.impl.MetaStore.Stat)6 CountDownLatch (java.util.concurrent.CountDownLatch)4 ManagedLedgerInfo (org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo)4 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)3 LedgerInfo (org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo.LedgerInfo)3 Test (org.testng.annotations.Test)3 BadVersionException (org.apache.bookkeeper.mledger.ManagedLedgerException.BadVersionException)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 Range (com.google.common.collect.Range)1 RateLimiter (com.google.common.util.concurrent.RateLimiter)1 Commands (com.yahoo.pulsar.common.api.Commands)1 MessageMetadata (com.yahoo.pulsar.common.api.proto.PulsarApi.MessageMetadata)1 ConcurrentLongHashMap (com.yahoo.pulsar.common.util.collections.ConcurrentLongHashMap)1 ByteBuf (io.netty.buffer.ByteBuf)1