Search in sources :

Example 1 with SchemaIndexMigrator

use of org.neo4j.storageengine.migration.SchemaIndexMigrator in project neo4j by neo4j.

the class StoreUpgraderTest method newUpgrader.

private StoreUpgrader newUpgrader(StoreVersionCheck storeVersionCheck, PageCache pageCache, Config config, MigrationProgressMonitor progressMonitor, PageCacheTracer pageCacheTracer, boolean forceUpgrade) {
    NullLogService instance = NullLogService.getInstance();
    BatchImporterFactory batchImporterFactory = BatchImporterFactory.withHighestPriority();
    RecordStorageMigrator defaultMigrator = new RecordStorageMigrator(fileSystem, pageCache, getTuningConfig(), instance, jobScheduler, pageCacheTracer, batchImporterFactory, INSTANCE);
    StorageEngineFactory storageEngineFactory = StorageEngineFactory.defaultStorageEngine();
    SchemaIndexMigrator indexMigrator = new SchemaIndexMigrator("Indexes", fileSystem, pageCache, IndexProvider.EMPTY.directoryStructure(), storageEngineFactory, true);
    LegacyTransactionLogsLocator logsLocator = new LegacyTransactionLogsLocator(config, databaseLayout);
    DatabaseHealth databaseHealth = new DatabaseHealth(NO_OP, NullLog.getInstance());
    Dependencies dependencies = new Dependencies();
    dependencies.satisfyDependencies(new Monitors());
    LogsUpgrader logsUpgrader = new LogsUpgrader(fileSystem, storageEngineFactory, databaseLayout, pageCache, logsLocator, config, dependencies, pageCacheTracer, INSTANCE, databaseHealth, forceUpgrade);
    StoreUpgrader upgrader = new StoreUpgrader(storeVersionCheck, progressMonitor, config, fileSystem, NullLogProvider.getInstance(), logsUpgrader, pageCacheTracer);
    upgrader.addParticipant(indexMigrator);
    upgrader.addParticipant(NOT_PARTICIPATING);
    upgrader.addParticipant(NOT_PARTICIPATING);
    upgrader.addParticipant(NOT_PARTICIPATING);
    upgrader.addParticipant(NOT_PARTICIPATING);
    upgrader.addParticipant(defaultMigrator);
    return upgrader;
}
Also used : DatabaseHealth(org.neo4j.monitoring.DatabaseHealth) StorageEngineFactory(org.neo4j.storageengine.api.StorageEngineFactory) Monitors(org.neo4j.monitoring.Monitors) NullLogService(org.neo4j.logging.internal.NullLogService) BatchImporterFactory(org.neo4j.internal.batchimport.BatchImporterFactory) Dependencies(org.neo4j.collection.Dependencies) SchemaIndexMigrator(org.neo4j.storageengine.migration.SchemaIndexMigrator)

Example 2 with SchemaIndexMigrator

use of org.neo4j.storageengine.migration.SchemaIndexMigrator in project neo4j by neo4j.

the class StoreUpgraderInterruptionTestIT method shouldSucceedWithUpgradeAfterPreviousAttemptDiedDuringMigration.

