Search in sources :

Example 16 with StoreVersionCheck

use of org.neo4j.storageengine.api.StoreVersionCheck in project neo4j by neo4j.

the class StoreUpgraderTest method notParticipatingParticipantsAreNotPartOfMigration.

@ParameterizedTest
@MethodSource("versions")
void notParticipatingParticipantsAreNotPartOfMigration(RecordFormats formats) throws IOException {
    init(formats);
    StoreVersionCheck check = getVersionCheck(pageCache);
    StoreUpgrader storeUpgrader = newUpgrader(check, pageCache);
    assertThat(storeUpgrader.getParticipants()).hasSize(2);
}
Also used : StoreVersionCheck(org.neo4j.storageengine.api.StoreVersionCheck) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 17 with StoreVersionCheck

use of org.neo4j.storageengine.api.StoreVersionCheck in project neo4j by neo4j.

the class StoreUpgraderTest method forbidRegistrationOfParticipantsWithSameName.

@ParameterizedTest
@MethodSource("versions")
void forbidRegistrationOfParticipantsWithSameName(RecordFormats formats) throws IOException {
    init(formats);
    StoreVersionCheck check = getVersionCheck(pageCache);
    StoreUpgrader upgrader = newUpgrader(check, allowMigrateConfig, pageCache);
    upgrader.addParticipant(new EmptyNamedMigrationParticipant("foo"));
    assertThrows(IllegalStateException.class, () -> upgrader.addParticipant(new EmptyNamedMigrationParticipant("foo")));
}
Also used : StoreVersionCheck(org.neo4j.storageengine.api.StoreVersionCheck) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 18 with StoreVersionCheck

use of org.neo4j.storageengine.api.StoreVersionCheck in project neo4j by neo4j.

the class RecordStoreVersionCheckTest method shouldReportFileWithIncorrectVersion.

@Test
void shouldReportFileWithIncorrectVersion() throws IOException {
    // given
    Path neoStore = emptyFile(fileSystem);
    long v1 = MetaDataStore.versionStringToLong("V1");
    MetaDataStore.setRecord(pageCache, neoStore, MetaDataStore.Position.STORE_VERSION, v1, databaseLayout.getDatabaseName(), NULL);
    RecordStoreVersionCheck storeVersionCheck = newStoreVersionCheck();
    // when
    StoreVersionCheck.Result result = storeVersionCheck.checkUpgrade("V2", NULL);
    // then
    assertFalse(result.outcome.isSuccessful());
    assertEquals(Outcome.unexpectedStoreVersion, result.outcome);
    assertEquals("V1", result.actualVersion);
}
Also used : Path(java.nio.file.Path) StoreVersionCheck(org.neo4j.storageengine.api.StoreVersionCheck) Test(org.junit.jupiter.api.Test)

Example 19 with StoreVersionCheck

use of org.neo4j.storageengine.api.StoreVersionCheck in project neo4j by neo4j.

the class RecordStoreVersionCheckTest method tracePageCacheAccessOnCheckUpgradable.

@Test
void tracePageCacheAccessOnCheckUpgradable() throws IOException {
    Path neoStore = emptyFile(fileSystem);
    String storeVersion = "V1";
    long v1 = MetaDataStore.versionStringToLong(storeVersion);
    MetaDataStore.setRecord(pageCache, neoStore, MetaDataStore.Position.STORE_VERSION, v1, databaseLayout.getDatabaseName(), NULL);
    RecordStoreVersionCheck storeVersionCheck = newStoreVersionCheck();
    var pageCacheTracer = new DefaultPageCacheTracer();
    var cursorContext = new CursorContext(pageCacheTracer.createPageCursorTracer("tracePageCacheAccessOnCheckUpgradable"));
    StoreVersionCheck.Result result = storeVersionCheck.checkUpgrade(storeVersion, cursorContext);
    assertTrue(result.outcome.isSuccessful());
    PageCursorTracer cursorTracer = cursorContext.getCursorTracer();
    assertThat(cursorTracer.pins()).isOne();
    assertThat(cursorTracer.unpins()).isOne();
    assertThat(cursorTracer.faults()).isOne();
}
Also used : Path(java.nio.file.Path) StoreVersionCheck(org.neo4j.storageengine.api.StoreVersionCheck) PageCursorTracer(org.neo4j.io.pagecache.tracing.cursor.PageCursorTracer) CursorContext(org.neo4j.io.pagecache.context.CursorContext) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer) Test(org.junit.jupiter.api.Test)

