use of org.neo4j.kernel.api.index.IndexProvider in project neo4j by neo4j.
the class IndexingServiceTest method shouldLogIndexStateOutliersOnInit.
@Test
void shouldLogIndexStateOutliersOnInit() throws Exception {
// given
IndexProvider provider = mockIndexProviderWithAccessor(PROVIDER_DESCRIPTOR);
Config config = Config.defaults(default_schema_provider, PROVIDER_DESCRIPTOR.name());
IndexProviderMap providerMap = life.add(new DefaultIndexProviderMap(buildIndexDependencies(provider, fulltextProvider()), config));
List<IndexDescriptor> indexes = new ArrayList<>();
int nextIndexId = 1;
IndexDescriptor populatingIndex = storeIndex(nextIndexId, nextIndexId++, 1, PROVIDER_DESCRIPTOR);
when(provider.getInitialState(eq(populatingIndex), any())).thenReturn(POPULATING);
indexes.add(populatingIndex);
IndexDescriptor failedIndex = storeIndex(nextIndexId, nextIndexId++, 1, PROVIDER_DESCRIPTOR);
when(provider.getInitialState(eq(failedIndex), any())).thenReturn(FAILED);
indexes.add(failedIndex);
for (int i = 0; i < 10; i++) {
IndexDescriptor indexRule = storeIndex(nextIndexId, nextIndexId++, 1, PROVIDER_DESCRIPTOR);
when(provider.getInitialState(eq(indexRule), any())).thenReturn(ONLINE);
indexes.add(indexRule);
}
for (int i = 0; i < nextIndexId; i++) {
nameLookup.label(i, "Label" + i);
}
life.add(IndexingServiceFactory.createIndexingService(config, mock(JobScheduler.class), providerMap, mock(IndexStoreViewFactory.class), nameLookup, indexes, internalLogProvider, userLogProvider, IndexingService.NO_MONITOR, schemaState, indexStatisticsStore, PageCacheTracer.NULL, INSTANCE, "", writable()));
nameLookup.propertyKey(1, "prop");
// when
life.init();
// then
assertThat(internalLogProvider).forLevel(INFO).containsMessages("IndexingService.init: index 1 on (:Label1 {prop}) is POPULATING", "IndexingService.init: index 2 on (:Label2 {prop}) is FAILED", "IndexingService.init: indexes not specifically mentioned above are ONLINE").doesNotContainMessage("IndexingService.init: index 3 on :Label3(prop) is ONLINE");
}
use of org.neo4j.kernel.api.index.IndexProvider in project neo4j by neo4j.
the class IndexingServiceTest method shouldLogIndexStateOutliersOnStart.
@Test
void shouldLogIndexStateOutliersOnStart() throws Throwable {
// given
IndexProvider provider = mockIndexProviderWithAccessor(PROVIDER_DESCRIPTOR);
Config config = Config.defaults(default_schema_provider, PROVIDER_DESCRIPTOR.name());
DefaultIndexProviderMap providerMap = new DefaultIndexProviderMap(buildIndexDependencies(provider, fulltextProvider()), config);
providerMap.init();
List<IndexDescriptor> indexes = new ArrayList<>();
int nextIndexId = 1;
IndexDescriptor populatingIndex = storeIndex(nextIndexId, nextIndexId++, 1, PROVIDER_DESCRIPTOR);
when(provider.getInitialState(eq(populatingIndex), any())).thenReturn(POPULATING);
indexes.add(populatingIndex);
IndexDescriptor failedIndex = storeIndex(nextIndexId, nextIndexId++, 1, PROVIDER_DESCRIPTOR);
when(provider.getInitialState(eq(failedIndex), any())).thenReturn(FAILED);
indexes.add(failedIndex);
for (int i = 0; i < 10; i++) {
IndexDescriptor indexRule = storeIndex(nextIndexId, nextIndexId++, 1, PROVIDER_DESCRIPTOR);
when(provider.getInitialState(eq(indexRule), any())).thenReturn(ONLINE);
indexes.add(indexRule);
}
for (int i = 0; i < nextIndexId; i++) {
nameLookup.label(i, "Label" + i);
}
IndexingService indexingService = IndexingServiceFactory.createIndexingService(config, mock(JobScheduler.class), providerMap, storeViewFactory, nameLookup, indexes, internalLogProvider, userLogProvider, IndexingService.NO_MONITOR, schemaState, indexStatisticsStore, PageCacheTracer.NULL, INSTANCE, "", writable());
when(indexStatisticsStore.indexSample(anyLong())).thenReturn(new IndexSample(100, 32, 32));
nameLookup.propertyKey(1, "prop");
// when
indexingService.init();
internalLogProvider.clear();
indexingService.start();
// then
assertThat(internalLogProvider).forLevel(INFO).containsMessages("IndexingService.start: index 1 on (:Label1 {prop}) is POPULATING", "IndexingService.start: index 2 on (:Label2 {prop}) is FAILED", "IndexingService.start: indexes not specifically mentioned above are ONLINE").doesNotContainMessage("IndexingService.start: index 3 on :Label3(prop) is ONLINE");
}
use of org.neo4j.kernel.api.index.IndexProvider in project neo4j by neo4j.
the class BatchInsertTest method shouldRunConstraintPopulationJobAtShutdown.
@ParameterizedTest
@MethodSource("params")
void shouldRunConstraintPopulationJobAtShutdown(int denseNodeThreshold) throws Throwable {
// GIVEN
IndexPopulator populator = mock(IndexPopulator.class);
IndexProvider provider = mock(IndexProvider.class);
IndexAccessor accessor = mock(IndexAccessor.class);
when(provider.getProviderDescriptor()).thenReturn(DESCRIPTOR);
when(provider.getPopulator(any(IndexDescriptor.class), any(IndexSamplingConfig.class), any(), any(), any(TokenNameLookup.class))).thenReturn(populator);
when(populator.sample(any(CursorContext.class))).thenReturn(new IndexSample());
when(provider.getOnlineAccessor(any(IndexDescriptor.class), any(IndexSamplingConfig.class), any(TokenNameLookup.class))).thenReturn(accessor);
when(provider.completeConfiguration(any(IndexDescriptor.class))).then(inv -> inv.getArgument(0));
BatchInserter inserter = newBatchInserterWithIndexProvider(singleInstanceIndexProviderFactory(KEY, provider), provider.getProviderDescriptor(), denseNodeThreshold);
inserter.createDeferredConstraint(label("Hacker")).assertPropertyIsUnique("handle").create();
long nodeId = inserter.createNode(map("handle", "Jakewins"), label("Hacker"));
// WHEN
inserter.shutdown();
// THEN
verify(provider).init();
verify(provider).start();
verify(provider).getPopulator(any(IndexDescriptor.class), any(IndexSamplingConfig.class), any(), any(), any(TokenNameLookup.class));
verify(populator).create();
verify(populator).add(argThat(c -> c.contains(add(nodeId, internalUniqueIndex.schema(), Values.of("Jakewins")))), any(CursorContext.class));
verify(populator).verifyDeferredConstraints(any(NodePropertyAccessor.class));
verify(populator).close(eq(true), any());
verify(provider).stop();
verify(provider).shutdown();
}
use of org.neo4j.kernel.api.index.IndexProvider 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
}
}
use of org.neo4j.kernel.api.index.IndexProvider in project neo4j by neo4j.
the class DefaultIndexProviderMap method completeConfiguration.
@Override
public IndexDescriptor completeConfiguration(IndexDescriptor index) {
IndexProviderDescriptor providerDescriptor = index.getIndexProvider();
IndexProvider provider = lookup(providerDescriptor);
return provider.completeConfiguration(index);
}
Aggregations