use of org.neo4j.common.TokenNameLookup in project neo4j by neo4j.
the class IndexingService method init.
/**
* Called while the database starts up, before recovery.
*/
@Override
public void init() throws IOException {
validateDefaultProviderExisting();
try (var cursorContext = new CursorContext(pageCacheTracer.createPageCursorTracer(INIT_TAG))) {
indexMapRef.modify(indexMap -> {
Map<InternalIndexState, List<IndexLogRecord>> indexStates = new EnumMap<>(InternalIndexState.class);
for (IndexDescriptor descriptor : indexDescriptors) {
// No index (except NLI) is allowed to have the name generated for NLI.
if (descriptor.getName().equals(IndexDescriptor.NLI_GENERATED_NAME) && !(descriptor.schema().isAnyTokenSchemaDescriptor() && descriptor.schema().entityType() == NODE)) {
throw new IllegalStateException("Index '" + descriptor.userDescription(tokenNameLookup) + "' is using a reserved name: '" + IndexDescriptor.NLI_GENERATED_NAME + "'. This index must be removed on an earlier version " + "to be able to use binaries for version 4.3 or newer.");
}
IndexProxy indexProxy;
IndexProviderDescriptor providerDescriptor = descriptor.getIndexProvider();
IndexProvider provider = providerMap.lookup(providerDescriptor);
InternalIndexState initialState = provider.getInitialState(descriptor, cursorContext);
indexStates.computeIfAbsent(initialState, internalIndexState -> new ArrayList<>()).add(new IndexLogRecord(descriptor));
internalLog.debug(indexStateInfo("init", initialState, descriptor));
switch(initialState) {
case ONLINE:
monitor.initialState(databaseName, descriptor, ONLINE);
indexProxy = indexProxyCreator.createOnlineIndexProxy(descriptor);
break;
case POPULATING:
// The database was shut down during population, or a crash has occurred, or some other sad thing.
monitor.initialState(databaseName, descriptor, POPULATING);
indexProxy = indexProxyCreator.createRecoveringIndexProxy(descriptor);
break;
case FAILED:
monitor.initialState(databaseName, descriptor, FAILED);
IndexPopulationFailure failure = failure(provider.getPopulationFailure(descriptor, cursorContext));
indexProxy = indexProxyCreator.createFailedIndexProxy(descriptor, failure);
break;
default:
throw new IllegalArgumentException("" + initialState);
}
indexMap.putIndexProxy(indexProxy);
}
logIndexStateSummary("init", indexStates);
return indexMap;
});
}
indexStatisticsStore.init();
}
use of org.neo4j.common.TokenNameLookup in project neo4j by neo4j.
the class SchemaStorageTest method shouldThrowExceptionOnRelationshipRuleNotFound.
@Test
void shouldThrowExceptionOnRelationshipRuleNotFound() {
TokenNameLookup tokenNameLookup = getDefaultTokenNameLookup();
var e = assertThrows(SchemaRuleNotFoundException.class, () -> storage.constraintsGetSingle(ConstraintDescriptorFactory.existsForRelType(TYPE1_ID, PROP1_ID), NULL));
assertThat(e, tokenNameLookup).hasUserMessage("No relationship type property existence constraint was found for -[:Type1 {prop1}]-.");
}
use of org.neo4j.common.TokenNameLookup in project neo4j by neo4j.
the class SchemaStorageTest method shouldThrowExceptionOnRelationshipDuplicateRuleFound.
@Test
void shouldThrowExceptionOnRelationshipDuplicateRuleFound() {
TokenNameLookup tokenNameLookup = getDefaultTokenNameLookup();
SchemaStorage schemaStorageSpy = Mockito.spy(storage);
when(schemaStorageSpy.streamAllSchemaRules(false, NULL)).thenReturn(Stream.of(getRelationshipPropertyExistenceConstraintRule(1L, TYPE1_ID, PROP1_ID), getRelationshipPropertyExistenceConstraintRule(2L, TYPE1_ID, PROP1_ID)));
var e = assertThrows(DuplicateSchemaRuleException.class, () -> schemaStorageSpy.constraintsGetSingle(ConstraintDescriptorFactory.existsForRelType(TYPE1_ID, PROP1_ID), NULL));
assertThat(e, tokenNameLookup).hasUserMessage("Multiple relationship type property existence constraints found for -[:Type1 {prop1}]-.");
}
use of org.neo4j.common.TokenNameLookup in project neo4j by neo4j.
the class GraphDbStructureGuide method showSchema.
private static void showSchema(DbStructureVisitor visitor, KernelTransaction ktx) throws IndexNotFoundKernelException {
TokenNameLookup nameLookup = ktx.tokenRead();
showIndices(visitor, ktx, nameLookup);
showUniqueConstraints(visitor, ktx, nameLookup);
}
use of org.neo4j.common.TokenNameLookup in project neo4j by neo4j.
the class LuceneIndexAccessorIT method shouldReadAllDocumentsInSchemaIndexAfterRandomAdditionsAndDeletions.
@Test
void shouldReadAllDocumentsInSchemaIndexAfterRandomAdditionsAndDeletions() throws Exception {
// given
IndexDescriptor descriptor = IndexPrototype.forSchema(SchemaDescriptor.forLabel(0, 1)).withName("test").materialise(1);
TokenNameLookup tokenNameLookup = mock(TokenNameLookup.class);
populateWithInitialNodes(descriptor, 0, new LongHashSet());
try (IndexAccessor accessor = indexProvider.getOnlineAccessor(descriptor, samplingConfig, tokenNameLookup)) {
// when
BitSet expectedEntities = writeRandomThings(accessor, descriptor);
int expectedCount = expectedEntities.cardinality();
// then
int count = 0;
try (BoundedIterable<Long> reader = accessor.newAllEntriesValueReader(NULL)) {
for (Long entityId : reader) {
count++;
assertThat(expectedEntities.get(toIntExact(entityId))).isTrue();
}
}
assertThat(count).isEqualTo(expectedCount);
}
}
Aggregations