Search in sources :

Example 1 with RecordStorageReader

use of org.neo4j.internal.recordstorage.RecordStorageReader in project neo4j by neo4j.

the class RelationshipGroupChecker method checkToRelationship.

/**
 * Check relationship groups to first in chain relationship. Run only on first node-range
 */
private void checkToRelationship(long fromGroupId, long toGroupId, PageCacheTracer pageCacheTracer) {
    try (var cursorContext = new CursorContext(pageCacheTracer.createPageCursorTracer(RELATIONSHIP_GROUPS_CHECKER_TAG));
        RecordReader<RelationshipGroupRecord> groupReader = new RecordReader<>(neoStores.getRelationshipGroupStore(), true, cursorContext);
        RecordReader<RelationshipGroupRecord> comparativeReader = new RecordReader<>(neoStores.getRelationshipGroupStore(), false, cursorContext);
        RecordStorageReader reader = new RecordStorageReader(neoStores);
        RecordRelationshipScanCursor relationshipCursor = reader.allocateRelationshipScanCursor(cursorContext)) {
        for (long id = fromGroupId; id < toGroupId && !context.isCancelled(); id++) {
            RelationshipGroupRecord record = groupReader.read(id);
            if (!record.inUse()) {
                continue;
            }
            long owningNode = record.getOwningNode();
            if (owningNode < 0) {
                reporter.forRelationshipGroup(record).illegalOwner();
            }
            checkValidToken(record, record.getType(), context.tokenHolders.relationshipTypeTokens(), neoStores.getRelationshipTypeTokenStore(), (group, token) -> reporter.forRelationshipGroup(group).illegalRelationshipType(), (group, token) -> reporter.forRelationshipGroup(group).relationshipTypeNotInUse(token), cursorContext);
            if (!NULL_REFERENCE.is(record.getNext())) {
                RelationshipGroupRecord comparativeRecord = comparativeReader.read(record.getNext());
                if (!comparativeRecord.inUse()) {
                    reporter.forRelationshipGroup(record).nextGroupNotInUse();
                } else {
                    if (record.getType() >= comparativeRecord.getType()) {
                        reporter.forRelationshipGroup(record).invalidTypeSortOrder();
                    }
                    if (owningNode != comparativeRecord.getOwningNode()) {
                        reporter.forRelationshipGroup(record).nextHasOtherOwner(comparativeRecord);
                    }
                }
            }
            checkRelationshipGroupRelationshipLink(relationshipCursor, record, record.getFirstOut(), RelationshipGroupLink.OUT, group -> reporter.forRelationshipGroup(group).firstOutgoingRelationshipNotInUse(), group -> reporter.forRelationshipGroup(group).firstOutgoingRelationshipNotFirstInChain(), group -> reporter.forRelationshipGroup(group).firstOutgoingRelationshipOfOtherType(), (group, rel) -> reporter.forRelationshipGroup(group).firstOutgoingRelationshipDoesNotShareNodeWithGroup(rel), cursorContext);
            checkRelationshipGroupRelationshipLink(relationshipCursor, record, record.getFirstIn(), RelationshipGroupLink.IN, group -> reporter.forRelationshipGroup(group).firstIncomingRelationshipNotInUse(), group -> reporter.forRelationshipGroup(group).firstIncomingRelationshipNotFirstInChain(), group -> reporter.forRelationshipGroup(group).firstIncomingRelationshipOfOtherType(), (group, rel) -> reporter.forRelationshipGroup(group).firstIncomingRelationshipDoesNotShareNodeWithGroup(rel), cursorContext);
            checkRelationshipGroupRelationshipLink(relationshipCursor, record, record.getFirstLoop(), RelationshipGroupLink.LOOP, group -> reporter.forRelationshipGroup(group).firstLoopRelationshipNotInUse(), group -> reporter.forRelationshipGroup(group).firstLoopRelationshipNotFirstInChain(), group -> reporter.forRelationshipGroup(group).firstLoopRelationshipOfOtherType(), (group, rel) -> reporter.forRelationshipGroup(group).firstLoopRelationshipDoesNotShareNodeWithGroup(rel), cursorContext);
        }
    }
}
Also used : RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) RecordStorageReader(org.neo4j.internal.recordstorage.RecordStorageReader) CursorContext(org.neo4j.io.pagecache.context.CursorContext) RecordRelationshipScanCursor(org.neo4j.internal.recordstorage.RecordRelationshipScanCursor)

Example 2 with RecordStorageReader

use of org.neo4j.internal.recordstorage.RecordStorageReader in project neo4j by neo4j.

the class BatchingNeoStoresTest method apply.

private static void apply(TxState txState, CommandCreationContext commandCreationContext, RecordStorageEngine storageEngine) throws Exception {
    List<StorageCommand> commands = new ArrayList<>();
    try (RecordStorageReader storageReader = storageEngine.newReader()) {
        storageEngine.createCommands(commands, txState, storageReader, commandCreationContext, ResourceLocker.IGNORE, LockTracer.NONE, BASE_TX_ID, v -> v, NULL, INSTANCE);
        CommandsToApply apply = new TransactionToApply(new PhysicalTransactionRepresentation(commands, new byte[0], 0, 0, 0, 0, ANONYMOUS), NULL);
        storageEngine.apply(apply, TransactionApplicationMode.INTERNAL);
    }
}
Also used : CommandsToApply(org.neo4j.storageengine.api.CommandsToApply) TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) RecordStorageReader(org.neo4j.internal.recordstorage.RecordStorageReader) StorageCommand(org.neo4j.storageengine.api.StorageCommand) ArrayList(java.util.ArrayList) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)

