use of org.neo4j.kernel.api.index.IndexSample in project neo4j by neo4j.
the class IndexingServiceTest method shouldSnapshotOnlineIndexes.
@Test
void shouldSnapshotOnlineIndexes() throws Exception {
// GIVEN
int indexId = 1;
int indexId2 = 2;
IndexDescriptor rule1 = storeIndex(indexId, 2, 3, PROVIDER_DESCRIPTOR);
IndexDescriptor rule2 = storeIndex(indexId2, 4, 5, PROVIDER_DESCRIPTOR);
IndexAccessor indexAccessor = mock(IndexAccessor.class);
IndexingService indexing = newIndexingServiceWithMockedDependencies(mock(IndexPopulator.class), indexAccessor, new DataUpdates(), rule1, rule2);
Path theFile = Path.of("Blah");
when(indexAccessor.snapshotFiles()).thenAnswer(newResourceIterator(theFile));
when(indexProvider.getInitialState(rule1, NULL)).thenReturn(ONLINE);
when(indexProvider.getInitialState(rule2, NULL)).thenReturn(ONLINE);
when(indexStatisticsStore.indexSample(anyLong())).thenReturn(new IndexSample(100L, 32L, 32L));
life.start();
// WHEN
ResourceIterator<Path> files = indexing.snapshotIndexFiles();
// THEN
// We get a snapshot per online index
assertThat(asCollection(files)).isEqualTo(asCollection(iterator(theFile, theFile)));
}
use of org.neo4j.kernel.api.index.IndexSample in project neo4j by neo4j.
the class IndexingServiceTest method shouldNotSnapshotPopulatingIndexes.
@Test
void shouldNotSnapshotPopulatingIndexes() throws Exception {
// GIVEN
CountDownLatch populatorLatch = new CountDownLatch(1);
IndexAccessor indexAccessor = mock(IndexAccessor.class);
int indexId = 1;
int indexId2 = 2;
IndexDescriptor index1 = storeIndex(indexId, 2, 3, PROVIDER_DESCRIPTOR);
IndexDescriptor index2 = storeIndex(indexId2, 4, 5, PROVIDER_DESCRIPTOR);
IndexingService indexing = newIndexingServiceWithMockedDependencies(populator, indexAccessor, new DataUpdates(), index1, index2);
Path theFile = Path.of("Blah");
doAnswer(waitForLatch(populatorLatch)).when(populator).create();
when(indexAccessor.snapshotFiles()).thenAnswer(newResourceIterator(theFile));
when(indexProvider.getInitialState(eq(index1), any())).thenReturn(POPULATING);
when(indexProvider.getInitialState(eq(index2), any())).thenReturn(ONLINE);
when(indexStatisticsStore.indexSample(anyLong())).thenReturn(new IndexSample(100, 32, 32));
life.start();
// WHEN
ResourceIterator<Path> files = indexing.snapshotIndexFiles();
// only now, after the snapshot, is the population job allowed to finish
populatorLatch.countDown();
waitForIndexesToComeOnline(indexing, index1, index2);
// THEN
// We get a snapshot from the online index, but no snapshot from the populating one
assertThat(asCollection(files)).isEqualTo(asCollection(iterator(theFile)));
}
use of org.neo4j.kernel.api.index.IndexSample in project neo4j by neo4j.
the class FusionIndexIT method shouldKeepIndexSamplesUpdated.
@Test
void shouldKeepIndexSamplesUpdated() {
// Given
createIndex();
assertThat(indexSample()).isEqualTo(new IndexSample(0, 0, 0, 0));
// When
try (Transaction tx = db.beginTx()) {
tx.createNode(label).setProperty(propKey, numberValue);
tx.createNode(label).setProperty(propKey, stringValue);
tx.createNode(label).setProperty(propKey, spatialValue);
tx.createNode(label).setProperty(propKey, temporalValue);
tx.commit();
}
// Then
assertEventually(this::indexSample, equalityCondition(new IndexSample(4, 4, 4)), 1, MINUTES);
}
use of org.neo4j.kernel.api.index.IndexSample in project neo4j by neo4j.
the class IndexingServiceTest method shouldLogIndexStateOnStart.
@Test
void shouldLogIndexStateOnStart() 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();
IndexDescriptor onlineIndex = storeIndex(1, 1, 1, PROVIDER_DESCRIPTOR);
IndexDescriptor populatingIndex = storeIndex(2, 1, 2, PROVIDER_DESCRIPTOR);
IndexDescriptor failedIndex = storeIndex(3, 2, 2, PROVIDER_DESCRIPTOR);
IndexingService indexingService = IndexingServiceFactory.createIndexingService(config, mock(JobScheduler.class), providerMap, storeViewFactory, nameLookup, asList(onlineIndex, populatingIndex, failedIndex), internalLogProvider, userLogProvider, IndexingService.NO_MONITOR, schemaState, indexStatisticsStore, PageCacheTracer.NULL, INSTANCE, "", writable());
when(provider.getInitialState(eq(onlineIndex), any())).thenReturn(ONLINE);
when(provider.getInitialState(eq(populatingIndex), any())).thenReturn(POPULATING);
when(provider.getInitialState(eq(failedIndex), any())).thenReturn(FAILED);
indexingService.init();
nameLookup.label(1, "LabelOne");
nameLookup.label(2, "LabelTwo");
nameLookup.propertyKey(1, "propertyOne");
nameLookup.propertyKey(2, "propertyTwo");
when(indexStatisticsStore.indexSample(anyLong())).thenReturn(new IndexSample(100L, 32L, 32L));
internalLogProvider.clear();
// when
indexingService.start();
// then
verify(provider).getPopulationFailure(eq(failedIndex), any());
assertThat(internalLogProvider).forLevel(DEBUG).containsMessages("IndexingService.start: index 1 on (:LabelOne {propertyOne}) is ONLINE", "IndexingService.start: index 2 on (:LabelOne {propertyTwo}) is POPULATING", "IndexingService.start: index 3 on (:LabelTwo {propertyTwo}) is FAILED");
}
use of org.neo4j.kernel.api.index.IndexSample in project neo4j by neo4j.
the class IndexingServiceTest method shouldNotLoseIndexDescriptorDueToOtherVerySimilarIndexDuringRecovery.
@Test
void shouldNotLoseIndexDescriptorDueToOtherVerySimilarIndexDuringRecovery() throws Exception {
// GIVEN
AtomicReference<BinaryLatch> populationStartLatch = latchedIndexPopulation();
long nodeId = 0;
Update update = addNodeUpdate(nodeId, "value");
when(indexStatisticsStore.indexSample(anyLong())).thenReturn(new IndexSample(100, 42, 42));
// For some reason the usual accessor returned null from newUpdater, even when told to return the updater
// so spying on a real object instead.
IndexAccessor accessor = spy(new TrackingIndexAccessor());
IndexingService indexing = newIndexingServiceWithMockedDependencies(populator, accessor, withData(update), index);
when(indexProvider.getInitialState(index, NULL)).thenReturn(ONLINE);
life.init();
populationStartLatch.getAndSet(new BinaryLatch()).release();
// WHEN dropping another index, which happens to be identical to the existing one except for different index config... while recovering
IndexConfig indexConfig = index.getIndexConfig().withIfAbsent("a", Values.booleanValue(true));
IndexDescriptor otherIndex = index.withIndexConfig(indexConfig);
indexing.createIndexes(AUTH_DISABLED, otherIndex);
indexing.dropIndex(otherIndex);
// and WHEN finally creating our index again (at a later point in recovery)
indexing.createIndexes(AUTH_DISABLED, index);
reset(accessor);
indexing.applyUpdates(nodeIdsAsIndexUpdates(nodeId), NULL);
// and WHEN starting, i.e. completing recovery
life.start();
IndexProxy indexProxy = indexing.getIndexProxy(index);
try {
assertNull(indexProxy.getDescriptor().getIndexConfig().get("a"));
// The existing online index got nuked during recovery.
assertThat(indexProxy.getState()).isEqualTo(POPULATING);
} finally {
populationStartLatch.get().release();
}
}
Aggregations