Search in sources :

Example 56 with StorageCommand

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

the class TransactionRecordStateTest method transactionRepresentationOf.

private PhysicalTransactionRepresentation transactionRepresentationOf(TransactionRecordState writeTransaction) throws TransactionFailureException {
    List<StorageCommand> commands = new ArrayList<>();
    writeTransaction.extractCommands(commands);
    PhysicalTransactionRepresentation tx = new PhysicalTransactionRepresentation(commands);
    tx.setHeader(new byte[0], 0, 0, 0, 0, 0, 0);
    return tx;
}
Also used : StorageCommand(org.neo4j.storageengine.api.StorageCommand) ArrayList(java.util.ArrayList) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)

Example 57 with StorageCommand

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

the class KernelTransactionImplementationTest method shouldUseStartTimeAndTxIdFromWhenStartingTxAsHeader.

@SuppressWarnings("unchecked")
@Test
public void shouldUseStartTimeAndTxIdFromWhenStartingTxAsHeader() throws Exception {
    // GIVEN a transaction starting at one point in time
    long startingTime = clock.millis();
    when(legacyIndexState.hasChanges()).thenReturn(true);
    doAnswer(invocation -> {
        @SuppressWarnings("unchecked") Collection<StorageCommand> commands = invocation.getArgumentAt(0, Collection.class);
        commands.add(mock(Command.class));
        return null;
    }).when(storageEngine).createCommands(any(Collection.class), any(TransactionState.class), any(StorageStatement.class), any(ResourceLocker.class), anyLong());
    try (KernelTransactionImplementation transaction = newTransaction(securityContext())) {
        SimpleStatementLocks statementLocks = new SimpleStatementLocks(mock(Locks.Client.class));
        transaction.initialize(5L, BASE_TX_COMMIT_TIMESTAMP, statementLocks, KernelTransaction.Type.implicit, AUTH_DISABLED, 0L);
        try (KernelStatement statement = transaction.acquireStatement()) {
            // which will pull it from the supplier and the mocking above
            statement.legacyIndexTxState();
        // will have it say that it has changes.
        }
        // WHEN committing it at a later point
        clock.forward(5, MILLISECONDS);
        // ...and simulating some other transaction being committed
        when(metaDataStore.getLastCommittedTransactionId()).thenReturn(7L);
        transaction.success();
    }
    // THEN start time and last tx when started should have been taken from when the transaction started
    assertEquals(5L, commitProcess.transaction.getLatestCommittedTxWhenStarted());
    assertEquals(startingTime, commitProcess.transaction.getTimeStarted());
    assertEquals(startingTime + 5, commitProcess.transaction.getTimeCommitted());
}
Also used : TransactionState(org.neo4j.kernel.api.txstate.TransactionState) StorageStatement(org.neo4j.storageengine.api.StorageStatement) StorageCommand(org.neo4j.storageengine.api.StorageCommand) ResourceLocker(org.neo4j.storageengine.api.lock.ResourceLocker) StorageCommand(org.neo4j.storageengine.api.StorageCommand) Command(org.neo4j.kernel.impl.transaction.command.Command) Collection(java.util.Collection) SimpleStatementLocks(org.neo4j.kernel.impl.locking.SimpleStatementLocks) NoOpClient(org.neo4j.kernel.impl.locking.NoOpClient) Test(org.junit.Test)

Example 58 with StorageCommand

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

the class RecoveryCorruptedTransactionLogIT method addCorruptedCommandsToLastLogFile.

