Search in sources :

Example 1 with BreakBuildIndexConsumer

use of org.apache.ignite.internal.processors.cache.index.IndexingTestUtils.BreakBuildIndexConsumer in project ignite by apache.

the class ResumeRebuildIndexTest method testDeleteIndexRebuildStateOnDestroyCache.

/**
 * Checks that when the caches are destroyed,
 * the index rebuild states will also be deleted.
 *
 * @throws Exception If failed.
 */
@Test
public void testDeleteIndexRebuildStateOnDestroyCache() throws Exception {
    IgniteEx n0 = startGrid(getTestIgniteInstanceName(0));
    prepareBeforeNodeStart();
    IgniteEx n1 = startGrid(getTestIgniteInstanceName(1));
    n0.cluster().state(ACTIVE);
    awaitPartitionMapExchange();
    for (int i = 0; i < 4; i++) {
        String cacheName = DEFAULT_CACHE_NAME + i;
        String grpName = i == 1 || i == 2 ? DEFAULT_CACHE_NAME + "_G" : null;
        populate(n1.getOrCreateCache(cacheCfg(cacheName, grpName)), 10_000);
        BreakBuildIndexConsumer breakRebuildIdxConsumer = addBreakRebuildIndexConsumer(n1, cacheName, 10);
        IgniteInternalCache<?, ?> cachex = n1.cachex(cacheName);
        int cacheSize = cachex.size();
        assertTrue(forceRebuildIndexes(n1, cachex.context()).isEmpty());
        IgniteInternalFuture<?> rebIdxFut = indexRebuildFuture(n1, cachex.context().cacheId());
        breakRebuildIdxConsumer.startBuildIdxFut.get(getTestTimeout());
        breakRebuildIdxConsumer.finishBuildIdxFut.onDone();
        assertThrows(log, () -> rebIdxFut.get(getTestTimeout()), Throwable.class, null);
        assertTrue(breakRebuildIdxConsumer.visitCnt.get() < cacheSize);
    }
    n1.destroyCache(DEFAULT_CACHE_NAME + 0);
    assertTrue(indexBuildStatusStorage(n1).rebuildCompleted(DEFAULT_CACHE_NAME + 0));
    n1.destroyCache(DEFAULT_CACHE_NAME + 1);
    assertTrue(indexBuildStatusStorage(n1).rebuildCompleted(DEFAULT_CACHE_NAME + 1));
    assertFalse(indexBuildStatusStorage(n1).rebuildCompleted(DEFAULT_CACHE_NAME + 2));
    assertFalse(indexBuildStatusStorage(n1).rebuildCompleted(DEFAULT_CACHE_NAME + 3));
    forceCheckpoint(n1);
    ConcurrentMap<String, IndexBuildStatusHolder> states = statuses(n1);
    assertFalse(states.containsKey(DEFAULT_CACHE_NAME + 0));
    assertFalse(states.containsKey(DEFAULT_CACHE_NAME + 1));
    assertTrue(states.containsKey(DEFAULT_CACHE_NAME + 2));
    assertTrue(states.containsKey(DEFAULT_CACHE_NAME + 3));
    stopGrid(1);
    awaitPartitionMapExchange();
    n0.destroyCache(DEFAULT_CACHE_NAME + 2);
    n0.destroyCache(DEFAULT_CACHE_NAME + 3);
    deleteCacheGrpDir(n1.name(), (dir, name) -> name.contains(DEFAULT_CACHE_NAME + 3) || name.contains(DEFAULT_CACHE_NAME + "_G"));
    n1 = startGrid(getTestIgniteInstanceName(1));
    assertTrue(indexBuildStatusStorage(n1).rebuildCompleted(DEFAULT_CACHE_NAME + 2));
    assertTrue(indexBuildStatusStorage(n1).rebuildCompleted(DEFAULT_CACHE_NAME + 3));
    forceCheckpoint(n1);
    states = statuses(n1);
    assertFalse(states.containsKey(DEFAULT_CACHE_NAME + 2));
    assertFalse(states.containsKey(DEFAULT_CACHE_NAME + 3));
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) IndexBuildStatusHolder(org.apache.ignite.internal.processors.query.aware.IndexBuildStatusHolder) BreakBuildIndexConsumer(org.apache.ignite.internal.processors.cache.index.IndexingTestUtils.BreakBuildIndexConsumer) Test(org.junit.Test)

Example 2 with BreakBuildIndexConsumer

use of org.apache.ignite.internal.processors.cache.index.IndexingTestUtils.BreakBuildIndexConsumer in project ignite by apache.

the class ResumeRebuildIndexTest method testRestartNodeFlowIndexRebuildStateStorage.