@Test
public void shouldSucceedWithUpgradeAfterPreviousAttemptDiedDuringMigration() throws IOException, ConsistencyCheckIncompleteException {
    MigrationTestUtils.prepareSampleLegacyDatabase(version, fs, workingDatabaseLayout.databaseDirectory(), prepareDirectory);
    RecordStoreVersionCheck versionCheck = new RecordStoreVersionCheck(fs, pageCache, workingDatabaseLayout, NullLogProvider.getInstance(), Config.defaults(), NULL);
    MigrationProgressMonitor progressMonitor = MigrationProgressMonitor.SILENT;
    LogService logService = NullLogService.getInstance();
    RecordStorageMigrator failingStoreMigrator = new RecordStorageMigrator(fs, pageCache, CONFIG, logService, jobScheduler, NULL, batchImporterFactory, INSTANCE) {

        @Override
        public void migrate(DatabaseLayout directoryLayout, DatabaseLayout migrationLayout, ProgressReporter progressReporter, String versionToMigrateFrom, String versionToMigrateTo, IndexImporterFactory indexImporterFactory) throws IOException, KernelException {
            super.migrate(directoryLayout, migrationLayout, progressReporter, versionToMigrateFrom, versionToMigrateTo, indexImporterFactory);
            throw new RuntimeException("This upgrade is failing");
        }
    };
    try {
        newUpgrader(versionCheck, progressMonitor, createIndexMigrator(), failingStoreMigrator).migrateIfNeeded(workingDatabaseLayout, false);
        fail("Should throw exception");
    } catch (RuntimeException e) {
        assertEquals("This upgrade is failing", e.getMessage());
    }
    assertTrue(checkNeoStoreHasFormatVersion(versionCheck, baselineFormat));
    RecordStorageMigrator migrator = new RecordStorageMigrator(fs, pageCache, CONFIG, logService, jobScheduler, NULL, batchImporterFactory, INSTANCE);
    IdGeneratorMigrator idMigrator = new IdGeneratorMigrator(fs, pageCache, CONFIG, NULL);
    SchemaIndexMigrator indexMigrator = createIndexMigrator();
    newUpgrader(versionCheck, progressMonitor, indexMigrator, migrator, idMigrator).migrateIfNeeded(workingDatabaseLayout, false);
    assertTrue(checkNeoStoreHasFormatVersion(versionCheck, successorFormat));
    // Since consistency checker is in read only mode we need to start/stop db to generate label scan store.
    startStopDatabase(neo4jLayout.homeDirectory());
    assertConsistentStore(workingDatabaseLayout);
}
Also used : MigrationProgressMonitor(org.neo4j.storageengine.migration.MigrationProgressMonitor) RecordStoreVersionCheck(org.neo4j.kernel.impl.storemigration.RecordStoreVersionCheck) RecordStorageMigrator(org.neo4j.kernel.impl.storemigration.RecordStorageMigrator) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) IndexImporterFactory(org.neo4j.internal.batchimport.IndexImporterFactory) ProgressReporter(org.neo4j.common.ProgressReporter) IdGeneratorMigrator(org.neo4j.kernel.impl.storemigration.IdGeneratorMigrator) SchemaIndexMigrator(org.neo4j.storageengine.migration.SchemaIndexMigrator) NullLogService(org.neo4j.logging.internal.NullLogService) LogService(org.neo4j.logging.internal.LogService) Test(org.junit.Test)

Example 3 with SchemaIndexMigrator

use of org.neo4j.storageengine.migration.SchemaIndexMigrator in project neo4j by neo4j.

the class SchemaIndexMigratorTest method schemaAndLabelIndexesRemovedAfterSuccessfulMigration.

@Test
void schemaAndLabelIndexesRemovedAfterSuccessfulMigration() throws IOException {
    StorageEngineFactory storageEngineFactory = mock(StorageEngineFactory.class);
    StoreVersion version = mock(StoreVersion.class);
    when(version.hasCompatibleCapabilities(any(), eq(CapabilityType.INDEX))).thenReturn(false);
    when(storageEngineFactory.versionInformation(anyString())).thenReturn(version);
    IndexImporterFactory indexImporterFactory = mock(IndexImporterFactory.class);
    IndexDirectoryStructure directoryStructure = mock(IndexDirectoryStructure.class);
    Path indexProviderRootDirectory = databaseLayout.file("just-some-directory");
    when(directoryStructure.rootDirectory()).thenReturn(indexProviderRootDirectory);
    SchemaIndexMigrator migrator = new SchemaIndexMigrator("Test migrator", fs, pageCache, directoryStructure, storageEngineFactory, true);
    when(indexProvider.getProviderDescriptor()).thenReturn(new IndexProviderDescriptor("key", "version"));
    migrator.migrate(databaseLayout, migrationLayout, progressReporter, "from", "to", indexImporterFactory);
    migrator.moveMigratedFiles(migrationLayout, databaseLayout, "from", "to");
    verify(fs).deleteRecursively(indexProviderRootDirectory);
}
Also used : Path(java.nio.file.Path) IndexDirectoryStructure(org.neo4j.kernel.api.index.IndexDirectoryStructure) StorageEngineFactory(org.neo4j.storageengine.api.StorageEngineFactory) StoreVersion(org.neo4j.storageengine.api.StoreVersion) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) IndexImporterFactory(org.neo4j.internal.batchimport.IndexImporterFactory) SchemaIndexMigrator(org.neo4j.storageengine.migration.SchemaIndexMigrator) Test(org.junit.jupiter.api.Test)

Example 4 with SchemaIndexMigrator

use of org.neo4j.storageengine.migration.SchemaIndexMigrator in project neo4j by neo4j.

the class SchemaIndexMigratorTest method shouldDeleteRelationshipIndexesAfterCrossFormatFamilyMigration.

