Search in sources :

Example 6 with TransactionLogWriter

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

the class ReversedSingleFileTransactionCursorTest method writeTransactions.

private void writeTransactions(int transactionCount, int minTransactionSize, int maxTransactionSize) throws IOException {
    FlushablePositionAwareChecksumChannel channel = logFile.getTransactionLogWriter().getChannel();
    TransactionLogWriter writer = logFile.getTransactionLogWriter();
    int previousChecksum = BASE_TX_CHECKSUM;
    for (int i = 0; i < transactionCount; i++) {
        previousChecksum = writer.append(tx(random.intBetween(minTransactionSize, maxTransactionSize)), ++txId, previousChecksum);
    }
    channel.prepareForFlush().flush();
// Don't close the channel, LogFile owns it
}
Also used : FlushablePositionAwareChecksumChannel(org.neo4j.kernel.impl.transaction.log.FlushablePositionAwareChecksumChannel) TransactionLogWriter(org.neo4j.kernel.impl.transaction.log.TransactionLogWriter)

Example 7 with TransactionLogWriter

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

the class CheckTxLogsTest method writeContent.

private void writeContent(File log, ThrowingConsumer<TransactionLogWriter, IOException> consumer) throws IOException {
    FileSystemAbstraction fs = ensureLogExists(log);
    try (StoreChannel channel = fs.open(log, "rw");
        LogVersionedStoreChannel versionedChannel = new PhysicalLogVersionedStoreChannel(channel, 0, (byte) 0);
        PhysicalFlushableChannel writableLogChannel = new PhysicalFlushableChannel(versionedChannel)) {
        long offset = channel.size();
        channel.position(offset);
        consumer.accept(new TransactionLogWriter(new LogEntryWriter(writableLogChannel)));
    }
}
Also used : FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) LogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) PhysicalFlushableChannel(org.neo4j.kernel.impl.transaction.log.PhysicalFlushableChannel) LogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel) StoreChannel(org.neo4j.io.fs.StoreChannel) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) TransactionLogWriter(org.neo4j.kernel.impl.transaction.log.TransactionLogWriter) LogEntryWriter(org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter)

Example 8 with TransactionLogWriter

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

the class CoreBootstrapper method appendNullTransactionLogEntryToSetRaftIndexToMinusOne.

private void appendNullTransactionLogEntryToSetRaftIndexToMinusOne() throws IOException {
    PhysicalLogFiles logFiles = new PhysicalLogFiles(storeDir, fs);
    ReadOnlyLogVersionRepository logVersionRepository = new ReadOnlyLogVersionRepository(pageCache, storeDir);
    ReadOnlyTransactionIdStore readOnlyTransactionIdStore = new ReadOnlyTransactionIdStore(pageCache, storeDir);
    PhysicalLogFile logFile = new PhysicalLogFile(fs, logFiles, Long.MAX_VALUE, /*don't rotate*/
    () -> readOnlyTransactionIdStore.getLastClosedTransactionId() - 1, logVersionRepository, new Monitors().newMonitor(PhysicalLogFile.Monitor.class), new LogHeaderCache(10));
    long dummyTransactionId;
    try (Lifespan lifespan = new Lifespan(logFile)) {
        FlushableChannel channel = logFile.getWriter();
        TransactionLogWriter writer = new TransactionLogWriter(new LogEntryWriter(channel));
        long lastCommittedTransactionId = readOnlyTransactionIdStore.getLastCommittedTransactionId();
        PhysicalTransactionRepresentation tx = new PhysicalTransactionRepresentation(Collections.emptyList());
        byte[] txHeaderBytes = LogIndexTxHeaderEncoding.encodeLogIndexAsTxHeader(-1);
        tx.setHeader(txHeaderBytes, -1, -1, -1, lastCommittedTransactionId, -1, -1);
        dummyTransactionId = lastCommittedTransactionId + 1;
        writer.append(tx, dummyTransactionId);
        channel.prepareForFlush().flush();
    }
    File neoStoreFile = new File(storeDir, MetaDataStore.DEFAULT_NAME);
    MetaDataStore.setRecord(pageCache, neoStoreFile, LAST_TRANSACTION_ID, dummyTransactionId);
}
Also used : PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles) ReadOnlyTransactionIdStore(org.neo4j.kernel.impl.transaction.log.ReadOnlyTransactionIdStore) FlushableChannel(org.neo4j.kernel.impl.transaction.log.FlushableChannel) Monitors(org.neo4j.kernel.monitoring.Monitors) TransactionLogWriter(org.neo4j.kernel.impl.transaction.log.TransactionLogWriter) LogEntryWriter(org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter) ReadOnlyLogVersionRepository(org.neo4j.kernel.impl.transaction.log.ReadOnlyLogVersionRepository) LogHeaderCache(org.neo4j.kernel.impl.transaction.log.LogHeaderCache) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) PhysicalLogFile(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile) File(java.io.File) PhysicalLogFile(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)

Example 9 with TransactionLogWriter

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

the class TransactionRecordStateTest method writeToChannel.

private void writeToChannel(TransactionRepresentation transaction, FlushableChannel channel) throws IOException {
    TransactionLogWriter writer = new TransactionLogWriter(new LogEntryWriter(channel));
    writer.append(transaction, 2);
}
Also used : TransactionLogWriter(org.neo4j.kernel.impl.transaction.log.TransactionLogWriter) LogEntryWriter(org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter)

Example 10 with TransactionLogWriter

use of org.neo4j.kernel.impl.transaction.log.TransactionLogWriter 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)

Aggregations

TransactionLogWriter (org.neo4j.kernel.impl.transaction.log.TransactionLogWriter)12 LogEntryWriter (org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter)6 LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)5 File (java.io.File)3 StoreChannel (org.neo4j.io.fs.StoreChannel)3 SimpleTransactionIdStore (org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore)3 PhysicalTransactionRepresentation (org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)3 LogFile (org.neo4j.kernel.impl.transaction.log.files.LogFile)3 LogFiles (org.neo4j.kernel.impl.transaction.log.files.LogFiles)3 Lifespan (org.neo4j.kernel.lifecycle.Lifespan)3 IOException (java.io.IOException)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 Test (org.junit.jupiter.api.Test)2 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)2 SimpleLogVersionRepository (org.neo4j.kernel.impl.transaction.SimpleLogVersionRepository)2 FlushableChannel (org.neo4j.kernel.impl.transaction.log.FlushableChannel)2 FlushablePositionAwareChecksumChannel (org.neo4j.kernel.impl.transaction.log.FlushablePositionAwareChecksumChannel)2 LogHeaderCache (org.neo4j.kernel.impl.transaction.log.LogHeaderCache)2 PhysicalLogFile (org.neo4j.kernel.impl.transaction.log.PhysicalLogFile)2 PhysicalLogFiles (org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles)2