/**
 * Checking the flow in case of an restart node for {@link IndexBuildStatusStorage}.
 *
 * @throws Exception If failed.
 */
@Test
public void testRestartNodeFlowIndexRebuildStateStorage() throws Exception {
    prepareBeforeNodeStart();
    IgniteEx n = startGrid(0);
    populate(n.cache(DEFAULT_CACHE_NAME), 1_000);
    GridCacheContext<?, ?> cacheCtx = n.cachex(DEFAULT_CACHE_NAME).context();
    BreakBuildIndexConsumer breakRebuildIdxConsumer = addBreakRebuildIndexConsumer(n, cacheCtx.name(), 10);
    assertTrue(forceRebuildIndexes(n, cacheCtx).isEmpty());
    IgniteInternalFuture<?> idxRebFut0 = indexRebuildFuture(n, cacheCtx.cacheId());
    breakRebuildIdxConsumer.startBuildIdxFut.get(getTestTimeout());
    breakRebuildIdxConsumer.finishBuildIdxFut.onDone();
    assertThrows(log, () -> idxRebFut0.get(getTestTimeout()), Throwable.class, null);
    forceCheckpoint();
    assertFalse(indexBuildStatusStorage(n).rebuildCompleted(cacheCtx.name()));
    assertNotNull(metaStorageOperation(n, metaStorage -> metaStorage.read(KEY_PREFIX + cacheCtx.name())));
    stopAllGrids();
    StopBuildIndexConsumer stopRebuildIdxConsumer = addStopRebuildIndexConsumer(n, cacheCtx.name());
    prepareBeforeNodeStart();
    n = startGrid(0);
    assertFalse(indexBuildStatusStorage(n).rebuildCompleted(cacheCtx.name()));
    assertNotNull(metaStorageOperation(n, metaStorage -> metaStorage.read(KEY_PREFIX + cacheCtx.name())));
    stopRebuildIdxConsumer.startBuildIdxFut.get(getTestTimeout());
    IgniteInternalFuture<?> idxRebFut1 = indexRebuildFuture(n, cacheCtx.cacheId());
    dbMgr(n).enableCheckpoints(false).get(getTestTimeout());
    stopRebuildIdxConsumer.finishBuildIdxFut.onDone();
    idxRebFut1.get(getTestTimeout());
    assertEquals(1_000, stopRebuildIdxConsumer.visitCnt.get());
    assertTrue(indexBuildStatusStorage(n).rebuildCompleted(cacheCtx.name()));
    assertNotNull(metaStorageOperation(n, metaStorage -> metaStorage.read(KEY_PREFIX + cacheCtx.name())));
    dbMgr(n).enableCheckpoints(true).get(getTestTimeout());
    forceCheckpoint();
    assertNull(metaStorageOperation(n, metaStorage -> metaStorage.read(KEY_PREFIX + cacheCtx.name())));
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) ACTIVE(org.apache.ignite.cluster.ClusterState.ACTIVE) INACTIVE(org.apache.ignite.cluster.ClusterState.INACTIVE) GridTestUtils.assertThrows(org.apache.ignite.testframework.GridTestUtils.assertThrows) IgniteEx(org.apache.ignite.internal.IgniteEx) Test(org.junit.Test) IndexesRebuildTaskEx.prepareBeforeNodeStart(org.apache.ignite.internal.processors.cache.index.IndexesRebuildTaskEx.prepareBeforeNodeStart) StopBuildIndexConsumer(org.apache.ignite.internal.processors.cache.index.IndexingTestUtils.StopBuildIndexConsumer) ThrowableFunction(org.apache.ignite.internal.util.function.ThrowableFunction) ConcurrentMap(java.util.concurrent.ConcurrentMap) BreakBuildIndexConsumer(org.apache.ignite.internal.processors.cache.index.IndexingTestUtils.BreakBuildIndexConsumer) IndexBuildStatusHolder(org.apache.ignite.internal.processors.query.aware.IndexBuildStatusHolder) GridTestUtils.deleteCacheGrpDir(org.apache.ignite.testframework.GridTestUtils.deleteCacheGrpDir) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) IndexBuildStatusStorage(org.apache.ignite.internal.processors.query.aware.IndexBuildStatusStorage) KEY_PREFIX(org.apache.ignite.internal.processors.query.aware.IndexBuildStatusStorage.KEY_PREFIX) IgniteInternalCache(org.apache.ignite.internal.processors.cache.IgniteInternalCache) IgniteEx(org.apache.ignite.internal.IgniteEx) StopBuildIndexConsumer(org.apache.ignite.internal.processors.cache.index.IndexingTestUtils.StopBuildIndexConsumer) BreakBuildIndexConsumer(org.apache.ignite.internal.processors.cache.index.IndexingTestUtils.BreakBuildIndexConsumer) Test(org.junit.Test)

