Search in sources :

Example 6 with SlowdownBuildIndexConsumer

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

the class ResumeCreateIndexTest method testConcurrentBuildNewIndexAndRebuildIndexes0.

/**
 * Checks that building a new index and rebuilding indexes at the same time
 * does not break the {@link IndexBuildStatusHolder}.
 * In this case, building a new index is completed earlier.
 *
 * @throws Exception If failed.
 */
@Test
public void testConcurrentBuildNewIndexAndRebuildIndexes0() throws Exception {
    String cacheName = DEFAULT_CACHE_NAME;
    IgniteEx n = prepareNodeToCreateNewIndex(cacheName, 100_000, true);
    String idxName = "IDX0";
    SlowdownBuildIndexConsumer slowdownIdxCreateConsumer = addSlowdownIdxCreateConsumer(n, idxName, 0);
    IgniteInternalFuture<List<List<?>>> createIdxFut = createIdxAsync(n.cache(cacheName), idxName);
    slowdownIdxCreateConsumer.startBuildIdxFut.get(getTestTimeout());
    checkInitStatus(n, cacheName, false, 1);
    SlowdownBuildIndexConsumer slowdownRebuildIdxConsumer = addSlowdownRebuildIndexConsumer(n, cacheName, 100);
    assertTrue(forceRebuildIndexes(n, n.cachex(cacheName).context()).isEmpty());
    checkInitStatus(n, cacheName, true, 1);
    IgniteInternalFuture<?> idxRebFut = indexRebuildFuture(n, CU.cacheId(cacheName));
    assertNotNull(idxRebFut);
    slowdownIdxCreateConsumer.finishBuildIdxFut.onDone();
    slowdownRebuildIdxConsumer.startBuildIdxFut.get(getTestTimeout());
    slowdownRebuildIdxConsumer.finishBuildIdxFut.onDone();
    createIdxFut.get(getTestTimeout());
    assertFalse(idxRebFut.isDone());
    checkInitStatus(n, cacheName, true, 0);
    slowdownRebuildIdxConsumer.sleepTime.set(0);
    idxRebFut.get(getTestTimeout());
    checkCompletedStatus(n, cacheName);
    enableCheckpointsAsync(n, getTestIgniteInstanceName(), true).get(getTestTimeout());
    checkNoStatus(n, cacheName);
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) List(java.util.List) SlowdownBuildIndexConsumer(org.apache.ignite.internal.processors.cache.index.IndexingTestUtils.SlowdownBuildIndexConsumer) Test(org.junit.Test)

Example 7 with SlowdownBuildIndexConsumer

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

the class ResumeCreateIndexTest method testNoCheckpointAfterIndexCreation.

/**
 * Checks that if there is no checkpoint after the index is created and the
 * node is restarted, the indexes will be rebuilt.
 *
 * @throws Exception If failed.
 */
@Test
public void testNoCheckpointAfterIndexCreation() throws Exception {
    String cacheName = DEFAULT_CACHE_NAME;
    IgniteEx n = prepareNodeToCreateNewIndex(cacheName, 10, true);
    String idxName = "IDX0";
    SlowdownBuildIndexConsumer slowdownIdxCreateConsumer = addSlowdownIdxCreateConsumer(n, idxName, 0);
    IgniteInternalFuture<List<List<?>>> createIdxFut = createIdxAsync(n.cache(cacheName), idxName);
    slowdownIdxCreateConsumer.startBuildIdxFut.get(getTestTimeout());
    checkInitStatus(n, cacheName, false, 1);
    slowdownIdxCreateConsumer.finishBuildIdxFut.onDone();
    createIdxFut.get(getTestTimeout());
    checkCompletedStatus(n, cacheName);
    stopGrid(0);
    IndexesRebuildTaskEx.prepareBeforeNodeStart();
    StopBuildIndexConsumer stopRebuildIdxConsumer = addStopRebuildIndexConsumer(n, cacheName);
    n = startGrid(0);
    stopRebuildIdxConsumer.startBuildIdxFut.get(getTestTimeout());
    IgniteInternalFuture<?> idxRebFut = indexRebuildFuture(n, CU.cacheId(cacheName));
    assertNotNull(idxRebFut);
    checkInitStatus(n, cacheName, true, 0);
    assertTrue(allIndexes(n).containsKey(new QueryIndexKey(cacheName, idxName)));
    stopRebuildIdxConsumer.finishBuildIdxFut.onDone();
    idxRebFut.get(getTestTimeout());
    forceCheckpoint();
    checkNoStatus(n, cacheName);
    assertEquals(10, selectPersonByName(n.cache(cacheName)).size());
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) List(java.util.List) StopBuildIndexConsumer(org.apache.ignite.internal.processors.cache.index.IndexingTestUtils.StopBuildIndexConsumer) SlowdownBuildIndexConsumer(org.apache.ignite.internal.processors.cache.index.IndexingTestUtils.SlowdownBuildIndexConsumer) QueryIndexKey(org.apache.ignite.internal.processors.query.QueryIndexKey) Test(org.junit.Test)

Aggregations

SlowdownBuildIndexConsumer (org.apache.ignite.internal.processors.cache.index.IndexingTestUtils.SlowdownBuildIndexConsumer)7 List (java.util.List)5 IgniteEx (org.apache.ignite.internal.IgniteEx)5 Test (org.junit.Test)5 StopBuildIndexConsumer (org.apache.ignite.internal.processors.cache.index.IndexingTestUtils.StopBuildIndexConsumer)2 QueryIndexKey (org.apache.ignite.internal.processors.query.QueryIndexKey)2