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;
}
}
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);
}
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());
}
}
}
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());
}
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;
}
Aggregations