Search in sources :

Example 6 with GridCacheDatabaseSharedManager

use of org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager 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 7 with GridCacheDatabaseSharedManager

use of org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager in project ignite by apache.

the class MockWalIteratorFactory method iterator.

/**
 * Creates iterator
 * @param wal WAL directory without node consistent id
 * @param walArchive WAL archive without node consistent id
 * @return iterator
 * @throws IgniteCheckedException if IO failed
 */
@SuppressWarnings("unchecked")
public WALIterator iterator(File wal, File walArchive) throws IgniteCheckedException {
    final DataStorageConfiguration persistentCfg1 = Mockito.mock(DataStorageConfiguration.class);
    when(persistentCfg1.getWalPath()).thenReturn(wal.getAbsolutePath());
    when(persistentCfg1.getWalArchivePath()).thenReturn(walArchive.getAbsolutePath());
    when(persistentCfg1.getWalSegments()).thenReturn(segments);
    when(persistentCfg1.getWalBufferSize()).thenReturn(DataStorageConfiguration.DFLT_WAL_BUFF_SIZE);
    when(persistentCfg1.getWalRecordIteratorBufferSize()).thenReturn(DataStorageConfiguration.DFLT_WAL_RECORD_ITERATOR_BUFFER_SIZE);
    final FileIOFactory fileIOFactory = new DataStorageConfiguration().getFileIOFactory();
    when(persistentCfg1.getFileIOFactory()).thenReturn(fileIOFactory);
    final IgniteConfiguration cfg = Mockito.mock(IgniteConfiguration.class);
    when(cfg.getDataStorageConfiguration()).thenReturn(persistentCfg1);
    final GridKernalContext ctx = Mockito.mock(GridKernalContext.class);
    when(ctx.config()).thenReturn(cfg);
    when(ctx.clientNode()).thenReturn(false);
    when(ctx.pdsFolderResolver()).thenReturn(new PdsFoldersResolver() {

        @Override
        public PdsFolderSettings resolveFolders() {
            return new PdsFolderSettings(new File("."), subfolderName, consistentId, null, false);
        }
    });
    final GridDiscoveryManager disco = Mockito.mock(GridDiscoveryManager.class);
    when(ctx.discovery()).thenReturn(disco);
    final IgniteWriteAheadLogManager mgr = new FileWriteAheadLogManager(ctx);
    final GridCacheSharedContext sctx = Mockito.mock(GridCacheSharedContext.class);
    when(sctx.kernalContext()).thenReturn(ctx);
    when(sctx.discovery()).thenReturn(disco);
    when(sctx.gridConfig()).thenReturn(cfg);
    final GridCacheDatabaseSharedManager db = Mockito.mock(GridCacheDatabaseSharedManager.class);
    when(db.pageSize()).thenReturn(pageSize);
    when(sctx.database()).thenReturn(db);
    when(sctx.logger(any(Class.class))).thenReturn(log);
    mgr.start(sctx);
    return mgr.replay(null);
}
Also used : FileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.FileIOFactory) IgniteWriteAheadLogManager(org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) GridKernalContext(org.apache.ignite.internal.GridKernalContext) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) GridDiscoveryManager(org.apache.ignite.internal.managers.discovery.GridDiscoveryManager) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) PdsFoldersResolver(org.apache.ignite.internal.processors.cache.persistence.filename.PdsFoldersResolver) FileWriteAheadLogManager(org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager) PdsFolderSettings(org.apache.ignite.internal.processors.cache.persistence.filename.PdsFolderSettings) File(java.io.File)

Example 8 with GridCacheDatabaseSharedManager

use of org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager in project ignite by apache.

the class WalRecoveryTxLogicalRecordsTest method testHistoricalRebalanceIterator.

/**
 * @throws Exception if failed.
 */
