use of org.apache.ignite.internal.processors.cache.persistence.tree.util.PageLockListener in project ignite by apache.
the class SharedPageLockTrackerTest method doTestTakeDumpByTime.
/**
*/
private void doTestTakeDumpByTime(int pagesCnt, int structuresCnt, int dumpTime, int threads) throws IgniteCheckedException, InterruptedException {
SharedPageLockTracker sharedPageLockTracker = new SharedPageLockTracker();
List<PageMeta> pageMetas = new CopyOnWriteArrayList<>();
int id = 1;
for (int i = 0; i < pagesCnt; i++) pageMetas.add(new PageMeta((id++) % structuresCnt, id++, id++, id++));
List<PageLockListener> pageLsnrs = new ArrayList<>();
for (int i = 0; i < structuresCnt; i++) pageLsnrs.add(sharedPageLockTracker.registerStructure("my-structure-" + i));
AtomicBoolean stop = new AtomicBoolean();
CountDownLatch awaitThreadStartLatch = new CountDownLatch(threads);
IgniteInternalFuture f = GridTestUtils.runMultiThreadedAsync(() -> {
List<PageLockListener> locks = new ArrayList<>(pageLsnrs);
List<PageMeta> pages = new ArrayList<>();
pages.addAll(pageMetas);
boolean latchDown = false;
while (!stop.get()) {
Collections.shuffle(locks);
Collections.shuffle(pages);
for (PageLockListener lsnr : locks) {
for (PageMeta pageMeta : pages) {
awaitRandom(5);
lsnr.onBeforeReadLock(pageMeta.structureId, pageMeta.pageId, pageMeta.page);
awaitRandom(5);
lsnr.onReadLock(pageMeta.structureId, pageMeta.pageId, pageMeta.page, pageMeta.pageAddr);
}
}
Collections.reverse(locks);
Collections.reverse(pages);
for (PageLockListener lsnr : locks) {
for (PageMeta pageMeta : pages) {
awaitRandom(5);
lsnr.onReadUnlock(pageMeta.structureId, pageMeta.pageId, pageMeta.page, pageMeta.pageAddr);
}
}
if (!latchDown) {
awaitThreadStartLatch.countDown();
latchDown = true;
}
}
}, threads, "PageLocker");
IgniteInternalFuture dumpFut = GridTestUtils.runAsync(() -> {
try {
awaitThreadStartLatch.await();
} catch (InterruptedException e) {
// Ignore.
return;
}
while (!stop.get()) {
awaitRandom(20);
SharedPageLockTrackerDump dump = sharedPageLockTracker.dump();
assertEquals(threads, dump.threadPageLockStates.size());
assertEquals(0, dump.threadPageLockStates.stream().filter(e -> e.invalidContext != null).count());
}
});
Thread.sleep(dumpTime);
stop.set(true);
f.get();
dumpFut.get();
}
Aggregations