use of org.apache.ignite.internal.processors.cache.index.IndexingTestUtils.StopBuildIndexConsumer in project ignite by apache.
the class ResumeCreateIndexTest method testPartialCheckpointNewIndexRows.
/**
* Checks that if a checkpoint fails after building a new index and the
* node restarts, then the indexes will be rebuilt.
*
* @throws Exception If failed.
*/
@Test
public void testPartialCheckpointNewIndexRows() throws Exception {
String cacheName = DEFAULT_CACHE_NAME;
IgniteEx n = prepareNodeToCreateNewIndex(cacheName, 100_000, false);
String idxName = "IDX0";
SlowdownBuildIndexConsumer slowdownIdxCreateConsumer = addSlowdownIdxCreateConsumer(n, idxName, 10);
IgniteInternalFuture<List<List<?>>> createIdxFut = createIdxAsync(n.cache(cacheName), idxName);
slowdownIdxCreateConsumer.startBuildIdxFut.get(getTestTimeout());
checkInitStatus(n, cacheName, false, 1);
String reason = getTestIgniteInstanceName();
IgniteInternalFuture<Void> awaitBeforeCpBeginFut = awaitBeforeCheckpointBeginAsync(n, reason);
IgniteInternalFuture<Void> disableCpFut = enableCheckpointsAsync(n, reason, false);
awaitBeforeCpBeginFut.get(getTestTimeout());
slowdownIdxCreateConsumer.finishBuildIdxFut.onDone();
disableCpFut.get(getTestTimeout());
slowdownIdxCreateConsumer.sleepTime.set(0);
createIdxFut.get(getTestTimeout());
checkCompletedStatus(n, cacheName);
stopGrid(0);
IndexesRebuildTaskEx.prepareBeforeNodeStart();
StopBuildIndexConsumer stopRebuildIdxConsumer = addStopRebuildIndexConsumer(n, cacheName);
n = startGrid(0);
stopRebuildIdxConsumer.startBuildIdxFut.get(getTestTimeout());
IgniteInternalFuture<?> rebIdxFut = indexRebuildFuture(n, CU.cacheId(cacheName));
assertNotNull(rebIdxFut);
checkInitStatus(n, cacheName, true, 0);
assertTrue(allIndexes(n).containsKey(new QueryIndexKey(cacheName, idxName)));
stopRebuildIdxConsumer.finishBuildIdxFut.onDone();
rebIdxFut.get(getTestTimeout());
forceCheckpoint();
checkNoStatus(n, cacheName);
assertEquals(100_000, selectPersonByName(n.cache(cacheName)).size());
}
use of org.apache.ignite.internal.processors.cache.index.IndexingTestUtils.StopBuildIndexConsumer 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());
}
use of org.apache.ignite.internal.processors.cache.index.IndexingTestUtils.StopBuildIndexConsumer 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())));
}
use of org.apache.ignite.internal.processors.cache.index.IndexingTestUtils.StopBuildIndexConsumer 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());
}
use of org.apache.ignite.internal.processors.cache.index.IndexingTestUtils.StopBuildIndexConsumer in project ignite by apache.
the class ForceRebuildIndexTest method testSequentialForceRebuildIndexes.
/**
* Checking that a forced rebuild of indexes is possible only after the previous one has finished.
*
* @throws Exception If failed.
*/
@Test
public void testSequentialForceRebuildIndexes() throws Exception {
prepareBeforeNodeStart();
IgniteEx n = startGrid(0);
populate(n.cache(DEFAULT_CACHE_NAME), 100);
GridCacheContext<?, ?> cacheCtx = n.cachex(DEFAULT_CACHE_NAME).context();
StopBuildIndexConsumer stopRebuildIdxConsumer = addStopRebuildIndexConsumer(n, cacheCtx.name());
// The forced rebuild has begun - no rejected.
assertEqualsCollections(emptyList(), forceRebuildIndexes(n, cacheCtx));
IgniteInternalFuture<?> idxRebFut0 = checkStartRebuildIndexes(n, cacheCtx);
stopRebuildIdxConsumer.startBuildIdxFut.get(getTestTimeout());
assertFalse(idxRebFut0.isDone());
// There will be no forced rebuilding since the previous one has not ended - they will be rejected.
assertEqualsCollections(F.asList(cacheCtx), forceRebuildIndexes(n, cacheCtx));
assertTrue(idxRebFut0 == indexRebuildFuture(n, cacheCtx.cacheId()));
stopRebuildIdxConsumer.finishBuildIdxFut.onDone();
idxRebFut0.get(getTestTimeout());
checkFinishRebuildIndexes(n, cacheCtx, 100);
assertEquals(100, stopRebuildIdxConsumer.visitCnt.get());
stopRebuildIdxConsumer.resetFutures();
// Forced rebuilding is possible again as the past is over - no rejected.
assertEqualsCollections(emptyList(), forceRebuildIndexes(n, cacheCtx));
IgniteInternalFuture<?> idxRebFut1 = checkStartRebuildIndexes(n, cacheCtx);
stopRebuildIdxConsumer.startBuildIdxFut.get(getTestTimeout());
assertFalse(idxRebFut1.isDone());
stopRebuildIdxConsumer.finishBuildIdxFut.onDone();
idxRebFut1.get(getTestTimeout());
checkFinishRebuildIndexes(n, cacheCtx, 100);
assertEquals(200, stopRebuildIdxConsumer.visitCnt.get());
}
Aggregations