Search in sources :

Example 1 with CountsAccessor

use of org.neo4j.kernel.impl.api.CountsAccessor in project neo4j by neo4j.

the class CountsOracle method verify.

public <Tracker extends CountsVisitor.Visitable & CountsAccessor> void verify(final Tracker tracker) {
    CountsRecordState seenState = new CountsRecordState();
    final CountsAccessor.Initializer initializer = new CountsAccessor.Initializer(seenState, seenState);
    List<CountsRecordState.Difference> differences = state.verify(new CountsVisitor.Visitable() {

        @Override
        public void accept(final CountsVisitor verifier) {
            tracker.accept(CountsVisitor.Adapter.multiplex(initializer, verifier));
        }
    });
    seenState.accept(new CountsVisitor() {

        @Override
        public void visitNodeCount(int labelId, long count) {
            long expected = tracker.nodeCount(labelId, newDoubleLongRegister()).readSecond();
            assertEquals("Should be able to read visited state.", expected, count);
        }

        @Override
        public void visitRelationshipCount(int startLabelId, int typeId, int endLabelId, long count) {
            long expected = tracker.relationshipCount(startLabelId, typeId, endLabelId, newDoubleLongRegister()).readSecond();
            assertEquals("Should be able to read visited state.", expected, count);
        }

        @Override
        public void visitIndexStatistics(long indexId, long updates, long size) {
            Register.DoubleLongRegister output = tracker.indexUpdatesAndSize(indexId, newDoubleLongRegister());
            assertEquals("Should be able to read visited state.", output.readFirst(), updates);
            assertEquals("Should be able to read visited state.", output.readSecond(), size);
        }

        @Override
        public void visitIndexSample(long indexId, long unique, long size) {
            Register.DoubleLongRegister output = tracker.indexSample(indexId, newDoubleLongRegister());
            assertEquals("Should be able to read visited state.", output.readFirst(), unique);
            assertEquals("Should be able to read visited state.", output.readSecond(), size);
        }
    });
    if (!differences.isEmpty()) {
        StringBuilder errors = new StringBuilder().append("Counts differ in ").append(differences.size()).append(" places...");
        for (CountsRecordState.Difference difference : differences) {
            errors.append("\n\t").append(difference);
        }
        throw new AssertionError(errors.toString());
    }
}
Also used : CountsRecordState(org.neo4j.kernel.impl.api.CountsRecordState) CountsAccessor(org.neo4j.kernel.impl.api.CountsAccessor) CountsVisitor(org.neo4j.kernel.impl.api.CountsVisitor) Registers.newDoubleLongRegister(org.neo4j.register.Registers.newDoubleLongRegister)

Example 2 with CountsAccessor

use of org.neo4j.kernel.impl.api.CountsAccessor in project neo4j by neo4j.

the class FullCheck method execute.

ConsistencySummaryStatistics execute(DirectStoreAccess stores, Log log, Monitor reportMonitor) throws ConsistencyCheckIncompleteException {
    ConsistencySummaryStatistics summary = new ConsistencySummaryStatistics();
    InconsistencyReport report = new InconsistencyReport(new InconsistencyMessageLogger(log), summary);
    OwnerCheck ownerCheck = new OwnerCheck(checkPropertyOwners);
    CountsBuilderDecorator countsBuilder = new CountsBuilderDecorator(stores.nativeStores());
    CheckDecorator decorator = new CheckDecorator.ChainCheckDecorator(ownerCheck, countsBuilder);
    CacheAccess cacheAccess = new DefaultCacheAccess(statistics.getCounts(), threads);
    RecordAccess records = recordAccess(stores.nativeStores(), cacheAccess);
    execute(stores, decorator, records, report, cacheAccess, reportMonitor);
    ownerCheck.scanForOrphanChains(progressFactory);
    if (checkGraph) {
        CountsAccessor countsAccessor = stores.nativeStores().getCounts();
        if (countsAccessor instanceof CountsTracker) {
            CountsTracker tracker = (CountsTracker) countsAccessor;
            try {
                tracker.start();
            } catch (Exception e) {
            // let's hope it was already started :)
            }
        }
        countsBuilder.checkCounts(countsAccessor, new ConsistencyReporter(records, report), progressFactory);
    }
    if (!summary.isConsistent()) {
        log.warn("Inconsistencies found: " + summary);
    }
    return summary;
}
Also used : DirectRecordAccess(org.neo4j.consistency.store.DirectRecordAccess) CacheSmallStoresRecordAccess(org.neo4j.consistency.store.CacheSmallStoresRecordAccess) RecordAccess(org.neo4j.consistency.store.RecordAccess) InconsistencyReport(org.neo4j.consistency.report.InconsistencyReport) ConsistencyReporter(org.neo4j.consistency.report.ConsistencyReporter) CacheAccess(org.neo4j.consistency.checking.cache.CacheAccess) DefaultCacheAccess(org.neo4j.consistency.checking.cache.DefaultCacheAccess) CountsAccessor(org.neo4j.kernel.impl.api.CountsAccessor) DefaultCacheAccess(org.neo4j.consistency.checking.cache.DefaultCacheAccess) CheckDecorator(org.neo4j.consistency.checking.CheckDecorator) CountsTracker(org.neo4j.kernel.impl.store.counts.CountsTracker) InconsistencyMessageLogger(org.neo4j.consistency.report.InconsistencyMessageLogger) ConsistencySummaryStatistics(org.neo4j.consistency.report.ConsistencySummaryStatistics)

Aggregations

CountsAccessor (org.neo4j.kernel.impl.api.CountsAccessor)2 CheckDecorator (org.neo4j.consistency.checking.CheckDecorator)1 CacheAccess (org.neo4j.consistency.checking.cache.CacheAccess)1 DefaultCacheAccess (org.neo4j.consistency.checking.cache.DefaultCacheAccess)1 ConsistencyReporter (org.neo4j.consistency.report.ConsistencyReporter)1 ConsistencySummaryStatistics (org.neo4j.consistency.report.ConsistencySummaryStatistics)1 InconsistencyMessageLogger (org.neo4j.consistency.report.InconsistencyMessageLogger)1 InconsistencyReport (org.neo4j.consistency.report.InconsistencyReport)1 CacheSmallStoresRecordAccess (org.neo4j.consistency.store.CacheSmallStoresRecordAccess)1 DirectRecordAccess (org.neo4j.consistency.store.DirectRecordAccess)1 RecordAccess (org.neo4j.consistency.store.RecordAccess)1 CountsRecordState (org.neo4j.kernel.impl.api.CountsRecordState)1 CountsVisitor (org.neo4j.kernel.impl.api.CountsVisitor)1 CountsTracker (org.neo4j.kernel.impl.store.counts.CountsTracker)1 Registers.newDoubleLongRegister (org.neo4j.register.Registers.newDoubleLongRegister)1