use of org.neo4j.internal.schema.IndexPrototype in project neo4j by neo4j.
the class RecordStorageReaderTestBase method createIndex.
protected IndexDescriptor createIndex(RelationshipType relType, String propertyKey) throws Exception {
TxState txState = new TxState();
int relTypeId = getOrCreateRelationshipTypeId(relType);
int propertyKeyId = getOrCreatePropertyKeyId(propertyKey);
long id = commitContext.reserveSchema();
IndexPrototype prototype = IndexPrototype.forSchema(forRelType(relTypeId, propertyKeyId)).withName("index_" + id);
IndexDescriptor index = prototype.materialise(id);
txState.indexDoAdd(index);
apply(txState);
return index;
}
use of org.neo4j.internal.schema.IndexPrototype in project neo4j by neo4j.
the class BuiltInProceduresIT method listAllLabelsMustNotBlockOnConstraintCreatingTransaction.
@Test
@Timeout(value = 6, unit = MINUTES)
void listAllLabelsMustNotBlockOnConstraintCreatingTransaction() throws Throwable {
// Given
KernelTransaction transaction = newTransaction(AnonymousContext.writeToken());
long nodeId = transaction.dataWrite().nodeCreate();
int labelId = transaction.tokenWrite().labelGetOrCreateForName("MyLabel");
int propKey = transaction.tokenWrite().propertyKeyCreateForName("prop", false);
transaction.dataWrite().nodeAddLabel(nodeId, labelId);
commit();
CountDownLatch constraintLatch = new CountDownLatch(1);
CountDownLatch commitLatch = new CountDownLatch(1);
FutureTask<Void> createConstraintTask = new FutureTask<>(() -> {
SchemaWrite schemaWrite = schemaWriteInNewTransaction();
try (Resource ignore = captureTransaction()) {
IndexPrototype prototype = IndexPrototype.uniqueForSchema(SchemaDescriptor.forLabel(labelId, propKey)).withName("constraint name");
schemaWrite.uniquePropertyConstraintCreate(prototype);
// We now hold a schema lock on the "MyLabel" label. Let the procedure calling transaction have a go.
constraintLatch.countDown();
commitLatch.await();
}
rollback();
return null;
});
Thread constraintCreator = new Thread(createConstraintTask);
constraintCreator.start();
// When
constraintLatch.await();
RawIterator<AnyValue[], ProcedureException> stream = procs().procedureCallRead(procs().procedureGet(procedureName("db", "labels")).id(), new AnyValue[0], ProcedureCallContext.EMPTY);
// Then
try {
assertThat(asList(stream)).containsExactly(new AnyValue[] { stringValue("MyLabel") });
} finally {
commitLatch.countDown();
}
createConstraintTask.get();
constraintCreator.join();
}
use of org.neo4j.internal.schema.IndexPrototype in project neo4j by neo4j.
the class IndexIT method shouldListCompositeMultiTokenRelationshipIndexesInTheCoreAPI.
@Test
void shouldListCompositeMultiTokenRelationshipIndexesInTheCoreAPI() throws Exception {
KernelTransaction transaction = newTransaction(AUTH_DISABLED);
long initialIndexCount = Iterators.count(transaction.schemaRead().indexesGetAll());
SchemaDescriptor schema = SchemaDescriptor.fulltext(EntityType.RELATIONSHIP, new int[] { relType, relType2 }, new int[] { propertyKeyId, propertyKeyId2 });
IndexPrototype prototype = IndexPrototype.forSchema(schema, FulltextIndexProviderFactory.DESCRIPTOR).withIndexType(IndexType.FULLTEXT).withName("index name");
transaction.schemaWrite().indexCreate(prototype);
commit();
try (org.neo4j.graphdb.Transaction tx = db.beginTx()) {
// then
Set<IndexDefinition> indexes = Iterables.asSet(tx.schema().getIndexes());
assertThat(indexes.size()).isEqualTo(initialIndexCount + 1);
IndexDefinition index = tx.schema().getIndexByName("index name");
assertThrows(IllegalStateException.class, index::getLabels);
assertThat(index.getRelationshipTypes()).containsOnly(withName(REL_TYPE), withName(REL_TYPE2));
assertThat(index.getPropertyKeys()).containsOnly(PROPERTY_KEY, PROPERTY_KEY2);
assertFalse(index.isConstraintIndex(), "should not be a constraint index");
assertTrue(index.isMultiTokenIndex(), "should be a multi-token index");
assertTrue(index.isCompositeIndex(), "should be a composite index");
assertFalse(index.isNodeIndex(), "should not be a node index");
assertTrue(index.isRelationshipIndex(), "should be a relationship index");
}
}
use of org.neo4j.internal.schema.IndexPrototype in project neo4j by neo4j.
the class IndexPopulationJobTest method tracePageCacheAccessIndexWithOneRelationship.
@Test
void tracePageCacheAccessIndexWithOneRelationship() {
String value = "value";
long nodeId = createNode(map(name, value), FIRST);
long relationship = createRelationship(map(name, age), likes, nodeId, nodeId);
int rel = tokenHolders.relationshipTypeTokens().getIdByName(likes.name());
int prop = tokenHolders.propertyKeyTokens().getIdByName(name);
IndexPrototype descriptor = IndexPrototype.forSchema(SchemaDescriptor.forRelType(rel, prop));
IndexPopulator actualPopulator = indexPopulator(descriptor);
TrackingIndexPopulator populator = new TrackingIndexPopulator(actualPopulator);
var pageCacheTracer = new DefaultPageCacheTracer();
IndexPopulationJob job = newIndexPopulationJob(populator, new FlippableIndexProxy(), EntityType.RELATIONSHIP, descriptor, pageCacheTracer);
job.run();
IndexEntryUpdate<?> update = IndexEntryUpdate.add(relationship, descriptor, Values.of(age));
assertTrue(populator.created);
assertEquals(Collections.singletonList(update), populator.includedSamples);
assertEquals(1, populator.adds.size());
assertTrue(populator.resultSampled);
assertTrue(populator.closeCall);
assertThat(pageCacheTracer.pins()).isEqualTo(17);
assertThat(pageCacheTracer.unpins()).isEqualTo(17);
assertThat(pageCacheTracer.hits()).isEqualTo(16);
assertThat(pageCacheTracer.faults()).isEqualTo(1);
}
use of org.neo4j.internal.schema.IndexPrototype in project neo4j by neo4j.
the class IndexPopulationJobTest method shouldPopulateIndexWithOneRelationship.
@Test
void shouldPopulateIndexWithOneRelationship() {
// GIVEN
String value = "Taylor";
long nodeId = createNode(map(name, value), FIRST);
long relationship = createRelationship(map(name, age), likes, nodeId, nodeId);
int relType = tokenHolders.relationshipTypeTokens().getIdByName(likes.name());
int propertyId = tokenHolders.propertyKeyTokens().getIdByName(name);
IndexPrototype descriptor = IndexPrototype.forSchema(SchemaDescriptor.forRelType(relType, propertyId));
IndexPopulator actualPopulator = indexPopulator(descriptor);
TrackingIndexPopulator populator = new TrackingIndexPopulator(actualPopulator);
IndexPopulationJob job = newIndexPopulationJob(populator, new FlippableIndexProxy(), EntityType.RELATIONSHIP, descriptor);
// WHEN
job.run();
// THEN
IndexEntryUpdate<?> update = IndexEntryUpdate.add(relationship, descriptor, Values.of(age));
assertTrue(populator.created);
assertEquals(Collections.singletonList(update), populator.includedSamples);
assertEquals(1, populator.adds.size());
assertTrue(populator.resultSampled);
assertTrue(populator.closeCall);
}
Aggregations