Search in sources :

Example 1 with FusionIndexProvider

use of org.neo4j.kernel.impl.index.schema.fusion.FusionIndexProvider in project neo4j by neo4j.

the class LuceneIndexSamplerReleaseTaskControlUnderFusionTest method failedIndexSamplingMustNotPreventIndexDrop.

/**
 * This test come from a support case where dropping an index would block forever after index sampling failed.
 * <p>
 * A fusion index has multiple {@link IndexSampler index samplers} that are called sequentially. If one fails, then the other will never be invoked.
 * This was a problem for {@link LuceneIndexSampler}. It owns a {@link TaskCoordinator.Task} that it will try to release in try-finally
 * in {@link LuceneIndexSampler#sampleIndex(CursorContext)}. But it never gets here because a prior {@link IndexSampler} fails.
 * <p>
 * Because the {@link TaskCoordinator.Task} was never released the lucene accessor would block forever, waiting for
 * {@link TaskCoordinator#awaitCompletion()}.
 * <p>
 * This situation was solved by making {@link IndexSampler} {@link java.io.Closeable} and include it in try-with-resource together with
 * {@link IndexReader} that created it.
 */
@Test
void failedIndexSamplingMustNotPreventIndexDrop() throws IOException, IndexEntryConflictException {
    LuceneIndexProvider luceneProvider = luceneProvider();
    // Otherwise no sampler will be created.
    makeSureIndexHasSomeData(luceneProvider);
    IndexProvider failingProvider = failingProvider();
    FusionIndexProvider fusionProvider = createFusionProvider(luceneProvider, failingProvider);
    try (IndexAccessor fusionAccessor = fusionProvider.getOnlineAccessor(descriptor, samplingConfig, tokenNameLookup)) {
        IndexSamplingJob indexSamplingJob = createIndexSamplingJob(fusionAccessor);
        // Call run from other thread
        try {
            indexSamplingJob.run();
        } catch (RuntimeException e) {
            assertSame(sampleException, e);
        }
        // then
        fusionAccessor.drop();
    // should not block forever
    }
}
Also used : IndexProvider(org.neo4j.kernel.api.index.IndexProvider) LuceneIndexProvider(org.neo4j.kernel.api.impl.schema.LuceneIndexProvider) FusionIndexProvider(org.neo4j.kernel.impl.index.schema.fusion.FusionIndexProvider) IndexSamplingJob(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingJob) FusionIndexProvider(org.neo4j.kernel.impl.index.schema.fusion.FusionIndexProvider) IndexAccessor(org.neo4j.kernel.api.index.IndexAccessor) LuceneIndexProvider(org.neo4j.kernel.api.impl.schema.LuceneIndexProvider) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)1 LuceneIndexProvider (org.neo4j.kernel.api.impl.schema.LuceneIndexProvider)1 IndexAccessor (org.neo4j.kernel.api.index.IndexAccessor)1 IndexProvider (org.neo4j.kernel.api.index.IndexProvider)1 IndexSamplingJob (org.neo4j.kernel.impl.api.index.sampling.IndexSamplingJob)1 FusionIndexProvider (org.neo4j.kernel.impl.index.schema.fusion.FusionIndexProvider)1