Search in sources :

Example 1 with RelationshipGroupDegreesStore

use of org.neo4j.internal.counts.RelationshipGroupDegreesStore in project neo4j by neo4j.

the class CountsStoreTransactionApplierTest method shouldNotifyCacheAccessOnHowManyUpdatesOnCountsWeHadSoFar.

@Test
void shouldNotifyCacheAccessOnHowManyUpdatesOnCountsWeHadSoFar() throws Exception {
    // GIVEN
    final CountsStore counts = mock(CountsStore.class);
    final CountsAccessor.Updater updater = mock(CountsAccessor.Updater.class);
    when(counts.apply(anyLong(), any(CursorContext.class))).thenReturn(updater);
    final RelationshipGroupDegreesStore groupDegreesStore = mock(RelationshipGroupDegreesStore.class);
    when(groupDegreesStore.apply(anyLong(), any(CursorContext.class))).thenReturn(mock(RelationshipGroupDegreesStore.Updater.class));
    final CountsStoreTransactionApplierFactory applier = new CountsStoreTransactionApplierFactory(counts, groupDegreesStore);
    // WHEN
    try (TransactionApplier txApplier = applier.startTx(new GroupOfCommands(2L), mock(BatchContext.class))) {
        txApplier.visitNodeCountsCommand(new Command.NodeCountsCommand(ANY_LABEL, 1));
    }
    // THEN
    verify(updater).incrementNodeCount(ANY_LABEL, 1);
}
Also used : RelationshipGroupDegreesStore(org.neo4j.internal.counts.RelationshipGroupDegreesStore) CountsAccessor(org.neo4j.counts.CountsAccessor) CursorContext(org.neo4j.io.pagecache.context.CursorContext) CountsStore(org.neo4j.counts.CountsStore) Test(org.junit.jupiter.api.Test)

Example 2 with RelationshipGroupDegreesStore

use of org.neo4j.internal.counts.RelationshipGroupDegreesStore in project neo4j by neo4j.

the class FullCheck method execute.

public ConsistencySummaryStatistics execute(PageCache pageCache, DirectStoreAccess stores, ThrowingSupplier<CountsStore, IOException> countsSupplier, ThrowingSupplier<RelationshipGroupDegreesStore, IOException> groupDegreesStoreSupplier, IndexAccessors.IndexAccessorLookup indexAccessorLookup, PageCacheTracer pageCacheTracer, MemoryTracker memoryTracker, Log log) throws ConsistencyCheckIncompleteException {
    ConsistencySummaryStatistics summary = new ConsistencySummaryStatistics();
    InconsistencyReport report = new InconsistencyReport(new InconsistencyMessageLogger(log, moreDescriptiveRecordToStrings(stores)), summary);
    CountsStore countsStore = getCountsStore(countsSupplier, log, summary);
    RelationshipGroupDegreesStore groupDegreesStore = getGroupDegreesStore(groupDegreesStoreSupplier, log, summary);
    execute(pageCache, stores, report, countsStore, groupDegreesStore, indexAccessorLookup, pageCacheTracer, memoryTracker);
    if (!summary.isConsistent()) {
        log.warn("Inconsistencies found: " + summary);
    }
    return summary;
}
Also used : InconsistencyReport(org.neo4j.consistency.report.InconsistencyReport) RelationshipGroupDegreesStore(org.neo4j.internal.counts.RelationshipGroupDegreesStore) InconsistencyMessageLogger(org.neo4j.consistency.report.InconsistencyMessageLogger) CountsStore(org.neo4j.counts.CountsStore) ConsistencySummaryStatistics(org.neo4j.consistency.report.ConsistencySummaryStatistics)

Example 3 with RelationshipGroupDegreesStore

use of org.neo4j.internal.counts.RelationshipGroupDegreesStore in project neo4j by neo4j.

the class DetectAllRelationshipInconsistenciesIT method shouldDetectSabotagedRelationshipWhereEverItIs.

