use of org.neo4j.kernel.impl.api.index.sampling.IndexSamplingJob 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
}
}
Aggregations