use of org.neo4j.kernel.impl.store.record.RelationshipRecord in project neo4j by neo4j.
the class TransactionRecordStateTest method assertDenseRelationshipCounts.
public static void assertDenseRelationshipCounts(RecordChangeSet recordChangeSet, long nodeId, int type, int outCount, int inCount) {
RelationshipGroupRecord group = getRelationshipGroup(recordChangeSet, recordChangeSet.getNodeRecords().getOrLoad(nodeId, null).forReadingData(), type).forReadingData();
assertNotNull(group);
RelationshipRecord rel;
long relId = group.getFirstOut();
if (relId != Record.NO_NEXT_RELATIONSHIP.intValue()) {
rel = recordChangeSet.getRelRecords().getOrLoad(relId, null).forReadingData();
// count is stored in the back pointer of the first relationship in the chain
assertEquals("Stored relationship count for OUTGOING differs", outCount, rel.getFirstPrevRel());
assertEquals("Manually counted relationships for OUTGOING differs", outCount, manuallyCountRelationships(recordChangeSet, nodeId, relId));
}
relId = group.getFirstIn();
if (relId != Record.NO_NEXT_RELATIONSHIP.intValue()) {
rel = recordChangeSet.getRelRecords().getOrLoad(relId, null).forReadingData();
assertEquals("Stored relationship count for INCOMING differs", inCount, rel.getSecondPrevRel());
assertEquals("Manually counted relationships for INCOMING differs", inCount, manuallyCountRelationships(recordChangeSet, nodeId, relId));
}
}
use of org.neo4j.kernel.impl.store.record.RelationshipRecord in project neo4j by neo4j.
the class WriteTransactionCommandOrderingTest method injectAllPossibleCommands.
private TransactionRecordState injectAllPossibleCommands() {
RecordChangeSet recordChangeSet = mock(RecordChangeSet.class);
RecordChanges<Integer, LabelTokenRecord, Void> labelTokenChanges = mock(RecordChanges.class);
RecordChanges<Integer, RelationshipTypeTokenRecord, Void> relationshipTypeTokenChanges = mock(RecordChanges.class);
RecordChanges<Integer, PropertyKeyTokenRecord, Void> propertyKeyTokenChanges = mock(RecordChanges.class);
RecordChanges<Long, NodeRecord, Void> nodeRecordChanges = mock(RecordChanges.class);
RecordChanges<Long, RelationshipRecord, Void> relationshipRecordChanges = mock(RecordChanges.class);
RecordChanges<Long, PropertyRecord, PrimitiveRecord> propertyRecordChanges = mock(RecordChanges.class);
RecordChanges<Long, RelationshipGroupRecord, Integer> relationshipGroupChanges = mock(RecordChanges.class);
RecordChanges<Long, SchemaRecord, SchemaRule> schemaRuleChanges = mock(RecordChanges.class);
when(recordChangeSet.getLabelTokenChanges()).thenReturn(labelTokenChanges);
when(recordChangeSet.getRelationshipTypeTokenChanges()).thenReturn(relationshipTypeTokenChanges);
when(recordChangeSet.getPropertyKeyTokenChanges()).thenReturn(propertyKeyTokenChanges);
when(recordChangeSet.getNodeRecords()).thenReturn(nodeRecordChanges);
when(recordChangeSet.getRelRecords()).thenReturn(relationshipRecordChanges);
when(recordChangeSet.getPropertyRecords()).thenReturn(propertyRecordChanges);
when(recordChangeSet.getRelGroupRecords()).thenReturn(relationshipGroupChanges);
when(recordChangeSet.getSchemaRuleChanges()).thenReturn(schemaRuleChanges);
List<RecordProxy<Long, NodeRecord, Void>> nodeChanges = new LinkedList<>();
RecordChange<Long, NodeRecord, Void> deletedNode = mock(RecordChange.class);
when(deletedNode.getBefore()).thenReturn(inUseNode());
when(deletedNode.forReadingLinkage()).thenReturn(missingNode());
nodeChanges.add(deletedNode);
RecordChange<Long, NodeRecord, Void> createdNode = mock(RecordChange.class);
when(createdNode.getBefore()).thenReturn(missingNode());
when(createdNode.forReadingLinkage()).thenReturn(createdNode());
nodeChanges.add(createdNode);
RecordChange<Long, NodeRecord, Void> updatedNode = mock(RecordChange.class);
when(updatedNode.getBefore()).thenReturn(inUseNode());
when(updatedNode.forReadingLinkage()).thenReturn(inUseNode());
nodeChanges.add(updatedNode);
when(nodeRecordChanges.changes()).thenReturn(nodeChanges);
when(nodeRecordChanges.changeSize()).thenReturn(3);
when(recordChangeSet.changeSize()).thenReturn(3);
when(labelTokenChanges.changes()).thenReturn(Collections.<RecordProxy<Integer, LabelTokenRecord, Void>>emptyList());
when(relationshipTypeTokenChanges.changes()).thenReturn(Collections.<RecordProxy<Integer, RelationshipTypeTokenRecord, Void>>emptyList());
when(propertyKeyTokenChanges.changes()).thenReturn(Collections.<RecordProxy<Integer, PropertyKeyTokenRecord, Void>>emptyList());
when(relationshipRecordChanges.changes()).thenReturn(Collections.<RecordProxy<Long, RelationshipRecord, Void>>emptyList());
when(propertyRecordChanges.changes()).thenReturn(Collections.<RecordProxy<Long, PropertyRecord, PrimitiveRecord>>emptyList());
when(relationshipGroupChanges.changes()).thenReturn(Collections.<RecordProxy<Long, RelationshipGroupRecord, Integer>>emptyList());
when(schemaRuleChanges.changes()).thenReturn(Collections.<RecordProxy<Long, SchemaRecord, SchemaRule>>emptyList());
NeoStores neoStores = mock(NeoStores.class);
when(neoStores.getNodeStore()).thenReturn(mock(NodeStore.class));
when(neoStores.getRelationshipGroupStore()).thenReturn(mock(RelationshipGroupStore.class));
when(neoStores.getRelationshipStore()).thenReturn(mock(RelationshipStore.class));
return new TransactionRecordState(neoStores, mock(IntegrityValidator.class), recordChangeSet, 0, null, null, null, null, null);
}
use of org.neo4j.kernel.impl.store.record.RelationshipRecord in project neo4j by neo4j.
the class RelationshipGroupStoreTest method assertRelationshipChain.
private static void assertRelationshipChain(RelationshipStore relationshipStore, Node node, long firstId, long... chainedIds) {
long nodeId = node.getId();
RelationshipRecord record = relationshipStore.getRecord(firstId, relationshipStore.newRecord(), NORMAL, CursorContext.NULL);
Set<Long> readChain = new HashSet<>();
readChain.add(firstId);
while (true) {
long nextId = record.getFirstNode() == nodeId ? record.getFirstNextRel() : record.getSecondNextRel();
if (nextId == -1) {
break;
}
readChain.add(nextId);
relationshipStore.getRecord(nextId, record, NORMAL, CursorContext.NULL);
}
Set<Long> expectedChain = new HashSet<>(Collections.singletonList(firstId));
for (long id : chainedIds) {
expectedChain.add(id);
}
assertEquals(expectedChain, readChain);
}
use of org.neo4j.kernel.impl.store.record.RelationshipRecord in project neo4j by neo4j.
the class PropertyDeleter method logInconsistentPropertyChain.
private void logInconsistentPropertyChain(PrimitiveRecord primitive, String causeMessage, Throwable cause) {
if (!config.get(GraphDatabaseInternalSettings.log_inconsistent_data_deletion)) {
return;
}
StringBuilder message = new StringBuilder(format("Deleted inconsistent property chain with %s for %s", causeMessage, primitive));
try (RecordPropertyCursor propertyCursor = new RecordPropertyCursor(neoStores.getPropertyStore(), cursorContext, memoryTracker)) {
if (primitive instanceof NodeRecord) {
NodeRecord node = (NodeRecord) primitive;
message.append(" with labels: ");
long[] labelIds = NodeLabelsField.parseLabelsField(node).get(neoStores.getNodeStore(), cursorContext);
message.append(LongStream.of(labelIds).mapToObj(labelId -> tokenNameLookup.labelGetName(toIntExact(labelId))).collect(Collectors.toList()));
propertyCursor.initNodeProperties(node.getNextProp(), node.getId());
} else if (primitive instanceof RelationshipRecord) {
RelationshipRecord relationship = (RelationshipRecord) primitive;
message.append(format(" with relationship type: %s", tokenNameLookup.relationshipTypeGetName(relationship.getType())));
propertyCursor.initRelationshipProperties(relationship.getNextProp(), relationship.getId());
}
// Use the cursor to read property values, because it's more flexible in reading data
MutableIntSet seenKeyIds = IntSets.mutable.empty();
while (propertyCursor.next()) {
int keyId = propertyCursor.propertyKey();
if (!seenKeyIds.add(keyId)) {
continue;
}
String key = tokenNameLookup.propertyKeyGetName(keyId);
Value value;
try {
value = propertyCursor.propertyValue();
} catch (Exception e) {
value = null;
}
String valueToString = value != null ? value.toString() : "<value could not be read>";
message.append(format("%n %s = %s", key, valueToString));
}
} catch (InconsistentDataReadException e) {
// Expected to occur on chain cycles, that's what we're here for
}
logProvider.getLog(InconsistentDataDeletion.class).error(message.toString(), cause);
}
use of org.neo4j.kernel.impl.store.record.RelationshipRecord in project neo4j by neo4j.
the class LogCommandSerializationV4_0 method readRelationshipRecord.
private static RelationshipRecord readRelationshipRecord(long id, ReadableChannel channel) throws IOException {
byte flags = channel.get();
boolean inUse = bitFlag(flags, Record.IN_USE.byteValue());
boolean requiresSecondaryUnit = bitFlag(flags, Record.REQUIRE_SECONDARY_UNIT);
boolean hasSecondaryUnit = bitFlag(flags, Record.HAS_SECONDARY_UNIT);
boolean usesFixedReferenceFormat = bitFlag(flags, Record.USES_FIXED_REFERENCE_FORMAT);
RelationshipRecord record;
if (inUse) {
record = new RelationshipRecord(id);
record.setLinks(channel.getLong(), channel.getLong(), channel.getInt());
record.setInUse(true);
record.setRequiresSecondaryUnit(requiresSecondaryUnit);
record.setFirstPrevRel(channel.getLong());
record.setFirstNextRel(channel.getLong());
record.setSecondPrevRel(channel.getLong());
record.setSecondNextRel(channel.getLong());
record.setNextProp(channel.getLong());
byte extraByte = channel.get();
record.setFirstInFirstChain((extraByte & 0x1) > 0);
record.setFirstInSecondChain((extraByte & 0x2) > 0);
if (hasSecondaryUnit) {
record.setSecondaryUnitIdOnLoad(channel.getLong());
}
record.setUseFixedReferences(usesFixedReferenceFormat);
} else {
record = new RelationshipRecord(id);
record.setLinks(-1, -1, channel.getInt());
record.setInUse(false);
}
if (bitFlag(flags, Record.CREATED_IN_TX)) {
record.setCreated();
}
return record;
}
Aggregations