@Test
void shouldDetectSabotagedRelationshipWhereEverItIs() throws Exception {
    // GIVEN a database which lots of relationships
    GraphDatabaseAPI db = getGraphDatabaseAPI();
    Sabotage sabotage;
    try {
        Node[] nodes = new Node[1_000];
        Relationship[] relationships = new Relationship[10_000];
        long additionalNodeId;
        try (Transaction tx = db.beginTx()) {
            for (int i = 0; i < nodes.length; i++) {
                nodes[i] = tx.createNode(label("Foo"));
            }
            additionalNodeId = tx.createNode().getId();
            for (int i = 0; i < 10_000; i++) {
                relationships[i] = random.among(nodes).createRelationshipTo(random.among(nodes), MyRelTypes.TEST);
            }
            tx.commit();
        }
        // WHEN sabotaging a random relationship
        DependencyResolver resolver = db.getDependencyResolver();
        NeoStores neoStores = resolver.resolveDependency(RecordStorageEngine.class).testAccessNeoStores();
        RelationshipStore relationshipStore = neoStores.getRelationshipStore();
        Relationship sabotagedRelationships = random.among(relationships);
        sabotage = sabotage(relationshipStore, sabotagedRelationships.getId(), additionalNodeId);
    } finally {
        managementService.shutdown();
    }
    // THEN the checker should find it, where ever it is in the store
    db = getGraphDatabaseAPI();
    try {
        DependencyResolver resolver = db.getDependencyResolver();
        RecordStorageEngine storageEngine = resolver.resolveDependency(RecordStorageEngine.class);
        NeoStores neoStores = storageEngine.testAccessNeoStores();
        CountsStore counts = (CountsStore) storageEngine.countsAccessor();
        RelationshipGroupDegreesStore groupDegreesStore = storageEngine.relationshipGroupDegreesStore();
        DirectStoreAccess directStoreAccess = new DirectStoreAccess(neoStores, db.getDependencyResolver().resolveDependency(IndexProviderMap.class), db.getDependencyResolver().resolveDependency(TokenHolders.class), db.getDependencyResolver().resolveDependency(IndexStatisticsStore.class), db.getDependencyResolver().resolveDependency(IdGeneratorFactory.class));
        int threads = random.intBetween(2, 10);
        FullCheck checker = new FullCheck(ProgressMonitorFactory.NONE, threads, ConsistencyFlags.DEFAULT, getTuningConfiguration(), DebugContext.NO_DEBUG, NodeBasedMemoryLimiter.DEFAULT);
        AssertableLogProvider logProvider = new AssertableLogProvider(true);
        ConsistencySummaryStatistics summary = checker.execute(resolver.resolveDependency(PageCache.class), directStoreAccess, () -> counts, () -> groupDegreesStore, null, PageCacheTracer.NULL, INSTANCE, logProvider.getLog(FullCheck.class));
        int relationshipInconsistencies = summary.getInconsistencyCountForRecordType(RecordType.RELATIONSHIP);
        assertTrue(relationshipInconsistencies > 0, "Couldn't detect sabotaged relationship " + sabotage);
        assertThat(logProvider).containsMessages(sabotage.after.toString());
    } finally {
        managementService.shutdown();
    }
}
Also used : Node(org.neo4j.graphdb.Node) RelationshipGroupDegreesStore(org.neo4j.internal.counts.RelationshipGroupDegreesStore) DirectStoreAccess(org.neo4j.consistency.store.DirectStoreAccess) IdGeneratorFactory(org.neo4j.internal.id.IdGeneratorFactory) IndexProviderMap(org.neo4j.kernel.impl.api.index.IndexProviderMap) CountsStore(org.neo4j.counts.CountsStore) DependencyResolver(org.neo4j.common.DependencyResolver) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) RecordStorageEngine(org.neo4j.internal.recordstorage.RecordStorageEngine) Relationship(org.neo4j.graphdb.Relationship) NeoStores(org.neo4j.kernel.impl.store.NeoStores) IndexStatisticsStore(org.neo4j.kernel.impl.api.index.stats.IndexStatisticsStore) RelationshipStore(org.neo4j.kernel.impl.store.RelationshipStore) TokenHolders(org.neo4j.token.TokenHolders) PageCache(org.neo4j.io.pagecache.PageCache) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) ConsistencySummaryStatistics(org.neo4j.consistency.report.ConsistencySummaryStatistics) Test(org.junit.jupiter.api.Test)

Example 4 with RelationshipGroupDegreesStore

use of org.neo4j.internal.counts.RelationshipGroupDegreesStore in project neo4j by neo4j.

the class FullCheckTokenIndexIT method check.

private ConsistencySummaryStatistics check(GraphDatabaseAPI database, Config config) throws ConsistencyCheckIncompleteException {
    DependencyResolver dependencyResolver = database.getDependencyResolver();
    RecordStorageEngine storageEngine = dependencyResolver.resolveDependency(RecordStorageEngine.class);
    NeoStores neoStores = storageEngine.testAccessNeoStores();
    IndexingService indexingService = dependencyResolver.resolveDependency(IndexingService.class);
    DirectStoreAccess directStoreAccess = new DirectStoreAccess(neoStores, dependencyResolver.resolveDependency(IndexProviderMap.class), dependencyResolver.resolveDependency(TokenHolders.class), dependencyResolver.resolveDependency(IndexStatisticsStore.class), dependencyResolver.resolveDependency(IdGeneratorFactory.class));
    CountsAccessor countsStore = storageEngine.countsAccessor();
    RelationshipGroupDegreesStore groupDegreesStore = storageEngine.relationshipGroupDegreesStore();
    PageCache pageCache = dependencyResolver.resolveDependency(PageCache.class);
    IndexAccessors.IndexAccessorLookup indexAccessorLookup = new LookupAccessorsFromRunningDb(indexingService);
    FullCheck checker = new FullCheck(ProgressMonitorFactory.NONE, defaultConsistencyCheckThreadsNumber(), ConsistencyFlags.DEFAULT, config, DebugContext.NO_DEBUG, NodeBasedMemoryLimiter.DEFAULT);
    return checker.execute(pageCache, directStoreAccess, () -> (CountsStore) countsStore, () -> groupDegreesStore, indexAccessorLookup, PageCacheTracer.NULL, INSTANCE, logProvider.getLog("test"));
}
Also used : IndexAccessors(org.neo4j.consistency.checking.index.IndexAccessors) DirectStoreAccess(org.neo4j.consistency.store.DirectStoreAccess) RelationshipGroupDegreesStore(org.neo4j.internal.counts.RelationshipGroupDegreesStore) IdGeneratorFactory(org.neo4j.internal.id.IdGeneratorFactory) CountsAccessor(org.neo4j.counts.CountsAccessor) IndexProviderMap(org.neo4j.kernel.impl.api.index.IndexProviderMap) DependencyResolver(org.neo4j.common.DependencyResolver) LookupAccessorsFromRunningDb(org.neo4j.consistency.LookupAccessorsFromRunningDb) RecordStorageEngine(org.neo4j.internal.recordstorage.RecordStorageEngine) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) NeoStores(org.neo4j.kernel.impl.store.NeoStores) IndexStatisticsStore(org.neo4j.kernel.impl.api.index.stats.IndexStatisticsStore) TokenHolders(org.neo4j.token.TokenHolders) PageCache(org.neo4j.io.pagecache.PageCache)

