Search in sources :

Example 71 with RelationshipGroupRecord

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));
}
Also used : RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) Command(org.neo4j.kernel.impl.transaction.command.Command) Test(org.junit.Test)

Example 72 with RelationshipGroupRecord

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()));
}
Also used : CommandReader(org.neo4j.storageengine.api.CommandReader) RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) Command(org.neo4j.kernel.impl.transaction.command.Command) PhysicalLogCommandReaderV2_2(org.neo4j.kernel.impl.transaction.command.PhysicalLogCommandReaderV2_2)

Example 73 with RelationshipGroupRecord

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();
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) BitSet(java.util.BitSet) Test(org.junit.Test)

Example 74 with RelationshipGroupRecord

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);
}
Also used : RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord)

Example 75 with RelationshipGroupRecord

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();
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) Test(org.junit.Test)

Aggregations

RelationshipGroupRecord (org.neo4j.kernel.impl.store.record.RelationshipGroupRecord)83 Test (org.junit.Test)42 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)24 GraphStoreFixture (org.neo4j.consistency.checking.GraphStoreFixture)11 IdGenerator (org.neo4j.consistency.checking.GraphStoreFixture.IdGenerator)11 TransactionDataBuilder (org.neo4j.consistency.checking.GraphStoreFixture.TransactionDataBuilder)11 ConsistencySummaryStatistics (org.neo4j.consistency.report.ConsistencySummaryStatistics)11 RelationshipRecord (org.neo4j.kernel.impl.store.record.RelationshipRecord)10 Command (org.neo4j.kernel.impl.transaction.command.Command)5 IOException (java.io.IOException)4 InMemoryClosableChannel (org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel)4 File (java.io.File)3 Node (org.neo4j.graphdb.Node)3 Relationship (org.neo4j.graphdb.Relationship)3 Transaction (org.neo4j.graphdb.Transaction)3 RecordStorageEngine (org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine)3 NeoStores (org.neo4j.kernel.impl.store.NeoStores)3 RelationshipStore (org.neo4j.kernel.impl.store.RelationshipStore)3 PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)3 RelationshipGroupCommand (org.neo4j.kernel.impl.transaction.command.Command.RelationshipGroupCommand)3