private void VerifyRecordFormat() { try { string expectedStoreVersion = _recordFormats.storeVersion(); long record = getRecord(_pageCache, _metadataStore, STORE_VERSION); if (record != MetaDataRecordFormat.FIELD_NOT_PRESENT) { string actualStoreVersion = versionLongToString(record); RecordFormats actualStoreFormat = RecordFormatSelector.selectForVersion(actualStoreVersion); if (!IsCompatibleFormats(actualStoreFormat)) { throw new UnexpectedStoreVersionException(actualStoreVersion, expectedStoreVersion); } } } catch (NoSuchFileException) { // Occurs when there is no file, which is obviously when creating a store. // Caught as an exception because we want to leave as much interaction with files as possible // to the page cache. } catch (IOException e) { throw new UnderlyingStorageException(e); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldCommunicateWhatCausesInabilityToUpgrade() public virtual void ShouldCommunicateWhatCausesInabilityToUpgrade() { // given //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final UpgradableDatabase upgradableDatabase = getUpgradableDatabase(); UpgradableDatabase upgradableDatabase = UpgradableDatabase; try { // when upgradableDatabase.CheckUpgradable(DatabaseLayout); fail("should not have been able to upgrade"); } catch (StoreUpgrader.UnexpectedUpgradingStoreVersionException e) { // then assertEquals(string.format(MESSAGE, Version, upgradableDatabase.CurrentVersion(), Version.Neo4jVersion), e.Message); } catch (StoreUpgrader.UnexpectedUpgradingStoreFormatException e) { // then assertNotSame(StandardFormatFamily.INSTANCE, RecordFormatSelector.selectForVersion(Version).FormatFamily); assertEquals(string.format(StoreUpgrader.UnexpectedUpgradingStoreFormatException.MESSAGE, GraphDatabaseSettings.record_format.name()), e.Message); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public void execute(String[] args) throws org.neo4j.commandline.admin.IncorrectUsage, org.neo4j.commandline.admin.CommandFailed public override void Execute(string[] args) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.nio.file.Path databaseDirectory = arguments.parse(args).getMandatoryPath("store"); Path databaseDirectory = _arguments.parse(args).getMandatoryPath("store"); Validators.CONTAINS_EXISTING_DATABASE.validate(databaseDirectory.toFile()); DatabaseLayout databaseLayout = DatabaseLayout.of(databaseDirectory.toFile()); try { using (System.IDisposable ignored = StoreLockChecker.Check(databaseLayout.StoreLayout), DefaultFileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction(), JobScheduler jobScheduler = createInitialisedScheduler(), PageCache pageCache = StandalonePageCacheFactory.createPageCache(fileSystem, jobScheduler)) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final String storeVersion = new org.neo4j.kernel.impl.storemigration.StoreVersionCheck(pageCache).getVersion(databaseLayout.metadataStore()).orElseThrow(() -> new org.neo4j.commandline.admin.CommandFailed(String.format("Could not find version metadata in store '%s'", databaseDirectory))); string storeVersion = (new StoreVersionCheck(pageCache)).getVersion(databaseLayout.MetadataStore()).orElseThrow(() => new CommandFailed(string.Format("Could not find version metadata in store '{0}'", databaseDirectory))); const string fmt = "%-30s%s"; @out.accept(string.format(fmt, "Store format version:", storeVersion)); RecordFormats format = RecordFormatSelector.selectForVersion(storeVersion); @out.accept(string.format(fmt, "Store format introduced in:", format.IntroductionVersion())); findSuccessor(format).map(next => string.format(fmt, "Store format superseded in:", next.introductionVersion())).ifPresent(@out); } } catch (StoreLockException e) { throw new CommandFailed("the database is in use -- stop Neo4j and try again", e); } catch (Exception e) { throw new CommandFailed(e.Message, e); } }
/// <summary> /// Assumed to only be called if <seealso cref="hasCurrentVersion(DatabaseLayout)"/> returns {@code false}. /// </summary> /// <param name="dbDirectoryLayout"> database directory structure. </param> /// <returns> the <seealso cref="RecordFormats"/> the current store (which is upgradable) is currently in. </returns> /// <exception cref="UpgradeMissingStoreFilesException"> if store cannot be upgraded due to some store files are missing. </exception> /// <exception cref="UpgradingStoreVersionNotFoundException"> if store cannot be upgraded due to store /// version cannot be determined. </exception> /// <exception cref="UnexpectedUpgradingStoreVersionException"> if store cannot be upgraded due to an unexpected store /// version found. </exception> /// <exception cref="UnexpectedUpgradingStoreFormatException"> if store cannot be upgraded due to an unexpected store /// format found. </exception> /// <exception cref="DatabaseNotCleanlyShutDownException"> if store cannot be upgraded due to not being cleanly shut down. </exception> public virtual RecordFormats CheckUpgradable(DatabaseLayout dbDirectoryLayout) { File neostoreFile = dbDirectoryLayout.MetadataStore(); Result result = _storeVersionCheck.hasVersion(neostoreFile, _format.storeVersion()); if (result.Outcome.Successful) { // This store already has the format that we want // Although this method should not have been called in this case. return(_format); } RecordFormats fromFormat; try { fromFormat = RecordFormatSelector.selectForVersion(result.ActualVersion); // If we are trying to open an enterprise store when configured to use community format, then inform the user // 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(Result.Outcome.attemptedStoreDowngrade, fromFormat.StoreVersion(), neostoreFile.AbsolutePath); } else { result = CheckCleanShutDownByCheckPoint(); if (result.Outcome.Successful) { return(fromFormat); } } } catch (System.ArgumentException) { result = new Result(Result.Outcome.unexpectedStoreVersion, result.ActualVersion, result.StoreFilename); } switch (result.Outcome.innerEnumValue) { case Result.Outcome.InnerEnum.missingStoreFile: throw new StoreUpgrader.UpgradeMissingStoreFilesException(GetPathToStoreFile(dbDirectoryLayout, result)); case Result.Outcome.InnerEnum.storeVersionNotFound: throw new StoreUpgrader.UpgradingStoreVersionNotFoundException(GetPathToStoreFile(dbDirectoryLayout, result)); case Result.Outcome.InnerEnum.attemptedStoreDowngrade: throw new StoreUpgrader.AttemptedDowngradeException(); case Result.Outcome.InnerEnum.unexpectedStoreVersion: throw new StoreUpgrader.UnexpectedUpgradingStoreVersionException(result.ActualVersion, _format.storeVersion()); case Result.Outcome.InnerEnum.storeNotCleanlyShutDown: throw new StoreUpgrader.DatabaseNotCleanlyShutDownException(); default: throw new System.ArgumentException("Unexpected outcome: " + result.Outcome.name()); } }