Example 5 with RelationshipGroupDegreesStore

use of org.neo4j.internal.counts.RelationshipGroupDegreesStore in project neo4j by neo4j.

the class IndexCheckingSelectorTest method checkIndex.

private ConsistencySummaryStatistics checkIndex() throws ConsistencyCheckIncompleteException {
    NeoStores neoStores = recordStorageEngine.testAccessNeoStores();
    DirectStoreAccess directStoreAccess = new DirectStoreAccess(neoStores, indexProviderMap, tokenHolders, indexStatisticsStore, idGeneratorFactory);
    CountsAccessor countsStore = recordStorageEngine.countsAccessor();
    RelationshipGroupDegreesStore groupDegreesStore = recordStorageEngine.relationshipGroupDegreesStore();
    IndexAccessors.IndexAccessorLookup indexAccessorLookup = new LookupAccessorsFromRunningDb(indexingService);
    FullCheck checker = new FullCheck(ProgressMonitorFactory.NONE, defaultConsistencyCheckThreadsNumber(), ConsistencyFlags.DEFAULT, Config.defaults(), debugContext, NodeBasedMemoryLimiter.DEFAULT);
    return checker.execute(pageCache, directStoreAccess, () -> (CountsStore) countsStore, () -> groupDegreesStore, indexAccessorLookup, NULL, INSTANCE, NullLog.getInstance());
}
Also used : LookupAccessorsFromRunningDb(org.neo4j.consistency.LookupAccessorsFromRunningDb) IndexAccessors(org.neo4j.consistency.checking.index.IndexAccessors) FullCheck(org.neo4j.consistency.checking.full.FullCheck) NeoStores(org.neo4j.kernel.impl.store.NeoStores) DirectStoreAccess(org.neo4j.consistency.store.DirectStoreAccess) RelationshipGroupDegreesStore(org.neo4j.internal.counts.RelationshipGroupDegreesStore) CountsAccessor(org.neo4j.counts.CountsAccessor)

Aggregations

RelationshipGroupDegreesStore (org.neo4j.internal.counts.RelationshipGroupDegreesStore)6 Test (org.junit.jupiter.api.Test)3 DirectStoreAccess (org.neo4j.consistency.store.DirectStoreAccess)3 CountsAccessor (org.neo4j.counts.CountsAccessor)3 CountsStore (org.neo4j.counts.CountsStore)3 NeoStores (org.neo4j.kernel.impl.store.NeoStores)3 DependencyResolver (org.neo4j.common.DependencyResolver)2 LookupAccessorsFromRunningDb (org.neo4j.consistency.LookupAccessorsFromRunningDb)2 IndexAccessors (org.neo4j.consistency.checking.index.IndexAccessors)2 ConsistencySummaryStatistics (org.neo4j.consistency.report.ConsistencySummaryStatistics)2 IdGeneratorFactory (org.neo4j.internal.id.IdGeneratorFactory)2 RecordStorageEngine (org.neo4j.internal.recordstorage.RecordStorageEngine)2 PageCache (org.neo4j.io.pagecache.PageCache)2 IndexProviderMap (org.neo4j.kernel.impl.api.index.IndexProviderMap)2 IndexStatisticsStore (org.neo4j.kernel.impl.api.index.stats.IndexStatisticsStore)2 RelationshipStore (org.neo4j.kernel.impl.store.RelationshipStore)2 TokenHolders (org.neo4j.token.TokenHolders)2 FullCheck (org.neo4j.consistency.checking.full.FullCheck)1 InconsistencyMessageLogger (org.neo4j.consistency.report.InconsistencyMessageLogger)1 InconsistencyReport (org.neo4j.consistency.report.InconsistencyReport)1