Search in sources :

Example 11 with IgniteInternalCache

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

the class GridIndexRebuildSelfTest method testDataRaceWhenMarkIdxRebuild.

/**
 * Test checks that there will be no data race between notifications about index rebuilding
 * and an indication that index has been rebuilt.
 *
 * Steps:
 * 1)Create a node with data filling;
 * 2)Stopping a node with deletion index.bin;
 * 3)Set a delay between notification and a note about index rebuilding;
 * 4)Restarting node with waiting index rebuild;
 * 5)Checking that index is not being rebuilt.
 *
 * @throws Exception if failed.
 */
@Test
public void testDataRaceWhenMarkIdxRebuild() throws Exception {
    IgniteEx srv = startServer();
    IgniteInternalCache internalCache = createAndFillTableWithIndex(srv);
    File idxFile = indexFile(internalCache);
    stopAllGrids();
    assertTrue(delete(idxFile));
    BlockingIndexesRebuildTask.slowRebuildIdxFut = true;
    srv = startServer();
    srv.cache(CACHE_NAME).indexReadyFuture().get();
    IgniteH2Indexing idx = (IgniteH2Indexing) srv.context().query().getIndexing();
    GridH2Table tbl = idx.schemaManager().dataTable(DFLT_SCHEMA, CACHE_NAME);
    assertNotNull(tbl);
    assertFalse(tbl.rebuildFromHashInProgress());
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) GridH2Table(org.apache.ignite.internal.processors.query.h2.opt.GridH2Table) IgniteInternalCache(org.apache.ignite.internal.processors.cache.IgniteInternalCache) File(java.io.File) DynamicIndexAbstractSelfTest(org.apache.ignite.internal.processors.cache.index.DynamicIndexAbstractSelfTest) Test(org.junit.Test)

Example 12 with IgniteInternalCache

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

the class GridIndexRebuildSelfTest method checkDataState.

/**
 * Check versions presence in index tree.
 *
 * @param srv Node.
 * @param afterRebuild Whether index rebuild has occurred.
 * @throws IgniteCheckedException if failed.
 */
@SuppressWarnings({ "ConstantConditions", "unchecked" })
protected void checkDataState(IgniteEx srv, boolean afterRebuild) throws IgniteCheckedException {
    IgniteInternalCache icache = srv.cachex(CACHE_NAME);
    IgniteCache cache = srv.cache(CACHE_NAME);
    assertNotNull(icache);
    for (IgniteCacheOffheapManager.CacheDataStore store : icache.context().offheap().cacheDataStores()) {
        GridCursor<? extends CacheDataRow> cur = store.cursor();
        while (cur.next()) {
            CacheDataRow row = cur.get();
            int key = row.key().value(icache.context().cacheObjectContext(), false);
            if (!afterRebuild || key <= AMOUNT / 2)
                assertEquals(key, cache.get(key));
            else
                assertEquals(-1, cache.get(key));
        }
    }
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) IgniteCacheOffheapManager(org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManager) IgniteCache(org.apache.ignite.IgniteCache) IgniteInternalCache(org.apache.ignite.internal.processors.cache.IgniteInternalCache)

Example 13 with IgniteInternalCache

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

the class GridIndexRebuildSelfTest method createAndFillTableWithIndex.

/**
 * Creating a cache, table, index and populating data.
 *
 * @param node Node.
 * @return Cache.
 * @throws Exception if failed.
 */
private IgniteInternalCache createAndFillTableWithIndex(IgniteEx node) throws Exception {
    requireNonNull(node);
    String cacheName = CACHE_NAME;
    execute(node, "CREATE TABLE T(k int primary key, v int) WITH \"cache_name=" + cacheName + ",wrap_value=false,atomicity=transactional\"");
    execute(node, "CREATE INDEX IDX ON T(v)");
    IgniteInternalCache cc = node.cachex(cacheName);
    assertNotNull(cc);
    putData(node, false);
    return cc;
}
Also used : IgniteInternalCache(org.apache.ignite.internal.processors.cache.IgniteInternalCache)

