Search in sources :

Example 1 with SchemaStorage

use of org.neo4j.kernel.impl.store.SchemaStorage 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 SchemaStorage

use of org.neo4j.kernel.impl.store.SchemaStorage in project neo4j by neo4j.

the class DumpStore method dumpSchemaStore.

private static void dumpSchemaStore(NeoStores neoStores, long[] ids) throws Exception {
    try (SchemaStore store = neoStores.getSchemaStore()) {
        final SchemaStorage storage = new SchemaStorage(store);
        new DumpStore<DynamicRecord, SchemaStore>(System.out) {

            @Override
            protected Object transform(DynamicRecord record) throws Exception {
                return record.inUse() && record.isStartRecord() ? storage.loadSingleSchemaRule(record.getId()) : null;
            }
        }.dump(store, ids);
    }
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) SchemaStorage(org.neo4j.kernel.impl.store.SchemaStorage) SchemaStore(org.neo4j.kernel.impl.store.SchemaStore)

Example 3 with SchemaStorage

use of org.neo4j.kernel.impl.store.SchemaStorage in project neo4j by neo4j.

the class DumpCountsStore method dumpCountsStore.

public static void dumpCountsStore(FileSystemAbstraction fs, File path, PrintStream out) throws IOException {
    try (PageCache pages = createPageCache(fs);
        Lifespan life = new Lifespan()) {
        if (fs.isDirectory(path)) {
            StoreFactory factory = new StoreFactory(path, pages, fs, NullLogProvider.getInstance());
            NeoStores neoStores = factory.openAllNeoStores();
            SchemaStorage schemaStorage = new SchemaStorage(neoStores.getSchemaStore());
            neoStores.getCounts().accept(new DumpCountsStore(out, neoStores, schemaStorage));
        } else {
            VisitableCountsTracker tracker = new VisitableCountsTracker(NullLogProvider.getInstance(), fs, pages, Config.empty(), path);
            if (fs.fileExists(path)) {
                tracker.visitFile(path, new DumpCountsStore(out));
            } else {
                life.add(tracker).accept(new DumpCountsStore(out));
            }
        }
    }
}
Also used : SchemaStorage(org.neo4j.kernel.impl.store.SchemaStorage) NeoStores(org.neo4j.kernel.impl.store.NeoStores) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) StandalonePageCacheFactory.createPageCache(org.neo4j.io.pagecache.impl.muninn.StandalonePageCacheFactory.createPageCache) PageCache(org.neo4j.io.pagecache.PageCache)

Example 4 with SchemaStorage

use of org.neo4j.kernel.impl.store.SchemaStorage in project neo4j by neo4j.

the class UniquenessConstraintCreationIT method committedConstraintRuleShouldCrossReferenceTheCorrespondingIndexRule.

@Test
public void committedConstraintRuleShouldCrossReferenceTheCorrespondingIndexRule() throws Exception {
    // when
    SchemaWriteOperations statement = schemaWriteOperationsInNewTransaction();
    statement.uniquePropertyConstraintCreate(descriptor);
    commit();
    // then
    SchemaStorage schema = new SchemaStorage(neoStores().getSchemaStore());
    IndexRule indexRule = schema.indexGetForSchema(NewIndexDescriptorFactory.uniqueForLabel(typeId, propertyKeyId));
    ConstraintRule constraintRule = schema.constraintsGetSingle(ConstraintDescriptorFactory.uniqueForLabel(typeId, propertyKeyId));
    assertEquals(constraintRule.getId(), indexRule.getOwningConstraint().longValue());
    assertEquals(indexRule.getId(), constraintRule.getOwnedIndex());
}
Also used : IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) SchemaWriteOperations(org.neo4j.kernel.api.SchemaWriteOperations) SchemaStorage(org.neo4j.kernel.impl.store.SchemaStorage) ConstraintRule(org.neo4j.kernel.impl.store.record.ConstraintRule) Test(org.junit.Test)

Example 5 with SchemaStorage

use of org.neo4j.kernel.impl.store.SchemaStorage in project neo4j by neo4j.

the class ConsistencyCheckTasks method createTasksForFullCheck.

