Search in sources :

Example 1 with IndexBuildStatusHolder

use of org.apache.ignite.internal.processors.query.aware.IndexBuildStatusHolder in project ignite by apache.

the class ResumeRebuildIndexTest method testDeleteIndexRebuildStateOnDestroyCache.

/**
 * Checks that when the caches are destroyed,
 * the index rebuild states will also be deleted.
 *
 * @throws Exception If failed.
 */
@Test
public void testDeleteIndexRebuildStateOnDestroyCache() throws Exception {
    IgniteEx n0 = startGrid(getTestIgniteInstanceName(0));
    prepareBeforeNodeStart();
    IgniteEx n1 = startGrid(getTestIgniteInstanceName(1));
    n0.cluster().state(ACTIVE);
    awaitPartitionMapExchange();
    for (int i = 0; i < 4; i++) {
        String cacheName = DEFAULT_CACHE_NAME + i;
        String grpName = i == 1 || i == 2 ? DEFAULT_CACHE_NAME + "_G" : null;
        populate(n1.getOrCreateCache(cacheCfg(cacheName, grpName)), 10_000);
        BreakBuildIndexConsumer breakRebuildIdxConsumer = addBreakRebuildIndexConsumer(n1, cacheName, 10);
        IgniteInternalCache<?, ?> cachex = n1.cachex(cacheName);
        int cacheSize = cachex.size();
        assertTrue(forceRebuildIndexes(n1, cachex.context()).isEmpty());
        IgniteInternalFuture<?> rebIdxFut = indexRebuildFuture(n1, cachex.context().cacheId());
        breakRebuildIdxConsumer.startBuildIdxFut.get(getTestTimeout());
        breakRebuildIdxConsumer.finishBuildIdxFut.onDone();
        assertThrows(log, () -> rebIdxFut.get(getTestTimeout()), Throwable.class, null);
        assertTrue(breakRebuildIdxConsumer.visitCnt.get() < cacheSize);
    }
    n1.destroyCache(DEFAULT_CACHE_NAME + 0);
    assertTrue(indexBuildStatusStorage(n1).rebuildCompleted(DEFAULT_CACHE_NAME + 0));
    n1.destroyCache(DEFAULT_CACHE_NAME + 1);
    assertTrue(indexBuildStatusStorage(n1).rebuildCompleted(DEFAULT_CACHE_NAME + 1));
    assertFalse(indexBuildStatusStorage(n1).rebuildCompleted(DEFAULT_CACHE_NAME + 2));
    assertFalse(indexBuildStatusStorage(n1).rebuildCompleted(DEFAULT_CACHE_NAME + 3));
    forceCheckpoint(n1);
    ConcurrentMap<String, IndexBuildStatusHolder> states = statuses(n1);
    assertFalse(states.containsKey(DEFAULT_CACHE_NAME + 0));
    assertFalse(states.containsKey(DEFAULT_CACHE_NAME + 1));
    assertTrue(states.containsKey(DEFAULT_CACHE_NAME + 2));
    assertTrue(states.containsKey(DEFAULT_CACHE_NAME + 3));
    stopGrid(1);
    awaitPartitionMapExchange();
    n0.destroyCache(DEFAULT_CACHE_NAME + 2);
    n0.destroyCache(DEFAULT_CACHE_NAME + 3);
    deleteCacheGrpDir(n1.name(), (dir, name) -> name.contains(DEFAULT_CACHE_NAME + 3) || name.contains(DEFAULT_CACHE_NAME + "_G"));
    n1 = startGrid(getTestIgniteInstanceName(1));
    assertTrue(indexBuildStatusStorage(n1).rebuildCompleted(DEFAULT_CACHE_NAME + 2));
    assertTrue(indexBuildStatusStorage(n1).rebuildCompleted(DEFAULT_CACHE_NAME + 3));
    forceCheckpoint(n1);
    states = statuses(n1);
    assertFalse(states.containsKey(DEFAULT_CACHE_NAME + 2));
    assertFalse(states.containsKey(DEFAULT_CACHE_NAME + 3));
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) IndexBuildStatusHolder(org.apache.ignite.internal.processors.query.aware.IndexBuildStatusHolder) BreakBuildIndexConsumer(org.apache.ignite.internal.processors.cache.index.IndexingTestUtils.BreakBuildIndexConsumer) Test(org.junit.Test)

Aggregations

IgniteEx (org.apache.ignite.internal.IgniteEx)1 BreakBuildIndexConsumer (org.apache.ignite.internal.processors.cache.index.IndexingTestUtils.BreakBuildIndexConsumer)1 IndexBuildStatusHolder (org.apache.ignite.internal.processors.query.aware.IndexBuildStatusHolder)1 Test (org.junit.Test)1