Search in sources :

Example 6 with CountsTracker

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

Example 7 with CountsTracker

use of org.neo4j.kernel.impl.store.counts.CountsTracker in project neo4j by neo4j.

the class CountsStoreTransactionApplierTest method shouldNotifyCacheAccessOnHowManyUpdatesOnCountsWeHadSoFar.

@Test
public void shouldNotifyCacheAccessOnHowManyUpdatesOnCountsWeHadSoFar() throws Exception {
    // GIVEN
    final CountsTracker tracker = mock(CountsTracker.class);
    final CountsAccessor.Updater updater = mock(CountsAccessor.Updater.class);
    when(tracker.apply(anyLong())).thenReturn(Optional.of(updater));
    final CountsStoreBatchTransactionApplier applier = new CountsStoreBatchTransactionApplier(tracker, TransactionApplicationMode.INTERNAL);
    // WHEN
    try (TransactionApplier txApplier = applier.startTx(new TransactionToApply(null, 2L))) {
        txApplier.visitNodeCountsCommand(new Command.NodeCountsCommand(ReadOperations.ANY_LABEL, 1));
    }
    // THEN
    verify(updater, times(1)).incrementNodeCount(ReadOperations.ANY_LABEL, 1);
}
Also used : Command(org.neo4j.kernel.impl.transaction.command.Command) CountsTracker(org.neo4j.kernel.impl.store.counts.CountsTracker) Test(org.junit.Test)

Example 8 with CountsTracker

use of org.neo4j.kernel.impl.store.counts.CountsTracker in project neo4j by neo4j.

the class HACountsPropagationTest method shouldPropagateRelationshipCountsInHA.

@Test
public void shouldPropagateRelationshipCountsInHA() throws Throwable {
    ManagedCluster cluster = clusterRule.startCluster();
    HighlyAvailableGraphDatabase master = cluster.getMaster();
    try (Transaction tx = master.beginTx()) {
        Node left = master.createNode();
        Node right = master.createNode(Label.label("A"));
        left.createRelationshipTo(right, RelationshipType.withName("Type"));
        tx.success();
    }
    cluster.sync();
    for (HighlyAvailableGraphDatabase db : cluster.getAllMembers()) {
        CountsTracker counts = counts(db);
        assertEquals(1, counts.relationshipCount(-1, -1, -1, newDoubleLongRegister()).readSecond());
        assertEquals(1, counts.relationshipCount(-1, -1, 0, newDoubleLongRegister()).readSecond());
        assertEquals(1, counts.relationshipCount(-1, 0, -1, newDoubleLongRegister()).readSecond());
        assertEquals(1, counts.relationshipCount(-1, 0, 0, newDoubleLongRegister()).readSecond());
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) ManagedCluster(org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster) Node(org.neo4j.graphdb.Node) CountsTracker(org.neo4j.kernel.impl.store.counts.CountsTracker) Test(org.junit.Test)

Example 9 with CountsTracker

use of org.neo4j.kernel.impl.store.counts.CountsTracker in project neo4j by neo4j.

the class HACountsPropagationTest method shouldPropagateNodeCountsInHA.

@Test
public void shouldPropagateNodeCountsInHA() throws Throwable {
    ManagedCluster cluster = clusterRule.startCluster();
    HighlyAvailableGraphDatabase master = cluster.getMaster();
    try (Transaction tx = master.beginTx()) {
        master.createNode();
        master.createNode(Label.label("A"));
        tx.success();
    }
    cluster.sync();
    for (HighlyAvailableGraphDatabase db : cluster.getAllMembers()) {
        CountsTracker counts = counts(db);
        assertEquals(2, counts.nodeCount(-1, newDoubleLongRegister()).readSecond());
        assertEquals(1, counts.nodeCount(0, /* A */
        newDoubleLongRegister()).readSecond());
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) ManagedCluster(org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster) CountsTracker(org.neo4j.kernel.impl.store.counts.CountsTracker) Test(org.junit.Test)

Example 10 with CountsTracker

use of org.neo4j.kernel.impl.store.counts.CountsTracker in project neo4j by neo4j.

the class IndexSamplingIntegrationTest method fetchIndexSamplingValues.

private DoubleLongRegister fetchIndexSamplingValues(GraphDatabaseService db) throws IndexNotFoundKernelException {
    try {
        // Then
        db = new TestGraphDatabaseFactory().newEmbeddedDatabase(testDirectory.graphDbDir());
        @SuppressWarnings("deprecation") GraphDatabaseAPI api = (GraphDatabaseAPI) db;
        CountsTracker countsTracker = api.getDependencyResolver().resolveDependency(RecordStorageEngine.class).testAccessNeoStores().getCounts();
        IndexSampleKey key = CountsKeyFactory.indexSampleKey(indexId(api));
        return countsTracker.get(key, Registers.newDoubleLongRegister());
    } finally {
        if (db != null) {
            db.shutdown();
        }
    }
}
Also used : IndexSampleKey(org.neo4j.kernel.impl.store.counts.keys.IndexSampleKey) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) CountsTracker(org.neo4j.kernel.impl.store.counts.CountsTracker)

Aggregations

CountsTracker (org.neo4j.kernel.impl.store.counts.CountsTracker)19 Test (org.junit.Test)10 IOException (java.io.IOException)4 CountsAccessor (org.neo4j.kernel.impl.api.CountsAccessor)4 Transaction (org.neo4j.graphdb.Transaction)3 UncloseableDelegatingFileSystemAbstraction (org.neo4j.graphdb.mockfs.UncloseableDelegatingFileSystemAbstraction)3 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)3 File (java.io.File)2 Node (org.neo4j.graphdb.Node)2 PagedFile (org.neo4j.io.pagecache.PagedFile)2 HighlyAvailableGraphDatabase (org.neo4j.kernel.ha.HighlyAvailableGraphDatabase)2 ManagedCluster (org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster)2 NeoStores (org.neo4j.kernel.impl.store.NeoStores)2 NodeStore (org.neo4j.kernel.impl.store.NodeStore)2 UnderlyingStorageException (org.neo4j.kernel.impl.store.UnderlyingStorageException)2 ReadOnlyCountsTracker (org.neo4j.kernel.impl.store.counts.ReadOnlyCountsTracker)2 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)2 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)2 InterruptedIOException (java.io.InterruptedIOException)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1