Search in sources :

Example 41 with StorageCommand

use of org.neo4j.storageengine.api.StorageCommand in project neo4j by neo4j.

the class TransactionRecordStateTest method preparingIndexRulesMustMarkSchemaRecordAsChanged.

@Test
void preparingIndexRulesMustMarkSchemaRecordAsChanged() throws Exception {
    neoStores = createStores();
    TransactionRecordState state = newTransactionRecordState();
    long ruleId = neoStores.getSchemaStore().nextId(NULL);
    IndexDescriptor rule = IndexPrototype.forSchema(forLabel(0, 1)).withName("index_" + ruleId).materialise(ruleId);
    state.schemaRuleCreate(ruleId, false, rule);
    List<StorageCommand> commands = new ArrayList<>();
    state.extractCommands(commands, INSTANCE);
    assertThat(commands.size()).isEqualTo(1);
    SchemaRuleCommand command = (SchemaRuleCommand) commands.get(0);
    assertThat(command.getMode()).isEqualTo(Command.Mode.CREATE);
    assertThat(command.getSchemaRule()).isEqualTo(rule);
    assertThat(command.getKey()).isEqualTo(ruleId);
    assertThat(command.getBefore().inUse()).isEqualTo(false);
    assertThat(command.getAfter().inUse()).isEqualTo(true);
    assertThat(command.getAfter().isConstraint()).isEqualTo(false);
    assertThat(command.getAfter().isCreated()).isEqualTo(true);
    assertThat(command.getAfter().getNextProp()).isEqualTo(Record.NO_NEXT_PROPERTY.longValue());
}
Also used : SchemaRuleCommand(org.neo4j.internal.recordstorage.Command.SchemaRuleCommand) StorageCommand(org.neo4j.storageengine.api.StorageCommand) ArrayList(java.util.ArrayList) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 42 with StorageCommand

use of org.neo4j.storageengine.api.StorageCommand in project neo4j by neo4j.

the class RecordStorageEngineTestUtils method applyLogicalChanges.

public static void applyLogicalChanges(RecordStorageEngine storageEngine, ThrowingBiConsumer<ReadableTransactionState, TxStateVisitor, Exception> changes) throws Exception {
    ReadableTransactionState txState = mock(ReadableTransactionState.class);
    doAnswer(invocationOnMock -> {
        TxStateVisitor visitor = invocationOnMock.getArgument(0);
        changes.accept(txState, visitor);
        return null;
    }).when(txState).accept(any());
    List<StorageCommand> commands = new ArrayList<>();
    NeoStores neoStores = storageEngine.testAccessNeoStores();
    MetaDataStore metaDataStore = neoStores.getMetaDataStore();
    CursorContext cursorContext = CursorContext.NULL;
    try (RecordStorageCommandCreationContext commandCreationContext = storageEngine.newCommandCreationContext(EmptyMemoryTracker.INSTANCE)) {
        commandCreationContext.initialize(cursorContext);
        storageEngine.createCommands(commands, txState, storageEngine.newReader(), commandCreationContext, ResourceLocker.IGNORE, LockTracer.NONE, metaDataStore.getLastCommittedTransactionId(), t -> t, cursorContext, EmptyMemoryTracker.INSTANCE);
        storageEngine.apply(new GroupOfCommands(metaDataStore.nextCommittingTransactionId(), commands.toArray(new StorageCommand[0])), TransactionApplicationMode.EXTERNAL);
    }
}
Also used : TxStateVisitor(org.neo4j.storageengine.api.txstate.TxStateVisitor) MetaDataStore(org.neo4j.kernel.impl.store.MetaDataStore) StorageCommand(org.neo4j.storageengine.api.StorageCommand) NeoStores(org.neo4j.kernel.impl.store.NeoStores) ArrayList(java.util.ArrayList) ReadableTransactionState(org.neo4j.storageengine.api.txstate.ReadableTransactionState) CursorContext(org.neo4j.io.pagecache.context.CursorContext)

Example 43 with StorageCommand

use of org.neo4j.storageengine.api.StorageCommand in project neo4j by neo4j.

the class LogCommandSerializationV4_0Test method readPropertyCommandWithSecondaryUnit.

