Search in sources :

Example 1 with UpgradableDatabase

use of org.neo4j.kernel.impl.storemigration.UpgradableDatabase in project neo4j by neo4j.

the class StoreMigratorIT method shouldComputeTheLastTxInfoCorrectly.

@Test
public void shouldComputeTheLastTxInfoCorrectly() throws Exception {
    // given
    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.mkdir(migrationDir);
    // when
    migrator.migrate(storeDirectory, migrationDir, progressMonitor.startSection("section"), versionToMigrateFrom, upgradableDatabase.currentVersion());
    // then
    assertTrue(txIdComparator.apply(migrator.readLastTxInformation(migrationDir)));
}
Also used : StoreVersionCheck(org.neo4j.kernel.impl.storemigration.StoreVersionCheck) LegacyStoreVersionCheck(org.neo4j.kernel.impl.storemigration.legacystore.LegacyStoreVersionCheck) UpgradableDatabase(org.neo4j.kernel.impl.storemigration.UpgradableDatabase) LegacyStoreVersionCheck(org.neo4j.kernel.impl.storemigration.legacystore.LegacyStoreVersionCheck) File(java.io.File) SilentMigrationProgressMonitor(org.neo4j.kernel.impl.storemigration.monitoring.SilentMigrationProgressMonitor) LogService(org.neo4j.kernel.impl.logging.LogService) NullLogService(org.neo4j.kernel.impl.logging.NullLogService) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

Example 2 with UpgradableDatabase

use of org.neo4j.kernel.impl.storemigration.UpgradableDatabase in project neo4j by neo4j.

the class StoreUpgraderInterruptionTestIT method shouldSucceedWithUpgradeAfterPreviousAttemptDiedDuringMovingFiles.

@Test
public void shouldSucceedWithUpgradeAfterPreviousAttemptDiedDuringMovingFiles() throws IOException, ConsistencyCheckIncompleteException {
    File workingDirectory = directory.directory("working");
    File prepareDirectory = directory.directory("prepare");
    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 moveMigratedFiles(File migrationDir, File storeDir, String versionToUpgradeFrom, String versionToMigrateTo) throws IOException {
            super.moveMigratedFiles(migrationDir, storeDir, versionToUpgradeFrom, 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());
    }
    assertTrue(checkNeoStoreHasDefaultFormatVersion(check, workingDirectory));
    assertTrue(allStoreFilesHaveNoTrailer(fs, workingDirectory));
    progressMonitor = new SilentMigrationProgressMonitor();
    StoreMigrator migrator = new StoreMigrator(fs, pageCache, CONFIG, logService, schemaIndexProvider);
    newUpgrader(upgradableDatabase, pageCache, progressMonitor, createIndexMigrator(), migrator).migrateIfNeeded(workingDirectory);
    assertTrue(checkNeoStoreHasDefaultFormatVersion(check, workingDirectory));
    assertTrue(allStoreFilesHaveNoTrailer(fs, workingDirectory));
    pageCache.close();
    // 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) File(java.io.File) SilentMigrationProgressMonitor(org.neo4j.kernel.impl.storemigration.monitoring.SilentMigrationProgressMonitor) 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 3 with UpgradableDatabase

use of org.neo4j.kernel.impl.storemigration.UpgradableDatabase in project neo4j by neo4j.

the class StoreUpgraderTest method shouldLeaveAllFilesUntouchedIfWrongVersionNumberFound.

@Test
public void shouldLeaveAllFilesUntouchedIfWrongVersionNumberFound() throws IOException {
    Set<String> applicableVersions = versionSet(StandardV2_0.STORE_VERSION, StandardV2_1.STORE_VERSION, StandardV2_2.STORE_VERSION);
    assumeTrue("Applicable only to specified version set.", applicableVersions.contains(version));
    File comparisonDirectory = new File("target/" + StoreUpgraderTest.class.getSimpleName() + "shouldLeaveAllFilesUntouchedIfWrongVersionNumberFound-comparison");
    changeVersionNumber(fileSystem, new File(dbDirectory, "neostore.nodestore.db"), "v0.9.5");
    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.UnexpectedUpgradingStoreVersionException e) {
    // expected
    }
    verifyFilesHaveSameContent(fileSystem, comparisonDirectory, dbDirectory);
}
Also used : StoreVersionCheck(org.neo4j.kernel.impl.storemigration.StoreVersionCheck) LegacyStoreVersionCheck(org.neo4j.kernel.impl.storemigration.legacystore.LegacyStoreVersionCheck) UpgradableDatabase(org.neo4j.kernel.impl.storemigration.UpgradableDatabase) Matchers.containsString(org.hamcrest.Matchers.containsString) 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 4 with UpgradableDatabase

use of org.neo4j.kernel.impl.storemigration.UpgradableDatabase in project neo4j by neo4j.

