Search in sources :

Example 16 with IndexConfig

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

the class IndexingServiceTest method shouldNotLoseIndexDescriptorDueToOtherVerySimilarIndexDuringRecovery.

@Test
void shouldNotLoseIndexDescriptorDueToOtherVerySimilarIndexDuringRecovery() throws Exception {
    // GIVEN
    AtomicReference<BinaryLatch> populationStartLatch = latchedIndexPopulation();
    long nodeId = 0;
    Update update = addNodeUpdate(nodeId, "value");
    when(indexStatisticsStore.indexSample(anyLong())).thenReturn(new IndexSample(100, 42, 42));
    // For some reason the usual accessor returned null from newUpdater, even when told to return the updater
    // so spying on a real object instead.
    IndexAccessor accessor = spy(new TrackingIndexAccessor());
    IndexingService indexing = newIndexingServiceWithMockedDependencies(populator, accessor, withData(update), index);
    when(indexProvider.getInitialState(index, NULL)).thenReturn(ONLINE);
    life.init();
    populationStartLatch.getAndSet(new BinaryLatch()).release();
    // WHEN dropping another index, which happens to be identical to the existing one except for different index config... while recovering
    IndexConfig indexConfig = index.getIndexConfig().withIfAbsent("a", Values.booleanValue(true));
    IndexDescriptor otherIndex = index.withIndexConfig(indexConfig);
    indexing.createIndexes(AUTH_DISABLED, otherIndex);
    indexing.dropIndex(otherIndex);
    // and WHEN finally creating our index again (at a later point in recovery)
    indexing.createIndexes(AUTH_DISABLED, index);
    reset(accessor);
    indexing.applyUpdates(nodeIdsAsIndexUpdates(nodeId), NULL);
    // and WHEN starting, i.e. completing recovery
    life.start();
    IndexProxy indexProxy = indexing.getIndexProxy(index);
    try {
        assertNull(indexProxy.getDescriptor().getIndexConfig().get("a"));
        // The existing online index got nuked during recovery.
        assertThat(indexProxy.getState()).isEqualTo(POPULATING);
    } finally {
        populationStartLatch.get().release();
    }
}
Also used : IndexSample(org.neo4j.kernel.api.index.IndexSample) IndexConfig(org.neo4j.internal.schema.IndexConfig) IndexAccessor(org.neo4j.kernel.api.index.IndexAccessor) IndexEntryUpdate(org.neo4j.storageengine.api.IndexEntryUpdate) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) BinaryLatch(org.neo4j.util.concurrent.BinaryLatch) Test(org.junit.jupiter.api.Test)

Example 17 with IndexConfig

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

the class SchemaStore method schemaIndexToMap.

private static void schemaIndexToMap(IndexDescriptor rule, Map<String, Value> map) {
    // Rule
    putStringProperty(map, PROP_SCHEMA_RULE_TYPE, "INDEX");
    IndexType indexType = rule.getIndexType();
    putStringProperty(map, PROP_INDEX_TYPE, indexType.name());
    if (rule.isUnique()) {
        putStringProperty(map, PROP_INDEX_RULE_TYPE, "UNIQUE");
        if (rule.getOwningConstraintId().isPresent()) {
            map.put(PROP_OWNING_CONSTRAINT, Values.longValue(rule.getOwningConstraintId().getAsLong()));
        }
    } else {
        putStringProperty(map, PROP_INDEX_RULE_TYPE, "NON_UNIQUE");
    }
    // Provider
    indexProviderToMap(rule, map);
    // Index config
    IndexConfig indexConfig = rule.getIndexConfig();
    indexConfigToMap(indexConfig, map);
}
Also used : IndexConfig(org.neo4j.internal.schema.IndexConfig) IndexType(org.neo4j.internal.schema.IndexType)

Example 18 with IndexConfig

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

the class IndexConfigMigrator method migrateIndexConfig.

public static SchemaRule migrateIndexConfig(SchemaRule rule, DatabaseLayout directoryLayout, FileSystemAbstraction fs, PageCache pageCache, IndexProviderMap indexProviderMap, Log log, CursorContext cursorContext) throws IOException {
    if (rule instanceof IndexDescriptor) {
        IndexDescriptor old = (IndexDescriptor) rule;
        long indexId = old.getId();
        IndexProviderDescriptor provider = old.getIndexProvider();
        IndexMigration indexMigration = IndexMigration.migrationFromOldProvider(provider.getKey(), provider.getVersion());
        IndexConfig indexConfig = indexMigration.extractIndexConfig(fs, pageCache, directoryLayout, indexId, cursorContext, log);
        IndexDescriptor newIndexReference = old.withIndexConfig(indexConfig);
        IndexProvider indexProvider = indexProviderMap.lookup(indexMigration.desiredAlternativeProvider);
        return indexProvider.completeConfiguration(newIndexReference);
    }
    return rule;
}
Also used : IndexProvider(org.neo4j.kernel.api.index.IndexProvider) IndexConfig(org.neo4j.internal.schema.IndexConfig) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor)

Example 19 with IndexConfig

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

the class FulltextIndexProviderTest method createIndex.

