use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.
the class FullCheckTokenIndexIT method updateNodeLabelIndex.
void updateNodeLabelIndex(GraphDatabaseAPI database, IndexDescriptor index) throws IOException, IndexEntryConflictException {
DependencyResolver dependencyResolver = database.getDependencyResolver();
IndexingService indexingService = dependencyResolver.resolveDependency(IndexingService.class);
IndexAccessors.IndexAccessorLookup indexAccessorLookup = new LookupAccessorsFromRunningDb(indexingService);
IndexAccessor accessor = indexAccessorLookup.apply(index);
try (IndexUpdater indexUpdater = accessor.newUpdater(IndexUpdateMode.ONLINE, CursorContext.NULL)) {
indexUpdater.process(IndexEntryUpdate.change(100, index, new long[0], new long[] { 1 }));
}
}
use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.
the class IndexingServiceTest method shouldDeliverUpdatesThatOccurDuringPopulationToPopulator.
@SuppressWarnings("unchecked")
@Test
void shouldDeliverUpdatesThatOccurDuringPopulationToPopulator() throws Exception {
// given
when(populator.newPopulatingUpdater(eq(propertyAccessor), any())).thenReturn(updater);
CountDownLatch populationLatch = new CountDownLatch(1);
Barrier.Control populationStartBarrier = new Barrier.Control();
IndexingService.Monitor monitor = new IndexingService.MonitorAdapter() {
@Override
public void indexPopulationScanStarting() {
populationStartBarrier.reached();
}
@Override
public void indexPopulationScanComplete() {
try {
populationLatch.await();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException("Index population monitor was interrupted", e);
}
}
};
IndexingService indexingService = newIndexingServiceWithMockedDependencies(populator, accessor, withData(addNodeUpdate(1, "value1")), monitor);
life.start();
// when
indexingService.createIndexes(AUTH_DISABLED, index);
IndexProxy proxy = indexingService.getIndexProxy(index);
assertEquals(POPULATING, proxy.getState());
populationStartBarrier.await();
populationStartBarrier.release();
IndexEntryUpdate<?> value2 = add(2, "value2");
try (IndexUpdater updater = proxy.newUpdater(IndexUpdateMode.ONLINE, NULL)) {
updater.process(value2);
}
populationLatch.countDown();
waitForIndexesToComeOnline(indexingService, index);
verify(populator).close(eq(true), any());
// then
assertEquals(ONLINE, proxy.getState());
InOrder order = inOrder(populator, accessor, updater);
order.verify(populator).create();
order.verify(populator).includeSample(add(1, "value1"));
order.verify(populator, times(1)).add(any(Collection.class), any(CursorContext.class));
order.verify(populator).scanCompleted(any(PhaseTracker.class), any(IndexPopulator.PopulationWorkScheduler.class), any(CursorContext.class));
order.verify(populator).newPopulatingUpdater(eq(propertyAccessor), any());
order.verify(populator).includeSample(any());
order.verify(updater).process(any());
order.verify(updater).close();
order.verify(populator).sample(any());
order.verify(populator).close(eq(true), any());
verifyNoMoreInteractions(updater);
verifyNoMoreInteractions(populator);
verifyNoInteractions(accessor);
}
use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.
the class IndexingServiceTest method shouldIncrementIndexUpdatesAfterStartingExistingOnlineIndexProxy.
@Test
public void shouldIncrementIndexUpdatesAfterStartingExistingOnlineIndexProxy() throws Exception {
// given
long indexId = 10;
IndexDescriptor indexDescriptor = uniqueIndex.materialise(indexId);
IndexingService indexingService = newIndexingServiceWithMockedDependencies(populator, accessor, withData(), indexDescriptor);
life.start();
// when
IndexProxy proxy = indexingService.getIndexProxy(indexDescriptor);
try (IndexUpdater updater = proxy.newUpdater(IndexUpdateMode.ONLINE, NULL)) {
updater.process(IndexEntryUpdate.add(123, indexDescriptor, stringValue("some value")));
}
// then
verify(indexStatisticsStore).incrementIndexUpdates(indexId, 1L);
}
use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.
the class IndexingServiceTest method shouldStillReportInternalIndexStateAsPopulatingWhenConstraintIndexIsDonePopulating.
@Test
void shouldStillReportInternalIndexStateAsPopulatingWhenConstraintIndexIsDonePopulating() throws Exception {
// given
when(accessor.newUpdater(any(IndexUpdateMode.class), any(CursorContext.class))).thenReturn(updater);
ValueIndexReader indexReader = mock(ValueIndexReader.class);
when(accessor.newValueReader()).thenReturn(indexReader);
doAnswer(new NodeIdsIndexReaderQueryAnswer(index)).when(indexReader).query(any(), any(), any(), any());
IndexingService indexingService = newIndexingServiceWithMockedDependencies(populator, accessor, withData());
life.start();
// when
IndexDescriptor index = constraintIndexRule(0, labelId, propertyKeyId, PROVIDER_DESCRIPTOR);
indexingService.createIndexes(AUTH_DISABLED, index);
IndexProxy proxy = indexingService.getIndexProxy(index);
// don't wait for index to come ONLINE here since we're testing that it doesn't
verify(populator, timeout(20000)).close(eq(true), any());
try (IndexUpdater updater = proxy.newUpdater(IndexUpdateMode.ONLINE, NULL)) {
updater.process(add(10, "foo"));
}
// then
assertEquals(POPULATING, proxy.getState());
InOrder order = inOrder(populator, accessor, updater);
order.verify(populator).create();
order.verify(populator).close(eq(true), any());
order.verify(accessor).newUpdater(eq(IndexUpdateMode.ONLINE), any());
order.verify(updater).process(add(10, "foo"));
order.verify(updater).close();
}
use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.
the class IndexingServiceTest method closingOfValidatedUpdatesShouldCloseUpdaters.
@Test
void closingOfValidatedUpdatesShouldCloseUpdaters() throws Exception {
// Given
long indexId1 = 1;
long indexId2 = 2;
int labelId1 = 24;
int labelId2 = 42;
IndexDescriptor index1 = storeIndex(indexId1, labelId1, propertyKeyId, PROVIDER_DESCRIPTOR);
IndexDescriptor index2 = storeIndex(indexId2, labelId2, propertyKeyId, PROVIDER_DESCRIPTOR);
IndexingService indexing = newIndexingServiceWithMockedDependencies(populator, accessor, withData());
IndexAccessor accessor1 = mock(IndexAccessor.class);
IndexUpdater updater1 = mock(IndexUpdater.class);
when(accessor1.newUpdater(any(IndexUpdateMode.class), any(CursorContext.class))).thenReturn(updater1);
IndexAccessor accessor2 = mock(IndexAccessor.class);
IndexUpdater updater2 = mock(IndexUpdater.class);
when(accessor2.newUpdater(any(IndexUpdateMode.class), any(CursorContext.class))).thenReturn(updater2);
when(indexProvider.getOnlineAccessor(eq(index1), any(IndexSamplingConfig.class), any(TokenNameLookup.class))).thenReturn(accessor1);
when(indexProvider.getOnlineAccessor(eq(index2), any(IndexSamplingConfig.class), any(TokenNameLookup.class))).thenReturn(accessor2);
life.start();
indexing.createIndexes(AUTH_DISABLED, index1);
indexing.createIndexes(AUTH_DISABLED, index2);
waitForIndexesToComeOnline(indexing, index1, index2);
verify(populator, timeout(10000).times(2)).close(eq(true), any());
// When
indexing.applyUpdates(asList(add(1, "foo", index1), add(2, "bar", index2)), NULL);
// Then
verify(updater1).close();
verify(updater2).close();
}
Aggregations