Search in sources :

Example 6 with BreakBuildIndexConsumer

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

the class ResumeRebuildIndexTest method testErrorFlowIndexRebuildStateStorage.

/**
 * Checking the flow in case of an error for {@link IndexBuildStatusStorage}.
 *
 * @throws Exception If failed.
 */
@Test
public void testErrorFlowIndexRebuildStateStorage() 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());
    assertFalse(indexBuildStatusStorage(n).rebuildCompleted(cacheCtx.name()));
    assertNotNull(metaStorageOperation(n, metaStorage -> metaStorage.read(KEY_PREFIX + cacheCtx.name())));
    breakRebuildIdxConsumer.startBuildIdxFut.get(getTestTimeout());
    breakRebuildIdxConsumer.finishBuildIdxFut.onDone();
    assertThrows(log, () -> idxRebFut0.get(getTestTimeout()), Throwable.class, null);
    assertTrue(breakRebuildIdxConsumer.visitCnt.get() < 1_000);
    forceCheckpoint();
    assertFalse(indexBuildStatusStorage(n).rebuildCompleted(cacheCtx.name()));
    assertNotNull(metaStorageOperation(n, metaStorage -> metaStorage.read(KEY_PREFIX + cacheCtx.name())));
    StopBuildIndexConsumer stopRebuildIdxConsumer = addStopRebuildIndexConsumer(n, cacheCtx.name());
    dbMgr(n).enableCheckpoints(false).get(getTestTimeout());
    assertTrue(forceRebuildIndexes(n, cacheCtx).isEmpty());
    IgniteInternalFuture<?> idxRebFut1 = indexRebuildFuture(n, cacheCtx.cacheId());
    assertFalse(indexBuildStatusStorage(n).rebuildCompleted(cacheCtx.name()));
    assertNotNull(metaStorageOperation(n, metaStorage -> metaStorage.read(KEY_PREFIX + cacheCtx.name())));
    stopRebuildIdxConsumer.startBuildIdxFut.get(getTestTimeout());
    stopRebuildIdxConsumer.finishBuildIdxFut.onDone();
    idxRebFut1.get(getTestTimeout());
    assertEquals(1_000, stopRebuildIdxConsumer.visitCnt.get());
    assertTrue(indexBuildStatusStorage(n).rebuildCompleted(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 7 with BreakBuildIndexConsumer

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

the class AbstractRebuildIndexTest method addBreakIdxCreateConsumer.

/**
 * Registering a {@link BreakBuildIndexConsumer} to {@link IgniteH2IndexingEx#addIdxCreateCacheRowConsumer}.
 *
 * @param n Node.
 * @param idxName Index name.
 * @param breakCnt Count of rows processed, after which an {@link IgniteCheckedException} will be thrown.
 * @return New instance of {@link BreakBuildIndexConsumer}.
 */
protected BreakBuildIndexConsumer addBreakIdxCreateConsumer(IgniteEx n, String idxName, int breakCnt) {
    BreakBuildIndexConsumer consumer = new BreakBuildIndexConsumer(getTestTimeout(), (c, r) -> c.visitCnt.get() >= breakCnt);
    addIdxCreateCacheRowConsumer(nodeName(n), idxName, consumer);
    return consumer;
}
Also used : 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