Search in sources :

Example 56 with IgniteEx

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);
        }
    }
}
Also used : GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) IgniteEx(org.apache.ignite.internal.IgniteEx) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) PageMemoryEx(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx) DummyPageIO(org.apache.ignite.internal.processors.cache.persistence.DummyPageIO) ByteBuffer(java.nio.ByteBuffer) FullPageId(org.apache.ignite.internal.pagemem.FullPageId)

Example 57 with IgniteEx

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());
}
Also used : IgnitePageStoreManager(org.apache.ignite.internal.pagemem.store.IgnitePageStoreManager) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) IgniteEx(org.apache.ignite.internal.IgniteEx) PageMemory(org.apache.ignite.internal.pagemem.PageMemory) PageMemoryImpl(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryImpl) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) WALPointer(org.apache.ignite.internal.pagemem.wal.WALPointer)

Example 58 with IgniteEx

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);
    }
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) FileWriteAheadLogManager(org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IOException(java.io.IOException) RandomAccessFileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory)

Example 59 with IgniteEx

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();
    }
}
Also used : Random(java.util.Random) HashMap(java.util.HashMap) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) IgniteEx(org.apache.ignite.internal.IgniteEx)

Example 60 with IgniteEx

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());
}
Also used : Transaction(org.apache.ignite.transactions.Transaction) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) IgniteEx(org.apache.ignite.internal.IgniteEx) FileWriteAheadLogManager(org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IOException(java.io.IOException)

Aggregations

IgniteEx (org.apache.ignite.internal.IgniteEx)396 Ignite (org.apache.ignite.Ignite)85 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)64 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)60 IgniteException (org.apache.ignite.IgniteException)46 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)37 Transaction (org.apache.ignite.transactions.Transaction)34 ArrayList (java.util.ArrayList)31 HashMap (java.util.HashMap)31 CountDownLatch (java.util.concurrent.CountDownLatch)28 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)27 IgniteCache (org.apache.ignite.IgniteCache)25 Map (java.util.Map)24 ClusterNode (org.apache.ignite.cluster.ClusterNode)20 CacheException (javax.cache.CacheException)19 GridCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager)19 UUID (java.util.UUID)18 Callable (java.util.concurrent.Callable)17 List (java.util.List)16 Random (java.util.Random)16