Search in sources :

Example 1 with StopBuildIndexConsumer

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

the class ResumeRebuildIndexTest method testNormalFlowIndexRebuildStateStorage.

/**
 * Checking normal flow for {@link IndexBuildStatusStorage}.
 *
 * @throws Exception If failed.
 */
@Test
public void testNormalFlowIndexRebuildStateStorage() throws Exception {
    prepareBeforeNodeStart();
    IgniteEx n = startGrid(0);
    populate(n.cache(DEFAULT_CACHE_NAME), 1_000);
    GridCacheContext<?, ?> cacheCtx = n.cachex(DEFAULT_CACHE_NAME).context();
    StopBuildIndexConsumer stopRebuildIdxConsumer = addStopRebuildIndexConsumer(n, cacheCtx.name());
    dbMgr(n).enableCheckpoints(false).get(getTestTimeout());
    assertTrue(forceRebuildIndexes(n, cacheCtx).isEmpty());
    IgniteInternalFuture<?> idxRebFut = 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();
    idxRebFut.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) Test(org.junit.Test)

Example 2 with StopBuildIndexConsumer

use of org.apache.ignite.internal.processors.cache.index.IndexingTestUtils.StopBuildIndexConsumer 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 StopBuildIndexConsumer

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

the class StopRebuildIndexTest method testInternalIndexingRebuildFuture.

/**
 * Checking the correctness of the {@code IgniteH2Indexing#idxRebuildFuts}.
 *
 * @throws Exception If failed.
 */
@Test
public void testInternalIndexingRebuildFuture() throws Exception {
    prepareBeforeNodeStart();
    IgniteEx n = startGrid(0);
    populate(n.cache(DEFAULT_CACHE_NAME), 10);
    GridCacheContext<?, ?> cacheCtx = n.cachex(DEFAULT_CACHE_NAME).context();
    addCacheRebuildRunner(nodeName(n), cacheCtx.name(), () -> assertNull(internalIndexRebuildFuture(n, cacheCtx.cacheId())));
    StopBuildIndexConsumer stopRebuildIdxConsumer = addStopRebuildIndexConsumer(n, cacheCtx.name());
    forceRebuildIndexes(n, cacheCtx);
    IgniteInternalFuture<?> rebFut0 = indexRebuildFuture(n, cacheCtx.cacheId());
    assertNotNull(rebFut0);
    SchemaIndexCacheFuture rebFut1 = internalIndexRebuildFuture(n, cacheCtx.cacheId());
    assertNotNull(rebFut1);
    stopRebuildIdxConsumer.startBuildIdxFut.get(getTestTimeout());
    assertFalse(rebFut0.isDone());
    assertFalse(rebFut1.isDone());
    assertNull(rebFut1.cancelToken().cancelException());
    stopRebuildIdxConsumer.finishBuildIdxFut.onDone();
    rebFut0.get(getTestTimeout());
    rebFut1.get(getTestTimeout());
    assertNull(rebFut1.cancelToken().cancelException());
    assertNull(indexRebuildFuture(n, cacheCtx.cacheId()));
    assertNull(internalIndexRebuildFuture(n, cacheCtx.cacheId()));
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) SchemaIndexCacheFuture(org.apache.ignite.internal.processors.query.schema.SchemaIndexCacheFuture) StopBuildIndexConsumer(org.apache.ignite.internal.processors.cache.index.IndexingTestUtils.StopBuildIndexConsumer) Test(org.junit.Test)

Example 4 with StopBuildIndexConsumer

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

the class ForceRebuildIndexTest method testSequentialRebuildIndexesOnExchange.

/**
 * Checking that sequential index rebuilds on exchanges will not intersection.
 *
 * @throws Exception If failed.
 */
