use of org.apache.ignite.internal.pagemem.PageMemory in project ignite by apache.
the class IgnitePdsCheckpointSimulationWithRealCpDisabledTest method testCheckpointSimulationMultiThreaded.
/**
* @throws Exception if failed.
*/
@Test
public void testCheckpointSimulationMultiThreaded() throws Exception {
IgniteEx ig = startGrid(0);
ig.cluster().active(true);
GridCacheSharedContext<Object, Object> shared = ig.context().cache().context();
GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager) shared.database();
IgnitePageStoreManager pageStore = shared.pageStore();
U.sleep(1_000);
// Disable integrated checkpoint thread.
dbMgr.enableCheckpoints(false).get();
// Must put something in partition 0 in order to initialize meta page.
// Otherwise we will violate page store integrity rules.
ig.cache(CACHE_NAME).put(0, 0);
PageMemory mem = shared.database().dataRegion(null).pageMemory();
IgniteBiTuple<Map<FullPageId, Integer>, WALPointer> res;
try {
res = runCheckpointing(ig, (PageMemoryImpl) mem, pageStore, shared.wal(), shared.cache().cache(CACHE_NAME).context().cacheId());
} catch (Throwable th) {
log().error("Error while running checkpointing", th);
throw th;
} finally {
dbMgr.enableCheckpoints(true).get();
stopAllGrids(false);
}
ig = startGrid(0);
ig.cluster().active(true);
shared = ig.context().cache().context();
dbMgr = (GridCacheDatabaseSharedManager) shared.database();
dbMgr.enableCheckpoints(false).get();
mem = shared.database().dataRegion(null).pageMemory();
verifyReads(ig.context(), res.get1(), mem, res.get2(), shared.wal());
}
use of org.apache.ignite.internal.pagemem.PageMemory in project ignite by apache.
the class PageMemoryTracker method checkPages.
/**
* Checks if there are any differences between the Ignite's data regions content and pages inside the tracker.
*
* @param checkAll Check all tracked pages, otherwise check until first error.
* @param checkPageCnt Check tracked and allocated pages count. This check can be done only if there is no
* concurrent modification of pages in the system (for example when checkpointWriteLock is held). Some threads
* (for example MVCC vacuum cleaner) can modify pages even if there is no activity from a users point of view.
* @return {@code true} if content of all tracked pages equals to content of these pages in the ignite instance.
*/
private boolean checkPages(boolean checkAll, boolean checkPageCnt) throws IgniteCheckedException {
if (!started)
throw new IgniteCheckedException("Page memory checking only possible when tracker is started.");
GridCacheProcessor cacheProc = gridCtx.cache();
boolean res = true;
synchronized (pageAllocatorMux) {
long totalAllocated = pageStoreAllocatedPages();
log.info(">>> Total tracked pages: " + pages.size());
log.info(">>> Total allocated pages: " + totalAllocated);
dumpStats();
if (emptyPds && checkPageCnt && pages.size() != totalAllocated) {
res = false;
log.error("Started from empty PDS, but tracked pages count not equals to allocated pages count");
dumpPagesCountDiff();
if (!checkAll)
return false;
}
}
Set<Integer> groupsWarned = new HashSet<>();
for (DirectMemoryPage page : pages.values()) {
FullPageId fullPageId = page.fullPageId();
PageMemory pageMem;
if (fullPageId.groupId() == MetaStorage.METASTORAGE_CACHE_ID)
pageMem = cacheProc.context().database().metaStorage().pageMemory();
else if (fullPageId.groupId() == TxLog.TX_LOG_CACHE_ID)
pageMem = cacheProc.context().database().dataRegion(TxLog.TX_LOG_CACHE_NAME).pageMemory();
else {
CacheGroupContext ctx = cacheProc.cacheGroup(fullPageId.groupId());
if (ctx != null)
pageMem = ctx.dataRegion().pageMemory();
else {
if (!groupsWarned.contains(fullPageId.groupId())) {
log.warning("Cache group " + fullPageId.groupId() + " not found.");
groupsWarned.add(fullPageId.groupId());
}
continue;
}
}
assert pageMem instanceof PageMemoryImpl;
long rmtPage = pageMem.acquirePage(fullPageId.groupId(), fullPageId.pageId());
try {
long rmtPageAddr = pageMem.readLockForce(fullPageId.groupId(), fullPageId.pageId(), rmtPage);
try {
page.lock();
try {
if (rmtPageAddr == 0L) {
res = false;
log.error("Can't lock page: " + fullPageId);
dumpHistory(page);
} else if (!comparePages(fullPageId, page, rmtPageAddr))
res = false;
if (!res && !checkAll)
return false;
} finally {
page.unlock();
}
} finally {
if (rmtPageAddr != 0L)
pageMem.readUnlock(fullPageId.groupId(), fullPageId.pageId(), rmtPage);
}
} finally {
pageMem.releasePage(fullPageId.groupId(), fullPageId.pageId(), rmtPage);
}
}
return res;
}
use of org.apache.ignite.internal.pagemem.PageMemory in project ignite by apache.
the class PageMemoryTracker method mockPageMemory.
/**
* Creates a mock for the Page Memory.
*/
private PageMemory mockPageMemory() {
PageMemory mock = mock(PageMemory.class);
when(mock.pageSize()).thenReturn(pageSize);
when(mock.realPageSize(Mockito.anyInt())).then(invocation -> {
int grpId = (Integer) invocation.getArguments()[0];
if (gridCtx.encryption().getActiveKey(grpId) == null)
return pageSize;
EncryptionSpi encSpi = ctx.igniteConfiguration().getEncryptionSpi();
return pageSize - (encSpi.encryptedSizeNoPadding(pageSize) - pageSize) - encSpi.blockSize();
});
when(mock.pageBuffer(Mockito.anyLong())).then(invocation -> {
long pageAddr = (Long) invocation.getArguments()[0];
return GridUnsafe.wrapPointer(pageAddr, pageSize);
});
when(mock.metrics()).thenReturn(new DataRegionMetricsImpl(new DataRegionConfiguration(), gridCtx));
return mock;
}
use of org.apache.ignite.internal.pagemem.PageMemory in project ignite by apache.
the class BPlusTreeReplaceRemoveRaceTest method createPageMemory.
/**
* @return Page memory.
*/
protected PageMemory createPageMemory() {
DataRegionConfiguration plcCfg = new DataRegionConfiguration().setInitialSize(1024 * MB).setMaxSize(1024 * MB);
PageMemory pageMem = new PageMemoryNoStoreImpl(log, new UnsafeMemoryProvider(log), null, PAGE_SIZE, plcCfg, new DataRegionMetricsImpl(plcCfg, new GridTestKernalContext(log())), true);
pageMem.start();
return pageMem;
}
use of org.apache.ignite.internal.pagemem.PageMemory in project ignite by apache.
the class SwapPathConstructionSelfTest method extractDefaultPageMemoryAllocPath.
/**
* @param context Context.
*/
private String extractDefaultPageMemoryAllocPath(GridKernalContext context) {
IgniteCacheDatabaseSharedManager dbMgr = context.cache().context().database();
Map<String, DataRegion> memPlcMap = U.field(dbMgr, "dataRegionMap");
PageMemory pageMem = memPlcMap.get("default").pageMemory();
Object memProvider = U.field(pageMem, "directMemoryProvider");
Object memProvider0 = U.field(memProvider, "memProvider");
return ((File) U.field(memProvider0, "allocationPath")).getAbsolutePath();
}
Aggregations