Search in sources :

Example 6 with ManagedLedgerInfo

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

the class MetaStoreImplZookeeperTest method readMalformedML.

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

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

        public void operationComplete(ManagedLedgerInfo 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) CountDownLatch(java.util.concurrent.CountDownLatch) ManagedLedgerInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo) Test(org.testng.annotations.Test)

Example 7 with ManagedLedgerInfo

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

the class MetaStoreImplZookeeperTest method failInCreatingMLnode.

@Test(timeOut = 20000)
void failInCreatingMLnode() throws Exception {
    MetaStore store = new MetaStoreImplZookeeper(zkc, executor);
    final CountDownLatch latch = new CountDownLatch(1);
    zkc.failAfter(1, Code.CONNECTIONLOSS);
    store.getManagedLedgerInfo("my_test", new MetaStoreCallback<MLDataFormats.ManagedLedgerInfo>() {

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

        public void operationComplete(ManagedLedgerInfo 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) CountDownLatch(java.util.concurrent.CountDownLatch) ManagedLedgerInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo) Test(org.testng.annotations.Test)

Example 8 with ManagedLedgerInfo

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

the class ManagedLedgerTest method testBackwardCompatiblityForMeta.

@Test
public void testBackwardCompatiblityForMeta() throws Exception {
    final ManagedLedgerInfo[] storedMLInfo = new ManagedLedgerInfo[3];
    final Stat[] versions = new Stat[1];
    ManagedLedgerFactory factory = new ManagedLedgerFactoryImpl(bkc, bkc.getZkHandle());
    ManagedLedgerConfig conf = new ManagedLedgerConfig();
    conf.setMaxEntriesPerLedger(1);
    conf.setRetentionSizeInMB(10);
    conf.setRetentionTime(1, TimeUnit.HOURS);
    ManagedLedger ml = factory.open("backward_test_ledger", conf);
    ml.openCursor("c1");
    ml.addEntry("msg1".getBytes());
    ml.addEntry("msg2".getBytes());
    ml.close();
    MetaStore store = new MetaStoreImplZookeeper(zkc, executor);
    CountDownLatch l1 = new CountDownLatch(1);
    // obtain the ledger info
    store.getManagedLedgerInfo("backward_test_ledger", new MetaStoreCallback<ManagedLedgerInfo>() {

        @Override
        public void operationComplete(ManagedLedgerInfo result, Stat version) {
            storedMLInfo[0] = result;
            versions[0] = version;
            l1.countDown();
        }

        @Override
        public void operationFailed(MetaStoreException e) {
            fail("on get ManagedLedgerInfo backward_test_ledger");
        }
    });
    l1.await();
    ManagedLedgerInfo.Builder builder1 = ManagedLedgerInfo.newBuilder();
    // simulate test for old ledger with no timestampl
    for (LedgerInfo info : storedMLInfo[0].getLedgerInfoList()) {
        LedgerInfo noTimestamp = ManagedLedgerInfo.LedgerInfo.newBuilder().mergeFrom(info).clearTimestamp().build();
        assertFalse(noTimestamp.hasTimestamp(), "expected old version info with no timestamp");
        builder1.addLedgerInfo(noTimestamp);
    }
    storedMLInfo[1] = builder1.build();
    // test timestamp on new ledger
    CountDownLatch l2 = new CountDownLatch(1);
    store.asyncUpdateLedgerIds("backward_test_ledger", storedMLInfo[1], versions[0], new MetaStoreCallback<Void>() {

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

        @Override
        public void operationFailed(MetaStoreException e) {
            fail("on asyncUpdateLedgerIds");
        }
    });
    // verify that after update ledgers have timestamp
    ManagedLedgerImpl newVersionLedger = (ManagedLedgerImpl) factory.open("backward_test_ledger", conf);
    List<LedgerInfo> mlInfo = newVersionLedger.getLedgersInfoAsList();
    assertTrue(mlInfo.stream().allMatch(new Predicate<LedgerInfo>() {

        @Override
        public boolean test(LedgerInfo ledgerInfo) {
            return ledgerInfo.hasTimestamp();
        }
    }));
}
Also used : ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) CountDownLatch(java.util.concurrent.CountDownLatch) ManagedLedgerInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo) Predicate(java.util.function.Predicate) ManagedLedgerInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo) LedgerInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo.LedgerInfo) MetaStoreException(org.apache.bookkeeper.mledger.ManagedLedgerException.MetaStoreException) Stat(org.apache.bookkeeper.mledger.impl.MetaStore.Stat) ManagedLedgerFactory(org.apache.bookkeeper.mledger.ManagedLedgerFactory) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) Test(org.testng.annotations.Test)

Example 9 with ManagedLedgerInfo

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

the class ManagedLedgerImpl method updateLedgersListAfterRollover.

private void updateLedgersListAfterRollover(MetaStoreCallback<Void> callback) {
    if (!ledgersListMutex.tryLock()) {
        // Defer update for later
        scheduledExecutor.schedule(() -> updateLedgersListAfterRollover(callback), 100, TimeUnit.MILLISECONDS);
        return;
    }
    ManagedLedgerInfo mlInfo = ManagedLedgerInfo.newBuilder().addAllLedgerInfo(ledgers.values()).build();
    if (log.isDebugEnabled()) {
        log.debug("[{}] Updating ledgers ids with new ledger. version={}", name, ledgersStat);
    }
    store.asyncUpdateLedgerIds(name, mlInfo, ledgersStat, callback);
}
Also used : ManagedLedgerInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo)

Example 10 with ManagedLedgerInfo

use of org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo 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)10 MetaStoreException (org.apache.bookkeeper.mledger.ManagedLedgerException.MetaStoreException)9 Stat (org.apache.bookkeeper.mledger.impl.MetaStore.Stat)8 CountDownLatch (java.util.concurrent.CountDownLatch)6 LedgerInfo (org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo.LedgerInfo)5 Test (org.testng.annotations.Test)5 MetaStoreCallback (org.apache.bookkeeper.mledger.impl.MetaStore.MetaStoreCallback)4 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)3 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 Range (com.google.common.collect.Range)1 RateLimiter (com.google.common.util.concurrent.RateLimiter)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 ParseException (com.google.protobuf.TextFormat.ParseException)1