use of org.apache.ignite.internal.processors.query.schema.SchemaIndexCacheFuture in project ignite by apache.
the class GridCommandHandlerIndexForceRebuildTest method testIndexRebuildUnderLoad.
/**
* Checks how index force rebuild command behaves when caches are under load.
*
* @throws Exception If failed.
*/
@Test
public void testIndexRebuildUnderLoad() throws Exception {
IgniteEx n = grid(0);
AtomicBoolean stopLoad = new AtomicBoolean(false);
String cacheName1 = "tmpCache1";
String cacheName2 = "tmpCache2";
List<String> caches = F.asList(cacheName1, cacheName2);
try {
for (String c : caches) createAndFillCache(n, c, "tmpGrp");
int cacheSize = n.cache(cacheName1).size();
for (String c : caches) blockRebuildIdx.put(c, new GridFutureAdapter<>());
assertEquals(EXIT_CODE_OK, execute("--cache", "indexes_force_rebuild", "--node-id", n.localNode().id().toString(), "--cache-names", cacheName1 + "," + cacheName2));
IgniteInternalFuture<?> putCacheFut = runAsync(() -> {
ThreadLocalRandom r = ThreadLocalRandom.current();
while (!stopLoad.get()) n.cache(cacheName1).put(r.nextInt(), new Person(r.nextInt(), valueOf(r.nextLong())));
});
assertTrue(waitForCondition(() -> n.cache(cacheName1).size() > cacheSize, getTestTimeout()));
for (String c : caches) {
IgniteInternalFuture<?> rebIdxFut = n.context().query().indexRebuildFuture(CU.cacheId(c));
assertNotNull(rebIdxFut);
assertFalse(rebIdxFut.isDone());
blockRebuildIdx.get(c).get(getTestTimeout());
}
IgniteInternalFuture<Boolean> destroyCacheFut = n.context().cache().dynamicDestroyCache(cacheName2, false, true, false, null);
SchemaIndexCacheFuture intlRebIdxFut = schemaIndexCacheFuture(n, CU.cacheId(cacheName2));
assertNotNull(intlRebIdxFut);
assertTrue(waitForCondition(() -> intlRebIdxFut.cancelToken().cancelException() != null, getTestTimeout()));
stopLoad.set(true);
blockRebuildIdx.clear();
waitForIndexesRebuild(n);
intlRebIdxFut.get(getTestTimeout());
destroyCacheFut.get(getTestTimeout());
putCacheFut.get(getTestTimeout());
injectTestSystemOut();
assertEquals(EXIT_CODE_OK, execute("--cache", "validate_indexes", "--check-crc", cacheName1));
assertContains(log, testOut.toString(), "no issues found.");
} finally {
stopLoad.set(true);
blockRebuildIdx.clear();
n.destroyCache(cacheName1);
n.destroyCache(cacheName2);
}
}
use of org.apache.ignite.internal.processors.query.schema.SchemaIndexCacheFuture 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()));
}
use of org.apache.ignite.internal.processors.query.schema.SchemaIndexCacheFuture in project ignite by apache.
the class StopRebuildIndexTest method stopRebuildIndexes.
/**
* Restart the rebuild of the indexes, checking that it completes gracefully.
*
* @param stopRebuildIndexes Stop index rebuild function.
* @param expThrowEx Expect an exception on index rebuild futures.
* @throws Exception If failed.
*/
private void stopRebuildIndexes(IgniteThrowableConsumer<IgniteEx> stopRebuildIndexes, boolean expThrowEx) throws Exception {
prepareBeforeNodeStart();
int keys = 100_000;
IgniteEx n = startGrid(0);
populate(n.cache(DEFAULT_CACHE_NAME), keys);
GridCacheContext<?, ?> cacheCtx = n.cachex(DEFAULT_CACHE_NAME).context();
addCacheRowConsumer(nodeName(n), cacheCtx.name(), row -> U.sleep(10));
forceRebuildIndexes(n, cacheCtx);
IgniteInternalFuture<?> fut0 = indexRebuildFuture(n, cacheCtx.cacheId());
assertNotNull(fut0);
SchemaIndexCacheFuture fut1 = internalIndexRebuildFuture(n, cacheCtx.cacheId());
assertNotNull(fut1);
CacheMetricsImpl metrics0 = cacheMetrics0(n, cacheCtx.name());
assertTrue(metrics0.isIndexRebuildInProgress());
assertFalse(fut0.isDone());
assertFalse(fut1.isDone());
assertNull(fut1.cancelToken().cancelException());
assertTrue(waitForCondition(() -> metrics0.getIndexRebuildKeysProcessed() >= keys / 100, getTestTimeout()));
assertTrue(metrics0.isIndexRebuildInProgress());
assertFalse(fut0.isDone());
assertFalse(fut1.isDone());
assertNull(fut1.cancelToken().cancelException());
stopRebuildIndexes.accept(n);
assertFalse(metrics0.isIndexRebuildInProgress());
assertTrue(metrics0.getIndexRebuildKeysProcessed() < keys);
if (expThrowEx) {
assertThrows(log, () -> fut0.get(getTestTimeout()), SchemaIndexOperationCancellationException.class, null);
assertThrows(log, () -> fut1.get(getTestTimeout()), SchemaIndexOperationCancellationException.class, null);
assertNotNull(fut1.cancelToken().cancelException());
} else {
fut0.get(getTestTimeout());
fut1.get(getTestTimeout());
assertNull(fut1.cancelToken().cancelException());
}
assertNull(internalIndexRebuildFuture(n, cacheCtx.cacheId()));
}
use of org.apache.ignite.internal.processors.query.schema.SchemaIndexCacheFuture in project ignite by apache.
the class IndexesRebuildTask method rebuild.
/**
* Start to rebuild.
*
* @param cctx Cache context.
* @param force Force rebuild indexes.
* @return A future of rebuilding cache indexes.
*/
@Nullable
public IgniteInternalFuture<?> rebuild(GridCacheContext<?, ?> cctx, boolean force, IndexRebuildCancelToken cancelTok) {
assert cctx != null;
if (!CU.affinityNode(cctx.localNode(), cctx.config().getNodeFilter()))
return null;
IgnitePageStoreManager pageStore = cctx.shared().pageStore();
SchemaIndexCacheVisitorClosure clo;
String cacheName = cctx.name();
if (pageStore == null || !pageStore.hasIndexStore(cctx.groupId())) {
boolean mvccEnabled = cctx.mvccEnabled();
// If there are no index store, rebuild all indexes.
clo = row -> cctx.queries().store(row, null, mvccEnabled);
} else {
Collection<InlineIndex> toRebuild = cctx.kernalContext().indexProcessor().treeIndexes(cctx, !force);
if (F.isEmpty(toRebuild))
return null;
clo = row -> cctx.kernalContext().indexProcessor().store(toRebuild, row, null, false);
}
// Closure prepared, do rebuild.
cctx.kernalContext().query().markAsRebuildNeeded(cctx, true);
GridFutureAdapter<Void> rebuildCacheIdxFut = new GridFutureAdapter<>();
// To avoid possible data race.
GridFutureAdapter<Void> outRebuildCacheIdxFut = new GridFutureAdapter<>();
IgniteLogger log = cctx.kernalContext().grid().log();
// An internal future for the ability to cancel index rebuilding.
SchemaIndexCacheFuture intRebFut = new SchemaIndexCacheFuture(cancelTok);
SchemaIndexCacheFuture prevIntRebFut = idxRebuildFuts.put(cctx.cacheId(), intRebFut);
// Check that the previous rebuild is completed.
assert prevIntRebFut == null;
cctx.kernalContext().query().onStartRebuildIndexes(cctx);
rebuildCacheIdxFut.listen(fut -> {
Throwable err = fut.error();
if (err == null) {
try {
cctx.kernalContext().query().markAsRebuildNeeded(cctx, false);
} catch (Throwable t) {
err = t;
}
}
if (err != null)
U.error(log, "Failed to rebuild indexes for cache: " + cacheName, err);
else
cctx.kernalContext().query().onFinishRebuildIndexes(cctx);
idxRebuildFuts.remove(cctx.cacheId(), intRebFut);
intRebFut.onDone(err);
outRebuildCacheIdxFut.onDone(err);
});
startRebuild(cctx, rebuildCacheIdxFut, clo, intRebFut.cancelToken());
return outRebuildCacheIdxFut;
}
use of org.apache.ignite.internal.processors.query.schema.SchemaIndexCacheFuture in project ignite by apache.
the class GridCommandHandlerIndexForceRebuildTest method schemaIndexCacheFuture.
/**
* Getting internal index rebuild future for cache.
*
* @param n Node.
* @param cacheId Cache id.
* @return Internal index rebuild future.
*/
@Nullable
private SchemaIndexCacheFuture schemaIndexCacheFuture(IgniteEx n, int cacheId) {
IndexesRebuildTask idxRebuild = n.context().indexProcessor().idxRebuild();
Map<Integer, SchemaIndexCacheFuture> idxRebuildFuts = getFieldValue(idxRebuild, "idxRebuildFuts");
return idxRebuildFuts.get(cacheId);
}
Aggregations