Search in sources :

Example 1 with DirectStoreAccess

use of org.neo4j.consistency.store.DirectStoreAccess in project neo4j by neo4j.

the class GraphStoreFixture method startDatabaseAndExtractComponents.

private void startDatabaseAndExtractComponents() {
    managementService = new TestDatabaseManagementServiceBuilder(testDirectory.homePath()).setFileSystem(testDirectory.getFileSystem()).setConfig(GraphDatabaseSettings.record_format, formatName).setConfig(GraphDatabaseInternalSettings.label_block_size, 60).setConfig(GraphDatabaseInternalSettings.consistency_check_on_apply, false).setConfig(getConfig()).build();
    database = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    DependencyResolver dependencyResolver = database.getDependencyResolver();
    commitProcess = new InternalTransactionCommitProcess(dependencyResolver.resolveDependency(TransactionAppender.class), dependencyResolver.resolveDependency(StorageEngine.class));
    transactionIdStore = database.getDependencyResolver().resolveDependency(TransactionIdStore.class);
    storageEngine = dependencyResolver.resolveDependency(RecordStorageEngine.class);
    neoStores = storageEngine.testAccessNeoStores();
    indexingService = dependencyResolver.resolveDependency(IndexingService.class);
    directStoreAccess = new DirectStoreAccess(neoStores, dependencyResolver.resolveDependency(IndexProviderMap.class), dependencyResolver.resolveDependency(TokenHolders.class), dependencyResolver.resolveDependency(IndexStatisticsStore.class), dependencyResolver.resolveDependency(IdGeneratorFactory.class));
    countsStore = storageEngine.countsAccessor();
    groupDegreesStore = storageEngine.relationshipGroupDegreesStore();
    pageCache = dependencyResolver.resolveDependency(PageCache.class);
}
Also used : TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) TransactionIdStore(org.neo4j.storageengine.api.TransactionIdStore) RecordStorageEngine(org.neo4j.internal.recordstorage.RecordStorageEngine) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) DirectStoreAccess(org.neo4j.consistency.store.DirectStoreAccess) InternalTransactionCommitProcess(org.neo4j.kernel.impl.api.InternalTransactionCommitProcess) PageCache(org.neo4j.io.pagecache.PageCache) DependencyResolver(org.neo4j.common.DependencyResolver)

Example 2 with DirectStoreAccess

use of org.neo4j.consistency.store.DirectStoreAccess 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 3 with DirectStoreAccess

use of org.neo4j.consistency.store.DirectStoreAccess in project neo4j by neo4j.

the class FullCheckIntegrationTest method shouldNotReportIndexInconsistenciesIfIndexIsFailed.

@Test
void shouldNotReportIndexInconsistenciesIfIndexIsFailed() throws Exception {
    // this test fails all indexes, and then destroys a record and makes sure we only get a failure for
    // the label scan store but not for any index
    // given
    DirectStoreAccess storeAccess = fixture.directStoreAccess();
    // fail all indexes
    Iterator<IndexDescriptor> rules = getValueIndexDescriptors();
    while (rules.hasNext()) {
        IndexDescriptor rule = rules.next();
        IndexSamplingConfig samplingConfig = new IndexSamplingConfig(Config.defaults());
        IndexPopulator populator = storeAccess.indexes().lookup(rule.getIndexProvider()).getPopulator(rule, samplingConfig, heapBufferFactory(1024), INSTANCE, tokenNameLookup);
        populator.markAsFailed("Oh noes! I was a shiny index and then I was failed");
        populator.close(false, NULL);
    }
    for (Long indexedNodeId : indexedNodes) {
        storeAccess.nativeStores().getNodeStore().updateRecord(notInUse(new NodeRecord(indexedNodeId).initialize(false, -1, false, -1, 0)), NULL);
    }
    // when
    ConsistencySummaryStatistics stats = check();
    // then
    // the label scan is pointing to 2 nodes not in use
    on(stats).verify(RecordType.LABEL_SCAN_DOCUMENT, 2).verify(RecordType.COUNTS, 2).andThatsAllFolks();
}
Also used : IndexSamplingConfig(org.neo4j.kernel.impl.api.index.IndexSamplingConfig) IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) DirectStoreAccess(org.neo4j.consistency.store.DirectStoreAccess) AtomicLong(java.util.concurrent.atomic.AtomicLong) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) ConsistencySummaryStatistics(org.neo4j.consistency.report.ConsistencySummaryStatistics) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 4 with DirectStoreAccess

