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();
}
}
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);
}
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;
}
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;
}
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()));
}
}
}
Aggregations