@Test
void shouldDeleteRelationshipIndexesAfterCrossFormatFamilyMigration() throws IOException {
    // given
    IndexProviderDescriptor provider = new IndexProviderDescriptor("k", "v");
    IndexDirectoryStructure directoryStructure = directoriesByProvider(databaseLayout.databaseDirectory()).forProvider(provider);
    StorageEngineFactory storageEngineFactory = mock(StorageEngineFactory.class);
    StoreVersion fromVersion = mock(StoreVersion.class);
    StoreVersion toVersion = mock(StoreVersion.class);
    when(fromVersion.hasCompatibleCapabilities(toVersion, CapabilityType.FORMAT)).thenReturn(false);
    when(storageEngineFactory.versionInformation("from")).thenReturn(fromVersion);
    when(storageEngineFactory.versionInformation("to")).thenReturn(toVersion);
    List<SchemaRule> schemaRules = new ArrayList<>();
    schemaRules.add(forSchema(SchemaDescriptor.forLabel(1, 2, 3)).withName("n1").materialise(1L));
    schemaRules.add(forSchema(SchemaDescriptor.forRelType(5, 3)).withName("r1").materialise(2L));
    schemaRules.add(forSchema(SchemaDescriptor.fulltext(RELATIONSHIP, new int[] { 1, 2, 3 }, new int[] { 4, 5, 6 })).withName("r2").materialise(3L));
    schemaRules.add(forSchema(SchemaDescriptor.fulltext(NODE, new int[] { 1, 2, 3 }, new int[] { 4, 5, 6 })).withName("n2").materialise(4L));
    when(storageEngineFactory.loadSchemaRules(any(), any(), any(), any(), any())).thenReturn(schemaRules);
    SchemaIndexMigrator migrator = new SchemaIndexMigrator("Test migrator", fs, pageCache, directoryStructure, storageEngineFactory, false);
    // when
    migrator.migrate(databaseLayout, migrationLayout, progressReporter, "from", "to", IndexImporterFactory.EMPTY);
    migrator.moveMigratedFiles(databaseLayout, migrationLayout, "from", "to");
    // then
    verify(fs, never()).deleteRecursively(directoryStructure.directoryForIndex(1L));
    verify(fs).deleteRecursively(directoryStructure.directoryForIndex(2L));
    verify(fs).deleteRecursively(directoryStructure.directoryForIndex(3L));
    verify(fs, never()).deleteRecursively(directoryStructure.directoryForIndex(4L));
}
Also used : IndexDirectoryStructure(org.neo4j.kernel.api.index.IndexDirectoryStructure) StorageEngineFactory(org.neo4j.storageengine.api.StorageEngineFactory) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) StoreVersion(org.neo4j.storageengine.api.StoreVersion) ArrayList(java.util.ArrayList) SchemaRule(org.neo4j.internal.schema.SchemaRule) SchemaIndexMigrator(org.neo4j.storageengine.migration.SchemaIndexMigrator) Test(org.junit.jupiter.api.Test)

Aggregations

SchemaIndexMigrator (org.neo4j.storageengine.migration.SchemaIndexMigrator)4 StorageEngineFactory (org.neo4j.storageengine.api.StorageEngineFactory)3 Test (org.junit.jupiter.api.Test)2 IndexImporterFactory (org.neo4j.internal.batchimport.IndexImporterFactory)2 IndexProviderDescriptor (org.neo4j.internal.schema.IndexProviderDescriptor)2 IndexDirectoryStructure (org.neo4j.kernel.api.index.IndexDirectoryStructure)2 NullLogService (org.neo4j.logging.internal.NullLogService)2 StoreVersion (org.neo4j.storageengine.api.StoreVersion)2 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 Dependencies (org.neo4j.collection.Dependencies)1 ProgressReporter (org.neo4j.common.ProgressReporter)1 BatchImporterFactory (org.neo4j.internal.batchimport.BatchImporterFactory)1 SchemaRule (org.neo4j.internal.schema.SchemaRule)1 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)1 IdGeneratorMigrator (org.neo4j.kernel.impl.storemigration.IdGeneratorMigrator)1 RecordStorageMigrator (org.neo4j.kernel.impl.storemigration.RecordStorageMigrator)1 RecordStoreVersionCheck (org.neo4j.kernel.impl.storemigration.RecordStoreVersionCheck)1 LogService (org.neo4j.logging.internal.LogService)1