use of org.apache.ignite.internal.IgniteEx in project ignite by apache.
the class IgnitePdsCheckpointSimulationWithRealCpDisabledTest method testDirtyFlag.
/**
* @throws Exception if failed.
*/
public void testDirtyFlag() throws Exception {
IgniteEx ig = startGrid(0);
ig.active(true);
GridCacheSharedContext<Object, Object> shared = ig.context().cache().context();
int cacheId = shared.cache().cache(cacheName).context().cacheId();
GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager) shared.database();
// Disable integrated checkpoint thread.
dbMgr.enableCheckpoints(false);
PageMemoryEx mem = (PageMemoryEx) dbMgr.dataRegion(null).pageMemory();
FullPageId[] pageIds = new FullPageId[100];
DummyPageIO pageIO = new DummyPageIO();
ig.context().cache().context().database().checkpointReadLock();
try {
for (int i = 0; i < pageIds.length; i++) pageIds[i] = new FullPageId(mem.allocatePage(cacheId, 0, PageIdAllocator.FLAG_DATA), cacheId);
for (FullPageId fullId : pageIds) {
long page = mem.acquirePage(fullId.groupId(), fullId.pageId());
try {
// page is dirty right after allocation
assertTrue(mem.isDirty(fullId.groupId(), fullId.pageId(), page));
long pageAddr = mem.writeLock(fullId.groupId(), fullId.pageId(), page);
try {
pageIO.initNewPage(pageAddr, fullId.pageId(), mem.pageSize());
assertTrue(mem.isDirty(fullId.groupId(), fullId.pageId(), page));
} finally {
mem.writeUnlock(fullId.groupId(), fullId.pageId(), page, null, true);
}
assertTrue(mem.isDirty(fullId.groupId(), fullId.pageId(), page));
} finally {
mem.releasePage(fullId.groupId(), fullId.pageId(), page);
}
}
} finally {
ig.context().cache().context().database().checkpointReadUnlock();
}
Collection<FullPageId> cpPages = mem.beginCheckpoint();
ig.context().cache().context().database().checkpointReadLock();
try {
for (FullPageId fullId : pageIds) {
assertTrue(cpPages.contains(fullId));
ByteBuffer buf = ByteBuffer.allocate(mem.pageSize());
long page = mem.acquirePage(fullId.groupId(), fullId.pageId());
try {
assertTrue(mem.isDirty(fullId.groupId(), fullId.pageId(), page));
long pageAddr = mem.writeLock(fullId.groupId(), fullId.pageId(), page);
try {
assertFalse(mem.isDirty(fullId.groupId(), fullId.pageId(), page));
for (int i = PageIO.COMMON_HEADER_END; i < mem.pageSize(); i++) PageUtils.putByte(pageAddr, i, (byte) 1);
} finally {
mem.writeUnlock(fullId.groupId(), fullId.pageId(), page, null, true);
}
assertTrue(mem.isDirty(fullId.groupId(), fullId.pageId(), page));
buf.rewind();
mem.getForCheckpoint(fullId, buf, null);
buf.position(PageIO.COMMON_HEADER_END);
while (buf.hasRemaining()) assertEquals((byte) 0, buf.get());
} finally {
mem.releasePage(fullId.groupId(), fullId.pageId(), page);
}
}
} finally {
ig.context().cache().context().database().checkpointReadUnlock();
}
mem.finishCheckpoint();
for (FullPageId fullId : pageIds) {
long page = mem.acquirePage(fullId.groupId(), fullId.pageId());
try {
assertTrue(mem.isDirty(fullId.groupId(), fullId.pageId(), page));
} finally {
mem.releasePage(fullId.groupId(), fullId.pageId(), page);
}
}
}
use of org.apache.ignite.internal.IgniteEx in project ignite by apache.
the class IgnitePdsCheckpointSimulationWithRealCpDisabledTest method testCheckpointSimulationMultiThreaded.
/**
* @throws Exception if failed.
*/
public void testCheckpointSimulationMultiThreaded() throws Exception {
IgniteEx ig = startGrid(0);
ig.active(true);
GridCacheSharedContext<Object, Object> shared = ig.context().cache().context();
GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager) shared.database();
IgnitePageStoreManager pageStore = shared.pageStore();
U.sleep(1_000);
// Disable integrated checkpoint thread.
dbMgr.enableCheckpoints(false).get();
// Must put something in partition 0 in order to initialize meta page.
// Otherwise we will violate page store integrity rules.
ig.cache(cacheName).put(0, 0);
PageMemory mem = shared.database().dataRegion(null).pageMemory();
IgniteBiTuple<Map<FullPageId, Integer>, WALPointer> res;
try {
res = runCheckpointing(ig, (PageMemoryImpl) mem, pageStore, shared.wal(), shared.cache().cache(cacheName).context().cacheId());
} catch (Throwable th) {
log().error("Error while running checkpointing", th);
throw th;
} finally {
dbMgr.enableCheckpoints(true).get();
stopAllGrids(false);
}
ig = startGrid(0);
ig.active(true);
shared = ig.context().cache().context();
dbMgr = (GridCacheDatabaseSharedManager) shared.database();
dbMgr.enableCheckpoints(false).get();
mem = shared.database().dataRegion(null).pageMemory();
verifyReads(res.get1(), mem, res.get2(), shared.wal());
}
use of org.apache.ignite.internal.IgniteEx in project ignite by apache.
the class IgnitePdsDiskErrorsRecoveringTest method emulateRecoveringOnWALWritingError.
/**
*/
private void emulateRecoveringOnWALWritingError() throws Exception {
final IgniteEx grid = startGrid(0);
FileWriteAheadLogManager wal = (FileWriteAheadLogManager) grid.context().cache().context().wal();
wal.setFileIOFactory(new LimitedSizeFileIOFactory(new RandomAccessFileIOFactory(), diskSpaceBytes));
grid.active(true);
int failedPosition = -1;
for (int i = 0; i < 1000; i++) {
byte payload = (byte) i;
byte[] data = new byte[2048];
Arrays.fill(data, payload);
try {
grid.cache(CACHE_NAME).put(i, data);
} catch (Exception e) {
failedPosition = i;
break;
}
}
// We must be able to put something into cache before fail.
Assert.assertTrue(failedPosition > 0);
// Grid should be automatically stopped after WAL fail.
awaitStop(grid);
// Grid should be successfully recovered after stopping.
IgniteEx recoveredGrid = startGrid(0);
recoveredGrid.active(true);
for (int i = 0; i < failedPosition; i++) {
byte payload = (byte) i;
byte[] data = new byte[2048];
Arrays.fill(data, payload);
byte[] actualData = (byte[]) recoveredGrid.cache(CACHE_NAME).get(i);
Assert.assertArrayEquals(data, actualData);
}
}
use of org.apache.ignite.internal.IgniteEx in project ignite by apache.
the class IgnitePdsNoActualWalHistoryTest method testWalBig.
/**
* @throws Exception if failed.
*/
public void testWalBig() throws Exception {
try {
IgniteEx ignite = startGrid(1);
ignite.active(true);
IgniteCache<Object, Object> cache = ignite.cache(CACHE_NAME);
Random rnd = new Random();
Map<Integer, IndexedObject> map = new HashMap<>();
for (int i = 0; i < 40_000; i++) {
if (i % 1000 == 0)
X.println(" >> " + i);
int k = rnd.nextInt(300_000);
IndexedObject v = new IndexedObject(rnd.nextInt(10_000));
cache.put(k, v);
map.put(k, v);
}
GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager) ignite.context().cache().context().database();
// Create many checkpoints to clean up the history.
dbMgr.wakeupForCheckpoint("test").get();
dbMgr.wakeupForCheckpoint("test").get();
dbMgr.wakeupForCheckpoint("test").get();
dbMgr.wakeupForCheckpoint("test").get();
dbMgr.wakeupForCheckpoint("test").get();
dbMgr.wakeupForCheckpoint("test").get();
dbMgr.wakeupForCheckpoint("test").get();
dbMgr.enableCheckpoints(false).get();
for (int i = 0; i < 50; i++) {
int k = rnd.nextInt(300_000);
IndexedObject v = new IndexedObject(rnd.nextInt(10_000));
cache.put(k, v);
map.put(k, v);
}
stopGrid(1);
ignite = startGrid(1);
ignite.active(true);
cache = ignite.cache(CACHE_NAME);
// Check.
for (Integer k : map.keySet()) assertEquals(map.get(k), cache.get(k));
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.internal.IgniteEx 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());
}
Aggregations