public Optional<String> getVersion( File neostoreFile ) throws IOException { long record = MetaDataStore.getRecord( pageCache, neostoreFile, STORE_VERSION ); if ( record == MetaDataRecordFormat.FIELD_NOT_PRESENT ) { return Optional.empty(); } return Optional.of( MetaDataStore.versionLongToString( record ) ); }
private boolean compareExpectedVersionWithStoreVersion( long expectedVersion, boolean allowUpgrade, Long readIndexVersion ) { boolean versionDiffers = readIndexVersion == null || readIndexVersion != expectedVersion; if ( versionDiffers ) { // We can throw a more explicit exception if we see that we're trying to run // with an older version than the store is. if ( readIndexVersion != null && expectedVersion < readIndexVersion ) { String expected = versionLongToString( expectedVersion ); String readVersion = versionLongToString( readIndexVersion ); throw new NotCurrentStoreVersionException( expected, readVersion, "Your index has been upgraded to " + readVersion + " and cannot run with an older version " + expected, false ); } else if ( !allowUpgrade ) { // We try to run with a newer version than the store is but isn't allowed to upgrade. throw new UpgradeNotAllowedByConfigurationException(); } } return versionDiffers; }
if ( value != MetaDataRecordFormat.FIELD_NOT_PRESENT ) String storeVersion = MetaDataStore.versionLongToString( value );
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 e ) { // 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 ); } }
@Test public void shouldFailUpgradeIfNotAllowed() { IndexProviderStore store = new IndexProviderStore( file, fileSystem, MetaDataStore.versionStringToLong( "3.1" ), true ); store.close(); store = new IndexProviderStore( file, fileSystem, MetaDataStore.versionStringToLong( "3.1" ), false ); store.close(); try { new IndexProviderStore( file, fileSystem, MetaDataStore.versionStringToLong( "3.5" ), false ); fail( "Shouldn't be able to upgrade there" ); } catch ( UpgradeNotAllowedByConfigurationException e ) { // Good } store = new IndexProviderStore( file, fileSystem, MetaDataStore.versionStringToLong( "3.5" ), true ); assertEquals( "3.5", MetaDataStore.versionLongToString( store.getIndexVersion() ) ); store.close(); }
public Optional<String> getVersion( File neostoreFile ) throws IOException { long record = MetaDataStore.getRecord( pageCache, neostoreFile, STORE_VERSION ); if ( record == MetaDataRecordFormat.FIELD_NOT_PRESENT ) { return Optional.empty(); } return Optional.of( MetaDataStore.versionLongToString( record ) ); }
private boolean compareExpectedVersionWithStoreVersion( long expectedVersion, boolean allowUpgrade, Long readIndexVersion ) { boolean versionDiffers = readIndexVersion == null || readIndexVersion != expectedVersion; if ( versionDiffers ) { // We can throw a more explicit exception if we see that we're trying to run // with an older version than the store is. if ( readIndexVersion != null && expectedVersion < readIndexVersion ) { String expected = versionLongToString( expectedVersion ); String readVersion = versionLongToString( readIndexVersion ); throw new NotCurrentStoreVersionException( expected, readVersion, "Your index has been upgraded to " + readVersion + " and cannot run with an older version " + expected, false ); } else if ( !allowUpgrade ) { // We try to run with a newer version than the store is but isn't allowed to upgrade. throw new UpgradeNotAllowedByConfigurationException(); } } return versionDiffers; }
if ( value != MetaDataRecordFormat.FIELD_NOT_PRESENT ) String storeVersion = MetaDataStore.versionLongToString( value );
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 e ) { // 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 ); } }