use of org.neo4j.storageengine.api.CommandReaderFactory in project neo4j by neo4j.
the class LogsUpgrader method upgrade.
public void upgrade(DatabaseLayout layout) {
CommandReaderFactory commandReaderFactory = storageEngineFactory.commandReaderFactory();
try (MetadataProvider store = getMetaDataStore()) {
TransactionLogInitializer logInitializer = new TransactionLogInitializer(fs, store, commandReaderFactory, tracer);
Path transactionLogsDirectory = layout.getTransactionLogsDirectory();
Path legacyLogsDirectory = legacyLogsLocator.getTransactionLogsDirectory();
boolean filesNeedsToMove = !transactionLogsDirectory.equals(legacyLogsDirectory);
LogFiles logFiles = LogFilesBuilder.logFilesBasedOnlyBuilder(legacyLogsDirectory, fs).withCommandReaderFactory(commandReaderFactory).build();
// Move log files to their intended directory, if they are not there already.
Path[] legacyFiles = logFiles.logFiles();
if (legacyFiles != null && legacyFiles.length > 0) {
if (filesNeedsToMove) {
for (Path legacyFile : legacyFiles) {
fs.copyFile(legacyFile, transactionLogsDirectory.resolve(legacyFile.getFileName()), EMPTY_COPY_OPTIONS);
}
}
logInitializer.initializeExistingLogFiles(layout, transactionLogsDirectory, UPGRADE_CHECKPOINT);
if (filesNeedsToMove) {
for (Path legacyFile : legacyFiles) {
fs.deleteFile(legacyFile);
}
}
} else {
// We didn't find any files in the legacy location.
// If the legacy location is the same as the intended location, then the log files are missing entirely.
// Otherwise, we will have to check if the log files are already present in the intended location and try to initialize them there.
logFiles = LogFilesBuilder.logFilesBasedOnlyBuilder(transactionLogsDirectory, fs).build();
legacyFiles = logFiles.logFiles();
if (legacyFiles != null && legacyFiles.length > 0) {
// The log files are already at their intended location, so initialize them there.
logInitializer.initializeExistingLogFiles(layout, transactionLogsDirectory, UPGRADE_CHECKPOINT);
} else if (config.get(fail_on_missing_files)) {
// recovered state or not.
throw new UpgradeNotAllowedException();
} else {
// The log files are missing entirely, but we were told to not think of this as an error condition,
// so we instead initialize an empty log file.
logInitializer.initializeEmptyLogFile(layout, transactionLogsDirectory, UPGRADE_CHECKPOINT);
}
}
} catch (Exception exception) {
throw new StoreUpgrader.TransactionLogsRelocationException("Failure on attempt to move transaction logs into new location.", exception);
}
}
Aggregations