private IndexDescriptor createIndex(int[] entityTokens, int[] propertyIds, String analyzer, EntityType entityType, boolean eventuallyConsistent) throws KernelException {
    IndexDescriptor fulltext;
    try (KernelTransactionImplementation transaction = getKernelTransaction()) {
        SchemaDescriptor schema = SchemaDescriptor.fulltext(entityType, entityTokens, propertyIds);
        IndexConfig config = IndexConfig.with(FulltextIndexSettingsKeys.ANALYZER, Values.stringValue(analyzer)).withIfAbsent(FulltextIndexSettingsKeys.EVENTUALLY_CONSISTENT, Values.of(eventuallyConsistent));
        IndexPrototype prototype = IndexPrototype.forSchema(schema, DESCRIPTOR).withIndexType(IndexType.FULLTEXT).withName(NAME).withIndexConfig(config);
        fulltext = transaction.schemaWrite().indexCreate(prototype);
        transaction.success();
    }
    return fulltext;
}
Also used : SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) IndexConfig(org.neo4j.internal.schema.IndexConfig) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor)

Example 20 with IndexConfig

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

the class GenericNativeIndexProviderTest method completeConfigurationMustNotOverrideExistingSettings.

@Test
void completeConfigurationMustNotOverrideExistingSettings() {
    // Given
    DatabaseIndexContext context = DatabaseIndexContext.builder(null, null, DEFAULT_DATABASE_NAME).build();
    GenericNativeIndexProvider provider = new GenericNativeIndexProvider(context, IndexDirectoryStructure.NONE, null, Config.defaults());
    Map<String, Value> existingSettings = new HashMap<>();
    CoordinateReferenceSystem existingCrs = CoordinateReferenceSystem.Cartesian;
    DoubleArray min = Values.doubleArray(new double[] { 0, 0 });
    DoubleArray max = Values.doubleArray(new double[] { 1, 1 });
    existingSettings.put(spatialMinSettingForCrs(existingCrs).getSettingName(), min);
    existingSettings.put(spatialMaxSettingForCrs(existingCrs).getSettingName(), max);
    IndexConfig existingIndexConfig = IndexConfig.with(existingSettings);
    LabelSchemaDescriptor incompleteSchema = SchemaDescriptor.forLabel(1, 1);
    IndexDescriptor incompleteDescriptor = IndexPrototype.forSchema(incompleteSchema, IndexProviderDescriptor.UNDECIDED).withName("index").materialise(1).withIndexConfig(existingIndexConfig);
    // When
    IndexDescriptor completedDescriptor = provider.completeConfiguration(incompleteDescriptor);
    // Then
    IndexConfig completedIndexConfig = completedDescriptor.getIndexConfig();
    for (CoordinateReferenceSystem crs : CoordinateReferenceSystem.all()) {
        if (crs.equals(existingCrs)) {
            // Assert value
            assertEquals(min, completedIndexConfig.get(spatialMinSettingForCrs(crs).getSettingName()));
            assertEquals(max, completedIndexConfig.get(spatialMaxSettingForCrs(crs).getSettingName()));
        } else {
            // Simply assert not null
            assertNotNull(completedIndexConfig.get(spatialMinSettingForCrs(crs).getSettingName()));
            assertNotNull(completedIndexConfig.get(spatialMaxSettingForCrs(crs).getSettingName()));
        }
    }
}
Also used : IndexConfig(org.neo4j.internal.schema.IndexConfig) HashMap(java.util.HashMap) Value(org.neo4j.values.storable.Value) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) CoordinateReferenceSystem(org.neo4j.values.storable.CoordinateReferenceSystem) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) DoubleArray(org.neo4j.values.storable.DoubleArray) Test(org.junit.jupiter.api.Test)

Aggregations

IndexConfig (org.neo4j.internal.schema.IndexConfig)21 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)10 Test (org.junit.jupiter.api.Test)9 Value (org.neo4j.values.storable.Value)6 IndexProviderDescriptor (org.neo4j.internal.schema.IndexProviderDescriptor)5 LabelSchemaDescriptor (org.neo4j.internal.schema.LabelSchemaDescriptor)4 SchemaDescriptor (org.neo4j.internal.schema.SchemaDescriptor)4 CoordinateReferenceSystem (org.neo4j.values.storable.CoordinateReferenceSystem)4 HashMap (java.util.HashMap)3 IndexPrototype (org.neo4j.internal.schema.IndexPrototype)3 Path (java.nio.file.Path)2 StringJoiner (java.util.StringJoiner)2 Config (org.neo4j.configuration.Config)2 FulltextSchemaDescriptor (org.neo4j.internal.schema.FulltextSchemaDescriptor)2 KernelTransactionImplementation (org.neo4j.kernel.impl.api.KernelTransactionImplementation)2 SpaceFillingCurveSettings (org.neo4j.kernel.impl.index.schema.config.SpaceFillingCurveSettings)2 BooleanValue (org.neo4j.values.storable.BooleanValue)2 DoubleArray (org.neo4j.values.storable.DoubleArray)2 IntValue (org.neo4j.values.storable.IntValue)2 StringValue (org.neo4j.values.storable.StringValue)2