use of org.neo4j.kernel.impl.storemigration.RecordStoreVersionCheck in project neo4j by neo4j.
the class StoreUpgraderInterruptionTestIT method shouldSucceedWithUpgradeAfterPreviousAttemptDiedDuringMigration.
@Test
public void shouldSucceedWithUpgradeAfterPreviousAttemptDiedDuringMigration() throws IOException, ConsistencyCheckIncompleteException {
MigrationTestUtils.prepareSampleLegacyDatabase(version, fs, workingDatabaseLayout.databaseDirectory(), prepareDirectory);
RecordStoreVersionCheck versionCheck = new RecordStoreVersionCheck(fs, pageCache, workingDatabaseLayout, NullLogProvider.getInstance(), Config.defaults(), NULL);
MigrationProgressMonitor progressMonitor = MigrationProgressMonitor.SILENT;
LogService logService = NullLogService.getInstance();
RecordStorageMigrator failingStoreMigrator = new RecordStorageMigrator(fs, pageCache, CONFIG, logService, jobScheduler, NULL, batchImporterFactory, INSTANCE) {
@Override
public void migrate(DatabaseLayout directoryLayout, DatabaseLayout migrationLayout, ProgressReporter progressReporter, String versionToMigrateFrom, String versionToMigrateTo, IndexImporterFactory indexImporterFactory) throws IOException, KernelException {
super.migrate(directoryLayout, migrationLayout, progressReporter, versionToMigrateFrom, versionToMigrateTo, indexImporterFactory);
throw new RuntimeException("This upgrade is failing");
}
};
try {
newUpgrader(versionCheck, progressMonitor, createIndexMigrator(), failingStoreMigrator).migrateIfNeeded(workingDatabaseLayout, false);
fail("Should throw exception");
} catch (RuntimeException e) {
assertEquals("This upgrade is failing", e.getMessage());
}
assertTrue(checkNeoStoreHasFormatVersion(versionCheck, baselineFormat));
RecordStorageMigrator migrator = new RecordStorageMigrator(fs, pageCache, CONFIG, logService, jobScheduler, NULL, batchImporterFactory, INSTANCE);
IdGeneratorMigrator idMigrator = new IdGeneratorMigrator(fs, pageCache, CONFIG, NULL);
SchemaIndexMigrator indexMigrator = createIndexMigrator();
newUpgrader(versionCheck, progressMonitor, indexMigrator, migrator, idMigrator).migrateIfNeeded(workingDatabaseLayout, false);
assertTrue(checkNeoStoreHasFormatVersion(versionCheck, successorFormat));
// Since consistency checker is in read only mode we need to start/stop db to generate label scan store.
startStopDatabase(neo4jLayout.homeDirectory());
assertConsistentStore(workingDatabaseLayout);
}
use of org.neo4j.kernel.impl.storemigration.RecordStoreVersionCheck in project neo4j by neo4j.
the class StoreUpgradeOnStartupTest method setup.
@Before
public void setup() throws IOException {
fileSystem = fileSystemRule.get();
PageCache pageCache = pageCacheRule.getPageCache(fileSystem);
workingHomeDir = testDir.homePath("working_" + version);
workingDatabaseLayout = Neo4jLayout.of(workingHomeDir).databaseLayout(DEFAULT_DATABASE_NAME);
check = new RecordStoreVersionCheck(fileSystem, pageCache, workingDatabaseLayout, NullLogProvider.getInstance(), Config.defaults(), NULL);
Path prepareDirectory = testDir.directory("prepare_" + version);
prepareSampleLegacyDatabase(version, fileSystem, workingDatabaseLayout.databaseDirectory(), prepareDirectory);
baselineFormat = RecordFormatSelector.selectForVersion(version);
successorFormat = RecordFormatSelector.findLatestFormatInFamily(baselineFormat).orElse(baselineFormat);
}
use of org.neo4j.kernel.impl.storemigration.RecordStoreVersionCheck in project neo4j by neo4j.
the class DefaultDatabaseManagerUpgradeIT method upgradeDatabaseMustThrowOnFailure.
@Test
void upgradeDatabaseMustThrowOnFailure() {
// Given
RuntimeException expectedException = new RuntimeException("Dammit Leroy!");
useThrowingMigrationLogProvider(expectedException);
createDbms();
GraphDatabaseAPI db = (GraphDatabaseAPI) dbms.database(DEFAULT_DATABASE_NAME);
DefaultDatabaseManager databaseManager = getDatabaseManager(db);
RecordStoreVersionCheck check = new RecordStoreVersionCheck(fs, getPageCache(db), databaseLayout, NullLogProvider.getInstance(), Config.defaults(), NULL);
assertFalse(db.isAvailable(100), "Expected database to have failed during startup because we don't allow upgrade.");
// When
NamedDatabaseId namedDatabaseId = db.databaseId();
DatabaseManagementException e = assertThrows(DatabaseManagementException.class, () -> databaseManager.upgradeDatabase(namedDatabaseId));
// Then
assertThat(e).hasMessage("Failed to upgrade " + namedDatabaseId);
assertThat(e).hasRootCause(expectedException);
assertFalse(db.isAvailable(100), "Expected database to be available after upgrade");
assertTrue(MigrationTestUtils.checkNeoStoreHasFormatVersion(check, StandardV3_4.RECORD_FORMATS), "Expected store not upgraded.");
}
use of org.neo4j.kernel.impl.storemigration.RecordStoreVersionCheck in project neo4j by neo4j.
the class DefaultDatabaseManagerUpgradeIT method upgradeDatabase.
@Test
void upgradeDatabase() {
// Given
createDbms();
GraphDatabaseAPI db = (GraphDatabaseAPI) dbms.database(DEFAULT_DATABASE_NAME);
DefaultDatabaseManager databaseManager = getDatabaseManager(db);
RecordStoreVersionCheck check = new RecordStoreVersionCheck(fs, getPageCache(db), databaseLayout, NullLogProvider.getInstance(), Config.defaults(), NULL);
assertFalse(db.isAvailable(100), "Expected database to have failed during startup because we don't allow upgrade.");
// When
databaseManager.upgradeDatabase(db.databaseId());
// Then
assertTrue(db.isAvailable(100), "Expected database to be available after upgrade");
RecordFormats expectedFormat = RecordFormatSelector.findLatestFormatInFamily(StandardV3_4.RECORD_FORMATS).orElseThrow();
assertTrue(MigrationTestUtils.checkNeoStoreHasFormatVersion(check, expectedFormat), "Expected store version to be default.");
}
use of org.neo4j.kernel.impl.storemigration.RecordStoreVersionCheck in project neo4j by neo4j.
the class StoreUpgraderInterruptionTestIT method shouldSucceedWithUpgradeAfterPreviousAttemptDiedDuringMovingFiles.
@Test
public void shouldSucceedWithUpgradeAfterPreviousAttemptDiedDuringMovingFiles() throws IOException, ConsistencyCheckIncompleteException {
MigrationTestUtils.prepareSampleLegacyDatabase(version, fs, workingDatabaseLayout.databaseDirectory(), prepareDirectory);
RecordStoreVersionCheck versionCheck = new RecordStoreVersionCheck(fs, pageCache, workingDatabaseLayout, NullLogProvider.getInstance(), Config.defaults(), NULL);
MigrationProgressMonitor progressMonitor = MigrationProgressMonitor.SILENT;
LogService logService = NullLogService.getInstance();
RecordStorageMigrator failingStoreMigrator = new RecordStorageMigrator(fs, pageCache, CONFIG, logService, jobScheduler, NULL, batchImporterFactory, INSTANCE) {
@Override
public void moveMigratedFiles(DatabaseLayout migrationLayout, DatabaseLayout directoryLayout, String versionToUpgradeFrom, String versionToMigrateTo) throws IOException {
super.moveMigratedFiles(migrationLayout, directoryLayout, versionToUpgradeFrom, versionToMigrateTo);
throw new RuntimeException("This upgrade is failing");
}
};
IdGeneratorMigrator idMigrator = new IdGeneratorMigrator(fs, pageCache, CONFIG, NULL);
assertTrue(checkNeoStoreHasFormatVersion(versionCheck, baselineFormat));
try {
newUpgrader(versionCheck, progressMonitor, createIndexMigrator(), failingStoreMigrator, idMigrator).migrateIfNeeded(workingDatabaseLayout, false);
fail("Should throw exception");
} catch (RuntimeException e) {
assertEquals("This upgrade is failing", e.getMessage());
}
RecordStorageMigrator migrator = new RecordStorageMigrator(fs, pageCache, CONFIG, logService, jobScheduler, NULL, batchImporterFactory, INSTANCE);
newUpgrader(versionCheck, progressMonitor, createIndexMigrator(), migrator, idMigrator).migrateIfNeeded(workingDatabaseLayout, false);
assertTrue(checkNeoStoreHasFormatVersion(versionCheck, successorFormat));
pageCache.close();
// Since consistency checker is in read only mode we need to start/stop db to generate label scan store.
startStopDatabase(neo4jLayout.homeDirectory());
assertConsistentStore(workingDatabaseLayout);
}
Aggregations