Search in sources :

Example 1 with Result

use of org.neo4j.kernel.impl.storemigration.StoreVersionCheck.Result in project neo4j by neo4j.

the class UpgradableDatabase method checkCleanShutDownByCheckPoint.

private Result checkCleanShutDownByCheckPoint(File storeDirectory) {
    // check version
    PhysicalLogFiles logFiles = new PhysicalLogFiles(storeDirectory, fs);
    LogEntryReader<ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader<>();
    LatestCheckPointFinder latestCheckPointFinder = new LatestCheckPointFinder(logFiles, fs, logEntryReader);
    try {
        LatestCheckPoint latestCheckPoint = latestCheckPointFinder.find(logFiles.getHighestLogVersion());
        if (!latestCheckPoint.commitsAfterCheckPoint) {
            return new Result(Result.Outcome.ok, null, null);
        }
    } catch (IOException e) {
    // ignore exception and return db not cleanly shutdown
    }
    return new Result(Result.Outcome.storeNotCleanlyShutDown, null, null);
}
Also used : LatestCheckPointFinder(org.neo4j.kernel.recovery.LatestCheckPointFinder) LatestCheckPoint(org.neo4j.kernel.recovery.LatestCheckPointFinder.LatestCheckPoint) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) IOException(java.io.IOException) PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel) Result(org.neo4j.kernel.impl.storemigration.StoreVersionCheck.Result)

Example 2 with Result

use of org.neo4j.kernel.impl.storemigration.StoreVersionCheck.Result in project neo4j by neo4j.

the class UpgradableDatabase method checkUpgradeable.

/**
     * Assumed to only be called if {@link #hasCurrentVersion(File)} returns {@code false}.
     *
     * @param storeDirectory the store to check for upgradability is in.
     * @return the {@link RecordFormats} the current store (which is upgradable) is currently in.
     * @throws UpgradeMissingStoreFilesException if store cannot be upgraded due to some store files are missing.
     * @throws UpgradingStoreVersionNotFoundException if store cannot be upgraded due to store
     * version cannot be determined.
     * @throws UnexpectedUpgradingStoreVersionException if store cannot be upgraded due to an unexpected store
     * version found.
     * @throws UnexpectedUpgradingStoreFormatException if store cannot be upgraded due to an unexpected store
     * format found.
     * @throws DatabaseNotCleanlyShutDownException if store cannot be upgraded due to not being cleanly shut down.
     */
public RecordFormats checkUpgradeable(File storeDirectory) {
    Result result = storeVersionCheck.hasVersion(new File(storeDirectory, MetaDataStore.DEFAULT_NAME), format.storeVersion());
    if (result.outcome.isSuccessful()) {
        // Although this method should not have been called in this case.
        return format;
    }
    RecordFormats fromFormat;
    try {
        fromFormat = RecordFormatSelector.selectForVersion(result.actualVersion);
        // of the config setting to change since downgrades aren't possible but the store can still be opened.
        if (FormatFamily.isLowerFamilyFormat(format, fromFormat)) {
            throw new StoreUpgrader.UnexpectedUpgradingStoreFormatException();
        }
        if (FormatFamily.isSameFamily(fromFormat, format) && (fromFormat.generation() > format.generation())) {
            // Tried to downgrade, that isn't supported
            result = new Result(Outcome.attemptedStoreDowngrade, fromFormat.storeVersion(), new File(storeDirectory, MetaDataStore.DEFAULT_NAME).getAbsolutePath());
        } else {
            result = fromFormat.hasCapability(Capability.VERSION_TRAILERS) ? checkCleanShutDownByVersionTrailer(storeDirectory, fromFormat) : checkCleanShutDownByCheckPoint(storeDirectory);
            if (result.outcome.isSuccessful()) {
                return fromFormat;
            }
        }
    } catch (IllegalArgumentException e) {
        result = new Result(Outcome.unexpectedStoreVersion, result.actualVersion, result.storeFilename);
    }
    switch(result.outcome) {
        case missingStoreFile:
            throw new StoreUpgrader.UpgradeMissingStoreFilesException(getPathToStoreFile(storeDirectory, result));
        case storeVersionNotFound:
            throw new StoreUpgrader.UpgradingStoreVersionNotFoundException(getPathToStoreFile(storeDirectory, result));
        case attemptedStoreDowngrade:
            throw new StoreUpgrader.AttemptedDowngradeException();
        case unexpectedStoreVersion:
            throw new StoreUpgrader.UnexpectedUpgradingStoreVersionException(result.actualVersion, format.storeVersion());
        case storeNotCleanlyShutDown:
            throw new StoreUpgrader.DatabaseNotCleanlyShutDownException();
        default:
            throw new IllegalArgumentException("Unexpected outcome: " + result.outcome.name());
    }
}
Also used : UpgradeMissingStoreFilesException(org.neo4j.kernel.impl.storemigration.StoreUpgrader.UpgradeMissingStoreFilesException) UnexpectedUpgradingStoreVersionException(org.neo4j.kernel.impl.storemigration.StoreUpgrader.UnexpectedUpgradingStoreVersionException) RecordFormats(org.neo4j.kernel.impl.store.format.RecordFormats) UpgradingStoreVersionNotFoundException(org.neo4j.kernel.impl.storemigration.StoreUpgrader.UpgradingStoreVersionNotFoundException) DatabaseNotCleanlyShutDownException(org.neo4j.kernel.impl.storemigration.StoreUpgrader.DatabaseNotCleanlyShutDownException) File(java.io.File) UnexpectedUpgradingStoreFormatException(org.neo4j.kernel.impl.storemigration.StoreUpgrader.UnexpectedUpgradingStoreFormatException) Result(org.neo4j.kernel.impl.storemigration.StoreVersionCheck.Result)

