Search in sources :

Example 21 with IndexProviderDescriptor

use of org.neo4j.internal.schema.IndexProviderDescriptor in project neo4j by neo4j.

the class IndexDirectoryStructureTest method shouldSeeCorrectDirectoriesForSubProvider.

@Test
void shouldSeeCorrectDirectoriesForSubProvider() {
    IndexDirectoryStructure parentStructure = directoriesByProvider(databaseStoreDir).forProvider(provider);
    IndexProviderDescriptor subProvider = new IndexProviderDescriptor("sub", "0.3");
    assertCorrectDirectories(directoriesBySubProvider(parentStructure).forProvider(subProvider), baseIndexDirectory.resolve(provider.getKey() + "-" + provider.getVersion()), baseIndexDirectory.resolve(provider.getKey() + "-" + provider.getVersion()).resolve(String.valueOf(indexId)).resolve(subProvider.getKey() + "-" + subProvider.getVersion()));
}
Also used : IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) Test(org.junit.jupiter.api.Test)

Example 22 with IndexProviderDescriptor

use of org.neo4j.internal.schema.IndexProviderDescriptor 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 23 with IndexProviderDescriptor

use of org.neo4j.internal.schema.IndexProviderDescriptor 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 24 with IndexProviderDescriptor

use of org.neo4j.internal.schema.IndexProviderDescriptor in project neo4j by neo4j.

the class OperationsTest method setUp.

@BeforeEach
void setUp() throws Exception {
    TxState realTxState = new TxState();
    txState = Mockito.spy(realTxState);
    when(transaction.getReasonIfTerminated()).thenReturn(Optional.empty());
    when(transaction.lockClient()).thenReturn(locks);
    when(transaction.dataWrite()).thenReturn(write);
    when(transaction.isOpen()).thenReturn(true);
    when(transaction.lockTracer()).thenReturn(LockTracer.NONE);
    when(transaction.txState()).thenReturn(txState);
    when(transaction.securityContext()).thenReturn(SecurityContext.authDisabled(AccessMode.Static.FULL, EMBEDDED_CONNECTION, DB_NAME));
    logHelper = new SecurityLogHelper(getFormat());
    securityLog = new CommunitySecurityLog((LogExtended) logHelper.getLogProvider().getLog(this.getClass()));
    when(transaction.securityAuthorizationHandler()).thenReturn(new SecurityAuthorizationHandler(securityLog));
    DefaultPooledCursors cursors = mock(DefaultPooledCursors.class);
    nodeCursor = mock(FullAccessNodeCursor.class);
    propertyCursor = mock(FullAccessPropertyCursor.class);
    relationshipCursor = mock(DefaultRelationshipScanCursor.class);
    when(cursors.allocateFullAccessNodeCursor(NULL)).thenReturn(nodeCursor);
    when(cursors.allocateFullAccessPropertyCursor(NULL, INSTANCE)).thenReturn(propertyCursor);
    when(cursors.allocateRelationshipScanCursor(NULL)).thenReturn(relationshipCursor);
    StorageEngine engine = mock(StorageEngine.class);
    storageReader = mock(StorageReader.class);
    storageReaderSnapshot = mock(StorageSchemaReader.class);
    when(storageReader.nodeExists(anyLong(), any())).thenReturn(true);
    when(storageReader.constraintsGetForLabel(anyInt())).thenReturn(Collections.emptyIterator());
    when(storageReader.constraintsGetAll()).thenReturn(Collections.emptyIterator());
    when(storageReader.schemaSnapshot()).thenReturn(storageReaderSnapshot);
    when(engine.newReader()).thenReturn(storageReader);
    indexingService = mock(IndexingService.class);
    Dependencies dependencies = new Dependencies();
    var facade = mock(GraphDatabaseFacade.class);
    dependencies.satisfyDependency(facade);
    allStoreHolder = new AllStoreHolder(storageReader, transaction, cursors, mock(GlobalProcedures.class), mock(SchemaState.class), indexingService, mock(IndexStatisticsStore.class), dependencies, Config.defaults(), INSTANCE);
    constraintIndexCreator = mock(ConstraintIndexCreator.class);
    tokenHolders = mockedTokenHolders();
    creationContext = mock(CommandCreationContext.class);
    IndexingProvidersService indexingProvidersService = mock(IndexingProvidersService.class);
    when(indexingProvidersService.indexProviderByName("native-btree-1.0")).thenReturn(GenericNativeIndexProvider.DESCRIPTOR);
    when(indexingProvidersService.getDefaultProvider()).thenReturn(GenericNativeIndexProvider.DESCRIPTOR);
    when(indexingProvidersService.indexProviderByName("fulltext-1.0")).thenReturn(FulltextIndexProviderFactory.DESCRIPTOR);
    when(indexingProvidersService.getFulltextProvider()).thenReturn(FulltextIndexProviderFactory.DESCRIPTOR);
    when(indexingProvidersService.indexProviderByName("provider-1.0")).thenReturn(new IndexProviderDescriptor("provider", "1.0"));
    when(indexingProvidersService.completeConfiguration(any())).thenAnswer(inv -> inv.getArgument(0));
    operations = new Operations(allStoreHolder, storageReader, mock(IndexTxStateUpdater.class), creationContext, transaction, new KernelToken(storageReader, creationContext, transaction, tokenHolders), cursors, constraintIndexCreator, mock(ConstraintSemantics.class), indexingProvidersService, Config.defaults(), INSTANCE, () -> KernelVersion.LATEST, mock(DbmsRuntimeRepository.class));
    operations.initialize(NULL);
    this.order = inOrder(locks, txState, storageReader, storageReaderSnapshot, creationContext);
}
Also used : StorageReader(org.neo4j.storageengine.api.StorageReader) CommunitySecurityLog(org.neo4j.internal.kernel.api.security.CommunitySecurityLog) IndexingProvidersService(org.neo4j.kernel.impl.api.index.IndexingProvidersService) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) SecurityLogHelper(org.neo4j.logging.SecurityLogHelper) LogExtended(org.neo4j.logging.log4j.LogExtended) StorageEngine(org.neo4j.storageengine.api.StorageEngine) SecurityAuthorizationHandler(org.neo4j.internal.kernel.api.security.SecurityAuthorizationHandler) CommandCreationContext(org.neo4j.storageengine.api.CommandCreationContext) ConstraintIndexCreator(org.neo4j.kernel.impl.api.state.ConstraintIndexCreator) StorageSchemaReader(org.neo4j.storageengine.api.StorageSchemaReader) TxState(org.neo4j.kernel.impl.api.state.TxState) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) Dependencies(org.neo4j.collection.Dependencies) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 25 with IndexProviderDescriptor

