use of org.neo4j.kernel.api.index.IndexEntryUpdate in project neo4j by neo4j.
the class BatchInserterImpl method repopulateAllIndexes.
private void repopulateAllIndexes() throws IOException, IndexEntryConflictException {
if (!labelsTouched) {
return;
}
final IndexRule[] rules = getIndexesNeedingPopulation();
final IndexPopulator[] populators = new IndexPopulator[rules.length];
// the store is uncontended at this point, so creating a local LockService is safe.
final NewIndexDescriptor[] descriptors = new NewIndexDescriptor[rules.length];
for (int i = 0; i < rules.length; i++) {
IndexRule rule = rules[i];
descriptors[i] = rule.getIndexDescriptor();
populators[i] = schemaIndexProviders.apply(rule.getProviderDescriptor()).getPopulator(rule.getId(), descriptors[i], new IndexSamplingConfig(config));
populators[i].create();
}
Visitor<NodeUpdates, IOException> propertyUpdateVisitor = updates -> {
for (int i = 0; i < descriptors.length; i++) {
Optional<IndexEntryUpdate> update = updates.forIndex(descriptors[i].schema());
if (update.isPresent()) {
try {
populators[i].add(Collections.singletonList(update.get()));
} catch (IndexEntryConflictException conflict) {
throw conflict.notAllowed(descriptors[i]);
}
}
}
return true;
};
List<NewIndexDescriptor> descriptorList = Arrays.asList(descriptors);
int[] labelIds = descriptorList.stream().mapToInt(index -> index.schema().getLabelId()).toArray();
int[] propertyKeyIds = descriptorList.stream().flatMapToInt(d -> Arrays.stream(d.schema().getPropertyIds())).toArray();
InitialNodeLabelCreationVisitor labelUpdateVisitor = new InitialNodeLabelCreationVisitor();
StoreScan<IOException> storeScan = indexStoreView.visitNodes(labelIds, (propertyKeyId) -> PrimitiveIntCollections.contains(propertyKeyIds, propertyKeyId), propertyUpdateVisitor, labelUpdateVisitor, true);
storeScan.run();
for (IndexPopulator populator : populators) {
populator.verifyDeferredConstraints(indexStoreView);
populator.close(true);
}
labelUpdateVisitor.close();
}
use of org.neo4j.kernel.api.index.IndexEntryUpdate in project neo4j by neo4j.
the class NonUniqueDatabaseIndexPopulatorTest method sampleIncludedUpdates.
@Test
public void sampleIncludedUpdates() throws Exception {
populator = newPopulator();
List<IndexEntryUpdate> updates = Arrays.asList(IndexEntryUpdate.add(1, labelSchemaDescriptor, "aaa"), IndexEntryUpdate.add(2, labelSchemaDescriptor, "bbb"), IndexEntryUpdate.add(3, labelSchemaDescriptor, "ccc"));
updates.forEach(populator::includeSample);
IndexSample sample = populator.sampleResult();
assertEquals(new IndexSample(3, 3, 3), sample);
}
use of org.neo4j.kernel.api.index.IndexEntryUpdate in project neo4j by neo4j.
the class NonUniqueDatabaseIndexPopulatorTest method addUpdates.
@Test
public void addUpdates() throws Exception {
populator = newPopulator();
List<IndexEntryUpdate> updates = Arrays.asList(IndexEntryUpdate.add(1, labelSchemaDescriptor, "foo"), IndexEntryUpdate.add(2, labelSchemaDescriptor, "bar"), IndexEntryUpdate.add(42, labelSchemaDescriptor, "bar"));
populator.add(updates);
index.maybeRefreshBlocking();
try (IndexReader reader = index.getIndexReader()) {
int propertyKeyId = labelSchemaDescriptor.getPropertyId();
PrimitiveLongIterator allEntities = reader.query(IndexQuery.exists(propertyKeyId));
assertArrayEquals(new long[] { 1, 2, 42 }, PrimitiveLongCollections.asArray(allEntities));
}
}
use of org.neo4j.kernel.api.index.IndexEntryUpdate in project neo4j by neo4j.
the class UniqueDatabaseIndexPopulatorTest method addUpdate.
private static void addUpdate(UniqueLuceneIndexPopulator populator, long nodeId, Object value) throws IOException, IndexEntryConflictException {
IndexEntryUpdate update = IndexEntryUpdate.add(nodeId, descriptor.schema(), value);
populator.add(Collections.singletonList(update));
}
use of org.neo4j.kernel.api.index.IndexEntryUpdate in project neo4j by neo4j.
the class BatchingMultipleIndexPopulatorTest method populateFromQueueDoesNothingIfThresholdNotReached.
@Test
public void populateFromQueueDoesNothingIfThresholdNotReached() throws Exception {
setProperty(QUEUE_THRESHOLD_NAME, 5);
BatchingMultipleIndexPopulator batchingPopulator = new BatchingMultipleIndexPopulator(mock(IndexStoreView.class), mock(ExecutorService.class), NullLogProvider.getInstance());
IndexPopulator populator = addPopulator(batchingPopulator, index1);
IndexUpdater updater = mock(IndexUpdater.class);
when(populator.newPopulatingUpdater(any())).thenReturn(updater);
IndexEntryUpdate update1 = IndexEntryUpdate.add(1, index1.schema(), "foo");
IndexEntryUpdate update2 = IndexEntryUpdate.add(2, index1.schema(), "bar");
batchingPopulator.queue(update1);
batchingPopulator.queue(update2);
batchingPopulator.populateFromQueueBatched(42);
verify(updater, never()).process(any());
verify(populator, never()).newPopulatingUpdater(any());
}
Aggregations