use of org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMetrics in project ignite by apache.
the class PageMemoryNoStoreImpl method allocatePage.
/**
* {@inheritDoc}
*/
@Override
public long allocatePage(int grpId, int partId, byte flags) {
assert started;
long relPtr = borrowFreePage(grpId);
long absPtr = 0;
if (relPtr != INVALID_REL_PTR) {
int pageIdx = PageIdUtils.pageIndex(relPtr);
Segment seg = segment(pageIdx);
absPtr = seg.absolute(pageIdx);
} else {
// No segments contained a free page.
Segment[] seg0 = segments;
Segment allocSeg = seg0[seg0.length - 1];
while (allocSeg != null) {
relPtr = allocSeg.allocateFreePage(flags);
if (relPtr != INVALID_REL_PTR) {
absPtr = allocSeg.absolute(PageIdUtils.pageIndex(relPtr));
allocatedPages.incrementAndGet();
PageMetrics grpPageMetrics = dataRegionMetrics.cacheGrpPageMetrics(grpId);
grpPageMetrics.totalPages().increment();
break;
} else
allocSeg = addSegment(seg0);
}
}
if (relPtr == INVALID_REL_PTR) {
IgniteOutOfMemoryException oom = new IgniteOutOfMemoryException("Out of memory in data region [" + "name=" + dataRegionCfg.getName() + ", initSize=" + U.readableSize(dataRegionCfg.getInitialSize(), false) + ", maxSize=" + U.readableSize(dataRegionCfg.getMaxSize(), false) + ", persistenceEnabled=" + dataRegionCfg.isPersistenceEnabled() + "] Try the following:" + U.nl() + " ^-- Increase maximum off-heap memory size (DataRegionConfiguration.maxSize)" + U.nl() + " ^-- Enable Ignite persistence (DataRegionConfiguration.persistenceEnabled)" + U.nl() + " ^-- Enable eviction or expiration policies");
if (ctx != null)
ctx.kernalContext().failure().process(new FailureContext(FailureType.CRITICAL_ERROR, oom));
throw oom;
}
assert (relPtr & ~PageIdUtils.PAGE_IDX_MASK) == 0 : U.hexLong(relPtr & ~PageIdUtils.PAGE_IDX_MASK);
// Assign page ID according to flags and partition ID.
long pageId = PageIdUtils.pageId(partId, flags, (int) relPtr);
writePageId(absPtr, pageId);
// TODO pass an argument to decide whether the page should be cleaned.
GridUnsafe.setMemory(absPtr + PAGE_OVERHEAD, sysPageSize - PAGE_OVERHEAD, (byte) 0);
return pageId;
}
use of org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMetrics in project ignite by apache.
the class IndexPagesMetricsPageDisplacementTest method testPageDisplacement.
/**
* Inserts data into the cache as long as it fills enough for some data pages to get dumped to the
* storage. Since index page metrics should reflect the number of in-memory pages, the metric value is expected to
* go down.
*/
@Test
public void testPageDisplacement() throws IgniteCheckedException {
int grpId = grid.cachex(TEST_CACHE_NAME).context().groupId();
DataRegion dataRegion = grid.context().cache().context().database().dataRegion(null);
PageMetrics pageMetrics = dataRegion.metrics().cacheGrpPageMetrics(grpId);
int personId = 0;
long idxPagesOnDisk;
long idxPagesInMemory;
do {
// insert data into the cache until some index pages get displaced to the storage
for (int i = 0; i < 100; i++, personId++) cache.put(personId, new Person(personId, "foobar"));
forceCheckpoint(grid);
idxPagesOnDisk = getIdxPagesOnDisk(grpId).size();
idxPagesInMemory = idxPageCounter.countIdxPagesInMemory(grpId);
assertThat(pageMetrics.indexPages().value(), is(idxPagesInMemory));
} while (idxPagesOnDisk <= idxPagesInMemory);
// load pages back into memory and check that the metric value has increased
touchIdxPages(grpId);
long allIdxPagesInMemory = idxPageCounter.countIdxPagesInMemory(grpId);
assertThat(allIdxPagesInMemory, greaterThan(idxPagesInMemory));
assertThat(pageMetrics.indexPages().value(), is(allIdxPagesInMemory));
}
use of org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMetrics in project ignite by apache.
the class PageHandler method doInitPage.
/**
* @param pageMem Page memory.
* @param grpId Group ID.
* @param pageId Page ID.
* @param page Page pointer.
* @param pageAddr Page address.
* @param init Initial IO.
* @param wal Write ahead log.
* @throws IgniteCheckedException If failed.
*/
private static void doInitPage(PageMemory pageMem, int grpId, long pageId, long page, long pageAddr, PageIO init, IgniteWriteAheadLogManager wal) throws IgniteCheckedException {
// TODO GG-11480
assert PageIO.getCrc(pageAddr) == 0;
PageMetrics metrics = pageMem.metrics().cacheGrpPageMetrics(grpId);
init.initNewPage(pageAddr, pageId, pageMem.realPageSize(grpId), metrics);
// Here we should never write full page, because it is known to be new.
if (isWalDeltaRecordNeeded(pageMem, grpId, pageId, page, wal, FALSE))
wal.log(new InitNewPageRecord(grpId, pageId, init.getType(), init.getVersion(), pageId));
}
use of org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMetrics in project ignite by apache.
the class PageMemoryNoStoreImpl method borrowFreePage.
/**
* @return Relative pointer to a free page that was borrowed from the allocated pool.
*/
private long borrowFreePage(int grpId) {
while (true) {
long freePageRelPtrMasked = freePageListHead.get();
long freePageRelPtr = freePageRelPtrMasked & ADDRESS_MASK;
// no free pages available
if (freePageRelPtr == INVALID_REL_PTR)
return INVALID_REL_PTR;
int pageIdx = PageIdUtils.pageIndex(freePageRelPtr);
Segment seg = segment(pageIdx);
long freePageAbsPtr = seg.absolute(pageIdx);
long nextFreePageRelPtr = GridUnsafe.getLong(freePageAbsPtr) & ADDRESS_MASK;
long cnt = ((freePageRelPtrMasked & COUNTER_MASK) + COUNTER_INC) & COUNTER_MASK;
if (freePageListHead.compareAndSet(freePageRelPtrMasked, nextFreePageRelPtr | cnt)) {
GridUnsafe.putLong(freePageAbsPtr, PAGE_MARKER);
allocatedPages.incrementAndGet();
PageMetrics grpPageMetrics = dataRegionMetrics.cacheGrpPageMetrics(grpId);
grpPageMetrics.totalPages().increment();
return freePageRelPtr;
}
}
}
use of org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMetrics in project ignite by apache.
the class PageMemoryNoStoreImpl method releaseFreePage.
/**
* @param pageId Page ID to release.
*/
private void releaseFreePage(int grpId, long pageId) {
int pageIdx = PageIdUtils.pageIndex(pageId);
// Clear out flags and file ID.
long relPtr = PageIdUtils.pageId(0, (byte) 0, pageIdx);
Segment seg = segment(pageIdx);
long absPtr = seg.absolute(pageIdx);
// Second, write clean relative pointer instead of page ID.
writePageId(absPtr, relPtr);
// Third, link the free page.
while (true) {
long freePageRelPtrMasked = freePageListHead.get();
long freePageRelPtr = freePageRelPtrMasked & RELATIVE_PTR_MASK;
GridUnsafe.putLong(absPtr, freePageRelPtr);
if (freePageListHead.compareAndSet(freePageRelPtrMasked, relPtr)) {
allocatedPages.decrementAndGet();
PageMetrics pageMetrics = dataRegionMetrics.cacheGrpPageMetrics(grpId);
pageMetrics.totalPages().decrement();
return;
}
}
}
Aggregations