use of org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager 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.processors.cache.persistence.GridCacheDatabaseSharedManager in project ignite by apache.
the class IgniteNodeStoppedDuringDisableWALTest method testStopNodeWithDisableWAL.
/**
* @param nodeStopPoint Stop point.
* @throws Exception If failed.
*/
private void testStopNodeWithDisableWAL(NodeStopPoint nodeStopPoint) throws Exception {
log.info("Start test crash " + nodeStopPoint);
IgniteEx ig0 = startGrid(0);
GridCacheSharedContext<Object, Object> sharedContext = ig0.context().cache().context();
GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager) sharedContext.database();
IgniteWriteAheadLogManager WALmgr = sharedContext.wal();
WALDisableContext walDisableContext = new WALDisableContext(dbMgr, sharedContext.pageStore(), log) {
@Override
protected void writeMetaStoreDisableWALFlag() throws IgniteCheckedException {
if (nodeStopPoint == NodeStopPoint.BEFORE_WRITE_KEY_TO_META_STORE)
failNode(nodeStopPoint);
super.writeMetaStoreDisableWALFlag();
if (nodeStopPoint == NodeStopPoint.AFTER_WRITE_KEY_TO_META_STORE)
failNode(nodeStopPoint);
}
@Override
protected void removeMetaStoreDisableWALFlag() throws IgniteCheckedException {
if (nodeStopPoint == NodeStopPoint.AFTER_CHECKPOINT_AFTER_ENABLE_WAL)
failNode(nodeStopPoint);
super.removeMetaStoreDisableWALFlag();
if (nodeStopPoint == NodeStopPoint.AFTER_REMOVE_KEY_TO_META_STORE)
failNode(nodeStopPoint);
}
@Override
protected void disableWAL(boolean disable) throws IgniteCheckedException {
if (disable) {
if (nodeStopPoint == NodeStopPoint.AFTER_CHECKPOINT_BEFORE_DISABLE_WAL)
failNode(nodeStopPoint);
super.disableWAL(disable);
if (nodeStopPoint == NodeStopPoint.AFTER_DISABLE_WAL)
failNode(nodeStopPoint);
} else {
super.disableWAL(disable);
if (nodeStopPoint == NodeStopPoint.AFTER_ENABLE_WAL)
failNode(nodeStopPoint);
}
}
};
setFieldValue(sharedContext.walState(), "walDisableContext", walDisableContext);
setFieldValue(WALmgr, "walDisableContext", walDisableContext);
ig0.context().internalSubscriptionProcessor().registerMetastorageListener(walDisableContext);
ig0.cluster().active(true);
try (IgniteDataStreamer<Integer, Integer> st = ig0.dataStreamer(DEFAULT_CACHE_NAME)) {
st.allowOverwrite(true);
for (int i = 0; i < GridTestUtils.SF.apply(10_000); i++) st.addData(i, -i);
}
boolean fail = false;
try (WALIterator it = sharedContext.wal().replay(null)) {
dbMgr.applyUpdatesOnRecovery(it, (ptr, rec) -> true, (entry) -> true);
} catch (IgniteCheckedException e) {
if (nodeStopPoint.needCleanUp)
fail = true;
}
Assert.assertEquals(nodeStopPoint.needCleanUp, fail);
Ignite ig1 = startGrid(0);
String msg = nodeStopPoint.toString();
int pageSize = ig1.configuration().getDataStorageConfiguration().getPageSize();
if (nodeStopPoint.needCleanUp) {
PdsFoldersResolver foldersResolver = ((IgniteEx) ig1).context().pdsFolderResolver();
File root = foldersResolver.resolveFolders().persistentStoreRootPath();
walkFileTree(root.toPath(), new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException {
String name = path.toFile().getName();
String filePath = path.toString();
String parentDirName = path.toFile().getParentFile().getName();
if (parentDirName.equals(METASTORAGE_DIR_NAME) || parentDirName.equals(TxLog.TX_LOG_CACHE_NAME))
return CONTINUE;
if (WAL_NAME_PATTERN.matcher(name).matches() || WAL_TEMP_NAME_PATTERN.matcher(name).matches())
return CONTINUE;
boolean failed = false;
if (name.endsWith(FilePageStoreManager.TMP_SUFFIX))
failed = true;
if (CP_FILE_NAME_PATTERN.matcher(name).matches())
failed = true;
if (name.startsWith(PART_FILE_PREFIX) && path.toFile().length() > pageSize)
failed = true;
if (name.startsWith(INDEX_FILE_NAME) && path.toFile().length() > pageSize)
failed = true;
if (failed)
fail(msg + " " + filePath + " " + path.toFile().length());
return CONTINUE;
}
});
}
}
use of org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager in project ignite by apache.
the class IgniteSequentialNodeCrashRecoveryTest method triggerCheckpoint.
/**
* @param ig Ignite instance.
*/
private void triggerCheckpoint(IgniteEx ig) {
GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager) ig.context().cache().context().database();
dbMgr.wakeupForCheckpoint("test-should-fail");
}
use of org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager in project ignite by apache.
the class IgniteSequentialNodeCrashRecoveryTest method captureDirtyPages.
/**
* @param g Ignite instance.
* @throws IgniteCheckedException If failed.
*/
private Collection<FullPageId> captureDirtyPages(IgniteEx g) throws IgniteCheckedException {
GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager) g.context().cache().context().database();
dbMgr.checkpointReadLock();
try {
// Moving free list pages to offheap.
for (CacheGroupContext group : g.context().cache().cacheGroups()) {
((GridCacheOffheapManager) group.offheap()).onMarkCheckpointBegin(new DummyCheckpointContext());
}
} finally {
dbMgr.checkpointReadUnlock();
}
// Capture a set of dirty pages.
PageMemoryImpl pageMem = (PageMemoryImpl) dbMgr.dataRegion("default").pageMemory();
return pageMem.dirtyPages();
}
use of org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager in project ignite by apache.
the class TxPartitionCounterStateAbstractTest method stopGrid.
/**
* @param skipCheckpointOnStop Skip checkpoint on stop.
* @param name Grid instance.
*/
protected void stopGrid(boolean skipCheckpointOnStop, String name) {
IgniteEx grid = grid(name);
if (skipCheckpointOnStop && persistenceEnabled()) {
GridCacheDatabaseSharedManager db = (GridCacheDatabaseSharedManager) grid.context().cache().context().database();
db.enableCheckpoints(false);
}
stopGrid(grid.name(), skipCheckpointOnStop);
}
Aggregations