use of org.neo4j.internal.schema.IndexProviderDescriptor in project neo4j by neo4j.

the class IndexCleanupIT method mustClearIndexDirectoryOnDropWhileFailed.

@ParameterizedTest
@EnumSource(SchemaIndex.class)
void mustClearIndexDirectoryOnDropWhileFailed(SchemaIndex schemaIndex) throws IOException {
    configureDb(schemaIndex);
    createIndex(db, true);
    IndexProviderDescriptor providerDescriptor = new IndexProviderDescriptor(schemaIndex.providerKey(), schemaIndex.providerVersion());
    SetInitialStateInNativeIndex setInitialStateInNativeIndex = new SetInitialStateInNativeIndex(BYTE_FAILED, providerDescriptor);
    restartDatabase(schemaIndex, setInitialStateInNativeIndex);
    try (Transaction tx = db.beginTx()) {
        for (IndexDefinition index : tx.schema().getIndexes()) {
            // ignore the lookup indexes which are there by default and have nothing to do with this test
            if (index.getIndexType() == IndexType.LOOKUP) {
                continue;
            }
            IndexState indexState = tx.schema().getIndexState(index);
            assertEquals(IndexState.FAILED, indexState, "expected index state to be " + IndexState.FAILED);
        }
        tx.commit();
    }
    // when
    dropAllIndexes();
    // then
    assertNoIndexFilesExisting(providerDirectories(fs, db));
}
Also used : SetInitialStateInNativeIndex(org.neo4j.index.SetInitialStateInNativeIndex) Transaction(org.neo4j.graphdb.Transaction) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) IndexState(org.neo4j.graphdb.schema.Schema.IndexState) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

IndexProviderDescriptor (org.neo4j.internal.schema.IndexProviderDescriptor)41 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)18 Test (org.junit.jupiter.api.Test)16 IndexProvider (org.neo4j.kernel.api.index.IndexProvider)11 IndexPrototype (org.neo4j.internal.schema.IndexPrototype)10 ArrayList (java.util.ArrayList)5 FulltextSchemaDescriptor (org.neo4j.internal.schema.FulltextSchemaDescriptor)5 IndexDirectoryStructure (org.neo4j.kernel.api.index.IndexDirectoryStructure)5 IndexConfig (org.neo4j.internal.schema.IndexConfig)4 LabelSchemaDescriptor (org.neo4j.internal.schema.LabelSchemaDescriptor)4 Path (java.nio.file.Path)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 IndexPopulator (org.neo4j.kernel.api.index.IndexPopulator)3 IOException (java.io.IOException)2 UncheckedIOException (java.io.UncheckedIOException)2 String.format (java.lang.String.format)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 EnumMap (java.util.EnumMap)2 HashMap (java.util.HashMap)2