Search in sources :

Example 1 with CommandReaderFactory

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);
    }
}
Also used : Path(java.nio.file.Path) TransactionLogInitializer(org.neo4j.kernel.impl.transaction.log.files.TransactionLogInitializer) MetadataProvider(org.neo4j.storageengine.api.MetadataProvider) CommandReaderFactory(org.neo4j.storageengine.api.CommandReaderFactory) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) UpgradeNotAllowedException(org.neo4j.storageengine.migration.UpgradeNotAllowedException) IOException(java.io.IOException) UpgradeNotAllowedException(org.neo4j.storageengine.migration.UpgradeNotAllowedException)

Aggregations

IOException (java.io.IOException)1 Path (java.nio.file.Path)1 LogFiles (org.neo4j.kernel.impl.transaction.log.files.LogFiles)1 TransactionLogInitializer (org.neo4j.kernel.impl.transaction.log.files.TransactionLogInitializer)1 CommandReaderFactory (org.neo4j.storageengine.api.CommandReaderFactory)1 MetadataProvider (org.neo4j.storageengine.api.MetadataProvider)1 UpgradeNotAllowedException (org.neo4j.storageengine.migration.UpgradeNotAllowedException)1