public void testHistoricalRebalanceIterator() throws Exception {
    System.setProperty(IgniteSystemProperties.IGNITE_PDS_WAL_REBALANCE_THRESHOLD, "0");
    extraCcfg = new CacheConfiguration(CACHE_NAME + "2");
    extraCcfg.setAffinity(new RendezvousAffinityFunction(false, PARTS));
    Ignite ignite = startGrid();
    try {
        ignite.cluster().active(true);
        GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager) ((IgniteEx) ignite).context().cache().context().database();
        dbMgr.waitForCheckpoint("test");
        // This number depends on wal history size.
        int entries = 25;
        IgniteCache<Integer, Integer> cache = ignite.cache(CACHE_NAME);
        IgniteCache<Integer, Integer> cache2 = ignite.cache(CACHE_NAME + "2");
        for (int i = 0; i < entries; i++) {
            // Put to partition 0.
            cache.put(i * PARTS, i * PARTS);
            // Put to partition 1.
            cache.put(i * PARTS + 1, i * PARTS + 1);
            // Put to another cache.
            cache2.put(i, i);
            dbMgr.waitForCheckpoint("test");
        }
        for (int i = 0; i < entries; i++) {
            assertEquals((Integer) (i * PARTS), cache.get(i * PARTS));
            assertEquals((Integer) (i * PARTS + 1), cache.get(i * PARTS + 1));
            assertEquals((Integer) (i), cache2.get(i));
        }
        CacheGroupContext grp = ((IgniteEx) ignite).context().cache().cacheGroup(CU.cacheId(CACHE_NAME));
        IgniteCacheOffheapManager offh = grp.offheap();
        AffinityTopologyVersion topVer = grp.affinity().lastVersion();
        IgniteDhtDemandedPartitionsMap map;
        for (int i = 0; i < entries; i++) {
            map = new IgniteDhtDemandedPartitionsMap();
            map.addHistorical(0, i, Long.MAX_VALUE, entries);
            try (IgniteRebalanceIterator it = offh.rebalanceIterator(map, topVer)) {
                assertNotNull(it);
                assertTrue("Not historical for iteration: " + i, it.historical(0));
                for (int j = i; j < entries; j++) {
                    assertTrue("i=" + i + ", j=" + j, it.hasNextX());
                    CacheDataRow row = it.next();
                    assertEquals(j * PARTS, (int) row.key().value(grp.cacheObjectContext(), false));
                    assertEquals(j * PARTS, (int) row.value().value(grp.cacheObjectContext(), false));
                }
                assertFalse(it.hasNext());
            }
            map = new IgniteDhtDemandedPartitionsMap();
            map.addHistorical(1, i, Long.MAX_VALUE, entries);
            try (IgniteRebalanceIterator it = offh.rebalanceIterator(map, topVer)) {
                assertNotNull(it);
                assertTrue("Not historical for iteration: " + i, it.historical(1));
                for (int j = i; j < entries; j++) {
                    assertTrue(it.hasNextX());
                    CacheDataRow row = it.next();
                    assertEquals(j * PARTS + 1, (int) row.key().value(grp.cacheObjectContext(), false));
                    assertEquals(j * PARTS + 1, (int) row.value().value(grp.cacheObjectContext(), false));
                }
                assertFalse(it.hasNext());
            }
        }
        stopAllGrids();
        // Check that iterator is valid after restart.
        ignite = startGrid();
        ignite.cluster().active(true);
        grp = ((IgniteEx) ignite).context().cache().cacheGroup(CU.cacheId(CACHE_NAME));
        offh = grp.offheap();
        topVer = grp.affinity().lastVersion();
        for (int i = 0; i < entries; i++) {
            long start = System.currentTimeMillis();
            map = new IgniteDhtDemandedPartitionsMap();
            map.addHistorical(0, i, Long.MAX_VALUE, entries);
            try (IgniteRebalanceIterator it = offh.rebalanceIterator(map, topVer)) {
                long end = System.currentTimeMillis();
                info("Time to get iterator: " + (end - start));
                assertTrue("Not historical for iteration: " + i, it.historical(0));
                assertNotNull(it);
                start = System.currentTimeMillis();
                for (int j = i; j < entries; j++) {
                    assertTrue("i=" + i + ", j=" + j, it.hasNextX());
                    CacheDataRow row = it.next();
                    assertEquals(j * PARTS, (int) row.key().value(grp.cacheObjectContext(), false));
                    assertEquals(j * PARTS, (int) row.value().value(grp.cacheObjectContext(), false));
                }
                end = System.currentTimeMillis();
                info("Time to iterate: " + (end - start));
                assertFalse(it.hasNext());
            }
            map = new IgniteDhtDemandedPartitionsMap();
            map.addHistorical(1, i, Long.MAX_VALUE, entries);
            try (IgniteRebalanceIterator it = offh.rebalanceIterator(map, topVer)) {
                assertNotNull(it);
                assertTrue("Not historical for iteration: " + i, it.historical(1));
                for (int j = i; j < entries; j++) {
                    assertTrue(it.hasNextX());
                    CacheDataRow row = it.next();
                    assertEquals(j * PARTS + 1, (int) row.key().value(grp.cacheObjectContext(), false));
                    assertEquals(j * PARTS + 1, (int) row.value().value(grp.cacheObjectContext(), false));
                }
                assertFalse(it.hasNext());
            }
        }
    } finally {
        stopAllGrids();
        System.clearProperty(IgniteSystemProperties.IGNITE_PDS_WAL_REBALANCE_THRESHOLD);
    }
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) IgniteRebalanceIterator(org.apache.ignite.internal.processors.cache.IgniteRebalanceIterator) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteDhtDemandedPartitionsMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.IgniteDhtDemandedPartitionsMap) IgniteCacheOffheapManager(org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManager) IgniteEx(org.apache.ignite.internal.IgniteEx) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) Ignite(org.apache.ignite.Ignite) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 9 with GridCacheDatabaseSharedManager