Example 3 with Result

use of org.neo4j.kernel.impl.storemigration.StoreVersionCheck.Result in project neo4j by neo4j.

the class LegacyStoreVersionCheck method hasVersion.

public Result hasVersion(File storeFile, String expectedVersion, boolean optional) {
    StoreChannel fileChannel = null;
    String storeFilename = storeFile.getName();
    byte[] expectedVersionBytes = UTF8.encode(expectedVersion);
    try {
        if (!fs.fileExists(storeFile)) {
            if (optional) {
                return new Result(Outcome.ok, null, storeFilename);
            }
            return new Result(Outcome.missingStoreFile, null, storeFilename);
        }
        fileChannel = fs.open(storeFile, "r");
        if (fileChannel.size() < expectedVersionBytes.length) {
            return new Result(Outcome.storeVersionNotFound, null, storeFilename);
        }
        String actualVersion = readVersion(fileChannel, expectedVersionBytes.length);
        if (!expectedVersion.equals(actualVersion)) {
            return new Result(Outcome.unexpectedStoreVersion, actualVersion, storeFilename);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        if (fileChannel != null) {
            try {
                fileChannel.close();
            } catch (IOException e) {
            // Ignore exception on close
            }
        }
    }
    return new Result(Outcome.ok, null, storeFilename);
}
Also used : StoreChannel(org.neo4j.io.fs.StoreChannel) IOException(java.io.IOException) Result(org.neo4j.kernel.impl.storemigration.StoreVersionCheck.Result)

Example 4 with Result

use of org.neo4j.kernel.impl.storemigration.StoreVersionCheck.Result in project neo4j by neo4j.

the class UpgradableDatabase method checkCleanShutDownByVersionTrailer.

private Result checkCleanShutDownByVersionTrailer(File storeDirectory, RecordFormats fromFormat) {
    Result result = null;
    for (StoreFile store : StoreFile.legacyStoreFilesForVersion(fromFormat.storeVersion())) {
        String expectedVersion = store.forVersion(fromFormat.storeVersion());
        File storeFile = new File(storeDirectory, store.storeFileName());
        result = legacyStoreVersionCheck.hasVersion(storeFile, expectedVersion, store.isOptional());
        if (!result.outcome.isSuccessful()) {
            break;
        }
    }
    return result;
}
Also used : File(java.io.File) Result(org.neo4j.kernel.impl.storemigration.StoreVersionCheck.Result)

Example 5 with Result

use of org.neo4j.kernel.impl.storemigration.StoreVersionCheck.Result in project neo4j by neo4j.

the class UpgradableDatabase method hasCurrentVersion.

public boolean hasCurrentVersion(File storeDir) {
    File neoStore = new File(storeDir, MetaDataStore.DEFAULT_NAME);
    Result result = storeVersionCheck.hasVersion(neoStore, format.storeVersion());
    switch(result.outcome) {
        case ok:
        case // let's assume the db is empty
        missingStoreFile:
            return true;
        case storeVersionNotFound:
        case unexpectedStoreVersion:
        case attemptedStoreDowngrade:
            return false;
        default:
            throw new IllegalArgumentException("Unknown outcome: " + result.outcome.name());
    }
}
Also used : File(java.io.File) Result(org.neo4j.kernel.impl.storemigration.StoreVersionCheck.Result)

Aggregations

Result (org.neo4j.kernel.impl.storemigration.StoreVersionCheck.Result)6 File (java.io.File)4 IOException (java.io.IOException)2 Test (org.junit.Test)1 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)1 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)1 StoreChannel (org.neo4j.io.fs.StoreChannel)1 PageCache (org.neo4j.io.pagecache.PageCache)1 Config (org.neo4j.kernel.configuration.Config)1 ConfiguringPageCacheFactory (org.neo4j.kernel.impl.pagecache.ConfiguringPageCacheFactory)1 RecordFormats (org.neo4j.kernel.impl.store.format.RecordFormats)1 DatabaseNotCleanlyShutDownException (org.neo4j.kernel.impl.storemigration.StoreUpgrader.DatabaseNotCleanlyShutDownException)1 UnexpectedUpgradingStoreFormatException (org.neo4j.kernel.impl.storemigration.StoreUpgrader.UnexpectedUpgradingStoreFormatException)1 UnexpectedUpgradingStoreVersionException (org.neo4j.kernel.impl.storemigration.StoreUpgrader.UnexpectedUpgradingStoreVersionException)1 UpgradeMissingStoreFilesException (org.neo4j.kernel.impl.storemigration.StoreUpgrader.UpgradeMissingStoreFilesException)1 UpgradingStoreVersionNotFoundException (org.neo4j.kernel.impl.storemigration.StoreUpgrader.UpgradingStoreVersionNotFoundException)1 StoreVersionCheck (org.neo4j.kernel.impl.storemigration.StoreVersionCheck)1 MigrationProgressMonitor (org.neo4j.kernel.impl.storemigration.monitoring.MigrationProgressMonitor)1 PhysicalLogFiles (org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles)1 ReadableClosablePositionAwareChannel (org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel)1