the class StoreUpgraderTest method shouldHaltUpgradeIfUpgradeConfigurationVetoesTheProcess.

@Test
public void shouldHaltUpgradeIfUpgradeConfigurationVetoesTheProcess() throws IOException {
    PageCache pageCache = pageCacheRule.getPageCache(fileSystem);
    Config deniedMigrationConfig = Config.embeddedDefaults(MapUtil.stringMap(GraphDatabaseSettings.allow_store_upgrade.name(), "false"));
    UpgradableDatabase upgradableDatabase = new UpgradableDatabase(fileSystem, new StoreVersionCheck(pageCache), new LegacyStoreVersionCheck(fileSystem), getRecordFormats());
    try {
        newUpgrader(upgradableDatabase, deniedMigrationConfig, pageCache).migrateIfNeeded(dbDirectory);
        fail("Should throw exception");
    } catch (UpgradeNotAllowedByConfigurationException e) {
    // expected
    }
}
Also used : UpgradeNotAllowedByConfigurationException(org.neo4j.kernel.impl.storemigration.UpgradeNotAllowedByConfigurationException) StoreVersionCheck(org.neo4j.kernel.impl.storemigration.StoreVersionCheck) LegacyStoreVersionCheck(org.neo4j.kernel.impl.storemigration.legacystore.LegacyStoreVersionCheck) Config(org.neo4j.kernel.configuration.Config) UpgradableDatabase(org.neo4j.kernel.impl.storemigration.UpgradableDatabase) LegacyStoreVersionCheck(org.neo4j.kernel.impl.storemigration.legacystore.LegacyStoreVersionCheck) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

Example 5 with UpgradableDatabase

use of org.neo4j.kernel.impl.storemigration.UpgradableDatabase in project neo4j by neo4j.

the class StoreUpgraderTest method shouldUpgradeAnOldFormatStore.

@Test
public void shouldUpgradeAnOldFormatStore() throws IOException, ConsistencyCheckIncompleteException {
    // Given
    PageCache pageCache = pageCacheRule.getPageCache(fileSystem);
    UpgradableDatabase upgradableDatabase = new UpgradableDatabase(fileSystem, new StoreVersionCheck(pageCache), new LegacyStoreVersionCheck(fileSystem), getRecordFormats());
    Set<String> versionSet = versionSet(StandardV2_0.STORE_VERSION, StandardV2_1.STORE_VERSION, StandardV2_2.STORE_VERSION);
    assertEquals(versionSet.contains(version), allLegacyStoreFilesHaveVersion(fileSystem, dbDirectory, version));
    // When
    newUpgrader(upgradableDatabase, pageCache).migrateIfNeeded(dbDirectory);
    // Then
    assertCorrectStoreVersion(getRecordFormats().storeVersion(), check, dbDirectory);
    assertTrue(allStoreFilesHaveNoTrailer(fileSystem, dbDirectory));
    // We leave logical logs in place since the new version can read the old
    assertFalse(containsAnyStoreFiles(fileSystem, isolatedMigrationDirectoryOf(dbDirectory)));
    // Since consistency checker is in read only mode we need to start/stop db to generate label scan store.
    startStopDatabase();
    assertConsistentStore(dbDirectory);
}
Also used : StoreVersionCheck(org.neo4j.kernel.impl.storemigration.StoreVersionCheck) LegacyStoreVersionCheck(org.neo4j.kernel.impl.storemigration.legacystore.LegacyStoreVersionCheck) UpgradableDatabase(org.neo4j.kernel.impl.storemigration.UpgradableDatabase) Matchers.containsString(org.hamcrest.Matchers.containsString) LegacyStoreVersionCheck(org.neo4j.kernel.impl.storemigration.legacystore.LegacyStoreVersionCheck) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

Aggregations

StoreVersionCheck (org.neo4j.kernel.impl.storemigration.StoreVersionCheck)17 UpgradableDatabase (org.neo4j.kernel.impl.storemigration.UpgradableDatabase)17 LegacyStoreVersionCheck (org.neo4j.kernel.impl.storemigration.legacystore.LegacyStoreVersionCheck)17 Test (org.junit.Test)16 PageCache (org.neo4j.io.pagecache.PageCache)16 File (java.io.File)14 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 Matchers.containsString (org.hamcrest.Matchers.containsString)3 StoreFactory (org.neo4j.kernel.impl.store.StoreFactory)3 UnableToUpgradeException (org.neo4j.kernel.impl.storemigration.StoreUpgrader.UnableToUpgradeException)3 StoreMigrator (org.neo4j.kernel.impl.storemigration.participant.StoreMigrator)3 IOException (java.io.IOException)2 FilenameFilter (java.io.FilenameFilter)1 Before (org.junit.Before)1 DelegatingFileSystemAbstraction (org.neo4j.graphdb.mockfs.DelegatingFileSystemAbstraction)1 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)1