use of org.neo4j.internal.schema.IndexDescriptor in project neo4j by neo4j.
the class RecordStorageReaderSchemaTest method shouldListAllIndexes.
@Test
void shouldListAllIndexes() throws Exception {
// Given
IndexDescriptor firstExpectedIndex = createIndex(label1, propertyKey);
IndexDescriptor secondExpectedIndex = createIndex(label2, propertyKey);
// When
Set<IndexDescriptor> indexes = asSet(storageReader.indexesGetAll());
// Then
Set<IndexDescriptor> expectedIndexes = asSet(firstExpectedIndex, secondExpectedIndex);
assertEquals(expectedIndexes, indexes);
}
use of org.neo4j.internal.schema.IndexDescriptor in project neo4j by neo4j.
the class RecordStorageReaderTestBase method createUniqueIndex.
private IndexDescriptor createUniqueIndex(Label label, String propertyKey) throws Exception {
TxState txState = new TxState();
int labelId = getOrCreateLabelId(label);
int propertyKeyId = getOrCreatePropertyKeyId(propertyKey);
long id = commitContext.reserveSchema();
IndexDescriptor index = IndexPrototype.uniqueForSchema(forLabel(labelId, propertyKeyId)).withName("constraint_" + id).materialise(id);
txState.indexDoAdd(index);
apply(txState);
return index;
}
use of org.neo4j.internal.schema.IndexDescriptor in project neo4j by neo4j.
the class RecordStorageReaderTestBase method createIndex.
protected IndexDescriptor createIndex(Label label, String propertyKey) throws Exception {
TxState txState = new TxState();
int labelId = getOrCreateLabelId(label);
int propertyKeyId = getOrCreatePropertyKeyId(propertyKey);
long id = commitContext.reserveSchema();
IndexPrototype prototype = IndexPrototype.forSchema(forLabel(labelId, propertyKeyId)).withName("index_" + id);
IndexDescriptor index = prototype.materialise(id);
txState.indexDoAdd(index);
apply(txState);
return index;
}
use of org.neo4j.internal.schema.IndexDescriptor in project neo4j by neo4j.
the class IndexingService method filterOutAndHandleInjectedTokenIndex.
/**
* Once upon a time there was something called label scan store.
* In essence, it was a btree used for indexing nodes, but it was not managed like other indexes.
* Most importantly, it did not have a record in the schema store.
* In 4.3, the label scan store was turned into a proper index referred to as node label index
* and got a corresponding record in a schema store.
* However, during a rolling upgrade until the cluster is fully upgraded to a version >= 4.3,
* a former label scan store behaves like a node label index, but does not have a record in schema store.
* We call such node label index as "injected".
* During an upgrade, a record in a schema store is created for the injected node label index.
* The purpose of this code is to catch the event when a new index descriptor for the injected node label index
* is submitted, filter it from the list of to-be-created indexes and swap the old descriptor on
* the injected node label index with the newly submitted descriptor.
* In other words, adding identity to an injected index is the only and very special case when
* {@link #createIndexes} is called with a descriptor for an already existing index
* and such operation needs to cause the index being linked to the new descriptor instead of
* a new index being created and because we effectively "remove" the old injected index and replace
* with the new we also need to clear the schema state.
* Of course it would be much simpler to close the injected index and create a new one with the new identity.
* The reason why the elaborate migration was introduced is not to interrupt any ongoing operations
* against the index by keeping the file/accessor of the injected label index open.
*/
private IndexDescriptor[] filterOutAndHandleInjectedTokenIndex(IndexDescriptor[] rules) {
IndexProxy nli = indexMapRef.indexMapSnapshot().getIndexProxy(IndexDescriptor.INJECTED_NLI_ID);
if (nli == null) {
return rules;
}
List<IndexDescriptor> filteredRules = new ArrayList<>();
for (IndexDescriptor rule : rules) {
if (rule.schema().isAnyTokenSchemaDescriptor() && rule.schema().entityType() == NODE) {
nli.changeIdentity(rule);
indexMapRef.modify(indexMap -> {
indexMap.putIndexProxy(nli);
indexMap.removeIndexProxy(IndexDescriptor.INJECTED_NLI_ID);
return indexMap;
});
schemaState.clear();
} else {
filteredRules.add(rule);
}
}
return filteredRules.toArray(IndexDescriptor[]::new);
}
use of org.neo4j.internal.schema.IndexDescriptor in project neo4j by neo4j.
the class IndexingService method populateIndexesOfAllTypes.
private void populateIndexesOfAllTypes(MutableLongObjectMap<IndexDescriptor> rebuildingDescriptors, IndexMap indexMap) {
Map<EntityType, MutableLongObjectMap<IndexDescriptor>> rebuildingDescriptorsByType = new EnumMap<>(EntityType.class);
for (IndexDescriptor descriptor : rebuildingDescriptors) {
rebuildingDescriptorsByType.computeIfAbsent(descriptor.schema().entityType(), type -> new LongObjectHashMap<>()).put(descriptor.getId(), descriptor);
}
for (Map.Entry<EntityType, MutableLongObjectMap<IndexDescriptor>> descriptorToPopulate : rebuildingDescriptorsByType.entrySet()) {
IndexPopulationJob populationJob = newIndexPopulationJob(descriptorToPopulate.getKey(), false, SYSTEM);
populate(descriptorToPopulate.getValue(), indexMap, populationJob);
}
}
Aggregations