use of org.neo4j.consistency.store.DirectStoreAccess 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 DirectStoreAccess

use of org.neo4j.consistency.store.DirectStoreAccess in project neo4j by neo4j.

the class GraphStoreFixture method writableTokenHolders.

public TokenHolders writableTokenHolders() {
    TokenHolder propertyKeyTokens = new DelegatingTokenHolder(buildTokenCreator((name, internal, tx, next) -> {
        int id = next.propertyKey();
        tx.propertyKey(id, name, internal);
        return id;
    }), TokenHolder.TYPE_PROPERTY_KEY);
    TokenHolder labelTokens = new DelegatingTokenHolder(buildTokenCreator((name, internal, tx, next) -> {
        int id = next.label();
        tx.nodeLabel(id, name, internal);
        return id;
    }), TokenHolder.TYPE_LABEL);
    TokenHolder relationshipTypeTokens = new DelegatingTokenHolder(buildTokenCreator((name, internal, tx, next) -> {
        int id = next.relationshipType();
        tx.relationshipType(id, name, internal);
        return id;
    }), TokenHolder.TYPE_RELATIONSHIP_TYPE);
    TokenHolders tokenHolders = new TokenHolders(propertyKeyTokens, labelTokens, relationshipTypeTokens);
    tokenHolders.setInitialTokens(allReadableTokens(directStoreAccess().nativeStores()), NULL);
    return tokenHolders;
}
Also used : MutableInt(org.apache.commons.lang3.mutable.MutableInt) SchemaRule(org.neo4j.internal.schema.SchemaRule) TokenCreator(org.neo4j.token.TokenCreator) StoreTokens.allReadableTokens(org.neo4j.internal.recordstorage.StoreTokens.allReadableTokens) Preconditions(org.neo4j.util.Preconditions) ThrowingSupplier(org.neo4j.function.ThrowingSupplier) TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) IndexStatisticsStore(org.neo4j.kernel.impl.api.index.stats.IndexStatisticsStore) NodeLabelsField(org.neo4j.kernel.impl.store.NodeLabelsField) StorageNodeCursor(org.neo4j.storageengine.api.StorageNodeCursor) DEFAULT_DATABASE_NAME(org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME) LookupAccessorsFromRunningDb(org.neo4j.consistency.LookupAccessorsFromRunningDb) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) Map(java.util.Map) AbstractBaseRecord(org.neo4j.kernel.impl.store.record.AbstractBaseRecord) NULL(org.neo4j.io.pagecache.context.CursorContext.NULL) PageCache(org.neo4j.io.pagecache.PageCache) RelationshipGroupDegreesStore(org.neo4j.internal.counts.RelationshipGroupDegreesStore) StorageEngine(org.neo4j.storageengine.api.StorageEngine) IndexProviderMap(org.neo4j.kernel.impl.api.index.IndexProviderMap) SchemaRecord(org.neo4j.kernel.impl.store.record.SchemaRecord) TestDirectory(org.neo4j.test.rule.TestDirectory) RecordStorageEngine(org.neo4j.internal.recordstorage.RecordStorageEngine) StandardCharsets(java.nio.charset.StandardCharsets) InternalTransactionCommitProcess(org.neo4j.kernel.impl.api.InternalTransactionCommitProcess) StoragePropertyCursor(org.neo4j.storageengine.api.StoragePropertyCursor) DirectStoreAccess(org.neo4j.consistency.store.DirectStoreAccess) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) RecordStore(org.neo4j.kernel.impl.store.RecordStore) INSTANCE(org.neo4j.memory.EmptyMemoryTracker.INSTANCE) StoreType(org.neo4j.kernel.impl.store.StoreType) ANY_LABEL(org.neo4j.internal.kernel.api.TokenRead.ANY_LABEL) NodeStore(org.neo4j.kernel.impl.store.NodeStore) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) CountsStore(org.neo4j.counts.CountsStore) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) TransactionAppender(org.neo4j.kernel.impl.transaction.log.TransactionAppender) IdGeneratorFactory(org.neo4j.internal.id.IdGeneratorFactory) System.currentTimeMillis(java.lang.System.currentTimeMillis) GraphDatabaseSettings(org.neo4j.configuration.GraphDatabaseSettings) TokenHolder(org.neo4j.token.api.TokenHolder) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) NeoStores(org.neo4j.kernel.impl.store.NeoStores) EntityUpdates(org.neo4j.storageengine.api.EntityUpdates) DelegatingTokenHolder(org.neo4j.token.DelegatingTokenHolder) StorageReader(org.neo4j.storageengine.api.StorageReader) TransactionApplicationMode(org.neo4j.storageengine.api.TransactionApplicationMode) GraphDatabaseInternalSettings(org.neo4j.configuration.GraphDatabaseInternalSettings) DependencyResolver(org.neo4j.common.DependencyResolver) Iterator(java.util.Iterator) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) Setting(org.neo4j.graphdb.config.Setting) IOException(java.io.IOException) IndexAccessors(org.neo4j.consistency.checking.index.IndexAccessors) PrefetchingIterator(org.neo4j.internal.helpers.collection.PrefetchingIterator) TokenStore(org.neo4j.kernel.impl.store.TokenStore) Neo4jLayout(org.neo4j.io.layout.Neo4jLayout) Consumer(java.util.function.Consumer) CountsAccessor(org.neo4j.counts.CountsAccessor) LongIterator(org.eclipse.collections.api.iterator.LongIterator) RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) KernelException(org.neo4j.exceptions.KernelException) TokenHolders(org.neo4j.token.TokenHolders) NamedToken(org.neo4j.token.api.NamedToken) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) CommitEvent(org.neo4j.kernel.impl.transaction.tracing.CommitEvent) RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) TransactionIdStore(org.neo4j.storageengine.api.TransactionIdStore) TokenHolder(org.neo4j.token.api.TokenHolder) DelegatingTokenHolder(org.neo4j.token.DelegatingTokenHolder) TokenHolders(org.neo4j.token.TokenHolders) DelegatingTokenHolder(org.neo4j.token.DelegatingTokenHolder)

