Search in sources :

Example 11 with LedgerRangeIterator

use of org.apache.bookkeeper.meta.LedgerManager.LedgerRangeIterator in project bookkeeper by apache.

the class LedgerManagerIteratorTest method testIterateNoLedgers.

@Test
public void testIterateNoLedgers() throws Exception {
    LedgerManager lm = getLedgerManager();
    LedgerRangeIterator lri = lm.getLedgerRanges();
    assertNotNull(lri);
    if (lri.hasNext()) {
        lri.next();
    }
    assertEquals(false, lri.hasNext());
}
Also used : LedgerRangeIterator(org.apache.bookkeeper.meta.LedgerManager.LedgerRangeIterator) Test(org.junit.Test)

Example 12 with LedgerRangeIterator

use of org.apache.bookkeeper.meta.LedgerManager.LedgerRangeIterator in project bookkeeper by apache.

the class LedgerManagerIteratorTest method testRemovalOfNodeJustTraversed.

@Test
public void testRemovalOfNodeJustTraversed() throws Throwable {
    if (baseConf.getLedgerManagerFactoryClass() != LongHierarchicalLedgerManagerFactory.class) {
        return;
    }
    LedgerManager lm = getLedgerManager();
    /* For LHLM, first two should be leaves on the same node, second should be on adjacent level 4 node
         * Removing all 3 once the iterator hits the first should result in the whole tree path ending
         * at that node disappearing.  If this happens after the iterator stops at that leaf, it should
         * result in a few NodeExists errors (handled silently) as the iterator fails back up the tree
         * to the next path.
         */
    Set<Long> toRemove = new TreeSet<>(Arrays.asList(3394498498348983841L, 3394498498348983842L, 3394498498348993841L));
    long first = 2345678901234567890L;
    // Nodes which should be listed anyway
    Set<Long> mustHave = new TreeSet<>(Arrays.asList(first, 6334994393848474732L));
    Set<Long> ids = new TreeSet<>();
    ids.addAll(toRemove);
    ids.addAll(mustHave);
    for (Long id : ids) {
        createLedger(lm, id, Optional.of(BKException.Code.OK));
    }
    Set<Long> found = new TreeSet<>();
    LedgerRangeIterator lri = lm.getLedgerRanges();
    while (lri.hasNext()) {
        LedgerManager.LedgerRange lr = lri.next();
        found.addAll(lr.getLedgers());
        if (lr.getLedgers().contains(first)) {
            for (long id : toRemove) {
                removeLedger(lm, id, Optional.of(BKException.Code.OK));
            }
            toRemove.clear();
        }
    }
    for (long id : mustHave) {
        assertTrue(found.contains(id));
    }
}
Also used : LedgerRangeIterator(org.apache.bookkeeper.meta.LedgerManager.LedgerRangeIterator) TreeSet(java.util.TreeSet) Test(org.junit.Test)

Example 13 with LedgerRangeIterator

use of org.apache.bookkeeper.meta.LedgerManager.LedgerRangeIterator in project bookkeeper by apache.

the class LedgerManagerIteratorTest method testSeveralContiguousLedgers.

@Test
public void testSeveralContiguousLedgers() throws Throwable {
    LedgerManager lm = getLedgerManager();
    Set<Long> ids = new TreeSet<>();
    for (long i = 0; i < 2000; ++i) {
        createLedger(lm, i, Optional.of(BKException.Code.OK));
        ids.add(i);
    }
    LedgerRangeIterator lri = lm.getLedgerRanges();
    assertNotNull(lri);
    Set<Long> returnedIds = ledgerRangeToSet(lri);
    assertEquals(ids, returnedIds);
    Set<Long> ledgersReadAsync = getLedgerIdsByUsingAsyncProcessLedgers(lm);
    assertEquals("Comparing LedgersIds read asynchronously", ids, ledgersReadAsync);
}
Also used : LedgerRangeIterator(org.apache.bookkeeper.meta.LedgerManager.LedgerRangeIterator) TreeSet(java.util.TreeSet) Test(org.junit.Test)

Example 14 with LedgerRangeIterator

use of org.apache.bookkeeper.meta.LedgerManager.LedgerRangeIterator in project bookkeeper by apache.

the class LedgerManagerIteratorTest method validateEmptyL4PathSkipped.

@Test
public void validateEmptyL4PathSkipped() throws Throwable {
    if (baseConf.getLedgerManagerFactoryClass() != LongHierarchicalLedgerManagerFactory.class) {
        return;
    }
    LedgerManager lm = getLedgerManager();
    Set<Long> ids = new TreeSet<>(Arrays.asList(2345678901234567890L, 3394498498348983841L, 6334994393848474732L, 7349370101927398483L));
    for (Long id : ids) {
        createLedger(lm, id, Optional.of(BKException.Code.OK));
    }
    String[] paths = { // Empty L4 path, must be skipped
    "/ledgers/633/4994/3938/4948" };
    for (String path : paths) {
        ZkUtils.createFullPathOptimistic(zkc, path, "data".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    }
    LedgerRangeIterator lri = lm.getLedgerRanges();
    assertNotNull(lri);
    Set<Long> returnedIds = ledgerRangeToSet(lri);
    assertEquals(ids, returnedIds);
    Set<Long> ledgersReadAsync = getLedgerIdsByUsingAsyncProcessLedgers(lm);
    assertEquals("Comparing LedgersIds read asynchronously", ids, ledgersReadAsync);
    lri = lm.getLedgerRanges();
    int emptyRanges = 0;
    while (lri.hasNext()) {
        if (lri.next().getLedgers().isEmpty()) {
            emptyRanges++;
        }
    }
    assertEquals(0, emptyRanges);
}
Also used : LedgerRangeIterator(org.apache.bookkeeper.meta.LedgerManager.LedgerRangeIterator) TreeSet(java.util.TreeSet) Test(org.junit.Test)

Aggregations

LedgerRangeIterator (org.apache.bookkeeper.meta.LedgerManager.LedgerRangeIterator)14 Test (org.junit.Test)11 TreeSet (java.util.TreeSet)9 LedgerRange (org.apache.bookkeeper.meta.LedgerManager.LedgerRange)3 ArrayList (java.util.ArrayList)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Checkpoint (org.apache.bookkeeper.bookie.CheckpointSource.Checkpoint)2 GarbageCollector (org.apache.bookkeeper.bookie.GarbageCollector)2 ScanAndCompareGarbageCollector (org.apache.bookkeeper.bookie.ScanAndCompareGarbageCollector)2 Random (java.util.Random)1 Set (java.util.Set)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 LedgerMetadata (org.apache.bookkeeper.client.LedgerMetadata)1