use of org.neo4j.kernel.api.index.IndexPopulator in project neo4j by neo4j.
the class MultipleIndexPopulatorTest method testMultiplePropertyUpdateFailures.
@Test
public void testMultiplePropertyUpdateFailures() throws IOException, IndexEntryConflictException {
PropertyAccessor propertyAccessor = mock(PropertyAccessor.class);
IndexEntryUpdate update1 = IndexEntryUpdate.add(1, index1, "foo");
IndexEntryUpdate update2 = IndexEntryUpdate.add(2, index1, "bar");
IndexUpdater updater = mock(IndexUpdater.class);
IndexPopulator populator = createIndexPopulator(updater);
addPopulator(populator, 1);
doThrow(getPopulatorException()).when(updater).process(any(IndexEntryUpdate.class));
IndexUpdater multipleIndexUpdater = multipleIndexPopulator.newPopulatingUpdater(propertyAccessor);
multipleIndexUpdater.process(update1);
multipleIndexUpdater.process(update2);
verify(updater).process(update1);
verify(updater, never()).process(update2);
verify(updater).close();
checkPopulatorFailure(populator);
}
use of org.neo4j.kernel.api.index.IndexPopulator in project neo4j by neo4j.
the class BatchingMultipleIndexPopulatorTest method populatorMarkedAsFailed.
@Test
public void populatorMarkedAsFailed() throws Exception {
setProperty(BATCH_SIZE_NAME, 2);
NodeUpdates update1 = nodeUpdates(1, propertyId, "aaa", labelId);
NodeUpdates update2 = nodeUpdates(1, propertyId, "bbb", labelId);
IndexStoreView storeView = newStoreView(update1, update2);
RuntimeException batchFlushError = new RuntimeException("Batch failed");
IndexPopulator populator;
ExecutorService executor = Executors.newSingleThreadExecutor();
try {
BatchingMultipleIndexPopulator batchingPopulator = new BatchingMultipleIndexPopulator(storeView, executor, NullLogProvider.getInstance());
populator = addPopulator(batchingPopulator, index1);
doThrow(batchFlushError).when(populator).add(Arrays.asList(forIndex(update1, index1), forIndex(update2, index1)));
batchingPopulator.indexAllNodes().run();
} finally {
executor.shutdown();
executor.awaitTermination(1, TimeUnit.MINUTES);
}
verify(populator).markAsFailed(failure(batchFlushError).asString());
}
use of org.neo4j.kernel.api.index.IndexPopulator in project neo4j by neo4j.
the class IndexProxyCreator method createPopulatingIndexProxy.
public IndexProxy createPopulatingIndexProxy(final long ruleId, final NewIndexDescriptor descriptor, final SchemaIndexProvider.Descriptor providerDescriptor, final boolean flipToTentative, final IndexingService.Monitor monitor, final IndexPopulationJob populationJob) throws IOException {
final FlippableIndexProxy flipper = new FlippableIndexProxy();
// TODO: This is here because there is a circular dependency from PopulatingIndexProxy to FlippableIndexProxy
final String indexUserDescription = indexUserDescription(descriptor, providerDescriptor);
IndexPopulator populator = populatorFromProvider(providerDescriptor, ruleId, descriptor, samplingConfig);
FailedIndexProxyFactory failureDelegateFactory = new FailedPopulatingIndexProxyFactory(descriptor, providerDescriptor, populator, indexUserDescription, new IndexCountsRemover(storeView, ruleId), logProvider);
PopulatingIndexProxy populatingIndex = new PopulatingIndexProxy(descriptor, providerDescriptor, populationJob);
populationJob.addPopulator(populator, ruleId, descriptor, providerDescriptor, indexUserDescription, flipper, failureDelegateFactory);
flipper.flipTo(populatingIndex);
// Prepare for flipping to online mode
flipper.setFlipTarget(() -> {
monitor.populationCompleteOn(descriptor);
OnlineIndexProxy onlineProxy = new OnlineIndexProxy(ruleId, descriptor, onlineAccessorFromProvider(providerDescriptor, ruleId, descriptor, samplingConfig), storeView, providerDescriptor, true);
if (flipToTentative) {
return new TentativeConstraintIndexProxy(flipper, onlineProxy);
}
return onlineProxy;
});
return new ContractCheckingIndexProxy(flipper, false);
}
use of org.neo4j.kernel.api.index.IndexPopulator in project neo4j by neo4j.
the class IndexProxyCreator method createFailedIndexProxy.
public IndexProxy createFailedIndexProxy(long ruleId, NewIndexDescriptor descriptor, SchemaIndexProvider.Descriptor providerDescriptor, IndexPopulationFailure populationFailure) {
IndexPopulator indexPopulator = populatorFromProvider(providerDescriptor, ruleId, descriptor, samplingConfig);
String indexUserDescription = indexUserDescription(descriptor, providerDescriptor);
IndexProxy proxy;
proxy = new FailedIndexProxy(descriptor, providerDescriptor, indexUserDescription, indexPopulator, populationFailure, new IndexCountsRemover(storeView, ruleId), logProvider);
proxy = new ContractCheckingIndexProxy(proxy, true);
return proxy;
}
use of org.neo4j.kernel.api.index.IndexPopulator 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();
}
Aggregations