Search in sources :

Example 6 with StoreVersion

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

the class SchemaIndexMigrator method migrate.

@Override
public void migrate(DatabaseLayout directoryLayout, DatabaseLayout migrationLayout, ProgressReporter progressReporter, String versionToMigrateFrom, String versionToMigrateTo, IndexImporterFactory indexImporterFactory) {
    StoreVersion fromVersion = storageEngineFactory.versionInformation(versionToMigrateFrom);
    StoreVersion toVersion = storageEngineFactory.versionInformation(versionToMigrateTo);
    deleteAllIndexes = checkIndexCapabilities && !fromVersion.hasCompatibleCapabilities(toVersion, CapabilityType.INDEX);
    deleteRelationshipIndexes = !fromVersion.hasCompatibleCapabilities(toVersion, CapabilityType.FORMAT);
}
Also used : StoreVersion(org.neo4j.storageengine.api.StoreVersion)

Example 7 with StoreVersion

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

the class StoreUpgrader method migrateIfNeeded.

/**
 * Upgrade the store format, if it is not the latest version or is different from the configured desired format.
 *
 * @param layout The layout of the existing database store.
 * @param forceUpgrade If {@code true}, the value of the {@link GraphDatabaseSettings#allow_upgrade} setting is ignored.
 */
public void migrateIfNeeded(DatabaseLayout layout, boolean forceUpgrade) throws IOException {
    // nothing to migrate
    if (!Files.exists(layout.databaseDirectory())) {
        return;
    }
    try (var cursorContext = new CursorContext(pageCacheTracer.createPageCursorTracer(STORE_UPGRADE_TAG))) {
        DatabaseLayout migrationStructure = DatabaseLayout.ofFlat(layout.file(MIGRATION_DIRECTORY));
        cleanupLegacyLeftOverDirsIn(layout.databaseDirectory());
        Path migrationStateFile = migrationStructure.file(MIGRATION_STATUS_FILE);
        // if migration directory exists than we might have failed to move files into the store dir so do it again
        if (hasCurrentVersion(storeVersionCheck, cursorContext) && !fileSystem.fileExists(migrationStateFile)) {
            // No migration needed
            return;
        }
        if (isUpgradeAllowed() || forceUpgrade) {
            migrate(layout, migrationStructure, migrationStateFile, cursorContext);
        } else {
            Optional<String> storeVersion = storeVersionCheck.storeVersion(cursorContext);
            if (storeVersion.isPresent()) {
                StoreVersion version = storeVersionCheck.versionInformation(storeVersion.get());
                if (version.hasCapability(IndexCapabilities.LuceneCapability.LUCENE_5)) {
                    throw new UpgradeNotAllowedException("Upgrade is required to migrate store to new major version.");
                } else {
                    String configuredVersion = storeVersionCheck.configuredVersion();
                    if (configuredVersion != null && !version.isCompatibleWith(storeVersionCheck.versionInformation(configuredVersion))) {
                        throw new UpgradeNotAllowedException();
                    }
                }
            }
        }
    }
}
Also used : Path(java.nio.file.Path) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) StoreVersion(org.neo4j.storageengine.api.StoreVersion) CursorContext(org.neo4j.io.pagecache.context.CursorContext) UpgradeNotAllowedException(org.neo4j.storageengine.migration.UpgradeNotAllowedException)

Aggregations

StoreVersion (org.neo4j.storageengine.api.StoreVersion)7 Path (java.nio.file.Path)2 Test (org.junit.jupiter.api.Test)2 IndexProviderDescriptor (org.neo4j.internal.schema.IndexProviderDescriptor)2 IndexDirectoryStructure (org.neo4j.kernel.api.index.IndexDirectoryStructure)2 StorageEngineFactory (org.neo4j.storageengine.api.StorageEngineFactory)2 SchemaIndexMigrator (org.neo4j.storageengine.migration.SchemaIndexMigrator)2 ArrayList (java.util.ArrayList)1 IndexImporterFactory (org.neo4j.internal.batchimport.IndexImporterFactory)1 SchemaRule (org.neo4j.internal.schema.SchemaRule)1 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)1 CursorContext (org.neo4j.io.pagecache.context.CursorContext)1 UpgradeNotAllowedException (org.neo4j.storageengine.migration.UpgradeNotAllowedException)1