Search in sources :

Example 1 with IndexSamplingConfig

use of org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig in project neo4j by neo4j.

the class FullCheckIntegrationTest method shouldReportNodesThatAreNotIndexed.

@Test
public void shouldReportNodesThatAreNotIndexed() throws Exception {
    // given
    IndexSamplingConfig samplingConfig = new IndexSamplingConfig(Config.empty());
    Iterator<IndexRule> indexRuleIterator = new SchemaStorage(fixture.directStoreAccess().nativeStores().getSchemaStore()).indexesGetAll();
    while (indexRuleIterator.hasNext()) {
        IndexRule indexRule = indexRuleIterator.next();
        IndexAccessor accessor = fixture.directStoreAccess().indexes().getOnlineAccessor(indexRule.getId(), indexRule.getIndexDescriptor(), samplingConfig);
        IndexUpdater updater = accessor.newUpdater(IndexUpdateMode.ONLINE);
        updater.remove(asPrimitiveLongSet(indexedNodes));
        updater.close();
        accessor.close();
    }
    // when
    ConsistencySummaryStatistics stats = check();
    // then
    on(stats).verify(RecordType.NODE, 1).andThatsAllFolks();
}
Also used : IndexSamplingConfig(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig) IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) SchemaRuleUtil.constraintIndexRule(org.neo4j.consistency.checking.SchemaRuleUtil.constraintIndexRule) SchemaStorage(org.neo4j.kernel.impl.store.SchemaStorage) IndexAccessor(org.neo4j.kernel.api.index.IndexAccessor) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) ConsistencySummaryStatistics(org.neo4j.consistency.report.ConsistencySummaryStatistics) Test(org.junit.Test)

Example 2 with IndexSamplingConfig

use of org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig in project neo4j by neo4j.

the class ReadOnlyLuceneSchemaIndexTest method setUp.

@Before
public void setUp() {
    PartitionedIndexStorage indexStorage = new PartitionedIndexStorage(DirectoryFactory.PERSISTENT, fileSystemRule.get(), testDirectory.directory(), "1", false);
    Config config = Config.empty();
    IndexSamplingConfig samplingConfig = new IndexSamplingConfig(config);
    luceneSchemaIndex = new ReadOnlyDatabaseSchemaIndex(indexStorage, NewIndexDescriptorFactory.forLabel(0, 0), samplingConfig, new ReadOnlyIndexPartitionFactory());
}
Also used : IndexSamplingConfig(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig) Config(org.neo4j.kernel.configuration.Config) IndexSamplingConfig(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig) PartitionedIndexStorage(org.neo4j.kernel.api.impl.index.storage.PartitionedIndexStorage) ReadOnlyIndexPartitionFactory(org.neo4j.kernel.api.impl.index.partition.ReadOnlyIndexPartitionFactory) Before(org.junit.Before)

Example 3 with IndexSamplingConfig

use of org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig in project neo4j by neo4j.

the class IndexingServiceFactory method createIndexingService.

public static IndexingService createIndexingService(Config config, JobScheduler scheduler, SchemaIndexProviderMap providerMap, IndexStoreView storeView, TokenNameLookup tokenNameLookup, Iterable<IndexRule> indexRules, LogProvider logProvider, IndexingService.Monitor monitor, Runnable schemaStateChangeCallback) {
    if (providerMap == null || providerMap.getDefaultProvider() == null) {
        throw new IllegalStateException("You cannot run the database without an index provider, " + "please make sure that a valid provider (subclass of " + SchemaIndexProvider.class.getName() + ") is on your classpath.");
    }
    IndexSamplingConfig samplingConfig = new IndexSamplingConfig(config);
    MultiPopulatorFactory multiPopulatorFactory = MultiPopulatorFactory.forConfig(config);
    IndexMapReference indexMapRef = new IndexMapReference();
    IndexSamplingControllerFactory factory = new IndexSamplingControllerFactory(samplingConfig, storeView, scheduler, tokenNameLookup, logProvider);
    IndexSamplingController indexSamplingController = factory.create(indexMapRef);
    IndexProxyCreator proxySetup = new IndexProxyCreator(samplingConfig, storeView, providerMap, tokenNameLookup, logProvider);
    return new IndexingService(proxySetup, providerMap, indexMapRef, storeView, indexRules, indexSamplingController, tokenNameLookup, scheduler, schemaStateChangeCallback, multiPopulatorFactory, logProvider, monitor);
}
Also used : IndexSamplingConfig(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig) SchemaIndexProvider(org.neo4j.kernel.api.index.SchemaIndexProvider) IndexSamplingController(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingController) IndexSamplingControllerFactory(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingControllerFactory)

Example 4 with IndexSamplingConfig

use of org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig 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)

Example 5 with IndexSamplingConfig

use of org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig in project neo4j by neo4j.

the class FullCheckIntegrationTest method shouldReportNodesWithDuplicatePropertyValueInUniqueIndex.

@Test
public void shouldReportNodesWithDuplicatePropertyValueInUniqueIndex() throws Exception {
    // given
    IndexSamplingConfig samplingConfig = new IndexSamplingConfig(Config.empty());
    Iterator<IndexRule> indexRuleIterator = new SchemaStorage(fixture.directStoreAccess().nativeStores().getSchemaStore()).indexesGetAll();
    while (indexRuleIterator.hasNext()) {
        IndexRule indexRule = indexRuleIterator.next();
        IndexAccessor accessor = fixture.directStoreAccess().indexes().getOnlineAccessor(indexRule.getId(), indexRule.getIndexDescriptor(), samplingConfig);
        IndexUpdater updater = accessor.newUpdater(IndexUpdateMode.ONLINE);
        updater.process(IndexEntryUpdate.add(42, indexRule.getIndexDescriptor().schema(), "value"));
        updater.close();
        accessor.close();
    }
    // when
    ConsistencySummaryStatistics stats = check();
    // then
    on(stats).verify(RecordType.NODE, 1).verify(RecordType.INDEX, 2).andThatsAllFolks();
}
Also used : IndexSamplingConfig(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig) IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) SchemaRuleUtil.constraintIndexRule(org.neo4j.consistency.checking.SchemaRuleUtil.constraintIndexRule) SchemaStorage(org.neo4j.kernel.impl.store.SchemaStorage) IndexAccessor(org.neo4j.kernel.api.index.IndexAccessor) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) ConsistencySummaryStatistics(org.neo4j.consistency.report.ConsistencySummaryStatistics) Test(org.junit.Test)

Aggregations

IndexSamplingConfig (org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig)10 Test (org.junit.Test)4 Config (org.neo4j.kernel.configuration.Config)4 IndexAccessor (org.neo4j.kernel.api.index.IndexAccessor)3 SchemaIndexProvider (org.neo4j.kernel.api.index.SchemaIndexProvider)3 IndexRule (org.neo4j.kernel.impl.store.record.IndexRule)3 File (java.io.File)2 SchemaRuleUtil.constraintIndexRule (org.neo4j.consistency.checking.SchemaRuleUtil.constraintIndexRule)2 ConsistencySummaryStatistics (org.neo4j.consistency.report.ConsistencySummaryStatistics)2 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)2 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 Boolean.parseBoolean (java.lang.Boolean.parseBoolean)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1