Search in sources :

Example 1 with CountsAccessor

use of org.neo4j.counts.CountsAccessor 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 2 with CountsAccessor

use of org.neo4j.counts.CountsAccessor 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)

Example 3 with CountsAccessor

use of org.neo4j.counts.CountsAccessor in project neo4j by neo4j.

the class CsvInputBatchImportIT method verifyImportedData.

// ======================================================
// Below is code for verifying the imported data
// ======================================================
private void verifyImportedData(List<InputEntity> nodeData, List<InputEntity> relationshipData) {
    // Build up expected data for the verification below
    Map<String, InputEntity> /*id*/
    expectedNodes = new HashMap<>();
    Map<String, String[]> expectedNodeNames = new HashMap<>();
    Map<String, Map<String, Consumer<Object>>> expectedNodePropertyVerifiers = new HashMap<>();
    Map<String, Map<String, Map<String, AtomicInteger>>> /*end node name*/
    expectedRelationships = new AutoCreatingHashMap<>(nested(nested(values(AtomicInteger.class))));
    Map<String, AtomicLong> expectedNodeCounts = new AutoCreatingHashMap<>(values(AtomicLong.class));
    Map<String, Map<String, Map<String, AtomicLong>>> expectedRelationshipCounts = new AutoCreatingHashMap<>(nested(nested(values(AtomicLong.class))));
    buildUpExpectedData(nodeData, relationshipData, expectedNodes, expectedNodeNames, expectedNodePropertyVerifiers, expectedRelationships, expectedNodeCounts, expectedRelationshipCounts);
    // Do the verification
    DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(testDirectory.homePath()).build();
    GraphDatabaseService db = managementService.database(DEFAULT_DATABASE_NAME);
    try (Transaction tx = db.beginTx()) {
        // Verify nodes
        for (Node node : tx.getAllNodes()) {
            String name = (String) node.getProperty("name");
            String[] labels = expectedNodeNames.remove(name);
            assertEquals(asSet(labels), names(node.getLabels()));
            // Verify node properties
            Map<String, Consumer<Object>> expectedPropertyVerifiers = expectedNodePropertyVerifiers.remove(name);
            Map<String, Object> actualProperties = node.getAllProperties();
            // The id does not exist in expected properties
            actualProperties.remove("id");
            for (Map.Entry actualProperty : actualProperties.entrySet()) {
                Consumer v = expectedPropertyVerifiers.get(actualProperty.getKey());
                if (v != null) {
                    v.accept(actualProperty.getValue());
                }
            }
        }
        assertEquals(0, expectedNodeNames.size());
        // Verify relationships
        for (Relationship relationship : tx.getAllRelationships()) {
            String startNodeName = (String) relationship.getStartNode().getProperty("name");
            Map<String, Map<String, AtomicInteger>> inner = expectedRelationships.get(startNodeName);
            String endNodeName = (String) relationship.getEndNode().getProperty("name");
            Map<String, AtomicInteger> innerInner = inner.get(endNodeName);
            String type = relationship.getType().name();
            int countAfterwards = innerInner.get(type).decrementAndGet();
            assertThat(countAfterwards).isGreaterThanOrEqualTo(0);
            if (countAfterwards == 0) {
                innerInner.remove(type);
                if (innerInner.isEmpty()) {
                    inner.remove(endNodeName);
                    if (inner.isEmpty()) {
                        expectedRelationships.remove(startNodeName);
                    }
                }
            }
        }
        assertEquals(0, expectedRelationships.size());
        RecordStorageEngine storageEngine = ((GraphDatabaseAPI) db).getDependencyResolver().resolveDependency(RecordStorageEngine.class);
        NeoStores neoStores = storageEngine.testAccessNeoStores();
        CountsAccessor counts = storageEngine.countsAccessor();
        Function<String, Integer> labelTranslationTable = translationTable(neoStores.getLabelTokenStore(), ANY_LABEL);
        for (Pair<Integer, Long> count : allNodeCounts(labelTranslationTable, expectedNodeCounts)) {
            assertEquals(count.other().longValue(), counts.nodeCount(count.first(), NULL), "Label count mismatch for label " + count.first());
        }
        Function<String, Integer> relationshipTypeTranslationTable = translationTable(neoStores.getRelationshipTypeTokenStore(), ANY_RELATIONSHIP_TYPE);
        for (Pair<RelationshipCountKey, Long> count : allRelationshipCounts(labelTranslationTable, relationshipTypeTranslationTable, expectedRelationshipCounts)) {
            RelationshipCountKey key = count.first();
            assertEquals(count.other().longValue(), counts.relationshipCount(key.startLabel, key.type, key.endLabel, NULL), "Label count mismatch for label " + key);
        }
        tx.commit();
    } finally {
        managementService.shutdown();
    }
}
Also used : AutoCreatingHashMap(org.neo4j.kernel.impl.util.AutoCreatingHashMap) HashMap(java.util.HashMap) AutoCreatingHashMap(org.neo4j.kernel.impl.util.AutoCreatingHashMap) Node(org.neo4j.graphdb.Node) CountsAccessor(org.neo4j.counts.CountsAccessor) Consumer(java.util.function.Consumer) InputEntity(org.neo4j.internal.batchimport.input.InputEntity) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicLong(java.util.concurrent.atomic.AtomicLong) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) Transaction(org.neo4j.graphdb.Transaction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RecordStorageEngine(org.neo4j.internal.recordstorage.RecordStorageEngine) Relationship(org.neo4j.graphdb.Relationship) NeoStores(org.neo4j.kernel.impl.store.NeoStores) AtomicLong(java.util.concurrent.atomic.AtomicLong) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) AutoCreatingHashMap(org.neo4j.kernel.impl.util.AutoCreatingHashMap)

Aggregations

CountsAccessor (org.neo4j.counts.CountsAccessor)3 NeoStores (org.neo4j.kernel.impl.store.NeoStores)3 LookupAccessorsFromRunningDb (org.neo4j.consistency.LookupAccessorsFromRunningDb)2 IndexAccessors (org.neo4j.consistency.checking.index.IndexAccessors)2 DirectStoreAccess (org.neo4j.consistency.store.DirectStoreAccess)2 RelationshipGroupDegreesStore (org.neo4j.internal.counts.RelationshipGroupDegreesStore)2 RecordStorageEngine (org.neo4j.internal.recordstorage.RecordStorageEngine)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Consumer (java.util.function.Consumer)1 DependencyResolver (org.neo4j.common.DependencyResolver)1 FullCheck (org.neo4j.consistency.checking.full.FullCheck)1 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)1 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)1 Node (org.neo4j.graphdb.Node)1 Relationship (org.neo4j.graphdb.Relationship)1 Transaction (org.neo4j.graphdb.Transaction)1