Example 14 with IgniteInternalCache

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

the class GridIndexRebuildWithMvccEnabledSelfTest method testIndexRebuild.

/**
 * {@inheritDoc}
 */
@Test
@Override
public void testIndexRebuild() throws Exception {
    IgniteEx srv = startServer();
    execute(srv, "CREATE TABLE T(k int primary key, v int) WITH \"cache_name=T,wrap_value=false," + "atomicity=transactional_snapshot\"");
    execute(srv, "CREATE INDEX IDX ON T(v)");
    IgniteInternalCache cc = srv.cachex(CACHE_NAME);
    assertNotNull(cc);
    lockVersion(srv);
    putData(srv, false);
    checkDataState(srv, false);
    File idxPath = indexFile(cc);
    stopAllGrids();
    assertTrue(U.delete(idxPath));
    srv = startServer();
    putData(srv, true);
    checkDataState(srv, true);
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteInternalCache(org.apache.ignite.internal.processors.cache.IgniteInternalCache) File(java.io.File) Test(org.junit.Test)

Example 15 with IgniteInternalCache

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

the class GridIndexRebuildWithMvccEnabledSelfTest method checkDataState.

/**
 * {@inheritDoc}
 */
@Override
protected void checkDataState(IgniteEx srv, boolean afterRebuild) throws IgniteCheckedException {
    IgniteInternalCache icache = srv.cachex(CACHE_NAME);
    assertNotNull(icache);
    CacheObjectContext coCtx = icache.context().cacheObjectContext();
    for (IgniteCacheOffheapManager.CacheDataStore store : icache.context().offheap().cacheDataStores()) {
        GridCursor<? extends CacheDataRow> cur = store.cursor();
        while (cur.next()) {
            CacheDataRow row = cur.get();
            int key = row.key().value(coCtx, false);
            List<IgniteBiTuple<Object, MvccVersion>> vers = store.mvccFindAllVersions(icache.context(), row.key());
            if (!afterRebuild || key <= AMOUNT / 2)
                assertEquals(key, vers.size());
            else {
                // For keys affected by concurrent put there are two versions -
                // -1 (concurrent put mark) and newest restored value as long as put cleans obsolete versions.
                assertEquals(2, vers.size());
                Object val0 = ((CacheObject) vers.get(0).getKey()).value(coCtx, false);
                Object val1 = ((CacheObject) vers.get(1).getKey()).value(coCtx, false);
                assertEquals(-1, val0);
                assertEquals(key, val1);
            }
        }
    }
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) IgniteCacheOffheapManager(org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManager) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) IgniteInternalCache(org.apache.ignite.internal.processors.cache.IgniteInternalCache) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) CacheObjectContext(org.apache.ignite.internal.processors.cache.CacheObjectContext)

Aggregations

IgniteInternalCache (org.apache.ignite.internal.processors.cache.IgniteInternalCache)32 IgniteEx (org.apache.ignite.internal.IgniteEx)11 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)8 Test (org.junit.Test)8 Ignite (org.apache.ignite.Ignite)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 ClusterNode (org.apache.ignite.cluster.ClusterNode)6 IgniteKernal (org.apache.ignite.internal.IgniteKernal)6 ArrayList (java.util.ArrayList)5 IgniteCache (org.apache.ignite.IgniteCache)5 File (java.io.File)4 Cache (javax.cache.Cache)4 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)4 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)4 List (java.util.List)3 GridKernalContext (org.apache.ignite.internal.GridKernalContext)3 GridCacheAdapter (org.apache.ignite.internal.processors.cache.GridCacheAdapter)3 IgniteCacheOffheapManager (org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManager)3 CacheDataRow (org.apache.ignite.internal.processors.cache.persistence.CacheDataRow)3