Search in sources :

Example 11 with StorageEngineFactory

use of org.neo4j.storageengine.api.StorageEngineFactory 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 12 with StorageEngineFactory

use of org.neo4j.storageengine.api.StorageEngineFactory 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)

Example 13 with StorageEngineFactory

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

the class RecoverIndexDropIT method shouldDropIndexOnRecovery.

@Test
void shouldDropIndexOnRecovery() throws IOException {
    // given a transaction stream ending in an INDEX DROP command.
    CommittedTransactionRepresentation dropTransaction = prepareDropTransaction();
    DatabaseManagementService managementService = configure(new TestDatabaseManagementServiceBuilder(databaseLayout)).build();
    GraphDatabaseService db = managementService.database(DEFAULT_DATABASE_NAME);
    long initialIndexCount = currentIndexCount(db);
    createIndex(db);
    StorageEngineFactory storageEngineFactory = ((GraphDatabaseAPI) db).getDependencyResolver().resolveDependency(StorageEngineFactory.class);
    managementService.shutdown();
    appendDropTransactionToTransactionLog(databaseLayout.getTransactionLogsDirectory(), dropTransaction, storageEngineFactory);
    // when recovering this (the drop transaction with the index file intact)
    Monitors monitors = new Monitors();
    AssertRecoveryIsPerformed recoveryMonitor = new AssertRecoveryIsPerformed();
    monitors.addMonitorListener(recoveryMonitor);
    managementService = configure(new TestDatabaseManagementServiceBuilder(databaseLayout).setMonitors(monitors)).build();
    db = managementService.database(DEFAULT_DATABASE_NAME);
    try {
        assertTrue(recoveryMonitor.recoveryWasRequired);
        // then
        assertEquals(initialIndexCount, currentIndexCount(db));
    } finally {
        // and the ability to shut down w/o failing on still open files
        managementService.shutdown();
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) StorageEngineFactory(org.neo4j.storageengine.api.StorageEngineFactory) Monitors(org.neo4j.monitoring.Monitors) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Example 14 with StorageEngineFactory

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

the class RecoveryCorruptedTransactionLogIT method startStopDatabase.

private void startStopDatabase() {
    DatabaseManagementService managementService = databaseFactory.build();
    storageEngineFactory = ((GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME)).getDependencyResolver().resolveDependency(StorageEngineFactory.class);
    managementService.shutdown();
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) StorageEngineFactory(org.neo4j.storageengine.api.StorageEngineFactory) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService)

Example 15 with StorageEngineFactory

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

the class KernelDiagnosticsIT method shouldIncludeNativeIndexFilesInTotalMappedSize.

@Test
void shouldIncludeNativeIndexFilesInTotalMappedSize() {
    for (GraphDatabaseSettings.SchemaIndex schemaIndex : GraphDatabaseSettings.SchemaIndex.values()) {
        // given
        Neo4jLayout layout = neo4jLayout;
        createIndexInIsolatedDbInstance(layout.homeDirectory(), schemaIndex);
        // when
        DatabaseLayout databaseLayout = layout.databaseLayout(DEFAULT_DATABASE_NAME);
        StorageEngineFactory storageEngineFactory = StorageEngineFactory.defaultStorageEngine();
        StoreFilesDiagnostics files = new StoreFilesDiagnostics(storageEngineFactory, fs, databaseLayout);
        SizeCapture capture = new SizeCapture();
        files.dump(capture::log);
        assertNotNull(capture.size);
        // then
        long expected = manuallyCountTotalMappedFileSize(databaseLayout.databaseDirectory());
        assertEquals(bytesToString(expected), capture.size);
    }
}
Also used : GraphDatabaseSettings(org.neo4j.configuration.GraphDatabaseSettings) StorageEngineFactory(org.neo4j.storageengine.api.StorageEngineFactory) StoreFilesDiagnostics(org.neo4j.kernel.diagnostics.providers.StoreFilesDiagnostics) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) Neo4jLayout(org.neo4j.io.layout.Neo4jLayout) Test(org.junit.jupiter.api.Test)

Aggregations

StorageEngineFactory (org.neo4j.storageengine.api.StorageEngineFactory)24 Test (org.junit.jupiter.api.Test)9 Path (java.nio.file.Path)7 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)7 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)5 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)5 TestDatabaseManagementServiceBuilder (org.neo4j.test.TestDatabaseManagementServiceBuilder)4 Dependencies (org.neo4j.collection.Dependencies)3 Config (org.neo4j.configuration.Config)3 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)3 CursorContext (org.neo4j.io.pagecache.context.CursorContext)3 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)3 StoreVersion (org.neo4j.storageengine.api.StoreVersion)3 SchemaIndexMigrator (org.neo4j.storageengine.migration.SchemaIndexMigrator)3 ArrayList (java.util.ArrayList)2 Transaction (org.neo4j.graphdb.Transaction)2 IndexProviderDescriptor (org.neo4j.internal.schema.IndexProviderDescriptor)2 Neo4jLayout (org.neo4j.io.layout.Neo4jLayout)2 PageCache (org.neo4j.io.pagecache.PageCache)2 IndexDirectoryStructure (org.neo4j.kernel.api.index.IndexDirectoryStructure)2