Example 3 with BreakBuildIndexConsumer

use of org.apache.ignite.internal.processors.cache.index.IndexingTestUtils.BreakBuildIndexConsumer in project ignite by apache.

the class ResumeCreateIndexTest method testErrorFlow.

/**
 * Checks that if errors occur while building a new index, then there will be no rebuilding of the indexes.
 *
 * @throws Exception If failed.
 */
@Test
public void testErrorFlow() throws Exception {
    String cacheName = DEFAULT_CACHE_NAME;
    IgniteEx n = prepareNodeToCreateNewIndex(cacheName, 10, true);
    String idxName = "IDX0";
    BreakBuildIndexConsumer breakBuildIdxConsumer = addBreakIdxCreateConsumer(n, idxName, 1);
    IgniteInternalFuture<List<List<?>>> createIdxFut = createIdxAsync(n.cache(cacheName), idxName);
    breakBuildIdxConsumer.startBuildIdxFut.get(getTestTimeout());
    checkInitStatus(n, cacheName, false, 1);
    breakBuildIdxConsumer.finishBuildIdxFut.onDone();
    assertThrows(log, () -> createIdxFut.get(getTestTimeout()), IgniteCheckedException.class, null);
    checkCompletedStatus(n, cacheName);
    enableCheckpointsAsync(n, getTestIgniteInstanceName(), true).get(getTestTimeout());
    checkNoStatus(n, cacheName);
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) List(java.util.List) BreakBuildIndexConsumer(org.apache.ignite.internal.processors.cache.index.IndexingTestUtils.BreakBuildIndexConsumer) Test(org.junit.Test)

Example 4 with BreakBuildIndexConsumer

use of org.apache.ignite.internal.processors.cache.index.IndexingTestUtils.BreakBuildIndexConsumer in project ignite by apache.

the class AbstractRebuildIndexTest method addBreakRebuildIndexConsumer.

/**
 * Registering a {@link BreakBuildIndexConsumer} to {@link IndexesRebuildTaskEx#addCacheRowConsumer}.
 *
 * @param n Node.
 * @param cacheName Cache name.
 * @param breakCnt Count of rows processed, after which an {@link IgniteCheckedException} will be thrown.
 * @return New instance of {@link BreakBuildIndexConsumer}.
 */
protected BreakBuildIndexConsumer addBreakRebuildIndexConsumer(IgniteEx n, String cacheName, int breakCnt) {
    BreakBuildIndexConsumer consumer = new BreakBuildIndexConsumer(getTestTimeout(), (c, r) -> c.visitCnt.get() >= breakCnt);
    addCacheRowConsumer(nodeName(n), cacheName, consumer);
    return consumer;
}
Also used : BreakBuildIndexConsumer(org.apache.ignite.internal.processors.cache.index.IndexingTestUtils.BreakBuildIndexConsumer)

Example 5 with BreakBuildIndexConsumer

use of org.apache.ignite.internal.processors.cache.index.IndexingTestUtils.BreakBuildIndexConsumer in project ignite by apache.

the class ResumeRebuildIndexTest method checkRestartRebuildIndexes.

/**
 * Check that for node the index rebuilding will be restarted
 * automatically after executing the function on the node.
 *
 * @param nodeCnt Node count.
 * @param function Function for node.
 * @throws Exception If failed.
 */
