Search in sources :

Example 1 with UnexpectedUpgradingStoreVersionException

use of org.neo4j.kernel.impl.storemigration.StoreUpgrader.UnexpectedUpgradingStoreVersionException 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)

Aggregations

File (java.io.File)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 Result (org.neo4j.kernel.impl.storemigration.StoreVersionCheck.Result)1