use of org.neo4j.internal.schema.IndexProviderDescriptor in project neo4j by neo4j.
the class LuceneFulltextIndexTest method mustNotOverwriteExistingCapabilities.
@Test
void mustNotOverwriteExistingCapabilities() {
IndexCapability capability = new IndexCapability() {
@Override
public IndexOrderCapability orderCapability(ValueCategory... valueCategories) {
return IndexOrderCapability.NONE;
}
@Override
public IndexValueCapability valueCapability(ValueCategory... valueCategories) {
return IndexValueCapability.NO;
}
};
FulltextSchemaDescriptor schema = SchemaDescriptor.fulltext(NODE, new int[] { 1 }, new int[] { 1 });
IndexProviderDescriptor providerDescriptor = indexProvider.getProviderDescriptor();
IndexDescriptor index = IndexPrototype.forSchema(schema, providerDescriptor).withName("index_1").materialise(1).withIndexCapability(capability);
IndexDescriptor completed = indexProvider.completeConfiguration(index);
assertSame(capability, completed.getCapability());
}
use of org.neo4j.internal.schema.IndexProviderDescriptor in project neo4j by neo4j.
the class BlockBasedIndexPopulatorTest method setup.
@BeforeEach
void setup() {
IndexProviderDescriptor providerDescriptor = new IndexProviderDescriptor("test", "v1");
IndexDirectoryStructure directoryStructure = directoriesByProvider(testDir.homePath()).forProvider(providerDescriptor);
indexFiles = new IndexFiles.Directory(fs, directoryStructure, INDEX_DESCRIPTOR.getId());
databaseIndexContext = DatabaseIndexContext.builder(pageCache, fs, DEFAULT_DATABASE_NAME).build();
jobScheduler = JobSchedulerFactory.createInitialisedScheduler();
populationWorkScheduler = wrapScheduler(jobScheduler);
}
use of org.neo4j.internal.schema.IndexProviderDescriptor in project neo4j by neo4j.
the class BuiltInProcedures method createIndex.
@Deprecated(since = "4.2.0", forRemoval = true)
@Description("Create a named schema index with specified index provider and configuration (optional). " + "Yield: name, labels, properties, providerName, status")
@Procedure(name = "db.createIndex", mode = SCHEMA, deprecatedBy = "CREATE INDEX command")
public Stream<SchemaIndexInfo> createIndex(@Name("indexName") String indexName, @Name("labels") List<String> labels, @Name("properties") List<String> properties, @Name("providerName") String providerName, @Name(value = "config", defaultValue = "{}") Map<String, Object> config) throws ProcedureException {
IndexProcedures indexProcedures = indexProcedures();
final IndexProviderDescriptor indexProviderDescriptor = getIndexProviderDescriptor(providerName);
return indexProcedures.createIndex(indexName, labels, properties, indexProviderDescriptor, config);
}
use of org.neo4j.internal.schema.IndexProviderDescriptor in project neo4j by neo4j.
the class IndexingService method start.
// Recovery semantics: This is to be called after init, and after the database has run recovery.
@Override
public void start() throws Exception {
state = State.STARTING;
// Recovery will not do refresh (update read views) while applying recovered transactions and instead
// do it at one point after recovery... i.e. here
indexMapRef.indexMapSnapshot().forEachIndexProxy(indexProxyOperation("refresh", IndexProxy::refresh));
final MutableLongObjectMap<IndexDescriptor> rebuildingDescriptors = new LongObjectHashMap<>();
indexMapRef.modify(indexMap -> {
Map<InternalIndexState, List<IndexLogRecord>> indexStates = new EnumMap<>(InternalIndexState.class);
Map<IndexProviderDescriptor, List<IndexLogRecord>> indexProviders = new HashMap<>();
// Find all indexes that are not already online, do not require rebuilding, and create them
indexMap.forEachIndexProxy((indexId, proxy) -> {
InternalIndexState state = proxy.getState();
IndexDescriptor descriptor = proxy.getDescriptor();
IndexProviderDescriptor providerDescriptor = descriptor.getIndexProvider();
IndexLogRecord indexLogRecord = new IndexLogRecord(descriptor);
indexStates.computeIfAbsent(state, internalIndexState -> new ArrayList<>()).add(indexLogRecord);
indexProviders.computeIfAbsent(providerDescriptor, indexProviderDescriptor -> new ArrayList<>()).add(indexLogRecord);
internalLog.debug(indexStateInfo("start", state, descriptor));
switch(state) {
case ONLINE:
case FAILED:
proxy.start();
break;
case POPULATING:
// Remember for rebuilding right below in this method
rebuildingDescriptors.put(indexId, descriptor);
break;
default:
throw new IllegalStateException("Unknown state: " + state);
}
});
logIndexStateSummary("start", indexStates);
logIndexProviderSummary(indexProviders);
dontRebuildIndexesInReadOnlyMode(rebuildingDescriptors);
// Drop placeholder proxies for indexes that need to be rebuilt
dropRecoveringIndexes(indexMap, rebuildingDescriptors.keySet());
// Rebuild indexes by recreating and repopulating them
populateIndexesOfAllTypes(rebuildingDescriptors, indexMap);
return indexMap;
});
indexStatisticsStore.start();
samplingController.recoverIndexSamples();
samplingController.start();
// So at this point we've started population of indexes that needs to be rebuilt in the background.
// Indexes backing uniqueness constraints are normally built within the transaction creating the constraint
// and so we shouldn't leave such indexes in a populating state after recovery.
// This is why we now go and wait for those indexes to be fully populated.
rebuildingDescriptors.forEachKeyValue((indexId, index) -> {
if (!index.isUnique()) {
// It's not a uniqueness constraint, so don't wait for it to be rebuilt
return;
}
IndexProxy proxy;
try {
proxy = getIndexProxy(index);
} catch (IndexNotFoundKernelException e) {
throw new IllegalStateException("What? This index was seen during recovery just now, why isn't it available now?", e);
}
if (proxy.getDescriptor().getOwningConstraintId().isEmpty()) {
// so there's no gain in waiting for this index.
return;
}
monitor.awaitingPopulationOfRecoveredIndex(index);
awaitOnlineAfterRecovery(proxy);
});
state = State.RUNNING;
}
use of org.neo4j.internal.schema.IndexProviderDescriptor in project neo4j by neo4j.
the class IndexWriterStep method createIndex.
private IndexDescriptor createIndex(EntityType entityType, IndexConfig config, SchemaRuleAccess schemaRule, SchemaStore schemaStore, MemoryTracker memoryTracker, CursorContext cursorContext) {
try {
IndexProviderDescriptor providerDescriptor = new IndexProviderDescriptor("token-lookup", "1.0");
IndexPrototype prototype = forSchema(forAnyEntityTokens(entityType)).withIndexType(LOOKUP).withIndexProvider(providerDescriptor);
String name = defaultIfEmpty(config.indexName(entityType), generateName(prototype, new String[] {}, new String[] {}));
IndexDescriptor descriptor = prototype.withName(name).materialise(schemaStore.nextId(cursorContext));
schemaRule.writeSchemaRule(descriptor, cursorContext, memoryTracker);
return descriptor;
} catch (KernelException e) {
throw new RuntimeException("Error preparing indexes", e);
}
}
Aggregations