Search in sources :

Example 26 with RelationshipGroupRecord

use of org.neo4j.kernel.impl.store.record.RelationshipGroupRecord in project neo4j by neo4j.

the class PhysicalLogCommandReaderV3_0Test method readRelationshipGroupCommandWithSecondaryUnit.

@Test
public void readRelationshipGroupCommandWithSecondaryUnit() throws IOException {
    // Given
    InMemoryClosableChannel channel = new InMemoryClosableChannel();
    RelationshipGroupRecord before = new RelationshipGroupRecord(42, 3);
    RelationshipGroupRecord after = new RelationshipGroupRecord(42, 3, 4, 5, 6, 7, 8, true);
    after.setRequiresSecondaryUnit(true);
    after.setSecondaryUnitId(17);
    after.setCreated();
    new Command.RelationshipGroupCommand(before, after).serialize(channel);
    // When
    PhysicalLogCommandReaderV3_0 reader = new PhysicalLogCommandReaderV3_0();
    Command command = reader.read(channel);
    assertTrue(command instanceof Command.RelationshipGroupCommand);
    Command.RelationshipGroupCommand relationshipGroupCommand = (Command.RelationshipGroupCommand) command;
    // Then
    assertEquals(before, relationshipGroupCommand.getBefore());
    assertEquals(after, relationshipGroupCommand.getAfter());
    verifySecondaryUnit(after, relationshipGroupCommand.getAfter());
}
Also used : RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) Test(org.junit.Test)

Example 27 with RelationshipGroupRecord

use of org.neo4j.kernel.impl.store.record.RelationshipGroupRecord in project neo4j by neo4j.

the class NeoStoreTransactionApplierTest method shouldApplyRelationshipGroupCommandToTheStoreInRecovery.

@Test
public void shouldApplyRelationshipGroupCommandToTheStoreInRecovery() throws Exception {
    // given
    final BatchTransactionApplier applier = newApplier(true);
    // when
    final RelationshipGroupRecord before = new RelationshipGroupRecord(42, 1);
    final RelationshipGroupRecord after = new RelationshipGroupRecord(42, 1, 2, 3, 4, 5, 6, true);
    final Command command = new Command.RelationshipGroupCommand(before, after);
    boolean result = apply(applier, command::handle, transactionToApply);
    // then
    assertFalse(result);
    verify(relationshipGroupStore, times(1)).setHighestPossibleIdInUse(after.getId());
    verify(relationshipGroupStore, times(1)).updateRecord(after);
}
Also used : RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) RelationshipTypeTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.RelationshipTypeTokenCommand) LabelTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.LabelTokenCommand) PropertyKeyTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.PropertyKeyTokenCommand) BatchTransactionApplier(org.neo4j.kernel.impl.api.BatchTransactionApplier) Test(org.junit.Test)

Example 28 with RelationshipGroupRecord

use of org.neo4j.kernel.impl.store.record.RelationshipGroupRecord in project neo4j by neo4j.

the class RelationshipGroupDefragmenter method run.

public void run(long memoryWeCanHoldForCertain, BatchingNeoStores neoStore, long highNodeId) {
    try (RelationshipGroupCache groupCache = new RelationshipGroupCache(AUTO, memoryWeCanHoldForCertain, highNodeId)) {
        // Read from the temporary relationship group store...
        RecordStore<RelationshipGroupRecord> fromStore = neoStore.getTemporaryRelationshipGroupStore();
        // and write into the main relationship group store
        RecordStore<RelationshipGroupRecord> toStore = neoStore.getRelationshipGroupStore();
        // Count all nodes, how many groups each node has each
        Configuration groupConfig = withBatchSize(config, neoStore.getRelationshipGroupStore().getRecordsPerPage());
        executeStage(new CountGroupsStage(groupConfig, fromStore, groupCache));
        long fromNodeId = 0;
        long toNodeId = 0;
        while (fromNodeId < highNodeId) {
            // See how many nodes' groups we can fit into the cache this iteration of the loop.
            // Groups that doesn't fit in this round will be included in consecutive rounds.
            toNodeId = groupCache.prepare(fromNodeId);
            monitor.defragmentingNodeRange(fromNodeId, toNodeId);
            // Cache those groups
            executeStage(new ScanAndCacheGroupsStage(groupConfig, fromStore, groupCache));
            // And write them in sequential order in the store
            executeStage(new WriteGroupsStage(groupConfig, groupCache, toStore));
            // Make adjustments for the next iteration
            fromNodeId = toNodeId;
        }
        // Now update nodes to point to the new groups
        ByteArray groupCountCache = groupCache.getGroupCountCache();
        groupCountCache.clear();
        Configuration nodeConfig = withBatchSize(config, neoStore.getNodeStore().getRecordsPerPage());
        executeStage(new NodeFirstGroupStage(nodeConfig, toStore, neoStore.getNodeStore(), groupCountCache));
    }
}
Also used : RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) ByteArray(org.neo4j.unsafe.impl.batchimport.cache.ByteArray)

Example 29 with RelationshipGroupRecord

use of org.neo4j.kernel.impl.store.record.RelationshipGroupRecord in project neo4j by neo4j.

the class EncodeGroupsStep method process.

@Override
protected void process(RelationshipGroupRecord[] batch, BatchSender sender) throws Throwable {
    int groupStartIndex = 0;
    for (int i = 0; i < batch.length; i++) {
        RelationshipGroupRecord group = batch[i];
        // The iterator over the groups will not produce real next pointers, they are instead
        // a count meaning how many groups come after it. This encoder will set the real group ids.
        long count = group.getNext();
        boolean lastInChain = count == 0;
        group.setId(nextId == -1 ? nextId = store.nextId() : nextId);
        if (!lastInChain) {
            group.setNext(nextId = store.nextId());
        } else {
            group.setNext(nextId = -1);
            // secondary units ends up very close by.
            for (int j = groupStartIndex; j <= i; j++) {
                store.prepareForCommit(batch[j]);
            }
            groupStartIndex = i + 1;
        }
    }
    assert groupStartIndex == batch.length;
    sender.send(batch);
}
Also used : RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord)

Example 30 with RelationshipGroupRecord

use of org.neo4j.kernel.impl.store.record.RelationshipGroupRecord in project neo4j by neo4j.

the class NodeFirstRelationshipProcessor method visit.

@Override
public long visit(long nodeId, long next, long out, long in, long loop) {
    // Here we'll use the already generated id (below) from the previous visit, if that so happened
    long id = relGroupStore.nextId();
    RelationshipGroupRecord groupRecord = new RelationshipGroupRecord(id);
    groupRecord.setType(relationshipType);
    groupRecord.setInUse(true);
    groupRecord.setFirstOut(out);
    groupRecord.setFirstIn(in);
    groupRecord.setFirstLoop(loop);
    groupRecord.setOwningNode(nodeId);
    groupRecord.setNext(next);
    relGroupStore.prepareForCommit(groupRecord);
    relGroupStore.updateRecord(groupRecord);
    return id;
}
Also used : RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord)

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