Aggregations

DirectStoreAccess (org.neo4j.consistency.store.DirectStoreAccess)7 NeoStores (org.neo4j.kernel.impl.store.NeoStores)5 DependencyResolver (org.neo4j.common.DependencyResolver)4 RelationshipGroupDegreesStore (org.neo4j.internal.counts.RelationshipGroupDegreesStore)4 RecordStorageEngine (org.neo4j.internal.recordstorage.RecordStorageEngine)4 PageCache (org.neo4j.io.pagecache.PageCache)4 IndexStatisticsStore (org.neo4j.kernel.impl.api.index.stats.IndexStatisticsStore)4 TokenHolders (org.neo4j.token.TokenHolders)4 LookupAccessorsFromRunningDb (org.neo4j.consistency.LookupAccessorsFromRunningDb)3 IndexAccessors (org.neo4j.consistency.checking.index.IndexAccessors)3 ConsistencySummaryStatistics (org.neo4j.consistency.report.ConsistencySummaryStatistics)3 CountsAccessor (org.neo4j.counts.CountsAccessor)3 IdGeneratorFactory (org.neo4j.internal.id.IdGeneratorFactory)3 IndexProviderMap (org.neo4j.kernel.impl.api.index.IndexProviderMap)3 IndexingService (org.neo4j.kernel.impl.api.index.IndexingService)3 Test (org.junit.jupiter.api.Test)2 FullCheck (org.neo4j.consistency.checking.full.FullCheck)2 CountsStore (org.neo4j.counts.CountsStore)2 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)2 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)2