Search in sources :

Example 71 with StorageCommand

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

the class NeoStoresTest method commitTx.

private void commitTx() throws Exception {
    try (CommandCreationContext commandCreationContext = storageEngine.newCommandCreationContext(INSTANCE)) {
        CursorContext cursorContext = NULL;
        commandCreationContext.initialize(cursorContext);
        List<StorageCommand> commands = new ArrayList<>();
        storageEngine.createCommands(commands, transactionState, storageReader, commandCreationContext, IGNORE, NONE, storageEngine.testAccessNeoStores().getMetaDataStore().getLastClosedTransactionId(), tx -> tx, cursorContext, INSTANCE);
        PhysicalTransactionRepresentation tx = new PhysicalTransactionRepresentation(commands);
        tx.setHeader(EMPTY_BYTE_ARRAY, -1, -1, -1, -1, AUTH_DISABLED);
        storageEngine.apply(new TransactionToApply(tx, cursorContext), INTERNAL);
    }
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) CommandCreationContext(org.neo4j.storageengine.api.CommandCreationContext) StorageCommand(org.neo4j.storageengine.api.StorageCommand) ArrayList(java.util.ArrayList) CursorContext(org.neo4j.io.pagecache.context.CursorContext) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)

Example 72 with StorageCommand

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

the class RecordStorageEngineTest method shouldCloseLockGroupAfterAppliers.

@Test
void shouldCloseLockGroupAfterAppliers() throws Exception {
    // given
    long nodeId = 5;
    LockService lockService = mock(LockService.class);
    Lock nodeLock = mock(Lock.class);
    when(lockService.acquireNodeLock(nodeId, EXCLUSIVE)).thenReturn(nodeLock);
    // <-- simply so that we can use InOrder mockito construct
    Consumer<Boolean> applierCloseCall = mock(Consumer.class);
    CapturingTransactionApplierFactoryChain applier = new CapturingTransactionApplierFactoryChain(applierCloseCall);
    RecordStorageEngine engine = recordStorageEngineBuilder().lockService(lockService).transactionApplierTransformer(applier::wrapAroundActualApplier).build();
    CommandsToApply commandsToApply = mock(CommandsToApply.class);
    when(commandsToApply.cursorContext()).thenReturn(NULL);
    when(commandsToApply.accept(any())).thenAnswer(invocationOnMock -> {
        // Visit one node command
        Visitor<StorageCommand, IOException> visitor = invocationOnMock.getArgument(0);
        NodeRecord after = new NodeRecord(nodeId);
        after.setInUse(true);
        visitor.visit(new Command.NodeCommand(new NodeRecord(nodeId), after));
        return null;
    });
    // when
    engine.apply(commandsToApply, TransactionApplicationMode.INTERNAL);
    // then
    InOrder inOrder = inOrder(lockService, applierCloseCall, nodeLock);
    inOrder.verify(lockService).acquireNodeLock(nodeId, EXCLUSIVE);
    inOrder.verify(applierCloseCall).accept(true);
    inOrder.verify(nodeLock).release();
    inOrder.verifyNoMoreInteractions();
}
Also used : InOrder(org.mockito.InOrder) LockService(org.neo4j.lock.LockService) StorageCommand(org.neo4j.storageengine.api.StorageCommand) IOException(java.io.IOException) Lock(org.neo4j.lock.Lock) CommandsToApply(org.neo4j.storageengine.api.CommandsToApply) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) StorageCommand(org.neo4j.storageengine.api.StorageCommand) Test(org.junit.jupiter.api.Test)

Example 73 with StorageCommand

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

the class TransactionRecordStateTest method deletingSchemaRuleMustAlsoDeletePropertyChain.

@Test
void deletingSchemaRuleMustAlsoDeletePropertyChain() 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);
    state.schemaRuleSetProperty(ruleId, 42, Values.booleanValue(true), rule);
    apply(state);
    state = newTransactionRecordState();
    state.schemaRuleDelete(ruleId, rule);
    List<StorageCommand> commands = new ArrayList<>();
    state.extractCommands(commands, INSTANCE);
    assertThat(commands.size()).isEqualTo(2);
    // Order matters. Rule deletes before property deletes.
    SchemaRuleCommand schemaCmd = (SchemaRuleCommand) commands.get(0);
    assertThat(schemaCmd.getKey()).isEqualTo(ruleId);
    assertThat(schemaCmd.getBefore().inUse()).isEqualTo(true);
    assertThat(schemaCmd.getAfter().inUse()).isEqualTo(false);
    PropertyCommand propCmd = (PropertyCommand) commands.get(1);
    assertThat(propCmd.getKey()).isEqualTo(schemaCmd.getBefore().getNextProp());
    assertThat(propCmd.getBefore().inUse()).isEqualTo(true);
    assertThat(propCmd.getAfter().inUse()).isEqualTo(false);
}
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) PropertyCommand(org.neo4j.internal.recordstorage.Command.PropertyCommand) Test(org.junit.jupiter.api.Test)