private void addCorruptedCommandsToLastLogFile(LogEntryWriterWrapper logEntryWriterWrapper) throws IOException {
    PositiveLogFilesBasedLogVersionRepository versionRepository = new PositiveLogFilesBasedLogVersionRepository(logFiles);
    LogFiles internalLogFiles = LogFilesBuilder.builder(databaseLayout, fileSystem).withLogVersionRepository(versionRepository).withTransactionIdStore(new SimpleTransactionIdStore()).withStoreId(StoreId.UNKNOWN).withCommandReaderFactory(StorageEngineFactory.defaultStorageEngine().commandReaderFactory()).build();
    try (Lifespan lifespan = new Lifespan(internalLogFiles)) {
        LogFile transactionLogFile = internalLogFiles.getLogFile();
        LogEntryWriter<FlushablePositionAwareChecksumChannel> realLogEntryWriter = transactionLogFile.getTransactionLogWriter().getWriter();
        LogEntryWriter<FlushablePositionAwareChecksumChannel> wrappedLogEntryWriter = logEntryWriterWrapper.wrap(realLogEntryWriter);
        StaticLogEntryWriterFactory<FlushablePositionAwareChecksumChannel> factory = new StaticLogEntryWriterFactory<>(wrappedLogEntryWriter);
        TransactionLogWriter writer = new TransactionLogWriter(realLogEntryWriter.getChannel(), factory);
        List<StorageCommand> commands = new ArrayList<>();
        commands.add(new Command.PropertyCommand(new PropertyRecord(1), new PropertyRecord(2)));
        commands.add(new Command.NodeCommand(new NodeRecord(2), new NodeRecord(3)));
        PhysicalTransactionRepresentation transaction = new PhysicalTransactionRepresentation(commands);
        transaction.setHeader(new byte[0], 0, 0, 0, 0, ANONYMOUS);
        writer.append(transaction, 1000, BASE_TX_CHECKSUM);
    }
}
Also used : SimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore) StorageCommand(org.neo4j.storageengine.api.StorageCommand) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) ArrayList(java.util.ArrayList) FlushablePositionAwareChecksumChannel(org.neo4j.kernel.impl.transaction.log.FlushablePositionAwareChecksumChannel) LogFile(org.neo4j.kernel.impl.transaction.log.files.LogFile) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) Command(org.neo4j.internal.recordstorage.Command) StorageCommand(org.neo4j.storageengine.api.StorageCommand) TransactionLogWriter(org.neo4j.kernel.impl.transaction.log.TransactionLogWriter) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)

Example 59 with StorageCommand

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

the class KernelTransactionsTest method newKernelTransactions.

private KernelTransactions newKernelTransactions(boolean testKernelTransactions, TransactionCommitProcess commitProcess, StorageReader firstReader, Config config, StorageReader... otherReaders) throws Throwable {
    Locks locks = mock(Locks.class);
    Locks.Client client = mock(Locks.Client.class);
    when(locks.newClient()).thenReturn(client);
    StorageEngine storageEngine = mock(StorageEngine.class);
    when(storageEngine.newReader()).thenReturn(firstReader, otherReaders);
    when(storageEngine.newCommandCreationContext(any())).thenReturn(mock(CommandCreationContext.class));
    doAnswer(invocation -> {
        Collection<StorageCommand> argument = invocation.getArgument(0);
        argument.add(mock(StorageCommand.class));
        return null;
    }).when(storageEngine).createCommands(anyCollection(), any(ReadableTransactionState.class), any(StorageReader.class), any(CommandCreationContext.class), any(ResourceLocker.class), any(LockTracer.class), anyLong(), any(TxStateVisitor.Decorator.class), any(CursorContext.class), any(MemoryTracker.class));
    return newKernelTransactions(locks, storageEngine, commitProcess, testKernelTransactions, config);
}
Also used : StorageReader(org.neo4j.storageengine.api.StorageReader) StorageCommand(org.neo4j.storageengine.api.StorageCommand) ResourceLocker(org.neo4j.lock.ResourceLocker) ReadableTransactionState(org.neo4j.storageengine.api.txstate.ReadableTransactionState) Locks(org.neo4j.kernel.impl.locking.Locks) LockTracer(org.neo4j.lock.LockTracer) CursorContext(org.neo4j.io.pagecache.context.CursorContext) StorageEngine(org.neo4j.storageengine.api.StorageEngine) MemoryTracker(org.neo4j.memory.MemoryTracker) CommandCreationContext(org.neo4j.storageengine.api.CommandCreationContext)

Example 60 with StorageCommand

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

the class LogCommandSerializationV4_3D_3Test method shouldReadAndWriteMetaDataCommand.

@Test
void shouldReadAndWriteMetaDataCommand() throws IOException {
    // Given
    InMemoryClosableChannel channel = new InMemoryClosableChannel();
    MetaDataRecord before = new MetaDataRecord(12);
    MetaDataRecord after = new MetaDataRecord(12);
    after.initialize(true, 999);
    new Command.MetaDataCommand(writer(), before, after).serialize(channel);
    // When
    CommandReader reader = createReader();
    StorageCommand command = reader.read(channel);
    assertTrue(command instanceof Command.MetaDataCommand);
    Command.MetaDataCommand readCommand = (Command.MetaDataCommand) command;
    // Then
    assertBeforeAndAfterEquals(readCommand, before, after);
}
Also used : CommandReader(org.neo4j.storageengine.api.CommandReader) InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) StorageCommand(org.neo4j.storageengine.api.StorageCommand) StorageCommand(org.neo4j.storageengine.api.StorageCommand) MetaDataRecord(org.neo4j.kernel.impl.store.record.MetaDataRecord) 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