use of org.neo4j.internal.recordstorage.Command.RelationshipGroupCommand in project neo4j by neo4j.
the class PhysicalLogCommandReadersTest method assertValidRelGroupCommand.
private static void assertValidRelGroupCommand(StorageCommand command) {
assertThat(command).isInstanceOf(RelationshipGroupCommand.class);
RelationshipGroupCommand relGroupCommand = (RelationshipGroupCommand) command;
RelationshipGroupRecord record = relGroupCommand.getAfter();
assertEquals(ID, record.getId());
if (IN_USE_FLAG == Record.IN_USE.byteValue()) {
Assertions.assertTrue(record.inUse());
} else if (IN_USE_FLAG == Record.NOT_IN_USE.byteValue()) {
Assertions.assertFalse(record.inUse());
} else {
throw new IllegalStateException("Illegal inUse flag: " + IN_USE_FLAG);
}
assertEquals(TYPE_AS_INT, record.getType());
assertEquals(NEXT, record.getNext());
assertEquals(FIRST_OUT, record.getFirstOut());
assertEquals(FIRST_IN, record.getFirstIn());
assertEquals(FIRST_LOOP, record.getNext());
assertEquals(OWNING_NODE, record.getOwningNode());
}
use of org.neo4j.internal.recordstorage.Command.RelationshipGroupCommand in project neo4j by neo4j.
the class HighIdTransactionApplierTest method shouldTrackSecondaryUnitIdsAsWell.
@Test
void shouldTrackSecondaryUnitIdsAsWell() throws Exception {
// GIVEN
HighIdTransactionApplier tracker = new HighIdTransactionApplier(neoStores);
NodeRecord node = new NodeRecord(5).initialize(true, 123, true, 456, 0);
node.setSecondaryUnitIdOnLoad(6);
RelationshipRecord relationship = new RelationshipRecord(10).initialize(true, 1, 2, 3, 4, 5, 6, 7, 8, true, true);
relationship.setSecondaryUnitIdOnLoad(12);
RelationshipGroupRecord relationshipGroup = new RelationshipGroupRecord(8).initialize(true, 0, 1, 2, 3, 4, 5);
relationshipGroup.setSecondaryUnitIdOnLoad(20);
// WHEN
tracker.visitNodeCommand(new NodeCommand(new NodeRecord(node.getId()), node));
tracker.visitRelationshipCommand(new RelationshipCommand(new RelationshipRecord(relationship.getId()), relationship));
tracker.visitRelationshipGroupCommand(new RelationshipGroupCommand(new RelationshipGroupRecord(relationshipGroup.getId()), relationshipGroup));
tracker.close();
// THEN
assertEquals(node.getSecondaryUnitId() + 1, neoStores.getNodeStore().getHighId());
assertEquals(relationship.getSecondaryUnitId() + 1, neoStores.getRelationshipStore().getHighId());
assertEquals(relationshipGroup.getSecondaryUnitId() + 1, neoStores.getRelationshipGroupStore().getHighId());
}
use of org.neo4j.internal.recordstorage.Command.RelationshipGroupCommand in project neo4j by neo4j.
the class Commands method createRelationshipGroup.
public static RelationshipGroupCommand createRelationshipGroup(long id, int type) {
RelationshipGroupRecord before = new RelationshipGroupRecord(id);
RelationshipGroupRecord after = new RelationshipGroupRecord(id).initialize(true, type, NULL_REFERENCE.longValue(), NULL_REFERENCE.longValue(), NULL_REFERENCE.longValue(), NULL_REFERENCE.longValue(), NULL_REFERENCE.longValue());
after.setCreated();
return new RelationshipGroupCommand(before, after);
}
use of org.neo4j.internal.recordstorage.Command.RelationshipGroupCommand in project neo4j by neo4j.
the class TransactionRecordStateTest method shouldPrepareRelevantRecords.
@Test
void shouldPrepareRelevantRecords() throws Exception {
PrepareTrackingRecordFormats format = new PrepareTrackingRecordFormats(Standard.LATEST_RECORD_FORMATS);
neoStores = createStores(Config.defaults(dense_node_threshold, 1), format);
// WHEN
TransactionRecordState state = newTransactionRecordState();
state.nodeCreate(0);
state.relModify(singleCreate(0, 0, 0, 0));
state.relModify(singleCreate(1, 0, 0, 0));
state.relModify(singleCreate(2, 0, 0, 0));
List<StorageCommand> commands = new ArrayList<>();
state.extractCommands(commands, INSTANCE);
// THEN
int nodes = 0;
int rels = 0;
int groups = 0;
for (StorageCommand command : commands) {
if (command instanceof NodeCommand) {
assertTrue(format.node().prepared(((NodeCommand) command).getAfter()));
nodes++;
} else if (command instanceof RelationshipCommand) {
assertTrue(format.relationship().prepared(((RelationshipCommand) command).getAfter()));
rels++;
} else if (command instanceof RelationshipGroupCommand) {
assertTrue(format.relationshipGroup().prepared(((RelationshipGroupCommand) command).getAfter()));
groups++;
}
}
assertEquals(1, nodes);
assertEquals(3, rels);
assertEquals(1, groups);
}
use of org.neo4j.internal.recordstorage.Command.RelationshipGroupCommand in project neo4j by neo4j.
the class TransactionRecordStateTest method shouldIgnoreRelationshipGroupCommandsForGroupThatIsCreatedAndDeletedInThisTx.
@Test
void shouldIgnoreRelationshipGroupCommandsForGroupThatIsCreatedAndDeletedInThisTx() throws Exception {
/*
* This test verifies that there are no transaction commands generated for a state diff that contains a
* relationship group that is created and deleted in this tx. This case requires special handling because
* relationship groups can be created and then deleted from disjoint code paths. Look at
* TransactionRecordState.extractCommands() for more details.
*
* The test setup looks complicated but all it does is mock properly a NeoStoreTransactionContext to
* return an Iterable<RecordSet> that contains a RelationshipGroup record which has been created in this
* tx and also is set notInUse.
*/
// Given:
// - dense node threshold of 5
// - node with 4 rels of type relationshipB and 1 rel of type relationshipB
neoStores = createStores(Config.defaults(dense_node_threshold, 5));
int relationshipA = 0;
int relationshipB = 1;
TransactionRecordState state = newTransactionRecordState();
state.nodeCreate(0);
state.relModify(singleCreate(0, relationshipA, 0, 0));
state.relModify(singleCreate(1, relationshipA, 0, 0));
state.relModify(singleCreate(2, relationshipA, 0, 0));
state.relModify(singleCreate(3, relationshipA, 0, 0));
state.relModify(singleCreate(4, relationshipB, 0, 0));
apply(state);
// When doing a tx where a relationship of type A for the node is create and rel of type relationshipB is deleted
state = newTransactionRecordState();
// here this node should be converted to dense and the groups should be created
// and the group relationshipB should be delete
state.relModify(new FlatRelationshipModifications(relationships(relationship(5, relationshipA, 0, 0)), relationships(relationship(4, relationshipB, 0, 0))));
// Then
Collection<StorageCommand> commands = new ArrayList<>();
state.extractCommands(commands, INSTANCE);
RelationshipGroupCommand group = singleRelationshipGroupCommand(commands);
assertEquals(relationshipA, group.getAfter().getType());
}
Aggregations