Search in sources :

Example 11 with LegacyStoreVersionCheck

use of org.neo4j.kernel.impl.storemigration.legacystore.LegacyStoreVersionCheck in project neo4j by neo4j.

the class StoreUpgraderTest method shouldRefuseToUpgradeIfAnyOfTheStoresWereNotShutDownCleanly.

@Test
public void shouldRefuseToUpgradeIfAnyOfTheStoresWereNotShutDownCleanly() throws IOException {
    File comparisonDirectory = new File("target/" + StoreUpgraderTest.class.getSimpleName() + "shouldRefuseToUpgradeIfAnyOfTheStoresWereNotShutDownCleanly-comparison");
    makeDbNotCleanlyShutdown(false);
    fileSystem.deleteRecursively(comparisonDirectory);
    fileSystem.copyRecursively(dbDirectory, comparisonDirectory);
    PageCache pageCache = pageCacheRule.getPageCache(fileSystem);
    UpgradableDatabase upgradableDatabase = new UpgradableDatabase(fileSystem, new StoreVersionCheck(pageCache), new LegacyStoreVersionCheck(fileSystem), getRecordFormats());
    try {
        newUpgrader(upgradableDatabase, pageCache).migrateIfNeeded(dbDirectory);
        fail("Should throw exception");
    } catch (StoreUpgrader.UnableToUpgradeException e) {
    // expected
    }
    verifyFilesHaveSameContent(fileSystem, comparisonDirectory, dbDirectory);
}
Also used : UnableToUpgradeException(org.neo4j.kernel.impl.storemigration.StoreUpgrader.UnableToUpgradeException) StoreVersionCheck(org.neo4j.kernel.impl.storemigration.StoreVersionCheck) LegacyStoreVersionCheck(org.neo4j.kernel.impl.storemigration.legacystore.LegacyStoreVersionCheck) UpgradableDatabase(org.neo4j.kernel.impl.storemigration.UpgradableDatabase) StoreUpgrader(org.neo4j.kernel.impl.storemigration.StoreUpgrader) LegacyStoreVersionCheck(org.neo4j.kernel.impl.storemigration.legacystore.LegacyStoreVersionCheck) MigrationTestUtils.truncateFile(org.neo4j.kernel.impl.storemigration.MigrationTestUtils.truncateFile) File(java.io.File) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

Example 12 with LegacyStoreVersionCheck

use of org.neo4j.kernel.impl.storemigration.legacystore.LegacyStoreVersionCheck in project neo4j by neo4j.

the class StoreUpgraderTest method upgraderShouldCleanupLegacyLeftoverAndMigrationDirs.

@Test
public void upgraderShouldCleanupLegacyLeftoverAndMigrationDirs() throws Exception {
    // Given
    fileSystem.deleteFile(new File(dbDirectory, StoreLogService.INTERNAL_LOG_NAME));
    fileSystem.mkdir(new File(dbDirectory, StoreUpgrader.MIGRATION_DIRECTORY));
    fileSystem.mkdir(new File(dbDirectory, StoreUpgrader.MIGRATION_LEFT_OVERS_DIRECTORY));
    fileSystem.mkdir(new File(dbDirectory, StoreUpgrader.MIGRATION_LEFT_OVERS_DIRECTORY + "_1"));
    fileSystem.mkdir(new File(dbDirectory, StoreUpgrader.MIGRATION_LEFT_OVERS_DIRECTORY + "_2"));
    fileSystem.mkdir(new File(dbDirectory, StoreUpgrader.MIGRATION_LEFT_OVERS_DIRECTORY + "_42"));
    PageCache pageCache = pageCacheRule.getPageCache(fileSystem);
    // When
    UpgradableDatabase upgradableDatabase = new UpgradableDatabase(fileSystem, new StoreVersionCheck(pageCache), new LegacyStoreVersionCheck(fileSystem), getRecordFormats());
    StoreUpgrader storeUpgrader = newUpgrader(upgradableDatabase, pageCache);
    storeUpgrader.migrateIfNeeded(dbDirectory);
    // Then
    assertThat(migrationHelperDirs(), is(emptyCollectionOf(File.class)));
}
Also used : StoreVersionCheck(org.neo4j.kernel.impl.storemigration.StoreVersionCheck) LegacyStoreVersionCheck(org.neo4j.kernel.impl.storemigration.legacystore.LegacyStoreVersionCheck) UpgradableDatabase(org.neo4j.kernel.impl.storemigration.UpgradableDatabase) StoreUpgrader(org.neo4j.kernel.impl.storemigration.StoreUpgrader) LegacyStoreVersionCheck(org.neo4j.kernel.impl.storemigration.legacystore.LegacyStoreVersionCheck) MigrationTestUtils.truncateFile(org.neo4j.kernel.impl.storemigration.MigrationTestUtils.truncateFile) File(java.io.File) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

