Search in sources :

Example 6 with SimpleTransactionIdStore

use of org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore in project neo4j by neo4j.

the class LogPruningIT method pruningStrategyShouldBeDynamic.

@Test
void pruningStrategyShouldBeDynamic() throws IOException {
    LogFiles logFiles = LogFilesBuilder.builder(db.databaseLayout(), fs).withLogVersionRepository(new SimpleLogVersionRepository()).withLastCommittedTransactionIdSupplier(() -> 1).withCommandReaderFactory(db.getDependencyResolver().resolveDependency(StorageEngineFactory.class).commandReaderFactory()).withTransactionIdStore(new SimpleTransactionIdStore()).build();
    // Force transaction log rotation
    writeTransactionsAndRotateTwice();
    // Checkpoint to make sure strategy is evaluated
    checkPointer.forceCheckPoint(triggerInfo);
    // Make sure file is still there since we have disable pruning. 3 transaction logs and 1 separate checkpoint file.
    assertThat(countTransactionLogs(logFiles)).isEqualTo(4);
    // Change pruning to true
    config.setDynamic(keep_logical_logs, FALSE, "LogPruningIT");
    // Checkpoint to make sure strategy is evaluated
    checkPointer.forceCheckPoint(triggerInfo);
    // Make sure file is removed
    assertThat(countTransactionLogs(logFiles)).isEqualTo(3);
}
Also used : SimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) SimpleLogVersionRepository(org.neo4j.kernel.impl.transaction.SimpleLogVersionRepository) Test(org.junit.jupiter.api.Test)

Example 7 with SimpleTransactionIdStore

use of org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore in project neo4j by neo4j.

the class Runner method call.

@Override
public Long call() throws Exception {
    long lastCommittedTransactionId;
    try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
        Lifespan life = new Lifespan()) {
        TransactionIdStore transactionIdStore = new SimpleTransactionIdStore();
        TransactionMetadataCache transactionMetadataCache = new TransactionMetadataCache();
        LogFiles logFiles = life.add(createLogFiles(transactionIdStore, fileSystem));
        TransactionAppender transactionAppender = life.add(createBatchingTransactionAppender(transactionIdStore, transactionMetadataCache, logFiles));
        ExecutorService executorService = Executors.newFixedThreadPool(threads);
        try {
            List<Future<?>> handlers = new ArrayList<>(threads);
            for (int i = 0; i < threads; i++) {
                TransactionRepresentationFactory factory = new TransactionRepresentationFactory();
                Worker task = new Worker(transactionAppender, factory, condition);
                handlers.add(executorService.submit(task));
            }
            // wait for all the workers to complete
            Futures.getAll(handlers);
        } finally {
            executorService.shutdown();
        }
        lastCommittedTransactionId = transactionIdStore.getLastCommittedTransactionId();
    }
    return lastCommittedTransactionId;
}
Also used : DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) TransactionIdStore(org.neo4j.storageengine.api.TransactionIdStore) SimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore) SimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore) TransactionAppender(org.neo4j.kernel.impl.transaction.log.TransactionAppender) BatchingTransactionAppender(org.neo4j.kernel.impl.transaction.log.BatchingTransactionAppender) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) ArrayList(java.util.ArrayList) TransactionMetadataCache(org.neo4j.kernel.impl.transaction.log.TransactionMetadataCache) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) Lifespan(org.neo4j.kernel.lifecycle.Lifespan)

Example 8 with SimpleTransactionIdStore

use of org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore in project neo4j by neo4j.

the class DumpCommandIT method databaseThatRequireRecoveryIsNotDumpable.

@Test
void databaseThatRequireRecoveryIsNotDumpable() throws IOException {
    LogFiles logFiles = LogFilesBuilder.builder(databaseLayout, testDirectory.getFileSystem()).withLogVersionRepository(new SimpleLogVersionRepository()).withTransactionIdStore(new SimpleTransactionIdStore()).withCommandReaderFactory(StorageEngineFactory.defaultStorageEngine().commandReaderFactory()).withStoreId(StoreId.UNKNOWN).build();
    try (Lifespan ignored = new Lifespan(logFiles)) {
        LogFile logFile = logFiles.getLogFile();
        LogEntryWriter writer = logFile.getTransactionLogWriter().getWriter();
        writer.writeStartEntry(0x123456789ABCDEFL, logFile.getLogFileInformation().getLastEntryId() + 1, BASE_TX_CHECKSUM, new byte[] { 0 });
    }
    CommandFailedException commandFailed = assertThrows(CommandFailedException.class, () -> execute("foo"));
    assertThat(commandFailed.getMessage()).startsWith("Active logical log detected, this might be a source of inconsistencies.");
}
Also used : LogFile(org.neo4j.kernel.impl.transaction.log.files.LogFile) SimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) SimpleLogVersionRepository(org.neo4j.kernel.impl.transaction.SimpleLogVersionRepository) LogEntryWriter(org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) CommandFailedException(org.neo4j.cli.CommandFailedException) Test(org.junit.jupiter.api.Test)

Example 9 with SimpleTransactionIdStore

use of org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore 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 10 with SimpleTransactionIdStore

use of org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore in project neo4j by neo4j.

the class VersionAwareLogEntryReaderIT method correctlyResetPositionWhenEndOfCommandsReached.

@Test
void correctlyResetPositionWhenEndOfCommandsReached() throws IOException {
    LogFiles logFiles = LogFilesBuilder.builder(databaseLayout, fs).withLogEntryReader(entryReader).withLogVersionRepository(new SimpleLogVersionRepository()).withTransactionIdStore(new SimpleTransactionIdStore()).withStoreId(StoreId.UNKNOWN).build();
    try (Lifespan lifespan = new Lifespan(logFiles)) {
        LogPosition logPosition = entryReader.lastPosition();
        assertEquals(0L, logPosition.getLogVersion());
        // this position in a log file before 0's are actually starting
        assertEquals(END_OF_DATA_OFFSET, logPosition.getByteOffset());
        for (int i = 0; i < 10; i++) {
            assertEquals(END_OF_DATA_OFFSET, getLastReadablePosition(logFiles));
        }
    }
}
Also used : SimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) SimpleLogVersionRepository(org.neo4j.kernel.impl.transaction.SimpleLogVersionRepository) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) Test(org.junit.jupiter.api.Test)

Aggregations

SimpleTransactionIdStore (org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore)23 Test (org.junit.jupiter.api.Test)17 SimpleLogVersionRepository (org.neo4j.kernel.impl.transaction.SimpleLogVersionRepository)17 LogFiles (org.neo4j.kernel.impl.transaction.log.files.LogFiles)14 Lifespan (org.neo4j.kernel.lifecycle.Lifespan)7 TransactionIdStore (org.neo4j.storageengine.api.TransactionIdStore)6 LogFile (org.neo4j.kernel.impl.transaction.log.files.LogFile)5 LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)4 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 LogVersionRepository (org.neo4j.storageengine.api.LogVersionRepository)3 ArrayList (java.util.ArrayList)2 Config (org.neo4j.configuration.Config)2 TestCommandReaderFactory (org.neo4j.kernel.impl.api.TestCommandReaderFactory)2 TransactionLogWriter (org.neo4j.kernel.impl.transaction.log.TransactionLogWriter)2 VersionAwareLogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader)2 DatabaseHealth (org.neo4j.monitoring.DatabaseHealth)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1