private void checkRestartRebuildIndexes(int nodeCnt, ThrowableFunction<IgniteEx, IgniteEx, Exception> function) throws Exception {
    assertTrue(nodeCnt > 0);
    for (int i = 0; i < nodeCnt - 1; i++) startGrid(getTestIgniteInstanceName(i + 1));
    prepareBeforeNodeStart();
    IgniteEx n = startGrid(0);
    populate(n.cache(DEFAULT_CACHE_NAME), 10_000);
    populate(n.getOrCreateCache(cacheCfg(DEFAULT_CACHE_NAME + 0, null)), 10_000);
    if (nodeCnt > 1)
        awaitPartitionMapExchange();
    IgniteInternalCache<?, ?> cachex0 = n.cachex(DEFAULT_CACHE_NAME);
    IgniteInternalCache<?, ?> cachex1 = n.cachex(DEFAULT_CACHE_NAME + 0);
    int cacheSize0 = cachex0.size();
    int cacheSize1 = cachex1.size();
    assertTrue(String.valueOf(cacheSize0), cacheSize0 >= 1_000);
    assertTrue(String.valueOf(cacheSize1), cacheSize1 >= 1_000);
    GridCacheContext<?, ?> cacheCtx0 = cachex0.context();
    GridCacheContext<?, ?> cacheCtx1 = cachex1.context();
    BreakBuildIndexConsumer breakRebuildIdxConsumer = addBreakRebuildIndexConsumer(n, cacheCtx0.name(), 10);
    StopBuildIndexConsumer stopRebuildIdxConsumer0 = addStopRebuildIndexConsumer(n, cacheCtx1.name());
    assertTrue(forceRebuildIndexes(n, cacheCtx0, cacheCtx1).isEmpty());
    IgniteInternalFuture<?> rebIdxFut0 = indexRebuildFuture(n, cacheCtx0.cacheId());
    IgniteInternalFuture<?> rebIdxFut1 = indexRebuildFuture(n, cacheCtx1.cacheId());
    breakRebuildIdxConsumer.startBuildIdxFut.get(getTestTimeout());
    breakRebuildIdxConsumer.finishBuildIdxFut.onDone();
    stopRebuildIdxConsumer0.startBuildIdxFut.get(getTestTimeout());
    stopRebuildIdxConsumer0.finishBuildIdxFut.onDone();
    assertThrows(log, () -> rebIdxFut0.get(getTestTimeout()), Throwable.class, null);
    assertTrue(breakRebuildIdxConsumer.visitCnt.get() < cacheSize0);
    rebIdxFut1.get(getTestTimeout());
    assertEquals(cacheSize1, stopRebuildIdxConsumer0.visitCnt.get());
    StopBuildIndexConsumer stopRebuildIdxConsumer1 = addStopRebuildIndexConsumer(n, cacheCtx0.name());
    stopRebuildIdxConsumer0.resetFutures();
    forceCheckpoint();
    n = function.apply(n);
    IgniteInternalFuture<?> rebIdxFut01 = indexRebuildFuture(n, cacheCtx0.cacheId());
    IgniteInternalFuture<?> rebIdxFut11 = indexRebuildFuture(n, cacheCtx1.cacheId());
    stopRebuildIdxConsumer1.startBuildIdxFut.get(getTestTimeout());
    stopRebuildIdxConsumer1.finishBuildIdxFut.onDone();
    assertThrows(log, () -> stopRebuildIdxConsumer0.startBuildIdxFut.get(1_000), IgniteFutureTimeoutCheckedException.class, null);
    stopRebuildIdxConsumer0.finishBuildIdxFut.onDone();
    rebIdxFut01.get(getTestTimeout());
    assertEquals(cacheSize0, stopRebuildIdxConsumer1.visitCnt.get());
    assertNull(rebIdxFut11);
    assertEquals(cacheSize1, stopRebuildIdxConsumer0.visitCnt.get());
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) StopBuildIndexConsumer(org.apache.ignite.internal.processors.cache.index.IndexingTestUtils.StopBuildIndexConsumer) BreakBuildIndexConsumer(org.apache.ignite.internal.processors.cache.index.IndexingTestUtils.BreakBuildIndexConsumer)

Aggregations

BreakBuildIndexConsumer (org.apache.ignite.internal.processors.cache.index.IndexingTestUtils.BreakBuildIndexConsumer)7 IgniteEx (org.apache.ignite.internal.IgniteEx)5 Test (org.junit.Test)4 StopBuildIndexConsumer (org.apache.ignite.internal.processors.cache.index.IndexingTestUtils.StopBuildIndexConsumer)3 IndexBuildStatusHolder (org.apache.ignite.internal.processors.query.aware.IndexBuildStatusHolder)3 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 ACTIVE (org.apache.ignite.cluster.ClusterState.ACTIVE)2 INACTIVE (org.apache.ignite.cluster.ClusterState.INACTIVE)2 IgniteFutureTimeoutCheckedException (org.apache.ignite.internal.IgniteFutureTimeoutCheckedException)2 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)2 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)2 IgniteInternalCache (org.apache.ignite.internal.processors.cache.IgniteInternalCache)2 IndexesRebuildTaskEx.prepareBeforeNodeStart (org.apache.ignite.internal.processors.cache.index.IndexesRebuildTaskEx.prepareBeforeNodeStart)2 IndexBuildStatusStorage (org.apache.ignite.internal.processors.query.aware.IndexBuildStatusStorage)2 KEY_PREFIX (org.apache.ignite.internal.processors.query.aware.IndexBuildStatusStorage.KEY_PREFIX)2 ThrowableFunction (org.apache.ignite.internal.util.function.ThrowableFunction)2 GridTestUtils.assertThrows (org.apache.ignite.testframework.GridTestUtils.assertThrows)2 GridTestUtils.deleteCacheGrpDir (org.apache.ignite.testframework.GridTestUtils.deleteCacheGrpDir)2 List (java.util.List)1