Search in sources :

Example 21 with IndexPopulator

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);
}
Also used : IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) IndexEntryUpdate(org.neo4j.kernel.api.index.IndexEntryUpdate) PropertyAccessor(org.neo4j.kernel.api.index.PropertyAccessor) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.Test)

Example 22 with IndexPopulator

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());
}
Also used : NodeUpdates(org.neo4j.kernel.api.index.NodeUpdates) IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) NeoStoreIndexStoreView(org.neo4j.kernel.impl.transaction.state.storeview.NeoStoreIndexStoreView) ExecutorService(java.util.concurrent.ExecutorService) Test(org.junit.Test)

Example 23 with IndexPopulator

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);
}
Also used : IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator)

Example 24 with IndexPopulator

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;
}
Also used : IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator)

Example 25 with IndexPopulator

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();
}
Also used : InternalIndexState(org.neo4j.kernel.api.index.InternalIndexState) Arrays(java.util.Arrays) SimpleKernelContext(org.neo4j.kernel.impl.spi.SimpleKernelContext) PropertyKeyTokenStore(org.neo4j.kernel.impl.store.PropertyKeyTokenStore) BatchRelationship(org.neo4j.unsafe.batchinsert.BatchRelationship) Iterators(org.neo4j.helpers.collection.Iterators) IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) RelationshipGroupGetter(org.neo4j.kernel.impl.transaction.state.RelationshipGroupGetter) PrimitiveIntCollections(org.neo4j.collection.primitive.PrimitiveIntCollections) RelationshipPropertyExistenceConstraintDefinition(org.neo4j.kernel.impl.coreapi.schema.RelationshipPropertyExistenceConstraintDefinition) NodeLabelsField.parseLabelsField(org.neo4j.kernel.impl.store.NodeLabelsField.parseLabelsField) NoOpClient(org.neo4j.kernel.impl.locking.NoOpClient) SchemaIndexProvider(org.neo4j.kernel.api.index.SchemaIndexProvider) CountsComputer(org.neo4j.kernel.impl.store.CountsComputer) PropertyStore.encodeString(org.neo4j.kernel.impl.store.PropertyStore.encodeString) Map(java.util.Map) PageCacheTracer(org.neo4j.io.pagecache.tracing.PageCacheTracer) NodeMultiPropertyDescriptor(org.neo4j.kernel.api.schema.NodeMultiPropertyDescriptor) DefaultSchemaIndexProviderMap(org.neo4j.kernel.impl.transaction.state.DefaultSchemaIndexProviderMap) KernelExtensions(org.neo4j.kernel.extension.KernelExtensions) IndexDefinitionImpl(org.neo4j.kernel.impl.coreapi.schema.IndexDefinitionImpl) NullLog(org.neo4j.logging.NullLog) NodeUpdates(org.neo4j.kernel.api.index.NodeUpdates) HighestSelectionStrategy(org.neo4j.kernel.extension.dependency.HighestSelectionStrategy) LabelTokenRecord(org.neo4j.kernel.impl.store.record.LabelTokenRecord) DefaultIdGeneratorFactory(org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory) RecordCursors(org.neo4j.kernel.impl.store.RecordCursors) SchemaStore(org.neo4j.kernel.impl.store.SchemaStore) ConstraintDefinition(org.neo4j.graphdb.schema.ConstraintDefinition) Locks(org.neo4j.kernel.impl.locking.Locks) UniquenessConstraint(org.neo4j.kernel.api.constraints.UniquenessConstraint) KernelExtensionFactory(org.neo4j.kernel.extension.KernelExtensionFactory) LabelScanStoreProvider(org.neo4j.kernel.impl.api.scan.LabelScanStoreProvider) RelationshipType(org.neo4j.graphdb.RelationshipType) NodeStore(org.neo4j.kernel.impl.store.NodeStore) GraphDatabaseSettings(org.neo4j.graphdb.factory.GraphDatabaseSettings) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) IndexCreatorImpl(org.neo4j.kernel.impl.coreapi.schema.IndexCreatorImpl) RelationshipTypeToken(org.neo4j.kernel.impl.core.RelationshipTypeToken) RecordFormatSelector(org.neo4j.kernel.impl.store.format.RecordFormatSelector) LabelScanStore(org.neo4j.kernel.api.labelscan.LabelScanStore) PageCacheLifecycle(org.neo4j.kernel.impl.pagecache.PageCacheLifecycle) IteratorWrapper(org.neo4j.helpers.collection.IteratorWrapper) ArrayList(java.util.ArrayList) InternalSchemaActions(org.neo4j.kernel.impl.coreapi.schema.InternalSchemaActions) RelationshipStore(org.neo4j.kernel.impl.store.RelationshipStore) BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) DirectRecordAccessSet(org.neo4j.unsafe.batchinsert.DirectRecordAccessSet) SchemaCache(org.neo4j.kernel.impl.api.store.SchemaCache) PropertyStore(org.neo4j.kernel.impl.store.PropertyStore) CreateConstraintFailureException(org.neo4j.kernel.api.exceptions.schema.CreateConstraintFailureException) PrimitiveLongCollections(org.neo4j.collection.primitive.PrimitiveLongCollections) DatabaseInfo(org.neo4j.kernel.impl.factory.DatabaseInfo) UnsatisfiedDependencyStrategies(org.neo4j.kernel.extension.UnsatisfiedDependencyStrategies) Listener(org.neo4j.kernel.impl.util.Listener) PrimitiveLongCollections.map(org.neo4j.collection.primitive.PrimitiveLongCollections.map) BaseNodeConstraintCreator(org.neo4j.kernel.impl.coreapi.schema.BaseNodeConstraintCreator) IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) NewIndexDescriptorFactory(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptorFactory) IOException(java.io.IOException) Label.label(org.neo4j.graphdb.Label.label) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) SchemaRule(org.neo4j.storageengine.api.schema.SchemaRule) IoPrimitiveUtils.safeCastLongToInt(org.neo4j.kernel.impl.util.IoPrimitiveUtils.safeCastLongToInt) File(java.io.File) Iterables(org.neo4j.helpers.collection.Iterables) ConstraintDescriptorFactory(org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptorFactory) IndexConfigStore(org.neo4j.kernel.impl.index.IndexConfigStore) RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) Boolean.parseBoolean(java.lang.Boolean.parseBoolean) SchemaIndexProviderMap(org.neo4j.kernel.impl.api.index.SchemaIndexProviderMap) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) NodeLabelUpdate(org.neo4j.kernel.api.labelscan.NodeLabelUpdate) NodePropertyExistenceConstraintDefinition(org.neo4j.kernel.impl.coreapi.schema.NodePropertyExistenceConstraintDefinition) AlreadyConstrainedException(org.neo4j.kernel.api.exceptions.schema.AlreadyConstrainedException) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) IndexSamplingConfig(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig) RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) PageCursorTracerSupplier(org.neo4j.io.pagecache.tracing.cursor.PageCursorTracerSupplier) PropertyDeleter(org.neo4j.kernel.impl.transaction.state.PropertyDeleter) Log(org.neo4j.logging.Log) IdGeneratorFactory(org.neo4j.kernel.impl.store.id.IdGeneratorFactory) StoreScan(org.neo4j.kernel.impl.api.index.StoreScan) Dependencies(org.neo4j.kernel.impl.util.Dependencies) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) LabelTokenStore(org.neo4j.kernel.impl.store.LabelTokenStore) NodePropertyDescriptor(org.neo4j.kernel.api.schema.NodePropertyDescriptor) RelationshipTypeTokenStore(org.neo4j.kernel.impl.store.RelationshipTypeTokenStore) DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) Record(org.neo4j.kernel.impl.store.record.Record) PageCache(org.neo4j.io.pagecache.PageCache) UnderlyingStorageException(org.neo4j.kernel.impl.store.UnderlyingStorageException) PropertyCreator(org.neo4j.kernel.impl.transaction.state.PropertyCreator) Collection(java.util.Collection) IndexCreator(org.neo4j.graphdb.schema.IndexCreator) IndexEntryUpdate(org.neo4j.kernel.api.index.IndexEntryUpdate) ConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor) KernelException(org.neo4j.kernel.api.exceptions.KernelException) LabelScanWriter(org.neo4j.kernel.api.labelscan.LabelScanWriter) DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) RecordStore(org.neo4j.kernel.impl.store.RecordStore) List(java.util.List) NamedLabelScanStoreSelectionStrategy(org.neo4j.kernel.extension.dependency.NamedLabelScanStoreSelectionStrategy) StoreLocker(org.neo4j.kernel.internal.StoreLocker) Entry(java.util.Map.Entry) Optional(java.util.Optional) EmbeddedGraphDatabase(org.neo4j.kernel.internal.EmbeddedGraphDatabase) Label(org.neo4j.graphdb.Label) SchemaDescriptorFactory(org.neo4j.kernel.api.schema_new.SchemaDescriptorFactory) LabelSchemaDescriptor(org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor) LogProvider(org.neo4j.logging.LogProvider) HashMap(java.util.HashMap) Token(org.neo4j.storageengine.api.Token) NotFoundException(org.neo4j.graphdb.NotFoundException) ConfiguringPageCacheFactory(org.neo4j.kernel.impl.pagecache.ConfiguringPageCacheFactory) UniquenessConstraintDefinition(org.neo4j.kernel.impl.coreapi.schema.UniquenessConstraintDefinition) RecordFormats(org.neo4j.kernel.impl.store.format.RecordFormats) ConstraintViolationException(org.neo4j.graphdb.ConstraintViolationException) NodeLabels(org.neo4j.kernel.impl.store.NodeLabels) IndexEntryConflictException(org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException) ConstraintCreator(org.neo4j.graphdb.schema.ConstraintCreator) NeoStores(org.neo4j.kernel.impl.store.NeoStores) StoreLogService(org.neo4j.kernel.impl.logging.StoreLogService) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) CountsTracker(org.neo4j.kernel.impl.store.counts.CountsTracker) RelationshipTypeTokenRecord(org.neo4j.kernel.impl.store.record.RelationshipTypeTokenRecord) PrintStream(java.io.PrintStream) Config(org.neo4j.kernel.configuration.Config) ConstraintRule(org.neo4j.kernel.impl.store.record.ConstraintRule) RecordProxy(org.neo4j.kernel.impl.transaction.state.RecordAccess.RecordProxy) StandardConstraintSemantics(org.neo4j.kernel.impl.constraints.StandardConstraintSemantics) LockService(org.neo4j.kernel.impl.locking.LockService) RelationshipCreator(org.neo4j.kernel.impl.transaction.state.RelationshipCreator) Iterator(java.util.Iterator) LongFunction(java.util.function.LongFunction) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) RecordAccess(org.neo4j.kernel.impl.transaction.state.RecordAccess) PropertyKeyTokenRecord(org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord) IdValidator(org.neo4j.kernel.impl.store.id.validation.IdValidator) PropertyTraverser(org.neo4j.kernel.impl.transaction.state.PropertyTraverser) PrimitiveRecord(org.neo4j.kernel.impl.store.record.PrimitiveRecord) NeoStoreIndexStoreView(org.neo4j.kernel.impl.transaction.state.storeview.NeoStoreIndexStoreView) Visitor(org.neo4j.helpers.collection.Visitor) Collections(java.util.Collections) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) IndexSamplingConfig(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig) Optional(java.util.Optional) IOException(java.io.IOException) UniquenessConstraint(org.neo4j.kernel.api.constraints.UniquenessConstraint) NodeUpdates(org.neo4j.kernel.api.index.NodeUpdates) IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) IndexEntryConflictException(org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException)