Example 20 with StoreVersionCheck

use of org.neo4j.storageengine.api.StoreVersionCheck in project neo4j by neo4j.

the class DatabaseMigrator method migrate.

/**
 * Performs construction of {@link StoreUpgrader} and all of the necessary participants and performs store
 * migration if that is required.
 *
 * @param forceUpgrade Ignore the value of the {@link GraphDatabaseSettings#allow_upgrade} setting.
 */
public void migrate(boolean forceUpgrade) throws IOException {
    StoreVersionCheck versionCheck = storageEngineFactory.versionCheck(fs, databaseLayout, config, pageCache, logService, pageCacheTracer);
    LogsUpgrader logsUpgrader = new LogsUpgrader(fs, storageEngineFactory, databaseLayout, pageCache, legacyLogsLocator, config, dependencyResolver, pageCacheTracer, memoryTracker, databaseHealth, forceUpgrade);
    Log userLog = logService.getUserLog(DatabaseMigrator.class);
    VisibleMigrationProgressMonitor progress = new VisibleMigrationProgressMonitor(userLog);
    LogProvider logProvider = logService.getInternalLogProvider();
    StoreUpgrader storeUpgrader = new StoreUpgrader(versionCheck, progress, config, fs, logProvider, logsUpgrader, pageCacheTracer);
    // Get all the participants from the storage engine and add them where they want to be
    var storeParticipants = storageEngineFactory.migrationParticipants(fs, config, pageCache, jobScheduler, logService, pageCacheTracer, memoryTracker);
    storeParticipants.forEach(storeUpgrader::addParticipant);
    IndexProviderMap indexProviderMap = dependencyResolver.resolveDependency(IndexProviderMap.class);
    IndexConfigMigrator indexConfigMigrator = new IndexConfigMigrator(fs, config, pageCache, logService, storageEngineFactory, indexProviderMap, logService.getUserLog(IndexConfigMigrator.class), pageCacheTracer, memoryTracker);
    storeUpgrader.addParticipant(indexConfigMigrator);
    IndexProviderMigrator indexProviderMigrator = new IndexProviderMigrator(fs, config, pageCache, logService, storageEngineFactory, pageCacheTracer, memoryTracker);
    storeUpgrader.addParticipant(indexProviderMigrator);
    // Do individual index provider migration last because they may delete files that we need in earlier steps.
    indexProviderMap.accept(provider -> storeUpgrader.addParticipant(provider.storeMigrationParticipant(fs, pageCache, storageEngineFactory)));
    try {
        storeUpgrader.migrateIfNeeded(databaseLayout, forceUpgrade);
    } catch (Exception e) {
        userLog.error("Error upgrading database. Database left intact and will likely not be able to start: " + e.toString());
        throw e;
    }
}
Also used : LogProvider(org.neo4j.logging.LogProvider) StoreVersionCheck(org.neo4j.storageengine.api.StoreVersionCheck) Log(org.neo4j.logging.Log) IndexProviderMap(org.neo4j.kernel.impl.api.index.IndexProviderMap) IOException(java.io.IOException)

Aggregations

StoreVersionCheck (org.neo4j.storageengine.api.StoreVersionCheck)20 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 MethodSource (org.junit.jupiter.params.provider.MethodSource)15 Path (java.nio.file.Path)7 Config (org.neo4j.configuration.Config)4 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)4 Test (org.junit.jupiter.api.Test)3 IOException (java.io.IOException)2 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)2 DefaultPageCacheTracer (org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer)2 ScanOnOpenOverwritingIdGeneratorFactory (org.neo4j.internal.id.ScanOnOpenOverwritingIdGeneratorFactory)1 CursorContext (org.neo4j.io.pagecache.context.CursorContext)1 PageCursorTracer (org.neo4j.io.pagecache.tracing.cursor.PageCursorTracer)1 IndexProviderMap (org.neo4j.kernel.impl.api.index.IndexProviderMap)1 NeoStores (org.neo4j.kernel.impl.store.NeoStores)1 StoreFactory (org.neo4j.kernel.impl.store.StoreFactory)1 UnableToUpgradeException (org.neo4j.kernel.impl.storemigration.StoreUpgrader.UnableToUpgradeException)1 Log (org.neo4j.logging.Log)1 LogProvider (org.neo4j.logging.LogProvider)1 StorageEngineFactory (org.neo4j.storageengine.api.StorageEngineFactory)1