Search in sources :

Example 1 with RecordStoreVersionCheck

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);
}
Also used : MigrationProgressMonitor(org.neo4j.storageengine.migration.MigrationProgressMonitor) RecordStoreVersionCheck(org.neo4j.kernel.impl.storemigration.RecordStoreVersionCheck) RecordStorageMigrator(org.neo4j.kernel.impl.storemigration.RecordStorageMigrator) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) IndexImporterFactory(org.neo4j.internal.batchimport.IndexImporterFactory) ProgressReporter(org.neo4j.common.ProgressReporter) IdGeneratorMigrator(org.neo4j.kernel.impl.storemigration.IdGeneratorMigrator) SchemaIndexMigrator(org.neo4j.storageengine.migration.SchemaIndexMigrator) NullLogService(org.neo4j.logging.internal.NullLogService) LogService(org.neo4j.logging.internal.LogService) Test(org.junit.Test)

Example 2 with RecordStoreVersionCheck

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);
}
Also used : Path(java.nio.file.Path) RecordStoreVersionCheck(org.neo4j.kernel.impl.storemigration.RecordStoreVersionCheck) PageCache(org.neo4j.io.pagecache.PageCache) Before(org.junit.Before)

Example 3 with RecordStoreVersionCheck

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.");
}
Also used : DatabaseManagementException(org.neo4j.dbms.api.DatabaseManagementException) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) RecordStoreVersionCheck(org.neo4j.kernel.impl.storemigration.RecordStoreVersionCheck) NamedDatabaseId(org.neo4j.kernel.database.NamedDatabaseId) Test(org.junit.jupiter.api.Test)

Example 4 with RecordStoreVersionCheck

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.");
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) RecordFormats(org.neo4j.kernel.impl.store.format.RecordFormats) RecordStoreVersionCheck(org.neo4j.kernel.impl.storemigration.RecordStoreVersionCheck) Test(org.junit.jupiter.api.Test)

Example 5 with RecordStoreVersionCheck

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);
}
Also used : MigrationProgressMonitor(org.neo4j.storageengine.migration.MigrationProgressMonitor) RecordStoreVersionCheck(org.neo4j.kernel.impl.storemigration.RecordStoreVersionCheck) RecordStorageMigrator(org.neo4j.kernel.impl.storemigration.RecordStorageMigrator) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) IdGeneratorMigrator(org.neo4j.kernel.impl.storemigration.IdGeneratorMigrator) NullLogService(org.neo4j.logging.internal.NullLogService) LogService(org.neo4j.logging.internal.LogService) Test(org.junit.Test)

Aggregations

RecordStoreVersionCheck (org.neo4j.kernel.impl.storemigration.RecordStoreVersionCheck)6 Test (org.junit.Test)3 IdGeneratorMigrator (org.neo4j.kernel.impl.storemigration.IdGeneratorMigrator)3 RecordStorageMigrator (org.neo4j.kernel.impl.storemigration.RecordStorageMigrator)3 LogService (org.neo4j.logging.internal.LogService)3 NullLogService (org.neo4j.logging.internal.NullLogService)3 MigrationProgressMonitor (org.neo4j.storageengine.migration.MigrationProgressMonitor)3 Test (org.junit.jupiter.api.Test)2 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)2 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)2 Path (java.nio.file.Path)1 Before (org.junit.Before)1 ProgressReporter (org.neo4j.common.ProgressReporter)1 DatabaseManagementException (org.neo4j.dbms.api.DatabaseManagementException)1 IndexImporterFactory (org.neo4j.internal.batchimport.IndexImporterFactory)1 PageCache (org.neo4j.io.pagecache.PageCache)1 DefaultPageCacheTracer (org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer)1 NamedDatabaseId (org.neo4j.kernel.database.NamedDatabaseId)1 RecordFormats (org.neo4j.kernel.impl.store.format.RecordFormats)1 SchemaIndexMigrator (org.neo4j.storageengine.migration.SchemaIndexMigrator)1