Search in sources :

Example 6 with StoreVersionCheck

use of org.neo4j.kernel.impl.storemigration.StoreVersionCheck 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 7 with StoreVersionCheck

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

the class StoreUpgraderTest method assertCorrectStoreVersion.

private static void assertCorrectStoreVersion(String expectedStoreVersion, StoreVersionCheck check, File storeDir) {
    File neoStoreFile = new File(storeDir, MetaDataStore.DEFAULT_NAME);
    StoreVersionCheck.Result result = check.hasVersion(neoStoreFile, expectedStoreVersion);
    assertTrue("Unexpected store version", result.outcome.isSuccessful());
}
Also used : StoreVersionCheck(org.neo4j.kernel.impl.storemigration.StoreVersionCheck) LegacyStoreVersionCheck(org.neo4j.kernel.impl.storemigration.legacystore.LegacyStoreVersionCheck) MigrationTestUtils.truncateFile(org.neo4j.kernel.impl.storemigration.MigrationTestUtils.truncateFile) File(java.io.File)

Example 8 with StoreVersionCheck

use of org.neo4j.kernel.impl.storemigration.StoreVersionCheck 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 9 with StoreVersionCheck

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

the class VersionCommand method execute.

@Override
public void execute(String[] args) throws IncorrectUsage, CommandFailed {
    final Path storeDir = arguments.parseMandatoryPath("store", args);
    Validators.CONTAINS_EXISTING_DATABASE.validate(storeDir.toFile());
    try (DefaultFileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
        PageCache pageCache = StandalonePageCacheFactory.createPageCache(fileSystem)) {
        final String storeVersion = new StoreVersionCheck(pageCache).getVersion(storeDir.resolve(MetaDataStore.DEFAULT_NAME).toFile()).orElseThrow(() -> new CommandFailed(String.format("Could not find version metadata in store '%s'", storeDir)));
        final String fmt = "%-25s%s";
        out.accept(String.format(fmt, "Store format version:", storeVersion));
        RecordFormats format = RecordFormatSelector.selectForVersion(storeVersion);
        out.accept(String.format(fmt, "Introduced in version:", format.introductionVersion()));
        findSuccessor(format).map(next -> String.format(fmt, "Superseded in version:", next.introductionVersion())).ifPresent(out);
        out.accept(String.format(fmt, "Current version:", Version.getNeo4jVersion()));
    } catch (IOException e) {
        throw new CommandFailed(e.getMessage(), e);
    }
}
Also used : MandatoryCanonicalPath(org.neo4j.commandline.arguments.common.MandatoryCanonicalPath) Path(java.nio.file.Path) PageCache(org.neo4j.io.pagecache.PageCache) Validators(org.neo4j.kernel.impl.util.Validators) StandalonePageCacheFactory(org.neo4j.io.pagecache.impl.muninn.StandalonePageCacheFactory) Version(org.neo4j.kernel.internal.Version) IOException(java.io.IOException) RecordFormatSelector(org.neo4j.kernel.impl.store.format.RecordFormatSelector) StoreVersionCheck(org.neo4j.kernel.impl.storemigration.StoreVersionCheck) AdminCommand(org.neo4j.commandline.admin.AdminCommand) RecordFormats(org.neo4j.kernel.impl.store.format.RecordFormats) Consumer(java.util.function.Consumer) MandatoryCanonicalPath(org.neo4j.commandline.arguments.common.MandatoryCanonicalPath) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) Arguments(org.neo4j.commandline.arguments.Arguments) OutsideWorld(org.neo4j.commandline.admin.OutsideWorld) RecordFormatSelector.findSuccessor(org.neo4j.kernel.impl.store.format.RecordFormatSelector.findSuccessor) MetaDataStore(org.neo4j.kernel.impl.store.MetaDataStore) CommandFailed(org.neo4j.commandline.admin.CommandFailed) IncorrectUsage(org.neo4j.commandline.admin.IncorrectUsage) Path(java.nio.file.Path) StoreVersionCheck(org.neo4j.kernel.impl.storemigration.StoreVersionCheck) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) RecordFormats(org.neo4j.kernel.impl.store.format.RecordFormats) CommandFailed(org.neo4j.commandline.admin.CommandFailed) IOException(java.io.IOException) PageCache(org.neo4j.io.pagecache.PageCache)