public List<ConsistencyCheckerTask> createTasksForFullCheck(boolean checkLabelScanStore, boolean checkIndexes, boolean checkGraph) {
    List<ConsistencyCheckerTask> tasks = new ArrayList<>();
    if (checkGraph) {
        MandatoryProperties mandatoryProperties = new MandatoryProperties(nativeStores);
        StoreProcessor processor = multiPass.processor(CheckStage.Stage1_NS_PropsLabels, PROPERTIES);
        tasks.add(create(CheckStage.Stage1_NS_PropsLabels.name(), nativeStores.getNodeStore(), processor, ROUND_ROBIN));
        //ReltionshipStore pass - check label counts using cached labels, check properties, skip nodes and relationships
        processor = multiPass.processor(CheckStage.Stage2_RS_Labels, LABELS);
        multiPass.reDecorateRelationship(processor, RelationshipRecordCheck.relationshipRecordCheckForwardPass());
        tasks.add(create(CheckStage.Stage2_RS_Labels.name(), nativeStores.getRelationshipStore(), processor, ROUND_ROBIN));
        //NodeStore pass - just cache nextRel and inUse
        tasks.add(new CacheTask.CacheNextRel(CheckStage.Stage3_NS_NextRel, cacheAccess, Scanner.scan(nativeStores.getNodeStore())));
        //RelationshipStore pass - check nodes inUse, FirstInFirst, FirstInSecond using cached info
        processor = multiPass.processor(CheckStage.Stage4_RS_NextRel, NODES);
        multiPass.reDecorateRelationship(processor, RelationshipRecordCheck.relationshipRecordCheckBackwardPass(new PropertyChain<>(mandatoryProperties.forRelationships(reporter))));
        tasks.add(create(CheckStage.Stage4_RS_NextRel.name(), nativeStores.getRelationshipStore(), processor, ROUND_ROBIN));
        //NodeStore pass - just cache nextRel and inUse
        multiPass.reDecorateNode(processor, NodeRecordCheck.toCheckNextRel(), true);
        multiPass.reDecorateNode(processor, NodeRecordCheck.toCheckNextRelationshipGroup(), false);
        tasks.add(new CacheTask.CheckNextRel(CheckStage.Stage5_Check_NextRel, cacheAccess, nativeStores, processor));
        // source chain
        //RelationshipStore pass - forward scan of source chain using the cache.
        processor = multiPass.processor(CheckStage.Stage6_RS_Forward, RELATIONSHIPS);
        multiPass.reDecorateRelationship(processor, RelationshipRecordCheck.relationshipRecordCheckSourceChain());
        tasks.add(create(CheckStage.Stage6_RS_Forward.name(), nativeStores.getRelationshipStore(), processor, QueueDistribution.RELATIONSHIPS));
        //RelationshipStore pass - reverse scan of source chain using the cache.
        processor = multiPass.processor(CheckStage.Stage7_RS_Backward, RELATIONSHIPS);
        multiPass.reDecorateRelationship(processor, RelationshipRecordCheck.relationshipRecordCheckSourceChain());
        tasks.add(create(CheckStage.Stage7_RS_Backward.name(), nativeStores.getRelationshipStore(), processor, QueueDistribution.RELATIONSHIPS));
        //relationshipGroup
        StoreProcessor relGrpProcessor = multiPass.processor(Stage.PARALLEL_FORWARD, RELATIONSHIP_GROUPS);
        tasks.add(create("RelationshipGroupStore-RelGrp", nativeStores.getRelationshipGroupStore(), relGrpProcessor, ROUND_ROBIN));
        PropertyReader propertyReader = new PropertyReader(nativeStores);
        tasks.add(recordScanner(CheckStage.Stage8_PS_Props.name(), new IterableStore<>(nativeStores.getNodeStore(), true), new PropertyAndNode2LabelIndexProcessor(reporter, checkIndexes ? indexes : null, propertyReader, cacheAccess, mandatoryProperties.forNodes(reporter)), CheckStage.Stage8_PS_Props, ROUND_ROBIN, new IterableStore<>(nativeStores.getPropertyStore(), true)));
        tasks.add(create("StringStore-Str", nativeStores.getStringStore(), multiPass.processor(Stage.SEQUENTIAL_FORWARD, STRINGS), ROUND_ROBIN));
        tasks.add(create("ArrayStore-Arrays", nativeStores.getArrayStore(), multiPass.processor(Stage.SEQUENTIAL_FORWARD, ARRAYS), ROUND_ROBIN));
    }
    // The schema store is verified in multiple passes that share state since it fits into memory
    // and we care about the consistency of back references (cf. SemanticCheck)
    // PASS 1: Dynamic record chains
    tasks.add(create("SchemaStore", nativeStores.getSchemaStore(), ROUND_ROBIN));
    // PASS 2: Rule integrity and obligation build up
    final SchemaRecordCheck schemaCheck = new SchemaRecordCheck(new SchemaStorage(nativeStores.getSchemaStore()));
    tasks.add(new SchemaStoreProcessorTask<>("SchemaStoreProcessor-check_rules", statistics, numberOfThreads, nativeStores.getSchemaStore(), nativeStores, "check_rules", schemaCheck, progress, cacheAccess, defaultProcessor, ROUND_ROBIN));
    // PASS 3: Obligation verification and semantic rule uniqueness
    tasks.add(new SchemaStoreProcessorTask<>("SchemaStoreProcessor-check_obligations", statistics, numberOfThreads, nativeStores.getSchemaStore(), nativeStores, "check_obligations", schemaCheck.forObligationChecking(), progress, cacheAccess, defaultProcessor, ROUND_ROBIN));
    if (checkGraph) {
        tasks.add(create("RelationshipTypeTokenStore", nativeStores.getRelationshipTypeTokenStore(), ROUND_ROBIN));
        tasks.add(create("PropertyKeyTokenStore", nativeStores.getPropertyKeyTokenStore(), ROUND_ROBIN));
        tasks.add(create("LabelTokenStore", nativeStores.getLabelTokenStore(), ROUND_ROBIN));
        tasks.add(create("RelationshipTypeNameStore", nativeStores.getRelationshipTypeNameStore(), ROUND_ROBIN));
        tasks.add(create("PropertyKeyNameStore", nativeStores.getPropertyKeyNameStore(), ROUND_ROBIN));
        tasks.add(create("LabelNameStore", nativeStores.getLabelNameStore(), ROUND_ROBIN));
        tasks.add(create("NodeDynamicLabelStore", nativeStores.getNodeDynamicLabelStore(), ROUND_ROBIN));
    }
    ConsistencyReporter filteredReporter = multiPass.reporter(NODES);
    if (checkLabelScanStore) {
        tasks.add(recordScanner("LabelScanStore", labelScanStore.allNodeLabelRanges(), new LabelScanDocumentProcessor(filteredReporter, new LabelScanCheck()), Stage.SEQUENTIAL_FORWARD, ROUND_ROBIN));
    }
    if (checkIndexes) {
        for (IndexRule indexRule : indexes.rules()) {
            tasks.add(recordScanner(format("Index_%d", indexRule.getId()), new IndexIterator(indexes.accessorFor(indexRule)), new IndexEntryProcessor(filteredReporter, new IndexCheck(indexRule)), Stage.SEQUENTIAL_FORWARD, ROUND_ROBIN));
        }
    }
    return tasks;
}
Also used : PropertyChain(org.neo4j.consistency.checking.PropertyChain) IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) LabelScanDocumentProcessor(org.neo4j.consistency.checking.labelscan.LabelScanDocumentProcessor) ConsistencyReporter(org.neo4j.consistency.report.ConsistencyReporter) ArrayList(java.util.ArrayList) IndexEntryProcessor(org.neo4j.consistency.checking.index.IndexEntryProcessor) IndexIterator(org.neo4j.consistency.checking.index.IndexIterator) SchemaRecordCheck(org.neo4j.consistency.checking.SchemaRecordCheck) SchemaStorage(org.neo4j.kernel.impl.store.SchemaStorage) CacheTask(org.neo4j.consistency.checking.cache.CacheTask) LabelScanCheck(org.neo4j.consistency.checking.labelscan.LabelScanCheck)

