use of org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager in project ignite by apache.
the class IgniteWalHistoryReservationsTest method isReserveListEmpty.
/**
* @return {@code true} if reserve list is empty.
*/
private boolean isReserveListEmpty(IgniteEx ig) {
FileWriteAheadLogManager wal = (FileWriteAheadLogManager) ig.context().cache().context().wal();
Object segmentAware = GridTestUtils.getFieldValue(wal, "segmentAware");
synchronized (segmentAware) {
Map reserved = GridTestUtils.getFieldValue(GridTestUtils.getFieldValue(segmentAware, "reservationStorage"), "reserved");
if (reserved.isEmpty())
return true;
}
return false;
}
use of org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager in project ignite by apache.
the class IgniteWalFlushFailoverTest method flushingErrorTest.
/**
* @throws Exception if failed.
*/
private void flushingErrorTest() throws Exception {
final IgniteEx grid = startGrid(0);
FileWriteAheadLogManager wal = (FileWriteAheadLogManager) grid.context().cache().context().wal();
boolean mmap = GridTestUtils.getFieldValue(wal, "mmap");
if (mmap)
return;
wal.setFileIOFactory(new FailingFileIOFactory(canFail));
try {
grid.active(true);
IgniteCache<Object, Object> cache = grid.cache(TEST_CACHE);
final int iterations = 100;
canFail.set(true);
for (int i = 0; i < iterations; i++) {
Transaction tx = grid.transactions().txStart(TransactionConcurrency.PESSIMISTIC, TransactionIsolation.READ_COMMITTED);
cache.put(i, "testValue" + i);
Thread.sleep(100L);
tx.commitAsync().get();
}
} catch (Exception expected) {
// There can be any exception. Do nothing.
}
// We should await successful stop of node.
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return grid.context().gateway().getState() == GridKernalState.STOPPED;
}
}, getTestTimeout());
}
use of org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager in project ignite by apache.
the class PageMemoryTracker method createWalManager.
/**
* Creates WAL manager.
*/
IgniteWriteAheadLogManager createWalManager() {
if (isEnabled()) {
return new FileWriteAheadLogManager(gridCtx) {
@Override
public WALPointer log(WALRecord record) throws IgniteCheckedException {
WALPointer res = super.log(record);
applyWalRecord(record);
return res;
}
@Override
public void resumeLogging(WALPointer lastPtr) throws IgniteCheckedException {
super.resumeLogging(lastPtr);
if (lastPtr == null)
emptyPds = true;
}
};
}
return null;
}
use of org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager 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.processors.cache.persistence.wal.FileWriteAheadLogManager in project ignite by apache.
the class IgniteDataStorageMetricsSelfTest method checkWalArchiveAndTotalSize.
/**
* Check the state of wal archive, and whether the total size of
* wal (and possibly wal archive) match what is expected.
*
* @param igniteEx Node.
* @param hasWalArchive Whether wal archiving is enabled.
* @throws Exception If failed.
*/
private void checkWalArchiveAndTotalSize(IgniteEx igniteEx, boolean hasWalArchive) throws Exception {
FileWriteAheadLogManager walMgr = walMgr(igniteEx);
SegmentRouter router = walMgr.getSegmentRouter();
assertEquals(router.hasArchive(), hasWalArchive);
// Wait to avoid race condition where new segments(and corresponding .tmp files) are created after totalSize has been calculated.
if (router.hasArchive()) {
int expWalWorkSegements = igniteEx.configuration().getDataStorageConfiguration().getWalSegments();
assertTrue(waitForCondition(() -> walFiles(router.getWalWorkDir()).length == expWalWorkSegements, 3000l));
assertTrue(waitForCondition(() -> walMgr.lastArchivedSegment() == walMgr.currentSegment() - 1, 3000l));
}
long totalSize = walMgr.totalSize(walFiles(router.getWalWorkDir()));
if (router.hasArchive())
totalSize += walMgr.totalSize(walFiles(router.getWalArchiveDir()));
assertEquals(totalSize, dbMgr(igniteEx).persistentStoreMetrics().getWalTotalSize());
assertEquals(totalSize, dsMetricsMXBean(igniteEx).getWalTotalSize());
assertEquals(totalSize, ((LongGauge) dsMetricRegistry(igniteEx).findMetric("WalTotalSize")).value());
}
Aggregations