private static UpgradableDatabase getUpgradableDatabase( PageCache pageCache, LogTailScanner tailScanner ) { return new UpgradableDatabase( new StoreVersionCheck( pageCache ), selectFormat(), tailScanner ); }
private void migrateStore( DatabaseLayout dbDirectoryLayout, DatabaseLayout migrationLayout, File migrationStateFile ) { // One or more participants would like to do migration progressMonitor.started( participants.size() ); MigrationStatus migrationStatus = MigrationStatus.readMigrationStatus( fileSystem, migrationStateFile ); String versionToMigrateFrom = null; // We don't need to migrate if we're at the phase where we have migrated successfully // and it's just a matter of moving over the files to the storeDir. if ( MigrationStatus.migrating.isNeededFor( migrationStatus ) ) { versionToMigrateFrom = upgradableDatabase.checkUpgradable( dbDirectoryLayout ).storeVersion(); cleanMigrationDirectory( migrationLayout.databaseDirectory() ); MigrationStatus.migrating.setMigrationStatus( fileSystem, migrationStateFile, versionToMigrateFrom ); migrateToIsolatedDirectory( dbDirectoryLayout, migrationLayout, versionToMigrateFrom ); MigrationStatus.moving.setMigrationStatus( fileSystem, migrationStateFile, versionToMigrateFrom ); } if ( MigrationStatus.moving.isNeededFor( migrationStatus ) ) { versionToMigrateFrom = MigrationStatus.moving.maybeReadInfo( fileSystem, migrationStateFile, versionToMigrateFrom ); moveMigratedFilesToStoreDirectory( participants, migrationLayout, dbDirectoryLayout, versionToMigrateFrom, upgradableDatabase.currentVersion() ); } cleanup( participants, migrationLayout ); progressMonitor.completed(); }
result = checkCleanShutDownByCheckPoint(); if ( result.outcome.isSuccessful() ) throw new StoreUpgrader.UpgradeMissingStoreFilesException( getPathToStoreFile( dbDirectoryLayout, result ) ); case storeVersionNotFound: throw new StoreUpgrader.UpgradingStoreVersionNotFoundException( getPathToStoreFile( dbDirectoryLayout, result ) ); case attemptedStoreDowngrade: throw new StoreUpgrader.AttemptedDowngradeException();
private void migrateToIsolatedDirectory( DatabaseLayout directoryLayout, DatabaseLayout migrationLayout, String versionToMigrateFrom ) { try { for ( StoreMigrationParticipant participant : participants ) { ProgressReporter progressReporter = progressMonitor.startSection( participant.getName() ); participant.migrate( directoryLayout, migrationLayout, progressReporter, versionToMigrateFrom, upgradableDatabase.currentVersion() ); progressReporter.completed(); } } catch ( IOException | UncheckedIOException e ) { throw new UnableToUpgradeException( "Failure doing migration", e ); } }
public void migrateIfNeeded( DatabaseLayout layout ) { DatabaseLayout migrationStructure = DatabaseLayout.of( layout.databaseDirectory(), MIGRATION_DIRECTORY ); cleanupLegacyLeftOverDirsIn( layout.databaseDirectory() ); File migrationStateFile = migrationStructure.file( MIGRATION_STATUS_FILE ); // if migration directory exists than we might have failed to move files into the store dir so do it again if ( upgradableDatabase.hasCurrentVersion( layout ) && !fileSystem.fileExists( migrationStateFile ) ) { // No migration needed return; } if ( isUpgradeAllowed() ) { migrateStore( layout, migrationStructure, migrationStateFile ); } else if ( !RecordFormatSelector.isStoreAndConfigFormatsCompatible( config, layout, fileSystem, pageCache, logProvider ) ) { throw new UpgradeNotAllowedByConfigurationException(); } }
private void migrateToIsolatedDirectory( DatabaseLayout directoryLayout, DatabaseLayout migrationLayout, String versionToMigrateFrom ) { try { for ( StoreMigrationParticipant participant : participants ) { ProgressReporter progressReporter = progressMonitor.startSection( participant.getName() ); participant.migrate( directoryLayout, migrationLayout, progressReporter, versionToMigrateFrom, upgradableDatabase.currentVersion() ); progressReporter.completed(); } } catch ( IOException | UncheckedIOException e ) { throw new UnableToUpgradeException( "Failure doing migration", e ); } }
public void migrateIfNeeded( DatabaseLayout layout ) { DatabaseLayout migrationStructure = DatabaseLayout.of( layout.databaseDirectory(), MIGRATION_DIRECTORY ); cleanupLegacyLeftOverDirsIn( layout.databaseDirectory() ); File migrationStateFile = migrationStructure.file( MIGRATION_STATUS_FILE ); // if migration directory exists than we might have failed to move files into the store dir so do it again if ( upgradableDatabase.hasCurrentVersion( layout ) && !fileSystem.fileExists( migrationStateFile ) ) { // No migration needed return; } if ( isUpgradeAllowed() ) { migrateStore( layout, migrationStructure, migrationStateFile ); } else if ( !RecordFormatSelector.isStoreAndConfigFormatsCompatible( config, layout, fileSystem, pageCache, logProvider ) ) { throw new UpgradeNotAllowedByConfigurationException(); } }
UpgradableDatabase upgradableDatabase = getUpgradableDatabase( pageCache ); String versionToMigrateTo = upgradableDatabase.currentVersion(); String versionToMigrateFrom = upgradableDatabase.checkUpgradable( databaseLayout ).storeVersion();
private UpgradableDatabase getUpgradableDatabase( StoreVersionCheck check ) throws IOException { VersionAwareLogEntryReader<ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader<>(); LogFiles logFiles = LogFilesBuilder.logFilesBasedOnlyBuilder( workingDatabaseLayout.databaseDirectory(), fs ).build(); LogTailScanner tailScanner = new LogTailScanner( logFiles, logEntryReader, new Monitors() ); return new UpgradableDatabase( check, Standard.LATEST_RECORD_FORMATS, tailScanner ); }
result = checkCleanShutDownByCheckPoint(); if ( result.outcome.isSuccessful() ) throw new StoreUpgrader.UpgradeMissingStoreFilesException( getPathToStoreFile( dbDirectoryLayout, result ) ); case storeVersionNotFound: throw new StoreUpgrader.UpgradingStoreVersionNotFoundException( getPathToStoreFile( dbDirectoryLayout, result ) ); case attemptedStoreDowngrade: throw new StoreUpgrader.AttemptedDowngradeException();
UpgradableDatabase upgradableDatabase = getUpgradableDatabase( pageCache, tailScanner ); String versionToMigrateFrom = upgradableDatabase.checkUpgradable( databaseLayout ).storeVersion(); SilentMigrationProgressMonitor progressMonitor = new SilentMigrationProgressMonitor(); StoreMigrator migrator = new StoreMigrator( fs, pageCache, CONFIG, logService, jobScheduler ); DatabaseLayout migrationLayout = directory.databaseLayout( StoreUpgrader.MIGRATION_DIRECTORY ); migrator.migrate( databaseLayout, migrationLayout, progressMonitor.startSection( "section" ), versionToMigrateFrom, upgradableDatabase.currentVersion() ); countsMigrator .migrate( databaseLayout, migrationLayout, progressMonitor.startSection( "section" ), versionToMigrateFrom, upgradableDatabase.currentVersion() ); countsMigrator = new CountsMigrator( fs, pageCache, CONFIG ); migrator.moveMigratedFiles( migrationLayout, databaseLayout, versionToMigrateFrom, upgradableDatabase.currentVersion() ); countsMigrator.moveMigratedFiles( migrationLayout, databaseLayout, versionToMigrateFrom, upgradableDatabase.currentVersion() );
/** * Performs construction of {@link StoreUpgrader} and all of the necessary participants and performs store * migration if that is required. * @param directoryStructure database to migrate */ public void migrate( DatabaseLayout directoryStructure ) { LogProvider logProvider = logService.getInternalLogProvider(); UpgradableDatabase upgradableDatabase = new UpgradableDatabase( new StoreVersionCheck( pageCache ), format, tailScanner ); StoreUpgrader storeUpgrader = new StoreUpgrader( upgradableDatabase, progressMonitor, config, fs, pageCache, logProvider ); ExplicitIndexMigrator explicitIndexMigrator = new ExplicitIndexMigrator( fs, explicitIndexProvider, logProvider ); StoreMigrator storeMigrator = new StoreMigrator( fs, pageCache, config, logService, jobScheduler ); NativeLabelScanStoreMigrator nativeLabelScanStoreMigrator = new NativeLabelScanStoreMigrator( fs, pageCache, config ); CountsMigrator countsMigrator = new CountsMigrator( fs, pageCache, config ); indexProviderMap.accept( provider -> storeUpgrader.addParticipant( provider.storeMigrationParticipant( fs, pageCache ) ) ); storeUpgrader.addParticipant( explicitIndexMigrator ); storeUpgrader.addParticipant( storeMigrator ); storeUpgrader.addParticipant( nativeLabelScanStoreMigrator ); storeUpgrader.addParticipant( countsMigrator ); storeUpgrader.migrateIfNeeded( directoryStructure ); } }
UpgradableDatabase upgradableDatabase = getUpgradableDatabase( pageCache, tailScanner ); String versionToMigrateFrom = upgradableDatabase.checkUpgradable( databaseLayout ).storeVersion(); SilentMigrationProgressMonitor progressMonitor = new SilentMigrationProgressMonitor(); StoreMigrator migrator = new StoreMigrator( fs, pageCache, CONFIG, logService, jobScheduler ); DatabaseLayout migrationLayout = directory.databaseLayout( StoreUpgrader.MIGRATION_DIRECTORY ); migrator.migrate( databaseLayout, migrationLayout, progressMonitor.startSection( "section" ), versionToMigrateFrom, upgradableDatabase.currentVersion() ); CountsMigrator countsMigrator = new CountsMigrator( fs, pageCache, CONFIG ); countsMigrator.migrate( databaseLayout, migrationLayout, progressMonitor.startSection( "section" ), versionToMigrateFrom, upgradableDatabase.currentVersion() ); migrator.moveMigratedFiles( migrationLayout, databaseLayout, versionToMigrateFrom, upgradableDatabase.currentVersion() ); countsMigrator.moveMigratedFiles( migrationLayout, databaseLayout, versionToMigrateFrom, upgradableDatabase.currentVersion() );
private UpgradableDatabase getUpgradableDatabase( PageCache pageCache ) throws IOException { VersionAwareLogEntryReader<ReadableClosablePositionAwareChannel> entryReader = new VersionAwareLogEntryReader<>(); LogFiles logFiles = LogFilesBuilder.logFilesBasedOnlyBuilder( databaseLayout.databaseDirectory(), fileSystem ) .withLogEntryReader( entryReader ).build(); LogTailScanner tailScanner = new LogTailScanner( logFiles, entryReader, new Monitors() ); return new UpgradableDatabase( new StoreVersionCheck( pageCache ), getRecordFormats(), tailScanner ); }
UpgradableDatabase upgradableDatabase = getUpgradableDatabase( pageCache, tailScanner ); String versionToMigrateFrom = upgradableDatabase.checkUpgradable( databaseLayout ).storeVersion(); SilentMigrationProgressMonitor progressMonitor = new SilentMigrationProgressMonitor(); StoreMigrator migrator = new StoreMigrator( fs, pageCache, CONFIG, logService, jobScheduler ); upgradableDatabase.currentVersion() ); countsMigrator .migrate( databaseLayout, migrationLayout, progressMonitor.startSection( "section" ), versionToMigrateFrom, upgradableDatabase.currentVersion() ); migrator.moveMigratedFiles( migrationLayout, databaseLayout, versionToMigrateFrom, upgradableDatabase.currentVersion() ); countsMigrator.moveMigratedFiles( migrationLayout, databaseLayout, versionToMigrateFrom, upgradableDatabase.currentVersion() );
/** * Performs construction of {@link StoreUpgrader} and all of the necessary participants and performs store * migration if that is required. * @param directoryStructure database to migrate */ public void migrate( DatabaseLayout directoryStructure ) { LogProvider logProvider = logService.getInternalLogProvider(); UpgradableDatabase upgradableDatabase = new UpgradableDatabase( new StoreVersionCheck( pageCache ), format, tailScanner ); StoreUpgrader storeUpgrader = new StoreUpgrader( upgradableDatabase, progressMonitor, config, fs, pageCache, logProvider ); ExplicitIndexMigrator explicitIndexMigrator = new ExplicitIndexMigrator( fs, explicitIndexProvider, logProvider ); StoreMigrator storeMigrator = new StoreMigrator( fs, pageCache, config, logService, jobScheduler ); NativeLabelScanStoreMigrator nativeLabelScanStoreMigrator = new NativeLabelScanStoreMigrator( fs, pageCache, config ); CountsMigrator countsMigrator = new CountsMigrator( fs, pageCache, config ); indexProviderMap.accept( provider -> storeUpgrader.addParticipant( provider.storeMigrationParticipant( fs, pageCache ) ) ); storeUpgrader.addParticipant( explicitIndexMigrator ); storeUpgrader.addParticipant( storeMigrator ); storeUpgrader.addParticipant( nativeLabelScanStoreMigrator ); storeUpgrader.addParticipant( countsMigrator ); storeUpgrader.migrateIfNeeded( directoryStructure ); } }
@Test public void shouldComputeTheLastTxInfoCorrectly() throws Exception { // given DatabaseLayout databaseLayout = directory.databaseLayout(); File prepare = directory.directory( "prepare" ); MigrationTestUtils.prepareSampleLegacyDatabase( version, fs, databaseLayout.databaseDirectory(), prepare ); // and a state of the migration saying that it has done the actual migration LogService logService = NullLogService.getInstance(); PageCache pageCache = pageCacheRule.getPageCache( fs ); LogTailScanner tailScanner = getTailScanner( databaseLayout.databaseDirectory() ); UpgradableDatabase upgradableDatabase = getUpgradableDatabase( pageCache, tailScanner ); String versionToMigrateFrom = upgradableDatabase.checkUpgradable( databaseLayout ).storeVersion(); SilentMigrationProgressMonitor progressMonitor = new SilentMigrationProgressMonitor(); StoreMigrator migrator = new StoreMigrator( fs, pageCache, CONFIG, logService, jobScheduler ); DatabaseLayout migrationLayout = directory.databaseLayout( StoreUpgrader.MIGRATION_DIRECTORY ); // when migrator.migrate( databaseLayout, migrationLayout, progressMonitor.startSection( "section" ), versionToMigrateFrom, upgradableDatabase.currentVersion() ); // then assertTrue( txIdComparator.apply( migrator.readLastTxInformation( migrationLayout ) ) ); }
@Test public void shouldComputeTheLastTxLogPositionCorrectly() throws Throwable { // GIVEN a legacy database DatabaseLayout databaseLayout = directory.databaseLayout(); File prepare = directory.directory( "prepare" ); MigrationTestUtils.prepareSampleLegacyDatabase( version, fs, databaseLayout.databaseDirectory(), prepare ); // and a state of the migration saying that it has done the actual migration LogService logService = NullLogService.getInstance(); PageCache pageCache = pageCacheRule.getPageCache( fs ); LogTailScanner tailScanner = getTailScanner( databaseLayout.databaseDirectory() ); UpgradableDatabase upgradableDatabase = getUpgradableDatabase( pageCache, tailScanner ); String versionToMigrateFrom = upgradableDatabase.checkUpgradable( databaseLayout ).storeVersion(); SilentMigrationProgressMonitor progressMonitor = new SilentMigrationProgressMonitor(); StoreMigrator migrator = new StoreMigrator( fs, pageCache, CONFIG, logService, jobScheduler ); DatabaseLayout migrationLayout = directory.databaseLayout( StoreUpgrader.MIGRATION_DIRECTORY ); // WHEN migrating migrator.migrate( databaseLayout, migrationLayout, progressMonitor.startSection( "section" ), versionToMigrateFrom, upgradableDatabase.currentVersion() ); // THEN it should compute the correct last tx log position assertEquals( expectedLogPosition, migrator.readLastTxLogPosition( migrationLayout ) ); }
private void migrateStore( DatabaseLayout dbDirectoryLayout, DatabaseLayout migrationLayout, File migrationStateFile ) { // One or more participants would like to do migration progressMonitor.started( participants.size() ); MigrationStatus migrationStatus = MigrationStatus.readMigrationStatus( fileSystem, migrationStateFile ); String versionToMigrateFrom = null; // We don't need to migrate if we're at the phase where we have migrated successfully // and it's just a matter of moving over the files to the storeDir. if ( MigrationStatus.migrating.isNeededFor( migrationStatus ) ) { versionToMigrateFrom = upgradableDatabase.checkUpgradable( dbDirectoryLayout ).storeVersion(); cleanMigrationDirectory( migrationLayout.databaseDirectory() ); MigrationStatus.migrating.setMigrationStatus( fileSystem, migrationStateFile, versionToMigrateFrom ); migrateToIsolatedDirectory( dbDirectoryLayout, migrationLayout, versionToMigrateFrom ); MigrationStatus.moving.setMigrationStatus( fileSystem, migrationStateFile, versionToMigrateFrom ); } if ( MigrationStatus.moving.isNeededFor( migrationStatus ) ) { versionToMigrateFrom = MigrationStatus.moving.maybeReadInfo( fileSystem, migrationStateFile, versionToMigrateFrom ); moveMigratedFilesToStoreDirectory( participants, migrationLayout, dbDirectoryLayout, versionToMigrateFrom, upgradableDatabase.currentVersion() ); } cleanup( participants, migrationLayout ); progressMonitor.completed(); }