Search in sources :

Example 21 with LogFiles

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

the class RecoveryHelpers method removeLastCheckpointRecordFromLastLogFile.

public static void removeLastCheckpointRecordFromLastLogFile(DatabaseLayout dbLayout, FileSystemAbstraction fs) throws IOException {
    LogFiles logFiles = buildLogFiles(dbLayout, fs);
    var checkpointFile = logFiles.getCheckpointFile();
    Optional<CheckpointInfo> latestCheckpoint = checkpointFile.findLatestCheckpoint();
    latestCheckpoint.ifPresent(checkpointInfo -> {
        LogPosition entryPosition = checkpointInfo.getCheckpointEntryPosition();
        try (StoreChannel storeChannel = fs.write(checkpointFile.getCurrentFile())) {
            storeChannel.truncate(entryPosition.getByteOffset());
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    });
}
Also used : StoreChannel(org.neo4j.io.fs.StoreChannel) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) CheckpointInfo(org.neo4j.kernel.impl.transaction.log.files.checkpoint.CheckpointInfo) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

Example 22 with LogFiles

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

the class RecoveryRequiredChecker method isRecoveryRequiredAt.

public boolean isRecoveryRequiredAt(DatabaseLayout databaseLayout, MemoryTracker memoryTracker) throws IOException {
    LogEntryReader reader = new VersionAwareLogEntryReader(storageEngineFactory.commandReaderFactory());
    LogFiles logFiles = buildLogFiles(databaseLayout, reader, memoryTracker);
    return isRecoveryRequiredAt(databaseLayout, logFiles);
}
Also used : LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) LogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.LogEntryReader) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader)

Example 23 with LogFiles

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

the class TransactionLogsInSeparateLocationIT method verifyTransactionLogs.

private void verifyTransactionLogs(Path txDirectory, Path storeDir, StorageEngineFactory storageEngineFactory) throws IOException {
    LogFiles storeDirLogs = LogFilesBuilder.logFilesBasedOnlyBuilder(storeDir, fileSystem).withCommandReaderFactory(storageEngineFactory.commandReaderFactory()).build();
    assertFalse(storeDirLogs.getLogFile().versionExists(0));
    LogFiles txDirectoryLogs = LogFilesBuilder.logFilesBasedOnlyBuilder(txDirectory, fileSystem).withCommandReaderFactory(storageEngineFactory.commandReaderFactory()).build();
    assertTrue(txDirectoryLogs.getLogFile().versionExists(0));
    try (PhysicalLogVersionedStoreChannel physicalLogVersionedStoreChannel = txDirectoryLogs.getLogFile().openForVersion(0)) {
        assertThat(physicalLogVersionedStoreChannel.size()).isGreaterThan(0L);
    }
}
Also used : LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel)

Example 24 with LogFiles

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

the class RecoveryIT method removeFileWithCheckpoint.

private void removeFileWithCheckpoint() throws IOException {
    LogFiles logFiles = buildLogFiles();
    fileSystem.deleteFileOrThrow(logFiles.getCheckpointFile().getCurrentFile());
}
Also used : LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles)

Example 25 with LogFiles

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

the class RecoveryIT method failToStartDatabaseWithTransactionLogsInLegacyLocation.

@Test
void failToStartDatabaseWithTransactionLogsInLegacyLocation() throws Exception {
    GraphDatabaseAPI database = createDatabase();
    generateSomeData(database);
    managementService.shutdown();
    LogFiles logFiles = buildLogFiles();
    Path[] txLogFiles = fileSystem.listFiles(logFiles.logFilesDirectory(), path -> path.getFileName().toString().startsWith(DEFAULT_NAME));
    txLogFiles = ArrayUtil.concat(txLogFiles, logFiles.getCheckpointFile().getDetachedCheckpointFiles());
    Path databasesDirectory = databaseLayout.getNeo4jLayout().databasesDirectory();
    DatabaseLayout legacyLayout = Neo4jLayout.ofFlat(databasesDirectory).databaseLayout(databaseLayout.getDatabaseName());
    LegacyTransactionLogsLocator logsLocator = new LegacyTransactionLogsLocator(Config.defaults(), legacyLayout);
    Path transactionLogsDirectory = logsLocator.getTransactionLogsDirectory();
    assertNotNull(txLogFiles);
    assertTrue(txLogFiles.length > 0);
    for (Path logFile : txLogFiles) {
        fileSystem.moveToDirectory(logFile, transactionLogsDirectory);
    }
    AssertableLogProvider logProvider = new AssertableLogProvider();
    builder.setInternalLogProvider(logProvider);
    GraphDatabaseAPI restartedDb = createDatabase();
    try {
        DatabaseStateService dbStateService = restartedDb.getDependencyResolver().resolveDependency(DatabaseStateService.class);
        var failure = dbStateService.causeOfFailure(restartedDb.databaseId());
        assertTrue(failure.isPresent());
        assertThat(failure.get()).hasRootCauseMessage("Transaction logs are missing and recovery is not possible.");
        assertThat(logProvider.serialize()).contains(txLogFiles[0].getFileName().toString());
    } finally {
        managementService.shutdown();
    }
}
Also used : Path(java.nio.file.Path) LegacyTransactionLogsLocator(org.neo4j.kernel.impl.storemigration.LegacyTransactionLogsLocator) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) DatabaseStateService(org.neo4j.dbms.DatabaseStateService) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.jupiter.api.Test)

Aggregations

LogFiles (org.neo4j.kernel.impl.transaction.log.files.LogFiles)61 Test (org.junit.jupiter.api.Test)33 LogFile (org.neo4j.kernel.impl.transaction.log.files.LogFile)21 SimpleTransactionIdStore (org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore)16 Path (java.nio.file.Path)13 IOException (java.io.IOException)10 SimpleLogVersionRepository (org.neo4j.kernel.impl.transaction.SimpleLogVersionRepository)10 LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)9 VersionAwareLogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader)9 Lifespan (org.neo4j.kernel.lifecycle.Lifespan)8 TransactionIdStore (org.neo4j.storageengine.api.TransactionIdStore)8 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)7 StoreChannel (org.neo4j.io.fs.StoreChannel)7 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)7 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)7 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 IndexingService (org.neo4j.kernel.impl.api.index.IndexingService)4 LogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.LogEntryReader)4 UncheckedIOException (java.io.UncheckedIOException)3