use of org.apache.ignite.internal.pagemem.PageMemory in project ignite by apache.
the class MetadataStorageSelfTest method metaAllocation.
/**
* @throws Exception If failed.
*/
private void metaAllocation() throws Exception {
PageMemory mem = memory(true);
int[] cacheIds = new int[] { 1, "partitioned".hashCode(), "replicated".hashCode() };
Map<Integer, Map<String, RootPage>> allocatedIdxs = new HashMap<>();
mem.start();
try {
final Map<Integer, MetadataStorage> storeMap = new HashMap<>();
for (int i = 0; i < 1_000; i++) {
int cacheId = cacheIds[i % cacheIds.length];
Map<String, RootPage> idxMap = allocatedIdxs.get(cacheId);
if (idxMap == null) {
idxMap = new HashMap<>();
allocatedIdxs.put(cacheId, idxMap);
}
String idxName;
do {
idxName = randomName();
} while (idxMap.containsKey(idxName));
MetadataStorage metaStore = storeMap.get(cacheId);
if (metaStore == null) {
metaStore = new MetadataStorage(mem, null, new AtomicLong(), cacheId, PageIdAllocator.INDEX_PARTITION, PageMemory.FLAG_IDX, null, mem.allocatePage(cacheId, PageIdAllocator.INDEX_PARTITION, PageMemory.FLAG_IDX), true);
storeMap.put(cacheId, metaStore);
}
final RootPage rootPage = metaStore.getOrAllocateForTree(idxName);
assertTrue(rootPage.isAllocated());
idxMap.put(idxName, rootPage);
}
for (int cacheId : cacheIds) {
Map<String, RootPage> idxMap = allocatedIdxs.get(cacheId);
for (Map.Entry<String, RootPage> entry : idxMap.entrySet()) {
String idxName = entry.getKey();
FullPageId rootPageId = entry.getValue().pageId();
final RootPage rootPage = storeMap.get(cacheId).getOrAllocateForTree(idxName);
assertEquals("Invalid root page ID restored [cacheId=" + cacheId + ", idxName=" + idxName + ']', rootPageId, rootPage.pageId());
assertFalse("Root page already allocated [cacheId=" + cacheId + ", idxName=" + idxName + ']', rootPage.isAllocated());
}
}
} finally {
mem.stop();
}
}
use of org.apache.ignite.internal.pagemem.PageMemory in project ignite by apache.
the class IgniteCacheDatabaseSharedManager method ensureFreeSpace.
/**
* See {@link GridCacheMapEntry#ensureFreeSpace()}
*
* @param memPlc Memory policy.
*/
public void ensureFreeSpace(MemoryPolicy memPlc) throws IgniteCheckedException {
if (memPlc == null)
return;
MemoryPolicyConfiguration plcCfg = memPlc.config();
if (plcCfg.getPageEvictionMode() == DataPageEvictionMode.DISABLED)
return;
long memorySize = plcCfg.getMaxSize();
PageMemory pageMem = memPlc.pageMemory();
int sysPageSize = pageMem.systemPageSize();
FreeListImpl freeListImpl = freeListMap.get(plcCfg.getName());
for (; ; ) {
long allocatedPagesCnt = pageMem.loadedPages();
int emptyDataPagesCnt = freeListImpl.emptyDataPages();
boolean shouldEvict = allocatedPagesCnt > (memorySize / sysPageSize * plcCfg.getEvictionThreshold()) && emptyDataPagesCnt < plcCfg.getEmptyPagesPoolSize();
if (shouldEvict)
memPlc.evictionTracker().evictDataPage();
else
break;
}
}
use of org.apache.ignite.internal.pagemem.PageMemory in project ignite by apache.
the class CacheFreeListImplSelfTest method createPageMemory.
/**
* @return Page memory.
*/
protected PageMemory createPageMemory(int pageSize, DataRegionConfiguration plcCfg) throws Exception {
PageMemory pageMem = new PageMemoryNoStoreImpl(log, new UnsafeMemoryProvider(log), null, pageSize, plcCfg, new DataRegionMetricsImpl(plcCfg), true);
pageMem.start();
return pageMem;
}
use of org.apache.ignite.internal.pagemem.PageMemory in project ignite by apache.
the class IgniteCacheDatabaseSharedManager method ensureFreeSpace.
/**
* See {@link GridCacheMapEntry#ensureFreeSpace()}
*
* @param memPlc data region.
*/
public void ensureFreeSpace(DataRegion memPlc) throws IgniteCheckedException {
if (memPlc == null)
return;
DataRegionConfiguration plcCfg = memPlc.config();
if (plcCfg.getPageEvictionMode() == DataPageEvictionMode.DISABLED || plcCfg.isPersistenceEnabled())
return;
long memorySize = plcCfg.getMaxSize();
PageMemory pageMem = memPlc.pageMemory();
int sysPageSize = pageMem.systemPageSize();
CacheFreeListImpl freeListImpl = freeListMap.get(plcCfg.getName());
for (; ; ) {
long allocatedPagesCnt = pageMem.loadedPages();
int emptyDataPagesCnt = freeListImpl.emptyDataPages();
boolean shouldEvict = allocatedPagesCnt > (memorySize / sysPageSize * plcCfg.getEvictionThreshold()) && emptyDataPagesCnt < plcCfg.getEmptyPagesPoolSize();
if (shouldEvict) {
memPlc.evictionTracker().evictDataPage();
memPlc.memoryMetrics().updateEvictionRate();
} else
break;
}
}
use of org.apache.ignite.internal.pagemem.PageMemory in project ignite by apache.
the class H2RowCache method touch.
/**
* Update page
*
* @param link Link.
* @throws IgniteCheckedException On error.
*/
private void touch(long link) throws IgniteCheckedException {
PageMemory mem = grpCtx.dataRegion().pageMemory();
int grpId = grpCtx.groupId();
final long pageId = PageIdUtils.pageId(link);
final long page = mem.acquirePage(grpId, pageId);
try {
// Touch page timestamp
mem.readLock(grpId, pageId, page);
mem.readUnlock(grpId, pageId, page);
} finally {
mem.releasePage(grpId, pageId, page);
}
}
Aggregations