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