@Test
public void testSequentialRebuildIndexesOnExchange() throws Exception {
    IgniteEx n = startGrid(0);
    populate(n.cache(DEFAULT_CACHE_NAME), 100);
    stopAllGridsWithDeleteIndexBin();
    prepareBeforeNodeStart();
    StopBuildIndexConsumer stopRebuildIdxConsumer = addStopRebuildIndexConsumer(n, DEFAULT_CACHE_NAME);
    n = startGrid(0);
    GridCacheContext<?, ?> cacheCtx = n.cachex(DEFAULT_CACHE_NAME).context();
    stopRebuildIdxConsumer.startBuildIdxFut.get(getTestTimeout());
    IgniteInternalFuture<?> idxRebFut = checkStartRebuildIndexes(n, cacheCtx);
    // To initiate an exchange.
    n.getOrCreateCache(DEFAULT_CACHE_NAME + "_1");
    assertTrue(idxRebFut == indexRebuildFuture(n, cacheCtx.cacheId()));
    stopRebuildIdxConsumer.finishBuildIdxFut.onDone();
    idxRebFut.get(getTestTimeout());
    checkFinishRebuildIndexes(n, cacheCtx, 100);
    assertEquals(100, stopRebuildIdxConsumer.visitCnt.get());
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) StopBuildIndexConsumer(org.apache.ignite.internal.processors.cache.index.IndexingTestUtils.StopBuildIndexConsumer) Test(org.junit.Test)

Example 5 with StopBuildIndexConsumer

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

the class ForceRebuildIndexTest method testForceRebuildIndexesAfterExchange.

/**
 * Checking that a forced index rebuild can only be performed after an index rebuild after an exchange.
 *
 * @throws Exception If failed.
 */
@Test
public void testForceRebuildIndexesAfterExchange() throws Exception {
    IgniteEx n = startGrid(0);
    populate(n.cache(DEFAULT_CACHE_NAME), 100);
    stopAllGridsWithDeleteIndexBin();
    prepareBeforeNodeStart();
    StopBuildIndexConsumer stopRebuildIdxConsumer = addStopRebuildIndexConsumer(n, DEFAULT_CACHE_NAME);
    n = startGrid(0);
    GridCacheContext<?, ?> cacheCtx = n.cachex(DEFAULT_CACHE_NAME).context();
    stopRebuildIdxConsumer.startBuildIdxFut.get(getTestTimeout());
    IgniteInternalFuture<?> idxRebFut0 = checkStartRebuildIndexes(n, cacheCtx);
    checkRebuildAfterExchange(n, cacheCtx.cacheId(), true);
    // There will be no forced rebuilding of indexes since it has not ended after the exchange - they will be rejected.
    assertEqualsCollections(F.asList(cacheCtx), forceRebuildIndexes(n, cacheCtx));
    assertTrue(idxRebFut0 == indexRebuildFuture(n, cacheCtx.cacheId()));
    checkRebuildAfterExchange(n, cacheCtx.cacheId(), true);
    stopRebuildIdxConsumer.finishBuildIdxFut.onDone();
    idxRebFut0.get(getTestTimeout());
    checkFinishRebuildIndexes(n, cacheCtx, 100);
    assertEquals(100, stopRebuildIdxConsumer.visitCnt.get());
    checkRebuildAfterExchange(n, cacheCtx.cacheId(), false);
    stopRebuildIdxConsumer.resetFutures();
    // A forced index rebuild will be triggered because it has ended after the exchange - no rejected.
    assertEqualsCollections(emptyList(), forceRebuildIndexes(n, cacheCtx));
    IgniteInternalFuture<?> idxRebFut1 = checkStartRebuildIndexes(n, cacheCtx);
    checkRebuildAfterExchange(n, cacheCtx.cacheId(), false);
    stopRebuildIdxConsumer.startBuildIdxFut.get(getTestTimeout());
    assertFalse(idxRebFut1.isDone());
    stopRebuildIdxConsumer.finishBuildIdxFut.onDone();
    idxRebFut1.get(getTestTimeout());
    checkFinishRebuildIndexes(n, cacheCtx, 100);
    checkRebuildAfterExchange(n, cacheCtx.cacheId(), false);
    assertEquals(200, stopRebuildIdxConsumer.visitCnt.get());
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) StopBuildIndexConsumer(org.apache.ignite.internal.processors.cache.index.IndexingTestUtils.StopBuildIndexConsumer) Test(org.junit.Test)

Aggregations

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