use of org.apache.ignite.internal.pagemem.PageMemory in project ignite by apache.
the class IgnitePdsRecoveryAfterFileCorruptionTest method testPageRecoveryAfterFileCorruption.
/**
* @throws Exception if failed.
*/
@Test
public void testPageRecoveryAfterFileCorruption() throws Exception {
IgniteEx ig = startGrid(0);
ig.cluster().state(ClusterState.ACTIVE);
IgniteCache<Integer, Integer> cache = ig.cache(cacheName);
// Put for create data store and init meta page.
cache.put(1, 1);
GridCacheSharedContext sharedCtx = ig.context().cache().context();
GridCacheDatabaseSharedManager psMgr = (GridCacheDatabaseSharedManager) sharedCtx.database();
FilePageStoreManager pageStore = (FilePageStoreManager) sharedCtx.pageStore();
U.sleep(1_000);
// Disable integrated checkpoint thread.
psMgr.enableCheckpoints(false).get();
PageMemory mem = sharedCtx.database().dataRegion(policyName).pageMemory();
DummyPageIO pageIO = new DummyPageIO();
int cacheId = sharedCtx.cache().cache(cacheName).context().cacheId();
int pagesCnt = getTotalPagesToTest();
FullPageId[] pages = new FullPageId[pagesCnt];
// Get lock to prevent assertion. A new page should be allocated under checkpoint lock.
psMgr.checkpointReadLock();
try {
for (int i = 0; i < pagesCnt; i++) {
pages[i] = new FullPageId(mem.allocatePage(cacheId, 0, PageIdAllocator.FLAG_DATA), cacheId);
initPage(mem, pageIO, pages[i]);
}
generateWal((PageMemoryImpl) mem, sharedCtx.pageStore(), sharedCtx.wal(), cacheId, pages);
} finally {
psMgr.checkpointReadUnlock();
}
eraseDataFromDisk(pageStore, cacheId, pages[0]);
stopAllGrids();
ig = startGrid(0);
ig.cluster().state(ClusterState.ACTIVE);
checkRestore(ig, pages);
// It is necessary to clear the current WAL history to make sure that the restored pages have been saved.
GridCacheSharedContext<Object, Object> cctx = ig.context().cache().context();
GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager) cctx.database();
FileWriteAheadLogManager wal = (FileWriteAheadLogManager) cctx.wal();
// Force checkpoint.
dbMgr.enableCheckpoints(true).get(getTestTimeout());
dbMgr.checkpointReadLock();
try {
WALPointer lastWalPtr = dbMgr.checkpointHistory().lastCheckpoint().checkpointMark();
// Move current WAL segment into the archive.
wal.log(new CheckpointRecord(null), RolloverType.NEXT_SEGMENT);
assertTrue(waitForCondition(() -> wal.lastArchivedSegment() >= lastWalPtr.index(), getTestTimeout()));
wal.truncate(lastWalPtr);
dbMgr.onWalTruncated(lastWalPtr);
} finally {
dbMgr.checkpointReadUnlock();
}
stopAllGrids();
ig = startGrid(0);
ig.cluster().state(ClusterState.ACTIVE);
checkRestore(ig, pages);
}
use of org.apache.ignite.internal.pagemem.PageMemory in project ignite by apache.
the class InlineIndexColumnTest method testPutGet.
/**
*/
private void testPutGet(Value v1, Value v2, Value v3) throws Exception {
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())), false);
pageMem.start();
long pageId = 0L;
long page = 0L;
try {
pageId = pageMem.allocatePage(CACHE_ID, 1, PageIdAllocator.FLAG_DATA);
page = pageMem.acquirePage(CACHE_ID, pageId);
long pageAddr = pageMem.readLock(CACHE_ID, pageId, page);
int off = 0;
int max = 255;
IndexKeyTypeSettings keyTypeSettings = new IndexKeyTypeSettings().inlineObjHash(false).stringOptimizedCompare(false);
InlineIndexKeyType keyType = InlineIndexKeyTypeRegistry.get(v1.getType(), keyTypeSettings);
off += keyType.put(pageAddr, off, idxKey(v1), max - off);
off += keyType.put(pageAddr, off, idxKey(v2), max - off);
off += keyType.put(pageAddr, off, idxKey(v3), max - off);
IndexKey v11 = keyType.get(pageAddr, 0, max);
IndexKey v22 = keyType.get(pageAddr, keyType.inlineSize(pageAddr, 0), max);
assertEquals(v1.getObject(), v11.key());
assertEquals(v2.getObject(), v22.key());
assertEquals(0, keyType.compare(pageAddr, 0, max, idxKey(v1)));
} finally {
if (page != 0L)
pageMem.releasePage(CACHE_ID, pageId, page);
pageMem.stop(true);
}
}
use of org.apache.ignite.internal.pagemem.PageMemory in project ignite by apache.
the class InlineIndexColumnTest method testBytes.
/**
*/
@Test
public void testBytes() throws Exception {
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())), false);
pageMem.start();
long pageId = 0L;
long page = 0L;
try {
pageId = pageMem.allocatePage(CACHE_ID, 1, PageIdAllocator.FLAG_DATA);
page = pageMem.acquirePage(CACHE_ID, pageId);
long pageAddr = pageMem.readLock(CACHE_ID, pageId, page);
int off = 0;
IndexKeyTypeSettings keyTypeSettings = new IndexKeyTypeSettings().inlineObjHash(false).stringOptimizedCompare(false);
InlineIndexKeyType keyType = InlineIndexKeyTypeRegistry.get(Value.BYTES, keyTypeSettings);
int maxSize = 3 + 3;
int savedBytesCnt = keyType.put(pageAddr, off, idxKey(ValueBytes.get(new byte[] { 1, 2, 3, 4, 5 }), keyTypeSettings), maxSize);
assertTrue(savedBytesCnt > 0);
assertTrue(savedBytesCnt <= maxSize);
maxSize = 3 + 5;
assertTrue(Arrays.equals(new byte[] { 1, 2, 3 }, (byte[]) keyType.get(pageAddr, off, maxSize).key()));
savedBytesCnt = keyType.put(pageAddr, off, idxKey(ValueBytes.get(new byte[] { 1, 2, 3, 4, 5 }), keyTypeSettings), maxSize);
assertTrue(savedBytesCnt > 0);
assertTrue(savedBytesCnt <= maxSize);
assertTrue(Arrays.equals(new byte[] { 1, 2, 3, 4, 5 }, (byte[]) keyType.get(pageAddr, off, maxSize).key()));
} finally {
if (page != 0L)
pageMem.releasePage(CACHE_ID, pageId, page);
pageMem.stop(true);
}
}
use of org.apache.ignite.internal.pagemem.PageMemory in project ignite by apache.
the class FreeListImplSelfTest method createPageMemory.
/**
* @return Page memory.
*/
protected PageMemory createPageMemory(int pageSize, MemoryPolicyConfiguration plcCfg) throws Exception {
PageMemory pageMem = new PageMemoryNoStoreImpl(log, new UnsafeMemoryProvider(log), null, pageSize, plcCfg, new MemoryMetricsImpl(plcCfg), true);
pageMem.start();
return pageMem;
}
use of org.apache.ignite.internal.pagemem.PageMemory in project ignite by apache.
the class IgniteCacheDatabaseSharedManager method initMemory.
/**
* @param memCfg memory configuration with common parameters.
* @param plcCfg memory policy with PageMemory specific parameters.
* @param memMetrics {@link MemoryMetrics} object to collect memory usage metrics.
* @return Memory policy instance.
*/
private MemoryPolicy initMemory(MemoryConfiguration memCfg, MemoryPolicyConfiguration plcCfg, MemoryMetricsImpl memMetrics) {
File allocPath = buildAllocPath(plcCfg);
DirectMemoryProvider memProvider = allocPath == null ? new UnsafeMemoryProvider(log) : new MappedFileMemoryProvider(log, allocPath);
PageMemory pageMem = createPageMemory(memProvider, memCfg, plcCfg, memMetrics);
return new MemoryPolicy(pageMem, plcCfg, memMetrics, createPageEvictionTracker(plcCfg, pageMem));
}
Aggregations