Example 13 with LegacyStoreVersionCheck

use of org.neo4j.kernel.impl.storemigration.legacystore.LegacyStoreVersionCheck in project neo4j by neo4j.

the class StoreUpgraderTest method shouldContinueMovingFilesIfUpgradeCancelledWhileMoving.

@Test
public void shouldContinueMovingFilesIfUpgradeCancelledWhileMoving() throws Exception {
    PageCache pageCache = pageCacheRule.getPageCache(fileSystem);
    UpgradableDatabase upgradableDatabase = new UpgradableDatabase(fileSystem, new StoreVersionCheck(pageCache), new LegacyStoreVersionCheck(fileSystem), getRecordFormats());
    String versionToMigrateTo = upgradableDatabase.currentVersion();
    String versionToMigrateFrom = upgradableDatabase.checkUpgradeable(dbDirectory).storeVersion();
    // GIVEN
    {
        StoreUpgrader upgrader = newUpgrader(upgradableDatabase, allowMigrateConfig, pageCache);
        String failureMessage = "Just failing";
        upgrader.addParticipant(participantThatWillFailWhenMoving(failureMessage));
        // WHEN
        try {
            upgrader.migrateIfNeeded(dbDirectory);
            fail("should have thrown");
        } catch (UnableToUpgradeException e) {
            // THEN
            assertTrue(e.getCause() instanceof IOException);
            assertEquals(failureMessage, e.getCause().getMessage());
        }
    }
    // AND WHEN
    {
        StoreUpgrader upgrader = newUpgrader(upgradableDatabase, pageCache);
        StoreMigrationParticipant observingParticipant = Mockito.mock(StoreMigrationParticipant.class);
        upgrader.addParticipant(observingParticipant);
        upgrader.migrateIfNeeded(dbDirectory);
        // THEN
        verify(observingParticipant, Mockito.times(0)).migrate(any(File.class), any(File.class), any(MigrationProgressMonitor.Section.class), eq(versionToMigrateFrom), eq(versionToMigrateTo));
        verify(observingParticipant, Mockito.times(1)).moveMigratedFiles(any(File.class), any(File.class), eq(versionToMigrateFrom), eq(versionToMigrateTo));
        verify(observingParticipant, Mockito.times(1)).cleanup(any(File.class));
    }
}
Also used : StoreVersionCheck(org.neo4j.kernel.impl.storemigration.StoreVersionCheck) LegacyStoreVersionCheck(org.neo4j.kernel.impl.storemigration.legacystore.LegacyStoreVersionCheck) UnableToUpgradeException(org.neo4j.kernel.impl.storemigration.StoreUpgrader.UnableToUpgradeException) SilentMigrationProgressMonitor(org.neo4j.kernel.impl.storemigration.monitoring.SilentMigrationProgressMonitor) MigrationProgressMonitor(org.neo4j.kernel.impl.storemigration.monitoring.MigrationProgressMonitor) StoreMigrationParticipant(org.neo4j.kernel.impl.storemigration.StoreMigrationParticipant) AbstractStoreMigrationParticipant(org.neo4j.kernel.impl.storemigration.participant.AbstractStoreMigrationParticipant) UpgradableDatabase(org.neo4j.kernel.impl.storemigration.UpgradableDatabase) Matchers.containsString(org.hamcrest.Matchers.containsString) StoreUpgrader(org.neo4j.kernel.impl.storemigration.StoreUpgrader) IOException(java.io.IOException) LegacyStoreVersionCheck(org.neo4j.kernel.impl.storemigration.legacystore.LegacyStoreVersionCheck) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