Example 3 with RecordStorageReader

use of org.neo4j.internal.recordstorage.RecordStorageReader in project neo4j by neo4j.

the class StoreScanChunkIT method differentChunksHaveDifferentCursors.

@Test
void differentChunksHaveDifferentCursors() {
    DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(testDirectory.homePath()).build();
    GraphDatabaseAPI database = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    try {
        RecordStorageEngine recordStorageEngine = database.getDependencyResolver().resolveDependency(RecordStorageEngine.class);
        NeoStores neoStores = recordStorageEngine.testAccessNeoStores();
        RecordStorageReader storageReader = new RecordStorageReader(neoStores);
        TestStoreScanChunk scanChunk1 = new TestStoreScanChunk(storageReader, false);
        TestStoreScanChunk scanChunk2 = new TestStoreScanChunk(storageReader, false);
        assertNotSame(scanChunk1.getCursor(), scanChunk2.getCursor());
        assertNotSame(scanChunk1.getStorePropertyCursor(), scanChunk2.getStorePropertyCursor());
    } finally {
        managementService.shutdown();
    }
}
Also used : TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) RecordStorageReader(org.neo4j.internal.recordstorage.RecordStorageReader) RecordStorageEngine(org.neo4j.internal.recordstorage.RecordStorageEngine) NeoStores(org.neo4j.kernel.impl.store.NeoStores) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Example 4 with RecordStorageReader

use of org.neo4j.internal.recordstorage.RecordStorageReader in project neo4j by neo4j.

the class DegreesRebuildFromStore method rebuild.

@Override
public void rebuild(RelationshipGroupDegreesStore.Updater updater, CursorContext cursorContext, MemoryTracker memoryTracker) {
    // === sketch of a more performant version
    // - Read all groups and for every group make a mark in a memory-structure like so:
    // (node) -> (type,active directions,out,in,loop)
    // - Read all relationships and for every matching node go into the memory-structure
    // if it's there then look up the type
    // if it's there then see if the direction matches any active direction
    // if it does then increment the counter in the correct slot
    // - Go though the memory-structure and write to the updater
    // 
    // If not all data can fit in memory then do multiple passes (node id range)
    RelationshipGroupStore groupStore = neoStores.getRelationshipGroupStore();
    try (RecordStorageReader storageReader = new RecordStorageReader(neoStores);
        StorageRelationshipTraversalCursor traversalCursor = storageReader.allocateRelationshipTraversalCursor(cursorContext);
        PageCursor groupCursor = groupStore.openPageCursorForReadingWithPrefetching(0, cursorContext)) {
        RelationshipGroupRecord groupRecord = groupStore.newRecord();
        long highGroupId = groupStore.getHighId();
        for (long id = groupStore.getNumberOfReservedLowIds(); id < highGroupId; id++) {
            groupStore.getRecordByCursor(id, groupRecord, RecordLoad.LENIENT_CHECK, groupCursor);
            if (groupRecord.inUse() && (groupRecord.hasExternalDegreesOut() || groupRecord.hasExternalDegreesIn() || groupRecord.hasExternalDegreesLoop())) {
                updateDegree(groupRecord.hasExternalDegreesOut(), groupRecord.getFirstOut(), groupRecord, OUTGOING, traversalCursor, updater);
                updateDegree(groupRecord.hasExternalDegreesIn(), groupRecord.getFirstIn(), groupRecord, INCOMING, traversalCursor, updater);
                updateDegree(groupRecord.hasExternalDegreesLoop(), groupRecord.getFirstLoop(), groupRecord, LOOP, traversalCursor, updater);
            }
        }
    }
}
Also used : RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) RecordStorageReader(org.neo4j.internal.recordstorage.RecordStorageReader) RelationshipGroupStore(org.neo4j.kernel.impl.store.RelationshipGroupStore) StorageRelationshipTraversalCursor(org.neo4j.storageengine.api.StorageRelationshipTraversalCursor) PageCursor(org.neo4j.io.pagecache.PageCursor)

Aggregations

RecordStorageReader (org.neo4j.internal.recordstorage.RecordStorageReader)4 RelationshipGroupRecord (org.neo4j.kernel.impl.store.record.RelationshipGroupRecord)2 ArrayList (java.util.ArrayList)1 Test (org.junit.jupiter.api.Test)1 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)1 RecordRelationshipScanCursor (org.neo4j.internal.recordstorage.RecordRelationshipScanCursor)1 RecordStorageEngine (org.neo4j.internal.recordstorage.RecordStorageEngine)1 PageCursor (org.neo4j.io.pagecache.PageCursor)1 CursorContext (org.neo4j.io.pagecache.context.CursorContext)1 TransactionToApply (org.neo4j.kernel.impl.api.TransactionToApply)1 NeoStores (org.neo4j.kernel.impl.store.NeoStores)1 RelationshipGroupStore (org.neo4j.kernel.impl.store.RelationshipGroupStore)1 PhysicalTransactionRepresentation (org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)1 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)1 CommandsToApply (org.neo4j.storageengine.api.CommandsToApply)1 StorageCommand (org.neo4j.storageengine.api.StorageCommand)1 StorageRelationshipTraversalCursor (org.neo4j.storageengine.api.StorageRelationshipTraversalCursor)1 TestDatabaseManagementServiceBuilder (org.neo4j.test.TestDatabaseManagementServiceBuilder)1