use of org.neo4j.internal.schema.LabelSchemaDescriptor in project neo4j by neo4j.
the class IndexPopulationJobTest method tracePageCacheAccessIndexWithOneNodePopulation.
@Test
void tracePageCacheAccessIndexWithOneNodePopulation() throws KernelException {
var value = "value";
long nodeId = createNode(map(name, value), FIRST);
IndexPopulator actualPopulator = indexPopulator(false);
TrackingIndexPopulator populator = new TrackingIndexPopulator(actualPopulator);
int label = tokenHolders.labelTokens().getIdByName(FIRST.name());
int prop = tokenHolders.propertyKeyTokens().getIdByName(name);
LabelSchemaDescriptor descriptor = SchemaDescriptor.forLabel(label, prop);
var pageCacheTracer = new DefaultPageCacheTracer();
IndexPopulationJob job = newIndexPopulationJob(populator, new FlippableIndexProxy(), EntityType.NODE, IndexPrototype.forSchema(descriptor), pageCacheTracer);
job.run();
IndexEntryUpdate<?> update = IndexEntryUpdate.add(nodeId, descriptor, Values.of(value));
assertTrue(populator.created);
assertEquals(Collections.singletonList(update), populator.includedSamples);
assertEquals(1, populator.adds.size());
assertTrue(populator.resultSampled);
assertTrue(populator.closeCall);
long pins = pageCacheTracer.pins();
assertThat(pins).isGreaterThan(0);
assertThat(pageCacheTracer.unpins()).isEqualTo(pins);
assertThat(pageCacheTracer.hits()).isGreaterThan(0).isLessThanOrEqualTo(pins);
assertThat(pageCacheTracer.faults()).isGreaterThan(0).isLessThanOrEqualTo(pins);
}
use of org.neo4j.internal.schema.LabelSchemaDescriptor in project neo4j by neo4j.
the class IndexCRUDIT method addingANodeWithPropertyShouldGetIndexed.
@Test
void addingANodeWithPropertyShouldGetIndexed() throws Exception {
// Given
String indexProperty = "indexProperty";
GatheringIndexWriter writer = newWriter();
createIndex(db, myLabel, indexProperty);
// When
int value1 = 12;
String otherProperty = "otherProperty";
int otherValue = 17;
Node node = createNode(map(indexProperty, value1, otherProperty, otherValue), myLabel);
// Then, for now, this should trigger two NodePropertyUpdates
try (Transaction tx = db.beginTx()) {
KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
TokenRead tokenRead = ktx.tokenRead();
int propertyKey1 = tokenRead.propertyKey(indexProperty);
int label = tokenRead.nodeLabel(myLabel.name());
LabelSchemaDescriptor descriptor = SchemaDescriptor.forLabel(label, propertyKey1);
assertThat(writer.updatesCommitted).isEqualTo(asSet(IndexEntryUpdate.add(node.getId(), descriptor, Values.of(value1))));
tx.commit();
}
// We get two updates because we both add a label and a property to be indexed
// in the same transaction, in the future, we should optimize this down to
// one NodePropertyUpdate.
}
use of org.neo4j.internal.schema.LabelSchemaDescriptor in project neo4j by neo4j.
the class BuiltInProceduresIT method listAllIndexes.
@Test
void listAllIndexes() throws Throwable {
// Given
KernelTransaction transaction = newTransaction(AUTH_DISABLED);
int labelId1 = transaction.tokenWrite().labelGetOrCreateForName("Person");
int labelId2 = transaction.tokenWrite().labelGetOrCreateForName("Age");
int propertyKeyId1 = transaction.tokenWrite().propertyKeyGetOrCreateForName("foo");
int propertyKeyId2 = transaction.tokenWrite().propertyKeyGetOrCreateForName("bar");
LabelSchemaDescriptor personFooDescriptor = forLabel(labelId1, propertyKeyId1);
LabelSchemaDescriptor ageFooDescriptor = forLabel(labelId2, propertyKeyId1);
LabelSchemaDescriptor personFooBarDescriptor = forLabel(labelId1, propertyKeyId1, propertyKeyId2);
transaction.schemaWrite().indexCreate(personFooDescriptor, "person foo index");
transaction.schemaWrite().uniquePropertyConstraintCreate(IndexPrototype.uniqueForSchema(ageFooDescriptor).withName("constraint name"));
transaction.schemaWrite().indexCreate(personFooBarDescriptor, "person foo bar index");
commit();
// let indexes come online
try (org.neo4j.graphdb.Transaction tx = db.beginTx()) {
tx.schema().awaitIndexesOnline(2, MINUTES);
tx.commit();
}
transaction = newTransaction();
IndexDescriptor personFooIndex = single(transaction.schemaRead().index(personFooDescriptor));
IndexDescriptor ageFooIndex = single(transaction.schemaRead().index(ageFooDescriptor));
IndexDescriptor personFooBarIndex = single(transaction.schemaRead().index(personFooBarDescriptor));
// When
RawIterator<AnyValue[], ProcedureException> stream = procs().procedureCallRead(procs().procedureGet(procedureName("db", "indexes")).id(), new AnyValue[0], ProcedureCallContext.EMPTY);
Set<AnyValue[]> result = new HashSet<>();
while (stream.hasNext()) {
result.add(stream.next());
}
// Then
assertThat(result).contains(dbIndexesResult(ageFooIndex.getId(), ageFooIndex.getName(), "ONLINE", 100D, "UNIQUE", "BTREE", "NODE", singletonList("Age"), singletonList("foo"), ageFooIndex.getIndexProvider().name()), dbIndexesResult(personFooIndex.getId(), personFooIndex.getName(), "ONLINE", 100D, "NONUNIQUE", "BTREE", "NODE", singletonList("Person"), singletonList("foo"), personFooIndex.getIndexProvider().name()), dbIndexesResult(personFooBarIndex.getId(), personFooBarIndex.getName(), "ONLINE", 100D, "NONUNIQUE", "BTREE", "NODE", singletonList("Person"), Arrays.asList("foo", "bar"), personFooBarIndex.getIndexProvider().name()));
commit();
}
use of org.neo4j.internal.schema.LabelSchemaDescriptor in project neo4j by neo4j.
the class BuiltInProceduresIT method listAllIndexesMustNotBlockOnConstraintCreatingTransaction.
@Test
@Timeout(value = 6, unit = MINUTES)
void listAllIndexesMustNotBlockOnConstraintCreatingTransaction() throws Throwable {
// Given
KernelTransaction transaction = newTransaction(AUTH_DISABLED);
int labelId1 = transaction.tokenWrite().labelGetOrCreateForName("Person");
int labelId2 = transaction.tokenWrite().labelGetOrCreateForName("Age");
int propertyKeyId1 = transaction.tokenWrite().propertyKeyGetOrCreateForName("foo");
int propertyKeyId2 = transaction.tokenWrite().propertyKeyGetOrCreateForName("bar");
int propertyKeyId3 = transaction.tokenWrite().propertyKeyGetOrCreateForName("baz");
LabelSchemaDescriptor personFooDescriptor = forLabel(labelId1, propertyKeyId1);
LabelSchemaDescriptor ageFooDescriptor = forLabel(labelId2, propertyKeyId1);
LabelSchemaDescriptor personFooBarDescriptor = forLabel(labelId1, propertyKeyId1, propertyKeyId2);
LabelSchemaDescriptor personBazDescriptor = forLabel(labelId1, propertyKeyId3);
transaction.schemaWrite().indexCreate(personFooDescriptor, "person foo index");
transaction.schemaWrite().uniquePropertyConstraintCreate(IndexPrototype.uniqueForSchema(ageFooDescriptor).withName("age foo constraint"));
transaction.schemaWrite().indexCreate(personFooBarDescriptor, "person foo bar index");
commit();
// let indexes come online
try (org.neo4j.graphdb.Transaction tx = db.beginTx()) {
tx.schema().awaitIndexesOnline(2, MINUTES);
tx.commit();
}
CountDownLatch constraintLatch = new CountDownLatch(1);
CountDownLatch commitLatch = new CountDownLatch(1);
AtomicLong personBazIndexId = new AtomicLong();
FutureTask<Void> createConstraintTask = new FutureTask<>(() -> {
SchemaWrite schemaWrite = schemaWriteInNewTransaction();
try (Resource ignore = captureTransaction()) {
ConstraintDescriptor personBazConstraint = schemaWrite.uniquePropertyConstraintCreate(IndexPrototype.uniqueForSchema(personBazDescriptor).withName("person baz constraint"));
personBazIndexId.set(personBazConstraint.asIndexBackedConstraint().ownedIndexId());
// 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();
transaction = newTransaction();
final SchemaReadCore schemaRead = transaction.schemaRead().snapshot();
IndexDescriptor personFooIndex = single(schemaRead.index(personFooDescriptor));
IndexDescriptor ageFooIndex = single(schemaRead.index(ageFooDescriptor));
IndexDescriptor personFooBarIndex = single(schemaRead.index(personFooBarDescriptor));
IndexDescriptor personBazIndex = single(schemaRead.index(personBazDescriptor));
commit();
RawIterator<AnyValue[], ProcedureException> stream = procs().procedureCallRead(procs().procedureGet(procedureName("db", "indexes")).id(), new AnyValue[0], ProcedureCallContext.EMPTY);
Set<Object[]> result = new HashSet<>();
while (stream.hasNext()) {
result.add(stream.next());
}
// Then
try {
assertThat(result).contains(dbIndexesResult(ageFooIndex.getId(), ageFooIndex.getName(), "ONLINE", 100D, "UNIQUE", "BTREE", "NODE", singletonList("Age"), singletonList("foo"), ageFooIndex.getIndexProvider().name()), dbIndexesResult(personFooIndex.getId(), personFooIndex.getName(), "ONLINE", 100D, "NONUNIQUE", "BTREE", "NODE", singletonList("Person"), singletonList("foo"), personFooIndex.getIndexProvider().name()), dbIndexesResult(personFooBarIndex.getId(), personFooBarIndex.getName(), "ONLINE", 100D, "NONUNIQUE", "BTREE", "NODE", singletonList("Person"), Arrays.asList("foo", "bar"), personFooBarIndex.getIndexProvider().name()), dbIndexesResult(personBazIndex.getId(), personBazIndex.getName(), /*???*/
"POPULATING", 100D, "UNIQUE", "BTREE", "NODE", singletonList("Person"), singletonList("baz"), personBazIndex.getIndexProvider().name()));
commit();
} finally {
commitLatch.countDown();
}
createConstraintTask.get();
constraintCreator.join();
}
use of org.neo4j.internal.schema.LabelSchemaDescriptor in project neo4j by neo4j.
the class KernelIT method createIndex.
private static IndexDescriptor createIndex(KernelTransaction transaction) throws KernelException {
TokenWrite tokenWrite = transaction.tokenWrite();
SchemaWrite schemaWrite = transaction.schemaWrite();
LabelSchemaDescriptor schema = forLabel(tokenWrite.labelGetOrCreateForName("hello"), tokenWrite.propertyKeyGetOrCreateForName("hepp"));
return schemaWrite.indexCreate(schema, null);
}
Aggregations