Example 10 with StoreVersionCheck

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

the class StoreMigratorTest method shouldNotDoActualStoreMigrationBetween3_0_5_and_next.

@Test
public void shouldNotDoActualStoreMigrationBetween3_0_5_and_next() throws Exception {
    // GIVEN a store in vE.H.0 format
    File storeDir = directory.directory();
    new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder(storeDir).setConfig(GraphDatabaseSettings.record_format, HighLimitV3_0_0.NAME).newGraphDatabase().shutdown();
    Config config = Config.embeddedDefaults(stringMap(pagecache_memory.name(), "8m"));
    try (FileSystemAbstraction fs = new DefaultFileSystemAbstraction();
        PageCache pageCache = new ConfiguringPageCacheFactory(fs, config, NULL, PageCursorTracerSupplier.NULL, NullLog.getInstance()).getOrCreatePageCache()) {
        // For test code sanity
        String fromStoreVersion = StoreVersion.HIGH_LIMIT_V3_0_0.versionString();
        Result hasVersionResult = new StoreVersionCheck(pageCache).hasVersion(new File(storeDir, NEO_STORE.fileName(STORE)), fromStoreVersion);
        assertTrue(hasVersionResult.actualVersion, hasVersionResult.outcome.isSuccessful());
        // WHEN
        StoreMigrator migrator = new StoreMigrator(fs, pageCache, config, NullLogService.getInstance(), NO_INDEX_PROVIDER);
        MigrationProgressMonitor.Section monitor = mock(MigrationProgressMonitor.Section.class);
        File migrationDir = new File(storeDir, "migration");
        fs.mkdirs(migrationDir);
        migrator.migrate(storeDir, migrationDir, monitor, fromStoreVersion, StoreVersion.HIGH_LIMIT_V3_0_6.versionString());
        // THEN
        verifyNoMoreInteractions(monitor);
    }
}
Also used : DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) Config(org.neo4j.kernel.configuration.Config) ConfiguringPageCacheFactory(org.neo4j.kernel.impl.pagecache.ConfiguringPageCacheFactory) Result(org.neo4j.kernel.impl.storemigration.StoreVersionCheck.Result) StoreVersionCheck(org.neo4j.kernel.impl.storemigration.StoreVersionCheck) MigrationProgressMonitor(org.neo4j.kernel.impl.storemigration.monitoring.MigrationProgressMonitor) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) File(java.io.File) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

Aggregations

StoreVersionCheck (org.neo4j.kernel.impl.storemigration.StoreVersionCheck)22 PageCache (org.neo4j.io.pagecache.PageCache)19 LegacyStoreVersionCheck (org.neo4j.kernel.impl.storemigration.legacystore.LegacyStoreVersionCheck)19 File (java.io.File)17 Test (org.junit.Test)17 UpgradableDatabase (org.neo4j.kernel.impl.storemigration.UpgradableDatabase)17 MigrationTestUtils.truncateFile (org.neo4j.kernel.impl.storemigration.MigrationTestUtils.truncateFile)9 SilentMigrationProgressMonitor (org.neo4j.kernel.impl.storemigration.monitoring.SilentMigrationProgressMonitor)9 NullLogService (org.neo4j.kernel.impl.logging.NullLogService)7 StoreUpgrader (org.neo4j.kernel.impl.storemigration.StoreUpgrader)7 LogService (org.neo4j.kernel.impl.logging.LogService)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 Before (org.junit.Before)2 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)2 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)2 Config (org.neo4j.kernel.configuration.Config)2