use of org.neo4j.internal.recordstorage.FlatRelationshipModifications.RelationshipData in project neo4j by neo4j.
the class DegreesRebuildFromStoreTest method generateData.
private void generateData(RecordStorageEngine storageEngine, int denseThreshold, int[] relationshipTypes) throws Exception {
int numNodes = 100;
long[] nodes = new long[numNodes];
applyLogicalChanges(storageEngine, (state, tx) -> {
NodeStore nodeStore = storageEngine.testAccessNeoStores().getNodeStore();
for (int i = 0; i < numNodes; i++) {
nodes[i] = nodeStore.nextId(NULL);
tx.visitCreatedNode(nodes[i]);
}
});
RelationshipStore relationshipStore = storageEngine.testAccessNeoStores().getRelationshipStore();
List<RelationshipData> relationships = new ArrayList<>();
int numRelationships = numNodes * denseThreshold;
for (int i = 0; i < numRelationships; i++) {
relationships.add(new RelationshipData(relationshipStore.nextId(NULL), random.among(relationshipTypes), random.among(nodes), random.among(nodes)));
}
applyLogicalChanges(storageEngine, (state, tx) -> {
NodeState nodeState = mock(NodeState.class);
when(nodeState.labelDiffSets()).thenReturn(LongDiffSets.EMPTY);
when(state.getNodeState(anyLong())).thenReturn(nodeState);
tx.visitRelationshipModifications(new FlatRelationshipModifications(relationships.toArray(new RelationshipData[0])));
});
}
use of org.neo4j.internal.recordstorage.FlatRelationshipModifications.RelationshipData in project neo4j by neo4j.
the class TransactionRecordStateTest method movingBilaterallyOfTheDenseNodeThresholdIsConsistent.
@Test
void movingBilaterallyOfTheDenseNodeThresholdIsConsistent() throws Exception {
neoStores = createStores(Config.defaults(dense_node_threshold, 10));
TransactionRecordState tx = newTransactionRecordState();
long nodeId = neoStores.getNodeStore().nextId(NULL);
tx.nodeCreate(nodeId);
int typeA = (int) neoStores.getRelationshipTypeTokenStore().nextId(NULL);
tx.createRelationshipTypeToken("A", typeA, false);
createRelationships(neoStores, tx, nodeId, typeA, INCOMING, 20);
TransactionApplierFactory applier = buildApplier(LockService.NO_LOCK_SERVICE);
apply(applier, transaction(tx));
tx = newTransactionRecordState();
int typeB = 1;
tx.createRelationshipTypeToken("B", typeB, false);
// WHEN
// i remove enough relationships to become dense and remove enough to become not dense
RelationshipData[] relationshipsOfTypeB = createRelationships(neoStores, tx, nodeId, typeB, OUTGOING, 5);
tx.relModify(new FlatRelationshipModifications(relationships(), relationshipsOfTypeB));
CommandsToApply ptx = transaction(tx);
apply(applier, ptx);
// THEN
// The dynamic label record in before should be the same id as in after, and should be in use
final AtomicBoolean foundRelationshipGroupInUse = new AtomicBoolean();
ptx.accept(command -> ((Command) command).handle(new CommandVisitor.Adapter() {
@Override
public boolean visitRelationshipGroupCommand(Command.RelationshipGroupCommand command) {
if (command.getAfter().inUse()) {
if (!foundRelationshipGroupInUse.get()) {
foundRelationshipGroupInUse.set(true);
} else {
fail();
}
}
return false;
}
}));
assertTrue(foundRelationshipGroupInUse.get(), "Did not create relationship group command");
}
use of org.neo4j.internal.recordstorage.FlatRelationshipModifications.RelationshipData in project neo4j by neo4j.
the class RelationshipModifierTest method sparseDelete.
@Test
void sparseDelete() {
// given
long node1 = createEmptyNode();
long node2 = createEmptyNode();
RelationshipData relationship = relationship(99, 1, node1, node2);
createRelationships(singletonList(relationship));
// when
modify(singleDelete(relationship));
// then
locks.assertHasLock(NODE, EXCLUSIVE, node1);
locks.assertNoLock(RELATIONSHIP_GROUP, EXCLUSIVE, node1);
locks.assertHasLock(NODE, EXCLUSIVE, node2);
locks.assertNoLock(RELATIONSHIP_GROUP, EXCLUSIVE, node2);
}
use of org.neo4j.internal.recordstorage.FlatRelationshipModifications.RelationshipData in project neo4j by neo4j.
the class RelationshipModifierTest method readRelationshipsFromStore.
private static Set<RelationshipData> readRelationshipsFromStore(long node, MapRecordStore store) {
Set<RelationshipData> relationships = new HashSet<>();
store.relationshipChainVisitor().visit(node, relationshipCollector(r -> relationships.add(new RelationshipData(r.getId(), r.getType(), r.getFirstNode(), r.getSecondNode()))));
return relationships;
}
use of org.neo4j.internal.recordstorage.FlatRelationshipModifications.RelationshipData in project neo4j by neo4j.
the class RelationshipModifierTest method generateRelationshipData.
private List<RelationshipData> generateRelationshipData(int count, long node, IntSupplier typeStrategy, LongSupplier otherNodeStrategy, Supplier<RelationshipDirection> directionStrategy) {
List<RelationshipData> relationships = new ArrayList<>(count);
for (int i = 0; i < count; i++) {
long otherNode = otherNodeStrategy.getAsLong();
RelationshipDirection direction = directionStrategy.get();
long start = direction == OUTGOING || direction == LOOP ? node : otherNode;
long end = direction == INCOMING || direction == LOOP ? node : otherNode;
relationships.add(new RelationshipData(nextRelationshipId(), typeStrategy.getAsInt(), start, end));
}
return relationships;
}
Aggregations