Aggregations

SchemaStorage (org.neo4j.kernel.impl.store.SchemaStorage)8 IndexRule (org.neo4j.kernel.impl.store.record.IndexRule)6 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 SchemaRuleUtil.constraintIndexRule (org.neo4j.consistency.checking.SchemaRuleUtil.constraintIndexRule)2 ConsistencySummaryStatistics (org.neo4j.consistency.report.ConsistencySummaryStatistics)2 IndexAccessor (org.neo4j.kernel.api.index.IndexAccessor)2 IndexUpdater (org.neo4j.kernel.api.index.IndexUpdater)2 IndexSamplingConfig (org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig)2 NeoStores (org.neo4j.kernel.impl.store.NeoStores)2 SchemaStore (org.neo4j.kernel.impl.store.SchemaStore)2 ConstraintRule (org.neo4j.kernel.impl.store.record.ConstraintRule)2 DynamicRecord (org.neo4j.kernel.impl.store.record.DynamicRecord)2 Matchers.anyLong (org.mockito.Matchers.anyLong)1 PropertyChain (org.neo4j.consistency.checking.PropertyChain)1 SchemaRecordCheck (org.neo4j.consistency.checking.SchemaRecordCheck)1 CacheTask (org.neo4j.consistency.checking.cache.CacheTask)1 IndexEntryProcessor (org.neo4j.consistency.checking.index.IndexEntryProcessor)1 IndexIterator (org.neo4j.consistency.checking.index.IndexIterator)1 LabelScanCheck (org.neo4j.consistency.checking.labelscan.LabelScanCheck)1