use of org.neo4j.kernel.impl.store.record.RelationshipGroupRecord in project neo4j by neo4j.
the class RelationshipGroupCommandV2_2Test method shouldSerializeAndDeserializeUnusedRecords.
@Test
public void shouldSerializeAndDeserializeUnusedRecords() throws Exception {
// Given
RelationshipGroupRecord before = new RelationshipGroupRecord(10, 12, 13, 14, 15, 16, 17, true);
RelationshipGroupRecord after = new RelationshipGroupRecord(10, 12);
after.setInUse(false);
// When
assertSerializationWorksFor(new Command.RelationshipGroupCommand(before, after));
}
use of org.neo4j.kernel.impl.store.record.RelationshipGroupRecord in project neo4j by neo4j.
the class RelationshipGroupCommandV2_2Test method assertSerializationWorksFor.
private void assertSerializationWorksFor(Command.RelationshipGroupCommand cmd) throws IOException {
InMemoryClosableChannel channel = new InMemoryClosableChannel();
cmd.serialize(channel);
CommandReader commandReader = new PhysicalLogCommandReaderV2_2();
Command.RelationshipGroupCommand result = (Command.RelationshipGroupCommand) commandReader.read(channel);
RelationshipGroupRecord recordBefore = cmd.getBefore();
RelationshipGroupRecord recordAfter = result.getAfter();
// Then
assertThat(recordBefore.getFirstIn(), equalTo(recordAfter.getFirstIn()));
assertThat(recordBefore.getFirstOut(), equalTo(recordAfter.getFirstOut()));
assertThat(recordBefore.getFirstLoop(), equalTo(recordAfter.getFirstLoop()));
assertThat(recordBefore.getNext(), equalTo(recordAfter.getNext()));
assertThat(recordBefore.getOwningNode(), equalTo(recordAfter.getOwningNode()));
assertThat(recordBefore.getPrev(), equalTo(recordAfter.getPrev()));
assertThat(recordBefore.getType(), equalTo(recordAfter.getType()));
}
use of org.neo4j.kernel.impl.store.record.RelationshipGroupRecord in project neo4j by neo4j.
the class RelationshipGroupDefragmenterTest method shouldDefragmentRelationshipGroupsWhenSomeDense.
@Test
public void shouldDefragmentRelationshipGroupsWhenSomeDense() throws Exception {
// GIVEN some nodes which has their groups scattered
int nodeCount = 100;
int relationshipTypeCount = 50;
RecordStore<RelationshipGroupRecord> groupStore = stores.getTemporaryRelationshipGroupStore();
RelationshipGroupRecord groupRecord = groupStore.newRecord();
RecordStore<NodeRecord> nodeStore = stores.getNodeStore();
NodeRecord nodeRecord = nodeStore.newRecord();
long cursor = 0;
BitSet initializedNodes = new BitSet();
for (int typeId = relationshipTypeCount - 1; typeId >= 0; typeId--) {
for (int nodeId = 0; nodeId < nodeCount; nodeId++, cursor++) {
// Reasoning behind this thing is that we want to have roughly 10% of the nodes dense
// right from the beginning and then some stray dense nodes coming into this in the
// middle of the type range somewhere
double comparison = typeId == 0 || initializedNodes.get(nodeId) ? 0.1 : 0.001;
if (random.nextDouble() < comparison) {
// next doesn't matter at all, as we're rewriting it anyway
// firstOut/In/Loop we could use in verification phase later
groupRecord.initialize(true, typeId, cursor, cursor + 1, cursor + 2, nodeId, 4);
groupRecord.setId(groupStore.nextId());
groupStore.updateRecord(groupRecord);
if (!initializedNodes.get(nodeId)) {
nodeRecord.initialize(true, -1, true, groupRecord.getId(), 0);
nodeRecord.setId(nodeId);
nodeStore.updateRecord(nodeRecord);
nodeStore.setHighestPossibleIdInUse(nodeId);
initializedNodes.set(nodeId);
}
}
}
}
// WHEN
defrag(nodeCount, groupStore);
// THEN all groups should sit sequentially in the store
verifyGroupsAreSequentiallyOrderedByNode();
}
use of org.neo4j.kernel.impl.store.record.RelationshipGroupRecord in project neo4j by neo4j.
the class RelationshipGroupDefragmenterTest method verifyGroupsAreSequentiallyOrderedByNode.
private void verifyGroupsAreSequentiallyOrderedByNode() {
RecordStore<RelationshipGroupRecord> store = stores.getRelationshipGroupStore();
long firstId = store.getNumberOfReservedLowIds();
long groupCount = store.getHighId() - firstId;
RelationshipGroupRecord groupRecord = store.newRecord();
RecordCursor<RelationshipGroupRecord> groupCursor = store.newRecordCursor(groupRecord).acquire(firstId, CHECK);
long highGroupId = store.getHighId();
long currentNodeId = -1;
int currentTypeId = -1;
int newGroupCount = 0;
int currentGroupLength = 0;
for (long id = firstId; id < highGroupId; id++, newGroupCount++) {
if (!groupCursor.next(id)) {
// This will be the case if we have double record units, just assert that fact
assertTrue(units > 1);
assertTrue(currentGroupLength > 0);
currentGroupLength--;
continue;
}
long nodeId = groupRecord.getOwningNode();
assertTrue("Expected a group for node >= " + currentNodeId + ", but was " + nodeId + " in " + groupRecord, nodeId >= currentNodeId);
if (nodeId != currentNodeId) {
currentNodeId = nodeId;
currentTypeId = -1;
if (units > 1) {
assertEquals(0, currentGroupLength);
}
currentGroupLength = 0;
}
currentGroupLength++;
assertTrue("Expected this group to have a next of current + " + units + " OR NULL, " + "but was " + groupRecord.toString(), groupRecord.getNext() == groupRecord.getId() + 1 || groupRecord.getNext() == Record.NO_NEXT_RELATIONSHIP.intValue());
assertTrue("Expected " + groupRecord + " to have type > " + currentTypeId, groupRecord.getType() > currentTypeId);
currentTypeId = groupRecord.getType();
}
assertEquals(groupCount, newGroupCount);
}
use of org.neo4j.kernel.impl.store.record.RelationshipGroupRecord in project neo4j by neo4j.
the class RelationshipGroupDefragmenterTest method shouldDefragmentRelationshipGroupsWhenAllDense.
@Test
public void shouldDefragmentRelationshipGroupsWhenAllDense() throws Exception {
// GIVEN some nodes which has their groups scattered
int nodeCount = 100;
int relationshipTypeCount = 50;
RecordStore<RelationshipGroupRecord> groupStore = stores.getTemporaryRelationshipGroupStore();
RelationshipGroupRecord groupRecord = groupStore.newRecord();
RecordStore<NodeRecord> nodeStore = stores.getNodeStore();
NodeRecord nodeRecord = nodeStore.newRecord();
long cursor = 0;
for (int typeId = relationshipTypeCount - 1; typeId >= 0; typeId--) {
for (long nodeId = 0; nodeId < nodeCount; nodeId++, cursor++) {
// next doesn't matter at all, as we're rewriting it anyway
// firstOut/In/Loop we could use in verification phase later
groupRecord.initialize(true, typeId, cursor, cursor + 1, cursor + 2, nodeId, 4);
groupRecord.setId(groupStore.nextId());
groupStore.updateRecord(groupRecord);
if (typeId == 0) {
// first round also create the nodes
nodeRecord.initialize(true, -1, true, groupRecord.getId(), 0);
nodeRecord.setId(nodeId);
nodeStore.updateRecord(nodeRecord);
nodeStore.setHighestPossibleIdInUse(nodeId);
}
}
}
// WHEN
defrag(nodeCount, groupStore);
// THEN all groups should sit sequentially in the store
verifyGroupsAreSequentiallyOrderedByNode();
}
Aggregations