use of org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager in project ignite by apache.

the class WalRecoveryTxLogicalRecordsTest method testWalAfterPreloading.

/**
 * @throws Exception If failed.
 */
public void testWalAfterPreloading() throws Exception {
    Ignite ignite = startGrid();
    ignite.cluster().active(true);
    try {
        GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager) ((IgniteEx) ignite).context().cache().context().database();
        dbMgr.enableCheckpoints(false).get();
        int entries = 100;
        try (IgniteDataStreamer<Integer, Integer> streamer = ignite.dataStreamer(CACHE_NAME)) {
            for (int i = 0; i < entries; i++) streamer.addData(i, i);
        }
        IgniteCache<Integer, Integer> cache = ignite.cache(CACHE_NAME);
        for (int i = 0; i < entries; i++) assertEquals(new Integer(i), cache.get(i));
        stopGrid();
        ignite = startGrid();
        ignite.cluster().active(true);
        cache = ignite.cache(CACHE_NAME);
        for (int i = 0; i < entries; i++) assertEquals(new Integer(i), cache.get(i));
    } finally {
        stopAllGrids();
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite)

Example 10 with GridCacheDatabaseSharedManager

use of org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager in project ignite by apache.

the class WalRecoveryTxLogicalRecordsTest method testWalTxSimple.

/**
 * @throws Exception If failed.
 */
public void testWalTxSimple() throws Exception {
    Ignite ignite = startGrid();
    ignite.cluster().active(true);
    try {
        GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager) ((IgniteEx) ignite).context().cache().context().database();
        dbMgr.enableCheckpoints(false).get();
        IgniteCache<Integer, IndexedValue> cache = ignite.cache(CACHE_NAME);
        int txCnt = 100;
        int keysPerTx = 10;
        for (int i = 0; i < txCnt; i++) {
            try (Transaction tx = ignite.transactions().txStart()) {
                for (int j = 0; j < keysPerTx; j++) {
                    int k = i * keysPerTx + j;
                    cache.put(k, new IndexedValue(k));
                }
                tx.commit();
            }
        }
        for (int i = 0; i < txCnt; i++) {
            for (int j = 0; j < keysPerTx; j++) {
                int k = i * keysPerTx + j;
                assertEquals(k, cache.get(k).value());
            }
        }
        stopGrid();
        ignite = startGrid();
        ignite.cluster().active(true);
        cache = ignite.cache(CACHE_NAME);
        for (int i = 0; i < txCnt; i++) {
            for (int j = 0; j < keysPerTx; j++) {
                int k = i * keysPerTx + j;
                assertEquals(k, cache.get(k).value());
            }
        }
        for (int i = 0; i < txCnt; i++) {
            for (int j = 0; j < keysPerTx; j++) {
                int k = i * keysPerTx + j;
                QueryCursor<List<?>> cur = cache.query(new SqlFieldsQuery("select sVal from IndexedValue where iVal=?").setArgs(k));
                List<List<?>> vals = cur.getAll();
                assertEquals(vals.size(), 1);
                assertEquals("string-" + k, vals.get(0).get(0));
            }
        }
    } finally {
        stopAllGrids();
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Transaction(org.apache.ignite.transactions.Transaction) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) PagesList(org.apache.ignite.internal.processors.cache.persistence.freelist.PagesList) AbstractFreeList(org.apache.ignite.internal.processors.cache.persistence.freelist.AbstractFreeList) List(java.util.List) ArrayList(java.util.ArrayList) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery)

Aggregations

GridCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager)28 IgniteEx (org.apache.ignite.internal.IgniteEx)19 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 Ignite (org.apache.ignite.Ignite)8 ArrayList (java.util.ArrayList)7 IgniteWriteAheadLogManager (org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager)6 WALPointer (org.apache.ignite.internal.pagemem.wal.WALPointer)6 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)5 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)5 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)4 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)4 FullPageId (org.apache.ignite.internal.pagemem.FullPageId)4 WALRecord (org.apache.ignite.internal.pagemem.wal.record.WALRecord)4 ByteBuffer (java.nio.ByteBuffer)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Random (java.util.Random)3 PageMemory (org.apache.ignite.internal.pagemem.PageMemory)3 IgnitePageStoreManager (org.apache.ignite.internal.pagemem.store.IgnitePageStoreManager)3 CheckpointRecord (org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord)3