Search in sources :

Example 41 with PhysicalTransactionRepresentation

use of org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation in project neo4j by neo4j.

the class PhysicalTransactionCursorTest method shouldCallTheVisitorWithTheFoundTransaction.

@Test
void shouldCallTheVisitorWithTheFoundTransaction() throws IOException {
    // given
    when(entryReader.readLogEntry(channel)).thenReturn(A_START_ENTRY, A_COMMAND_ENTRY, A_COMMIT_ENTRY);
    // when
    cursor.next();
    // then
    PhysicalTransactionRepresentation txRepresentation = new PhysicalTransactionRepresentation(singletonList(A_COMMAND_ENTRY.getCommand()));
    assertEquals(new CommittedTransactionRepresentation(A_START_ENTRY, txRepresentation, A_COMMIT_ENTRY), cursor.get());
}
Also used : PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) Test(org.junit.jupiter.api.Test)

Example 42 with PhysicalTransactionRepresentation

use of org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation 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 43 with PhysicalTransactionRepresentation

use of org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation in project neo4j by neo4j.

the class IndexWorkSyncTransactionApplicationStressIT method tx.

private static TransactionToApply tx(List<StorageCommand> commands) {
    PhysicalTransactionRepresentation txRepresentation = new PhysicalTransactionRepresentation(commands, new byte[0], -1, -1, -1, -1, ANONYMOUS);
    TransactionToApply tx = new TransactionToApply(txRepresentation, NULL);
    tx.commitment(NO_COMMITMENT, 0);
    return tx;
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)

Example 44 with PhysicalTransactionRepresentation

use of org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation in project neo4j by neo4j.

the class BatchingNeoStoresTest method apply.

private static void apply(TxState txState, CommandCreationContext commandCreationContext, RecordStorageEngine storageEngine) throws Exception {
    List<StorageCommand> commands = new ArrayList<>();
    try (RecordStorageReader storageReader = storageEngine.newReader()) {
        storageEngine.createCommands(commands, txState, storageReader, commandCreationContext, ResourceLocker.IGNORE, LockTracer.NONE, BASE_TX_ID, v -> v, NULL, INSTANCE);
        CommandsToApply apply = new TransactionToApply(new PhysicalTransactionRepresentation(commands, new byte[0], 0, 0, 0, 0, ANONYMOUS), NULL);
        storageEngine.apply(apply, TransactionApplicationMode.INTERNAL);
    }
}
Also used : CommandsToApply(org.neo4j.storageengine.api.CommandsToApply) TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) RecordStorageReader(org.neo4j.internal.recordstorage.RecordStorageReader) StorageCommand(org.neo4j.storageengine.api.StorageCommand) ArrayList(java.util.ArrayList) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)

Example 45 with PhysicalTransactionRepresentation

use of org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation in project neo4j by neo4j.

the class CommitProcessTracingIT method tracePageCacheAccessOnTransactionApply.

@Test
void tracePageCacheAccessOnTransactionApply() throws TransactionFailureException {
    var transaction = new PhysicalTransactionRepresentation(List.of(new Command.NodeCountsCommand(1, 2)), EMPTY_BYTE_ARRAY, 0, 0, 0, 0, ANONYMOUS);
    var pageCacheTracer = new DefaultPageCacheTracer();
    try (var cursorContext = new CursorContext(pageCacheTracer.createPageCursorTracer("tracePageCacheAccessOnTransactionApply"))) {
        assertZeroCursor(cursorContext);
        commitProcess.commit(new TransactionToApply(transaction, cursorContext), NULL, EXTERNAL);
        assertCursor(cursorContext, 3);
    }
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) CursorContext(org.neo4j.io.pagecache.context.CursorContext) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer) Test(org.junit.jupiter.api.Test)

Aggregations

PhysicalTransactionRepresentation (org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)49 StorageCommand (org.neo4j.storageengine.api.StorageCommand)14 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)12 TransactionToApply (org.neo4j.kernel.impl.api.TransactionToApply)11 TransactionRepresentation (org.neo4j.kernel.impl.transaction.TransactionRepresentation)6 LogEntryCommand (org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand)6 Test (org.junit.jupiter.api.Test)5 LogEntryStart (org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart)5 CursorContext (org.neo4j.io.pagecache.context.CursorContext)4 LogEntry (org.neo4j.kernel.impl.transaction.log.entry.LogEntry)4 LogEntryCommit (org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit)4 ByteBuf (io.netty.buffer.ByteBuf)3 NetworkFlushableByteBuf (org.neo4j.causalclustering.messaging.NetworkFlushableByteBuf)3 NeoStores (org.neo4j.kernel.impl.store.NeoStores)3 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)3 CommittedTransactionRepresentation (org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation)3 Command (org.neo4j.kernel.impl.transaction.command.Command)3 LogEntryWriter (org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter)3 ReplicatedTransaction (org.neo4j.causalclustering.core.state.machines.tx.ReplicatedTransaction)2