Search in sources :

Example 1 with NodeCommand

use of org.neo4j.internal.recordstorage.Command.NodeCommand in project neo4j by neo4j.

the class LabelAndIndexUpdateBatchingIT method findCutoffIndex.

private static int findCutoffIndex(Collection<TransactionRepresentation> transactions) throws IOException {
    Iterator<TransactionRepresentation> iterator = transactions.iterator();
    for (int i = 0; iterator.hasNext(); i++) {
        TransactionRepresentation tx = iterator.next();
        CommandExtractor extractor = new CommandExtractor();
        tx.accept(extractor);
        List<StorageCommand> nodeCommands = extractor.commands.stream().filter(command -> command instanceof NodeCommand).collect(toList());
        if (nodeCommands.size() == 1) {
            return i;
        }
    }
    throw new AssertionError("Couldn't find the transaction which would be the cut-off point");
}
Also used : Visitor(org.neo4j.internal.helpers.collection.Visitor) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Label(org.neo4j.graphdb.Label) NodeCommand(org.neo4j.internal.recordstorage.Command.NodeCommand) LogicalTransactionStore(org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore) CursorContext(org.neo4j.io.pagecache.context.CursorContext) TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) ArrayList(java.util.ArrayList) StorageCommand(org.neo4j.storageengine.api.StorageCommand) Iterators.singleOrNull(org.neo4j.internal.helpers.collection.Iterators.singleOrNull) DEFAULT_DATABASE_NAME(org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) EXTERNAL(org.neo4j.storageengine.api.TransactionApplicationMode.EXTERNAL) Transaction(org.neo4j.graphdb.Transaction) Iterator(java.util.Iterator) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) Collection(java.util.Collection) IOException(java.io.IOException) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Test(org.junit.jupiter.api.Test) MetadataProvider(org.neo4j.storageengine.api.MetadataProvider) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) TransactionCommitProcess(org.neo4j.kernel.impl.api.TransactionCommitProcess) TransactionCursor(org.neo4j.kernel.impl.transaction.log.TransactionCursor) CommitEvent(org.neo4j.kernel.impl.transaction.tracing.CommitEvent) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) StorageCommand(org.neo4j.storageengine.api.StorageCommand) NodeCommand(org.neo4j.internal.recordstorage.Command.NodeCommand)

Example 2 with NodeCommand

use of org.neo4j.internal.recordstorage.Command.NodeCommand 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());
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) RelationshipGroupCommand(org.neo4j.internal.recordstorage.Command.RelationshipGroupCommand) RelationshipCommand(org.neo4j.internal.recordstorage.Command.RelationshipCommand) NodeCommand(org.neo4j.internal.recordstorage.Command.NodeCommand) Test(org.junit.jupiter.api.Test)

Example 3 with NodeCommand

use of org.neo4j.internal.recordstorage.Command.NodeCommand in project neo4j by neo4j.

the class ApplyRecoveredTransactionsTest method shouldSetCorrectHighIdWhenApplyingExternalTransactions.

@Test
void shouldSetCorrectHighIdWhenApplyingExternalTransactions() throws Exception {
    // WHEN recovering a transaction that creates some data
    long nodeId = neoStores.getNodeStore().nextId(NULL);
    long relationshipId = neoStores.getRelationshipStore().nextId(NULL);
    int type = 1;
    applyExternalTransaction(1, new NodeCommand(new NodeRecord(nodeId), inUse(created(new NodeRecord(nodeId)))), new RelationshipCommand(null, inUse(created(with(new RelationshipRecord(relationshipId), nodeId, nodeId, type)))));
    // and when, later on, recovering a transaction deleting some of those
    applyExternalTransaction(2, new NodeCommand(inUse(created(new NodeRecord(nodeId))), new NodeRecord(nodeId)), new RelationshipCommand(null, new RelationshipRecord(relationshipId)));
    // THEN that should be possible and the high ids should be correct, i.e. highest applied + 1
    assertEquals(nodeId + 1, neoStores.getNodeStore().getHighId());
    assertEquals(relationshipId + 1, neoStores.getRelationshipStore().getHighId());
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) RelationshipCommand(org.neo4j.internal.recordstorage.Command.RelationshipCommand) NodeCommand(org.neo4j.internal.recordstorage.Command.NodeCommand) Test(org.junit.jupiter.api.Test)

Example 4 with NodeCommand

use of org.neo4j.internal.recordstorage.Command.NodeCommand in project neo4j by neo4j.

the class Commands method createNode.

public static NodeCommand createNode(long id, long... dynamicLabelRecordIds) {
    NodeRecord record = new NodeRecord(id);
    record.setInUse(true);
    record.setCreated();
    if (dynamicLabelRecordIds.length > 0) {
        Collection<DynamicRecord> dynamicRecords = dynamicRecords(dynamicLabelRecordIds);
        record.setLabelField(DynamicNodeLabels.dynamicPointer(dynamicRecords), dynamicRecords);
    }
    return new NodeCommand(new NodeRecord(id), record);
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) NodeCommand(org.neo4j.internal.recordstorage.Command.NodeCommand)

Example 5 with NodeCommand

use of org.neo4j.internal.recordstorage.Command.NodeCommand 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);
}
Also used : StorageCommand(org.neo4j.storageengine.api.StorageCommand) ArrayList(java.util.ArrayList) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) RelationshipGroupCommand(org.neo4j.internal.recordstorage.Command.RelationshipGroupCommand) RelationshipCommand(org.neo4j.internal.recordstorage.Command.RelationshipCommand) NodeCommand(org.neo4j.internal.recordstorage.Command.NodeCommand) Test(org.junit.jupiter.api.Test)

Aggregations

NodeCommand (org.neo4j.internal.recordstorage.Command.NodeCommand)8 Test (org.junit.jupiter.api.Test)6 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)6 RelationshipCommand (org.neo4j.internal.recordstorage.Command.RelationshipCommand)3 RelationshipRecord (org.neo4j.kernel.impl.store.record.RelationshipRecord)3 ArrayList (java.util.ArrayList)2 PropertyCommand (org.neo4j.internal.recordstorage.Command.PropertyCommand)2 RelationshipGroupCommand (org.neo4j.internal.recordstorage.Command.RelationshipGroupCommand)2 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)2 PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)2 StorageCommand (org.neo4j.storageengine.api.StorageCommand)2 Value (org.neo4j.values.storable.Value)2 IOException (java.io.IOException)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Collectors.toList (java.util.stream.Collectors.toList)1 LongArrayList (org.eclipse.collections.impl.list.mutable.primitive.LongArrayList)1 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)1 DEFAULT_DATABASE_NAME (org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME)1