Aggregations

IndexPopulator (org.neo4j.kernel.api.index.IndexPopulator)45 Test (org.junit.Test)37 IndexEntryUpdate (org.neo4j.kernel.api.index.IndexEntryUpdate)11 PropertyAccessor (org.neo4j.kernel.api.index.PropertyAccessor)8 IndexUpdater (org.neo4j.kernel.api.index.IndexUpdater)7 IndexSamplingConfig (org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig)7 NeoStoreIndexStoreView (org.neo4j.kernel.impl.transaction.state.storeview.NeoStoreIndexStoreView)7 NodeUpdates (org.neo4j.kernel.api.index.NodeUpdates)6 SchemaIndexProvider (org.neo4j.kernel.api.index.SchemaIndexProvider)6 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)6 BatchInserter (org.neo4j.unsafe.batchinsert.BatchInserter)5 ExecutorService (java.util.concurrent.ExecutorService)3 LabelSchemaDescriptor (org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor)3 IndexPopulation (org.neo4j.kernel.impl.api.index.MultipleIndexPopulator.IndexPopulation)3 NeoStores (org.neo4j.kernel.impl.store.NeoStores)3 NodeStore (org.neo4j.kernel.impl.store.NodeStore)3 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)3 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)3 IntPredicate (java.util.function.IntPredicate)2 NodeLabelUpdate (org.neo4j.kernel.api.labelscan.NodeLabelUpdate)2