@Test
void readPropertyCommandWithSecondaryUnit() throws IOException {
    InMemoryClosableChannel channel = new InMemoryClosableChannel();
    PropertyRecord before = new PropertyRecord(1);
    PropertyRecord after = new PropertyRecord(1);
    after.setSecondaryUnitIdOnCreate(78);
    new Command.PropertyCommand(writer(), before, after).serialize(channel);
    CommandReader reader = createReader();
    StorageCommand command = reader.read(channel);
    assertTrue(command instanceof Command.PropertyCommand);
    Command.PropertyCommand propertyCommand = (Command.PropertyCommand) command;
    // Then
    assertBeforeAndAfterEquals(propertyCommand, before, after);
}
Also used : CommandReader(org.neo4j.storageengine.api.CommandReader) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) StorageCommand(org.neo4j.storageengine.api.StorageCommand) StorageCommand(org.neo4j.storageengine.api.StorageCommand) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

Example 44 with StorageCommand

use of org.neo4j.storageengine.api.StorageCommand in project neo4j by neo4j.

the class LogCommandSerializationV4_0Test method readPropertyCommandWithNonRequiredSecondaryUnit.

@Test
void readPropertyCommandWithNonRequiredSecondaryUnit() throws IOException {
    InMemoryClosableChannel channel = new InMemoryClosableChannel();
    PropertyRecord before = new PropertyRecord(1);
    PropertyRecord after = new PropertyRecord(1);
    after.setSecondaryUnitIdOnCreate(78);
    new Command.PropertyCommand(writer(), before, after).serialize(channel);
    CommandReader reader = createReader();
    StorageCommand command = reader.read(channel);
    assertTrue(command instanceof Command.PropertyCommand);
    Command.PropertyCommand propertyCommand = (Command.PropertyCommand) command;
    // Then
    assertBeforeAndAfterEquals(propertyCommand, before, after);
}
Also used : CommandReader(org.neo4j.storageengine.api.CommandReader) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) StorageCommand(org.neo4j.storageengine.api.StorageCommand) StorageCommand(org.neo4j.storageengine.api.StorageCommand) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

Example 45 with StorageCommand

use of org.neo4j.storageengine.api.StorageCommand in project neo4j by neo4j.

the class LogCommandSerializationV4_3D_3Test method shouldReadRelationshipGroupExtendedCommandIncludingExternalDegrees.

@Test
void shouldReadRelationshipGroupExtendedCommandIncludingExternalDegrees() throws Throwable {
    // Given
    InMemoryClosableChannel channel = new InMemoryClosableChannel();
    RelationshipGroupRecord before = new RelationshipGroupRecord(42).initialize(false, 3, NULL_REF, NULL_REF, NULL_REF, NULL_REF, NULL_REF);
    RelationshipGroupRecord after = new RelationshipGroupRecord(42).initialize(true, (1 << Short.SIZE) + 10, 4, 5, 6, 7, 8);
    after.setHasExternalDegreesOut(random.nextBoolean());
    after.setHasExternalDegreesIn(random.nextBoolean());
    after.setHasExternalDegreesLoop(random.nextBoolean());
    after.setCreated();
    new Command.RelationshipGroupCommand(writer(), before, after).serialize(channel);
    // When
    CommandReader reader = createReader();
    StorageCommand command = reader.read(channel);
    assertTrue(command instanceof Command.RelationshipGroupCommand);
    Command.RelationshipGroupCommand relationshipGroupCommand = (Command.RelationshipGroupCommand) command;
    // Then
    assertBeforeAndAfterEquals(relationshipGroupCommand, before, after);
}
Also used : CommandReader(org.neo4j.storageengine.api.CommandReader) RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) StorageCommand(org.neo4j.storageengine.api.StorageCommand) StorageCommand(org.neo4j.storageengine.api.StorageCommand) Test(org.junit.jupiter.api.Test)

Aggregations

StorageCommand (org.neo4j.storageengine.api.StorageCommand)77 ArrayList (java.util.ArrayList)39 Test (org.junit.jupiter.api.Test)34 CommandReader (org.neo4j.storageengine.api.CommandReader)23 InMemoryClosableChannel (org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel)22 RepeatedTest (org.junit.jupiter.api.RepeatedTest)19 PhysicalTransactionRepresentation (org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)14 LongArrayList (org.eclipse.collections.impl.list.mutable.primitive.LongArrayList)10 Test (org.junit.Test)10 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)9 RelationshipGroupRecord (org.neo4j.kernel.impl.store.record.RelationshipGroupRecord)9 PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)8 Command (org.neo4j.kernel.impl.transaction.command.Command)7 NodeCommand (org.neo4j.kernel.impl.transaction.command.Command.NodeCommand)7 LogEntryCommand (org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand)7 SchemaRuleCommand (org.neo4j.internal.recordstorage.Command.SchemaRuleCommand)6 NeoStores (org.neo4j.kernel.impl.store.NeoStores)6 IOException (java.io.IOException)5 PropertyCommand (org.neo4j.internal.recordstorage.Command.PropertyCommand)5 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)5