use of org.apache.bookkeeper.meta.LedgerManager.LedgerRangeIterator in project bookkeeper by apache.
the class LedgerManagerIteratorTest method checkConcurrentModifications.
@Test
public void checkConcurrentModifications() throws Throwable {
final int numWriters = 10;
final int numCheckers = 10;
final int numLedgers = 100;
final long runtime = TimeUnit.NANOSECONDS.convert(2, TimeUnit.SECONDS);
final boolean longRange = baseConf.getLedgerManagerFactoryClass() == LongHierarchicalLedgerManagerFactory.class;
final Set<Long> mustExist = new TreeSet<>();
LedgerManager lm = getLedgerManager();
Random rng = new Random();
for (int i = 0; i < numLedgers; ++i) {
long lid = Math.abs(rng.nextLong());
if (!longRange) {
lid %= 1000000;
}
createLedger(lm, lid, Optional.of(BKException.Code.OK));
mustExist.add(lid);
}
final long start = MathUtils.nowInNano();
final CountDownLatch latch = new CountDownLatch(1);
ArrayList<Thread> threads = new ArrayList<>();
for (int i = 0; i < numWriters; ++i) {
Thread thread = new Thread(safeWrapper(() -> {
LedgerManager writerLM = getIndependentLedgerManager();
Random writerRNG = new Random(rng.nextLong());
try {
latch.await();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
fail("Checker interrupted");
}
while (MathUtils.elapsedNanos(start) < runtime) {
long candidate = 0;
do {
candidate = Math.abs(writerRNG.nextLong());
if (!longRange) {
candidate %= 1000000;
}
} while (mustExist.contains(candidate));
try {
createLedger(writerLM, candidate, Optional.empty());
removeLedger(writerLM, candidate, Optional.empty());
} catch (Throwable e) {
fail("Got exception thrashing store: " + e.toString());
}
}
}));
thread.start();
threads.add(thread);
}
for (int i = 0; i < numCheckers; ++i) {
Thread thread = new Thread(safeWrapper(() -> {
LedgerManager checkerLM = getIndependentLedgerManager();
try {
latch.await();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
fail("Checker interrupted");
e.printStackTrace();
}
while (MathUtils.elapsedNanos(start) < runtime) {
try {
LedgerRangeIterator lri = checkerLM.getLedgerRanges();
Set<Long> returnedIds = ledgerRangeToSet(lri);
for (long id : mustExist) {
assertTrue(returnedIds.contains(id));
}
Set<Long> ledgersReadAsync = getLedgerIdsByUsingAsyncProcessLedgers(checkerLM);
for (long id : mustExist) {
assertTrue(ledgersReadAsync.contains(id));
}
} catch (IOException | InterruptedException e) {
e.printStackTrace();
fail("Got exception scanning ledgers: " + e.toString());
}
}
}));
thread.start();
threads.add(thread);
}
latch.countDown();
for (Thread thread : threads) {
thread.join();
}
}
use of org.apache.bookkeeper.meta.LedgerManager.LedgerRangeIterator in project bookkeeper by apache.
the class LedgerManagerIteratorTest method testWithSeveralIncompletePaths.
@Test
public void testWithSeveralIncompletePaths() 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 = { // top level, W-4292762
"/ledgers/000/0000/0000", // shares two path segments with the first one, comes after
"/ledgers/234/5678/9999", // shares one path segment with the second one, comes first
"/ledgers/339/0000/0000", // shares three path segments with the third one, comes first
"/ledgers/633/4994/3938/0000", // close to max long, at end
"/ledgers/922/3372/0000/0000" };
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);
}
use of org.apache.bookkeeper.meta.LedgerManager.LedgerRangeIterator in project bookkeeper by apache.
the class LedgerManagerIteratorTest method hierarchicalLedgerManagerAsyncProcessLedgersTest.
@Test
public void hierarchicalLedgerManagerAsyncProcessLedgersTest() throws Throwable {
Assume.assumeTrue(baseConf.getLedgerManagerFactoryClass().equals(HierarchicalLedgerManagerFactory.class));
LedgerManager lm = getLedgerManager();
LedgerRangeIterator lri = lm.getLedgerRanges();
Set<Long> ledgerIds = new TreeSet<>(Arrays.asList(1234L, 123456789123456789L));
for (Long ledgerId : ledgerIds) {
createLedger(lm, ledgerId, Optional.of(BKException.Code.OK));
}
Set<Long> ledgersReadThroughIterator = ledgerRangeToSet(lri);
assertEquals("Comparing LedgersIds read through Iterator", ledgerIds, ledgersReadThroughIterator);
Set<Long> ledgersReadAsync = getLedgerIdsByUsingAsyncProcessLedgers(lm);
assertEquals("Comparing LedgersIds read asynchronously", ledgerIds, ledgersReadAsync);
}
use of org.apache.bookkeeper.meta.LedgerManager.LedgerRangeIterator in project bookkeeper by apache.
the class LedgerManagerIteratorTest method testSingleLedger.
@Test
public void testSingleLedger() throws Throwable {
LedgerManager lm = getLedgerManager();
long id = 2020202;
createLedger(lm, id, Optional.of(BKException.Code.OK));
LedgerRangeIterator lri = lm.getLedgerRanges();
assertNotNull(lri);
Set<Long> lids = ledgerRangeToSet(lri);
assertEquals(lids.size(), 1);
assertEquals(lids.iterator().next().longValue(), id);
Set<Long> ledgersReadAsync = getLedgerIdsByUsingAsyncProcessLedgers(lm);
assertEquals("Comparing LedgersIds read asynchronously", lids, ledgersReadAsync);
}
use of org.apache.bookkeeper.meta.LedgerManager.LedgerRangeIterator in project bookkeeper by apache.
the class LedgerManagerIteratorTest method testTwoLedgers.
@Test
public void testTwoLedgers() throws Throwable {
LedgerManager lm = getLedgerManager();
Set<Long> ids = new TreeSet<>(Arrays.asList(101010101L, 2020340302L));
for (Long id : ids) {
createLedger(lm, id, Optional.of(BKException.Code.OK));
}
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);
}
Aggregations