use of org.apache.ignite.internal.pagemem.PageMemory in project ignite by apache.
the class PageMemoryNoLoadSelfTest method testPageIdRotation.
/**
* @throws Exception If failed.
*/
@Test
public void testPageIdRotation() throws Exception {
PageMemory mem = memory();
mem.start();
try {
int pages = 5;
Collection<FullPageId> old = new ArrayList<>();
Collection<FullPageId> updated = new ArrayList<>();
for (int i = 0; i < pages; i++) old.add(allocatePage(mem));
// Check that initial pages are accessible.
for (FullPageId id : old) {
long pageApsPtr = mem.acquirePage(id.groupId(), id.pageId());
try {
long pageAddr = mem.writeLock(id.groupId(), id.pageId(), pageApsPtr);
assertNotNull(pageAddr);
try {
PAGE_IO.initNewPage(pageAddr, id.pageId(), mem.realPageSize(id.groupId()), null);
long updId = PageIdUtils.rotatePageId(id.pageId());
PageIO.setPageId(pageAddr, updId);
updated.add(new FullPageId(updId, id.groupId()));
} finally {
mem.writeUnlock(id.groupId(), id.pageId(), pageApsPtr, null, true);
}
} finally {
mem.releasePage(id.groupId(), id.pageId(), pageApsPtr);
}
}
// Check that updated pages are inaccessible using old IDs.
for (FullPageId id : old) {
long pageApsPtr = mem.acquirePage(id.groupId(), id.pageId());
try {
long pageAddr = mem.writeLock(id.groupId(), id.pageId(), pageApsPtr);
if (pageAddr != 0L) {
mem.writeUnlock(id.groupId(), id.pageId(), pageApsPtr, null, false);
fail("Was able to acquire page write lock.");
}
mem.readLock(id.groupId(), id.pageId(), pageApsPtr);
if (pageAddr != 0) {
mem.readUnlock(id.groupId(), id.pageId(), pageApsPtr);
fail("Was able to acquire page read lock.");
}
} finally {
mem.releasePage(id.groupId(), id.pageId(), pageApsPtr);
}
}
// Check that updated pages are accessible using new IDs.
for (FullPageId id : updated) {
long pageApsPtr = mem.acquirePage(id.groupId(), id.pageId());
try {
long pageAddr = mem.writeLock(id.groupId(), id.pageId(), pageApsPtr);
assertNotSame(0L, pageAddr);
try {
assertEquals(id.pageId(), PageIO.getPageId(pageAddr));
} finally {
mem.writeUnlock(id.groupId(), id.pageId(), pageApsPtr, null, false);
}
pageAddr = mem.readLock(id.groupId(), id.pageId(), pageApsPtr);
assertNotSame(0L, pageAddr);
try {
assertEquals(id.pageId(), PageIO.getPageId(pageAddr));
} finally {
mem.readUnlock(id.groupId(), id.pageId(), pageApsPtr);
}
} finally {
mem.releasePage(id.groupId(), id.pageId(), pageApsPtr);
}
}
} finally {
mem.stop(true);
}
}
use of org.apache.ignite.internal.pagemem.PageMemory in project ignite by apache.
the class PageMemoryNoLoadSelfTest method testPageTearingInner.
/**
* @throws Exception If failed.
*/
@Test
public void testPageTearingInner() throws Exception {
PageMemory mem = memory();
mem.start();
try {
FullPageId fullId1 = allocatePage(mem);
FullPageId fullId2 = allocatePage(mem);
long page1 = mem.acquirePage(fullId1.groupId(), fullId1.pageId());
try {
long page2 = mem.acquirePage(fullId2.groupId(), fullId2.pageId());
info("Allocated pages [page1Id=" + fullId1.pageId() + ", page1=" + page1 + ", page2Id=" + fullId2.pageId() + ", page2=" + page2 + ']');
try {
writePage(mem, fullId1, page1, 1);
writePage(mem, fullId2, page2, 2);
readPage(mem, fullId1.pageId(), page1, 1);
readPage(mem, fullId2.pageId(), page2, 2);
// Check read after read.
readPage(mem, fullId1.pageId(), page1, 1);
readPage(mem, fullId2.pageId(), page2, 2);
} finally {
mem.releasePage(fullId2.groupId(), fullId2.pageId(), page2);
}
} finally {
mem.releasePage(fullId1.groupId(), fullId1.pageId(), page1);
}
} finally {
mem.stop(true);
}
}
use of org.apache.ignite.internal.pagemem.PageMemory in project ignite by apache.
the class IgnitePdsCheckpointSimulationWithRealCpDisabledTest method testPageWalEntries.
/**
* @throws Exception if failed.
*/
@Test
public void testPageWalEntries() throws Exception {
IgniteEx ig = startGrid(0);
ig.cluster().active(true);
GridCacheSharedContext<Object, Object> sharedCtx = ig.context().cache().context();
int cacheId = sharedCtx.cache().cache(CACHE_NAME).context().cacheId();
GridCacheDatabaseSharedManager db = (GridCacheDatabaseSharedManager) sharedCtx.database();
PageMemory pageMem = sharedCtx.database().dataRegion(null).pageMemory();
IgniteWriteAheadLogManager wal = sharedCtx.wal();
db.enableCheckpoints(false).get();
int pageCnt = 100;
List<FullPageId> pageIds = new ArrayList<>();
for (int i = 0; i < pageCnt; i++) {
db.checkpointReadLock();
try {
pageIds.add(new FullPageId(pageMem.allocatePage(cacheId, PageIdAllocator.INDEX_PARTITION, PageIdAllocator.FLAG_IDX), cacheId));
} finally {
db.checkpointReadUnlock();
}
}
UUID cpId = UUID.randomUUID();
WALPointer start = wal.log(new CheckpointRecord(cpId, null));
wal.flush(start, false);
ig.context().cache().context().database().checkpointReadLock();
try {
for (FullPageId pageId : pageIds) writePageData(pageId, pageMem);
} finally {
ig.context().cache().context().database().checkpointReadUnlock();
}
// Data will not be written to the page store.
stopAllGrids();
ig = startGrid(0);
ig.cluster().active(true);
sharedCtx = ig.context().cache().context();
db = (GridCacheDatabaseSharedManager) sharedCtx.database();
wal = sharedCtx.wal();
db.enableCheckpoints(false);
try (PartitionMetaStateRecordExcludeIterator it = new PartitionMetaStateRecordExcludeIterator(wal.replay(start))) {
IgniteBiTuple<WALPointer, WALRecord> tup = it.next();
assert tup.get2() instanceof CheckpointRecord : tup.get2();
assertEquals(start, tup.get1());
CheckpointRecord cpRec = (CheckpointRecord) tup.get2();
assertEquals(cpId, cpRec.checkpointId());
assertNull(cpRec.checkpointMark());
assertFalse(cpRec.end());
int idx = 0;
while (idx < pageIds.size()) {
tup = it.next();
assert tup.get2() instanceof PageSnapshot : tup.get2().getClass();
PageSnapshot snap = (PageSnapshot) tup.get2();
// there are extra tracking pages, skip them
long trackingPageFor = TrackingPageIO.VERSIONS.latest().trackingPageFor(snap.fullPageId().pageId(), pageMem.pageSize());
if (trackingPageFor == snap.fullPageId().pageId()) {
tup = it.next();
assertTrue(tup.get2() instanceof PageSnapshot);
snap = (PageSnapshot) tup.get2();
}
assertEquals(pageIds.get(idx), snap.fullPageId());
idx++;
}
}
}
use of org.apache.ignite.internal.pagemem.PageMemory in project ignite by apache.
the class IgnitePdsPageReplacementTest method testPageReplacement.
/**
* @throws Exception If fail.
*/
@Test
public void testPageReplacement() throws Exception {
final IgniteEx ig = startGrid(0);
ig.active(true);
final PageMemory memory = getMemory(ig);
writeData(ig, memory, CU.cacheId(cacheName));
}
use of org.apache.ignite.internal.pagemem.PageMemory in project ignite by apache.
the class IndexPageCounter method countIdxPagesInMemory.
/**
* Returns the number of index pages residing inside the Page Memory of the given cache group.
*/
long countIdxPagesInMemory(int grpId) throws IgniteCheckedException {
DataRegion dataRegion = grid.context().cache().context().database().dataRegion(null);
PageMemory pageMemory = dataRegion.pageMemory();
long idxPageCnt = 0;
for (int i = 0; i < pageMemory.loadedPages(); i++) {
long pageId = PageIdUtils.pageId(PageIdAllocator.INDEX_PARTITION, (byte) 0, i);
if (persistenceEnabled) {
// if persistence is enabled, avoid loading a displaced page into memory
PageMemoryImpl pageMemoryImpl = (PageMemoryImpl) dataRegion.pageMemory();
if (!pageMemoryImpl.hasLoadedPage(new FullPageId(pageId, grpId)))
continue;
}
long pageAddr = pageMemory.acquirePage(grpId, pageId);
try {
long pageReadAddr = pageMemory.readLockForce(grpId, pageId, pageAddr);
try {
// check the rotation ID in case a page was freed (its page type does not get overwritten)
long rotationId = PageIdUtils.rotationId(PageIO.getPageId(pageReadAddr));
long prevRotationId = pageIdToRotationId.computeIfAbsent(pageId, id -> rotationId);
if (prevRotationId == rotationId && PageIO.isIndexPage(PageIO.getType(pageReadAddr)))
idxPageCnt += 1;
} finally {
pageMemory.readUnlock(grpId, pageId, pageAddr);
}
} finally {
pageMemory.releasePage(grpId, pageId, pageAddr);
}
}
return idxPageCnt;
}
Aggregations