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);
}
});
}
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);
}
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);
}
}
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());
}
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();
}
}
Aggregations