Example 14 with LegacyStoreVersionCheck

use of org.neo4j.kernel.impl.storemigration.legacystore.LegacyStoreVersionCheck 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);
}
Also used : StoreVersionCheck(org.neo4j.kernel.impl.storemigration.StoreVersionCheck) LegacyStoreVersionCheck(org.neo4j.kernel.impl.storemigration.legacystore.LegacyStoreVersionCheck) UpgradableDatabase(org.neo4j.kernel.impl.storemigration.UpgradableDatabase) StoreMigrator(org.neo4j.kernel.impl.storemigration.participant.StoreMigrator) LegacyStoreVersionCheck(org.neo4j.kernel.impl.storemigration.legacystore.LegacyStoreVersionCheck) SchemaIndexMigrator(org.neo4j.kernel.impl.storemigration.participant.SchemaIndexMigrator) SilentMigrationProgressMonitor(org.neo4j.kernel.impl.storemigration.monitoring.SilentMigrationProgressMonitor) File(java.io.File) PageCache(org.neo4j.io.pagecache.PageCache) LogService(org.neo4j.kernel.impl.logging.LogService) NullLogService(org.neo4j.kernel.impl.logging.NullLogService) Test(org.junit.Test)

Example 15 with LegacyStoreVersionCheck

use of org.neo4j.kernel.impl.storemigration.legacystore.LegacyStoreVersionCheck 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);
}
Also used : FilenameFilter(java.io.FilenameFilter) StoreVersionCheck(org.neo4j.kernel.impl.storemigration.StoreVersionCheck) LegacyStoreVersionCheck(org.neo4j.kernel.impl.storemigration.legacystore.LegacyStoreVersionCheck) DelegatingFileSystemAbstraction(org.neo4j.graphdb.mockfs.DelegatingFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) UpgradableDatabase(org.neo4j.kernel.impl.storemigration.UpgradableDatabase) StoreMigrator(org.neo4j.kernel.impl.storemigration.participant.StoreMigrator) IOException(java.io.IOException) StoreUpgrader(org.neo4j.kernel.impl.storemigration.StoreUpgrader) LegacyStoreVersionCheck(org.neo4j.kernel.impl.storemigration.legacystore.LegacyStoreVersionCheck) MigrationTestUtils.truncateFile(org.neo4j.kernel.impl.storemigration.MigrationTestUtils.truncateFile) File(java.io.File) DelegatingFileSystemAbstraction(org.neo4j.graphdb.mockfs.DelegatingFileSystemAbstraction) SilentMigrationProgressMonitor(org.neo4j.kernel.impl.storemigration.monitoring.SilentMigrationProgressMonitor) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

Aggregations

LegacyStoreVersionCheck (org.neo4j.kernel.impl.storemigration.legacystore.LegacyStoreVersionCheck)21 File (java.io.File)17 PageCache (org.neo4j.io.pagecache.PageCache)17 StoreVersionCheck (org.neo4j.kernel.impl.storemigration.StoreVersionCheck)17 UpgradableDatabase (org.neo4j.kernel.impl.storemigration.UpgradableDatabase)17 Test (org.junit.Test)16 SilentMigrationProgressMonitor (org.neo4j.kernel.impl.storemigration.monitoring.SilentMigrationProgressMonitor)8 MigrationTestUtils.truncateFile (org.neo4j.kernel.impl.storemigration.MigrationTestUtils.truncateFile)7 LogService (org.neo4j.kernel.impl.logging.LogService)6 NullLogService (org.neo4j.kernel.impl.logging.NullLogService)6 StoreUpgrader (org.neo4j.kernel.impl.storemigration.StoreUpgrader)6 StoreMigrator (org.neo4j.kernel.impl.storemigration.participant.StoreMigrator)4 IOException (java.io.IOException)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 StoreFactory (org.neo4j.kernel.impl.store.StoreFactory)3 UnableToUpgradeException (org.neo4j.kernel.impl.storemigration.StoreUpgrader.UnableToUpgradeException)3 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)2 FilenameFilter (java.io.FilenameFilter)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1