use of org.neo4j.kernel.impl.storemigration.UpgradableDatabase in project neo4j by neo4j.
the class StoreUpgraderInterruptionTestIT method shouldSucceedWithUpgradeAfterPreviousAttemptDiedDuringMigration.
@Test
public void shouldSucceedWithUpgradeAfterPreviousAttemptDiedDuringMigration() throws IOException, ConsistencyCheckIncompleteException {
MigrationTestUtils.prepareSampleLegacyDatabase(version, fs, workingDirectory, prepareDirectory);
PageCache pageCache = pageCacheRule.getPageCache(fs);
StoreVersionCheck check = new StoreVersionCheck(pageCache);
UpgradableDatabase upgradableDatabase = new UpgradableDatabase(fs, check, new LegacyStoreVersionCheck(fs), Standard.LATEST_RECORD_FORMATS);
SilentMigrationProgressMonitor progressMonitor = new SilentMigrationProgressMonitor();
LogService logService = NullLogService.getInstance();
StoreMigrator failingStoreMigrator = new StoreMigrator(fs, pageCache, CONFIG, logService, schemaIndexProvider) {
@Override
public void migrate(File sourceStoreDir, File targetStoreDir, MigrationProgressMonitor.Section progressMonitor, String versionToMigrateFrom, String versionToMigrateTo) throws IOException {
super.migrate(sourceStoreDir, targetStoreDir, progressMonitor, versionToMigrateFrom, versionToMigrateTo);
throw new RuntimeException("This upgrade is failing");
}
};
assertEquals(!StandardV2_3.STORE_VERSION.equals(version), allLegacyStoreFilesHaveVersion(fs, workingDirectory, version));
try {
newUpgrader(upgradableDatabase, pageCache, progressMonitor, createIndexMigrator(), failingStoreMigrator).migrateIfNeeded(workingDirectory);
fail("Should throw exception");
} catch (RuntimeException e) {
assertEquals("This upgrade is failing", e.getMessage());
}
assertEquals(!StandardV2_3.STORE_VERSION.equals(version), allLegacyStoreFilesHaveVersion(fs, workingDirectory, version));
progressMonitor = new SilentMigrationProgressMonitor();
StoreMigrator migrator = new StoreMigrator(fs, pageCache, CONFIG, logService, schemaIndexProvider);
SchemaIndexMigrator indexMigrator = createIndexMigrator();
newUpgrader(upgradableDatabase, pageCache, progressMonitor, indexMigrator, migrator).migrateIfNeeded(workingDirectory);
assertTrue(checkNeoStoreHasDefaultFormatVersion(check, workingDirectory));
assertTrue(allStoreFilesHaveNoTrailer(fs, workingDirectory));
// Since consistency checker is in read only mode we need to start/stop db to generate label scan store.
startStopDatabase(workingDirectory);
assertConsistentStore(workingDirectory);
}
use of org.neo4j.kernel.impl.storemigration.UpgradableDatabase in project neo4j by neo4j.
the class StoreUpgraderTest method failMigrationWhenFailDuringTransactionInformationRetrieval.
@Test
public void failMigrationWhenFailDuringTransactionInformationRetrieval() throws IOException {
File storeDirectory = directory.graphDbDir();
File prepare = directory.directory("prepare");
FileSystemAbstraction fs = new DelegatingFileSystemAbstraction(fileSystem) {
@Override
public File[] listFiles(File directory, FilenameFilter filter) {
if (filter == LegacyLogFilenames.versionedLegacyLogFilesFilter) {
sneakyThrow(new IOException("Enforced IO Exception Fail to open file"));
}
return super.listFiles(directory, filter);
}
};
prepareSampleDatabase(version, fs, storeDirectory, prepare);
// and a state of the migration saying that it has done the actual migration
PageCache pageCache = pageCacheRule.getPageCache(fs);
// remove metadata store record to force tx info lookup in tx logs
MetaDataStore.setRecord(pageCache, new File(storeDirectory, MetaDataStore.DEFAULT_NAME), MetaDataStore.Position.LAST_TRANSACTION_COMMIT_TIMESTAMP, MetaDataRecordFormat.FIELD_NOT_PRESENT);
UpgradableDatabase upgradableDatabase = new UpgradableDatabase(fs, new StoreVersionCheck(pageCache), new LegacyStoreVersionCheck(fs), getRecordFormats()) {
@Override
public RecordFormats checkUpgradeable(File storeDirectory) {
return getRecordFormats();
}
};
SilentMigrationProgressMonitor progressMonitor = new SilentMigrationProgressMonitor();
StoreMigrator defaultMigrator = new StoreMigrator(fs, pageCache, getTuningConfig(), NullLogService.getInstance(), schemaIndexProvider);
StoreUpgrader upgrader = new StoreUpgrader(upgradableDatabase, progressMonitor, allowMigrateConfig, fs, pageCache, NullLogProvider.getInstance());
upgrader.addParticipant(defaultMigrator);
expectedException.expect(UnableToUpgradeException.class);
expectedException.expectCause(instanceOf(IOException.class));
expectedException.expectCause(hasMessage(containsString("Enforced IO Exception Fail to open file")));
upgrader.migrateIfNeeded(storeDirectory);
}
use of org.neo4j.kernel.impl.storemigration.UpgradableDatabase in project neo4j by neo4j.
the class StoreUpgraderTest method upgradeShouldNotLeaveLeftoverAndMigrationDirs.
@Test
public void upgradeShouldNotLeaveLeftoverAndMigrationDirs() throws Exception {
// Given
fileSystem.deleteFile(new File(dbDirectory, StoreLogService.INTERNAL_LOG_NAME));
PageCache pageCache = pageCacheRule.getPageCache(fileSystem);
UpgradableDatabase upgradableDatabase = new UpgradableDatabase(fileSystem, new StoreVersionCheck(pageCache), new LegacyStoreVersionCheck(fileSystem), getRecordFormats());
// When
newUpgrader(upgradableDatabase, allowMigrateConfig, pageCache).migrateIfNeeded(dbDirectory);
// Then
assertThat(migrationHelperDirs(), is(emptyCollectionOf(File.class)));
}
use of org.neo4j.kernel.impl.storemigration.UpgradableDatabase in project neo4j by neo4j.
the class StoreUpgraderTest method upgradedNeoStoreShouldHaveNewUpgradeTimeAndUpgradeId.
@Test
public void upgradedNeoStoreShouldHaveNewUpgradeTimeAndUpgradeId() throws Exception {
// Given
fileSystem.deleteFile(new File(dbDirectory, StoreLogService.INTERNAL_LOG_NAME));
PageCache pageCache = pageCacheRule.getPageCache(fileSystem);
UpgradableDatabase upgradableDatabase = new UpgradableDatabase(fileSystem, new StoreVersionCheck(pageCache), new LegacyStoreVersionCheck(fileSystem), getRecordFormats());
// When
newUpgrader(upgradableDatabase, allowMigrateConfig, pageCache).migrateIfNeeded(dbDirectory);
// Then
StoreFactory factory = new StoreFactory(dbDirectory, pageCache, fileSystem, NullLogProvider.getInstance());
try (NeoStores neoStores = factory.openAllNeoStores()) {
assertThat(neoStores.getMetaDataStore().getUpgradeTransaction(), equalTo(neoStores.getMetaDataStore().getLastCommittedTransaction()));
assertThat(neoStores.getMetaDataStore().getUpgradeTime(), not(equalTo(MetaDataStore.FIELD_NOT_INITIALIZED)));
long minuteAgo = System.currentTimeMillis() - MINUTES.toMillis(1);
assertThat(neoStores.getMetaDataStore().getUpgradeTime(), greaterThan(minuteAgo));
}
}
use of org.neo4j.kernel.impl.storemigration.UpgradableDatabase in project neo4j by neo4j.
the class StoreMigratorIT method shouldBeAbleToResumeMigrationOnMoving.
@Test
public void shouldBeAbleToResumeMigrationOnMoving() throws Exception {
// GIVEN a legacy database
File storeDirectory = directory.graphDbDir();
File prepare = directory.directory("prepare");
MigrationTestUtils.prepareSampleLegacyDatabase(version, fs, storeDirectory, prepare);
// and a state of the migration saying that it has done the actual migration
LogService logService = NullLogService.getInstance();
PageCache pageCache = pageCacheRule.getPageCache(fs);
UpgradableDatabase upgradableDatabase = new UpgradableDatabase(fs, new StoreVersionCheck(pageCache), new LegacyStoreVersionCheck(fs), selectFormat());
String versionToMigrateFrom = upgradableDatabase.checkUpgradeable(storeDirectory).storeVersion();
SilentMigrationProgressMonitor progressMonitor = new SilentMigrationProgressMonitor();
StoreMigrator migrator = new StoreMigrator(fs, pageCache, CONFIG, logService, schemaIndexProvider);
File migrationDir = new File(storeDirectory, StoreUpgrader.MIGRATION_DIRECTORY);
fs.mkdirs(migrationDir);
migrator.migrate(storeDirectory, migrationDir, progressMonitor.startSection("section"), versionToMigrateFrom, upgradableDatabase.currentVersion());
// WHEN simulating resuming the migration
progressMonitor = new SilentMigrationProgressMonitor();
migrator = new StoreMigrator(fs, pageCache, CONFIG, logService, schemaIndexProvider);
migrator.moveMigratedFiles(migrationDir, storeDirectory, versionToMigrateFrom, upgradableDatabase.currentVersion());
// THEN starting the new store should be successful
StoreFactory storeFactory = new StoreFactory(storeDirectory, pageCache, fs, logService.getInternalLogProvider());
storeFactory.openAllNeoStores().close();
}
Aggregations