@Test public void shouldNotAccidentallyDeleteStoreFilesIfNoMigrationWasRequired() throws IOException { // given CountsMigrator migrator = new CountsMigrator( fs, null, Config.defaults() ); DatabaseLayout sourceLayout = directory.databaseLayout(); File countsStoreFileA = sourceLayout.countStoreA(); File countsStoreFileB = sourceLayout.countStoreB(); fs.create( countsStoreFileA ); fs.create( countsStoreFileB ); DatabaseLayout migrationLayout = directory.databaseLayout( "migration" ); String versionToMigrateFrom = StoreVersion.STANDARD_V3_2.versionString(); String versionToMigrateTo = StoreVersion.STANDARD_V3_4.versionString(); migrator.migrate( sourceLayout, migrationLayout, SilentProgressReporter.INSTANCE, versionToMigrateFrom, versionToMigrateTo ); assertEquals( "Invalid test assumption: There should not have been migration for those versions", 0, migrationLayout.listDatabaseFiles( ( dir, name ) -> true ).length ); // when migrator.moveMigratedFiles( migrationLayout, sourceLayout, versionToMigrateFrom, versionToMigrateTo ); // then assertTrue( fs.fileExists( countsStoreFileA ) ); assertTrue( fs.fileExists( countsStoreFileB ) ); } }
@Override public void migrate( DatabaseLayout directoryLayout, DatabaseLayout migrationLayout, ProgressReporter progressMonitor, String versionToMigrateFrom, String versionToMigrateTo ) throws IOException { if ( countStoreRebuildRequired( versionToMigrateFrom ) ) { // create counters from scratch fileOperation( DELETE, fileSystem, migrationLayout, migrationLayout, COUNTS_STORE_FILES, true, null ); File neoStore = directoryLayout.metadataStore(); long lastTxId = MetaDataStore.getRecord( pageCache, neoStore, Position.LAST_TRANSACTION_ID ); try { rebuildCountsFromScratch( directoryLayout, migrationLayout, lastTxId, progressMonitor, versionToMigrateTo, pageCache, NullLogProvider.getInstance() ); } catch ( StoreFailureException e ) { //This means that we did not perform a full migration, as the formats had the same capabilities. Thus // we should use the store directory for information when rebuilding the count store. Note that we // still put the new count store in the migration directory. rebuildCountsFromScratch( directoryLayout, migrationLayout, lastTxId, progressMonitor, versionToMigrateFrom, pageCache, NullLogProvider.getInstance() ); } migrated = true; } }
/** * 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 ); } }
private StoreUpgrader newUpgrader( UpgradableDatabase upgradableDatabase, PageCache pageCache, Config config, MigrationProgressMonitor progressMonitor ) { NullLogService instance = NullLogService.getInstance(); StoreMigrator defaultMigrator = new StoreMigrator( fileSystem, pageCache, getTuningConfig(), instance, jobScheduler ); CountsMigrator countsMigrator = new CountsMigrator( fileSystem, pageCache, getTuningConfig() ); SchemaIndexMigrator indexMigrator = new SchemaIndexMigrator( fileSystem, IndexProvider.EMPTY ); StoreUpgrader upgrader = new StoreUpgrader( upgradableDatabase, progressMonitor, config, fileSystem, pageCache, NullLogProvider.getInstance() ); upgrader.addParticipant( indexMigrator ); upgrader.addParticipant( AbstractStoreMigrationParticipant.NOT_PARTICIPATING ); upgrader.addParticipant( AbstractStoreMigrationParticipant.NOT_PARTICIPATING ); upgrader.addParticipant( AbstractStoreMigrationParticipant.NOT_PARTICIPATING ); upgrader.addParticipant( AbstractStoreMigrationParticipant.NOT_PARTICIPATING ); upgrader.addParticipant( defaultMigrator ); upgrader.addParticipant( countsMigrator ); return upgrader; }
SilentMigrationProgressMonitor progressMonitor = new SilentMigrationProgressMonitor(); StoreMigrator migrator = new StoreMigrator( fs, pageCache, CONFIG, logService, jobScheduler ); CountsMigrator countsMigrator = new CountsMigrator( fs, pageCache, CONFIG ); 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 ); } }
@Override public void migrate( DatabaseLayout directoryLayout, DatabaseLayout migrationLayout, ProgressReporter progressMonitor, String versionToMigrateFrom, String versionToMigrateTo ) throws IOException { if ( countStoreRebuildRequired( versionToMigrateFrom ) ) { // create counters from scratch fileOperation( DELETE, fileSystem, migrationLayout, migrationLayout, COUNTS_STORE_FILES, true, null ); File neoStore = directoryLayout.metadataStore(); long lastTxId = MetaDataStore.getRecord( pageCache, neoStore, Position.LAST_TRANSACTION_ID ); try { rebuildCountsFromScratch( directoryLayout, migrationLayout, lastTxId, progressMonitor, versionToMigrateTo, pageCache, NullLogProvider.getInstance() ); } catch ( StoreFailureException e ) { //This means that we did not perform a full migration, as the formats had the same capabilities. Thus // we should use the store directory for information when rebuilding the count store. Note that we // still put the new count store in the migration directory. rebuildCountsFromScratch( directoryLayout, migrationLayout, lastTxId, progressMonitor, versionToMigrateFrom, pageCache, NullLogProvider.getInstance() ); } migrated = true; } }
SilentMigrationProgressMonitor progressMonitor = new SilentMigrationProgressMonitor(); StoreMigrator migrator = new StoreMigrator( fs, pageCache, CONFIG, logService, jobScheduler ); CountsMigrator countsMigrator = new CountsMigrator( fs, pageCache, CONFIG ); DatabaseLayout migrationLayout = directory.databaseLayout( StoreUpgrader.MIGRATION_DIRECTORY ); 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() );
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() );