Example 74 with StorageCommand

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

the class TransactionRecordStateTest method shouldCreateProperBeforeAndAfterPropertyCommandsWhenAddingProperty.

@Test
void shouldCreateProperBeforeAndAfterPropertyCommandsWhenAddingProperty() throws Exception {
    neoStores = createStores();
    // GIVEN
    TransactionRecordState recordState = newTransactionRecordState();
    int nodeId = 1;
    recordState.nodeCreate(nodeId);
    // WHEN
    recordState.nodeAddProperty(nodeId, propertyId1, value1);
    Collection<StorageCommand> commands = new ArrayList<>();
    recordState.extractCommands(commands, INSTANCE);
    PropertyCommand propertyCommand = singlePropertyCommand(commands);
    // THEN
    PropertyRecord before = propertyCommand.getBefore();
    assertFalse(before.inUse());
    assertFalse(before.iterator().hasNext());
    PropertyRecord after = propertyCommand.getAfter();
    assertTrue(after.inUse());
    assertEquals(1, count(after));
}
Also used : PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) StorageCommand(org.neo4j.storageengine.api.StorageCommand) ArrayList(java.util.ArrayList) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) PropertyCommand(org.neo4j.internal.recordstorage.Command.PropertyCommand) Test(org.junit.jupiter.api.Test)

Example 75 with StorageCommand

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

the class TransactionRecordStateTest method settingSchemaRulePropertyMustUpdateSchemaRecordIfChainHeadChanges.

@Test
void settingSchemaRulePropertyMustUpdateSchemaRecordIfChainHeadChanges() 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);
    apply(state);
    state = newTransactionRecordState();
    state.schemaRuleSetProperty(ruleId, 42, Values.booleanValue(true), rule);
    List<StorageCommand> commands = new ArrayList<>();
    state.extractCommands(commands, INSTANCE);
    assertThat(commands.size()).isEqualTo(2);
    // Order matters. Props added before schema.
    PropertyCommand propCmd = (PropertyCommand) commands.get(0);
    assertThat(propCmd.getSchemaRuleId()).isEqualTo(ruleId);
    assertThat(propCmd.getBefore().inUse()).isEqualTo(false);
    assertThat(propCmd.getAfter().inUse()).isEqualTo(true);
    assertThat(propCmd.getAfter().isCreated()).isEqualTo(true);
    assertThat(propCmd.getAfter().getSchemaRuleId()).isEqualTo(ruleId);
    SchemaRuleCommand schemaCmd = (SchemaRuleCommand) commands.get(1);
    assertThat(schemaCmd.getSchemaRule()).isEqualTo(rule);
    assertThat(schemaCmd.getBefore().inUse()).isEqualTo(true);
    assertThat(schemaCmd.getBefore().getNextProp()).isEqualTo(Record.NO_NEXT_PROPERTY.longValue());
    assertThat(schemaCmd.getAfter().inUse()).isEqualTo(true);
    assertThat(schemaCmd.getAfter().isCreated()).isEqualTo(false);
    assertThat(schemaCmd.getAfter().getNextProp()).isEqualTo(propCmd.getKey());
    apply(transaction(commands));
    state = newTransactionRecordState();
    state.schemaRuleSetProperty(ruleId, 42, Values.booleanValue(false), rule);
    commands.clear();
    state.extractCommands(commands, INSTANCE);
    assertThat(commands.size()).isEqualTo(1);
    propCmd = (PropertyCommand) commands.get(0);
    assertThat(propCmd.getSchemaRuleId()).isEqualTo(ruleId);
    assertThat(propCmd.getBefore().inUse()).isEqualTo(true);
    assertThat(propCmd.getAfter().inUse()).isEqualTo(true);
    assertThat(propCmd.getAfter().isCreated()).isEqualTo(false);
}
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) PropertyCommand(org.neo4j.internal.recordstorage.Command.PropertyCommand) 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