Search in sources :

Example 46 with RelationshipRecord

use of org.neo4j.kernel.impl.store.record.RelationshipRecord in project neo4j by neo4j.

the class BatchInsertRelationshipsStep method process.

@Override
protected void process(Batch<InputRelationship, RelationshipRecord> batch, BatchSender sender) throws Throwable {
    for (int i = 0, propertyBlockCursor = 0; i < batch.input.length; i++) {
        InputRelationship input = batch.input[i];
        int propertyBlockCount = batch.propertyBlocksLengths[i];
        // Create relationship
        long startNodeId = batch.ids[i * 2];
        long endNodeId = batch.ids[i * 2 + 1];
        if (startNodeId != -1 && endNodeId != -1) {
            long id = relationshipIdGenerator.nextId();
            int typeId = typeToId.applyAsInt(input.typeAsObject());
            relationshipCreator.relationshipCreate(id, typeId, startNodeId, endNodeId, recordAccess, noopLockClient);
            // Set properties
            RelationshipRecord record = recordAccess.getRelRecords().getOrLoad(id, null).forChangingData();
            if (input.hasFirstPropertyId()) {
                record.setNextProp(input.firstPropertyId());
            } else {
                if (propertyBlockCount > 0) {
                    reassignDynamicRecordIds(propertyStore, batch.propertyBlocks, propertyBlockCursor, propertyBlockCount);
                    long firstProp = propertyCreator.createPropertyChain(record, blockIterator.dressArray(batch.propertyBlocks, propertyBlockCursor, propertyBlockCount), recordAccess.getPropertyRecords());
                    record.setNextProp(firstProp);
                }
            }
        }
        // else --> This is commonly known as input relationship referring to missing node IDs
        propertyBlockCursor += propertyBlockCount;
    }
    pendingRelationshipChanges += batch.input.length;
    if (pendingRelationshipChanges >= 50_000) {
        // <-- happens to be called close even though this impl just flushes
        recordAccess.close();
        pendingRelationshipChanges = 0;
    }
}
Also used : RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) InputRelationship(org.neo4j.unsafe.impl.batchimport.input.InputRelationship)

Example 47 with RelationshipRecord

use of org.neo4j.kernel.impl.store.record.RelationshipRecord in project neo4j by neo4j.

the class BatchInserterImpl method getRelationshipById.

@Override
public BatchRelationship getRelationshipById(long relId) {
    RelationshipRecord record = getRelationshipRecord(relId).forReadingData();
    RelationshipType type = (RelationshipType) relationshipTypeTokens.byId(record.getType());
    return new BatchRelationship(record.getId(), record.getFirstNode(), record.getSecondNode(), type);
}
Also used : RelationshipType(org.neo4j.graphdb.RelationshipType) RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) BatchRelationship(org.neo4j.unsafe.batchinsert.BatchRelationship)

Example 48 with RelationshipRecord

use of org.neo4j.kernel.impl.store.record.RelationshipRecord in project neo4j by neo4j.

the class StorageLayerRelTypesAndDegreeTest method markRandomRelsInChainNotInUse.

private void markRandomRelsInChainNotInUse(long relId) {
    if (relId != NO_NEXT_RELATIONSHIP.intValue()) {
        RelationshipRecord record = getRelRecord(relId);
        boolean shouldBeMarked = random.nextBoolean();
        if (shouldBeMarked) {
            record.setInUse(false);
            update(record);
        }
        markRandomRelsInChainNotInUse(record.getFirstNextRel());
        boolean isLoopRelationship = record.getFirstNextRel() == record.getSecondNextRel();
        if (!isLoopRelationship) {
            markRandomRelsInChainNotInUse(record.getSecondNextRel());
        }
    }
}
Also used : RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord)

Example 49 with RelationshipRecord

use of org.neo4j.kernel.impl.store.record.RelationshipRecord in project neo4j by neo4j.

the class ApplyRecoveredTransactionsTest method shouldSetCorrectHighIdWhenApplyingExternalTransactions.

@Test
public void shouldSetCorrectHighIdWhenApplyingExternalTransactions() throws Exception {
    // WHEN recovering a transaction that creates some data
    long nodeId = neoStores.getNodeStore().nextId();
    long relationshipId = neoStores.getRelationshipStore().nextId();
    int type = 1;
    applyExternalTransaction(1, new NodeCommand(new NodeRecord(nodeId), inUse(created(new NodeRecord(nodeId)))), new RelationshipCommand(null, inUse(created(with(new RelationshipRecord(relationshipId), nodeId, nodeId, type)))));
    // and when, later on, recovering a transaction deleting some of those
    applyExternalTransaction(2, new NodeCommand(inUse(created(new NodeRecord(nodeId))), new NodeRecord(nodeId)), new RelationshipCommand(null, new RelationshipRecord(relationshipId)));
    // THEN that should be possible and the high ids should be correct, i.e. highest applied + 1
    assertEquals(nodeId + 1, neoStores.getNodeStore().getHighId());
    assertEquals(relationshipId + 1, neoStores.getRelationshipStore().getHighId());
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) RelationshipCommand(org.neo4j.kernel.impl.transaction.command.Command.RelationshipCommand) NodeCommand(org.neo4j.kernel.impl.transaction.command.Command.NodeCommand) Test(org.junit.Test)

Example 50 with RelationshipRecord

use of org.neo4j.kernel.impl.store.record.RelationshipRecord in project neo4j by neo4j.

the class TransactionRecordStateTest method manuallyCountRelationships.

private static int manuallyCountRelationships(RecordChangeSet recordChangeSet, long nodeId, long firstRelId) {
    int count = 0;
    long relId = firstRelId;
    while (relId != Record.NO_NEXT_RELATIONSHIP.intValue()) {
        count++;
        RelationshipRecord record = recordChangeSet.getRelRecords().getOrLoad(relId, null).forReadingData();
        relId = record.getFirstNode() == nodeId ? record.getFirstNextRel() : record.getSecondNextRel();
    }
    return count;
}
Also used : RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord)

Aggregations

RelationshipRecord (org.neo4j.kernel.impl.store.record.RelationshipRecord)207 Test (org.junit.Test)73 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)69 ConsistencyReport (org.neo4j.consistency.report.ConsistencyReport)43 Test (org.junit.jupiter.api.Test)34 RelationshipTypeTokenRecord (org.neo4j.kernel.impl.store.record.RelationshipTypeTokenRecord)30 PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)19 RelationshipGroupRecord (org.neo4j.kernel.impl.store.record.RelationshipGroupRecord)19 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 RelationshipStore (org.neo4j.kernel.impl.store.RelationshipStore)14 GraphStoreFixture (org.neo4j.consistency.checking.GraphStoreFixture)12 IdGenerator (org.neo4j.consistency.checking.GraphStoreFixture.IdGenerator)12 ConsistencySummaryStatistics (org.neo4j.consistency.report.ConsistencySummaryStatistics)12 TransactionDataBuilder (org.neo4j.consistency.checking.GraphStoreFixture.TransactionDataBuilder)11 InMemoryClosableChannel (org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel)11 RecordAccessStub (org.neo4j.consistency.store.RecordAccessStub)9 InputRelationship (org.neo4j.unsafe.impl.batchimport.input.InputRelationship)8 RepeatedTest (org.junit.jupiter.api.RepeatedTest)7 IOException (java.io.IOException)6 CursorContext (org.neo4j.io.pagecache.context.CursorContext)6