Search in sources :

Example 16 with SchemaWrite

use of org.neo4j.internal.kernel.api.SchemaWrite in project neo4j by neo4j.

the class IndexIT method shouldDisallowDroppingIndexThatDoesNotExist.

@Test
void shouldDisallowDroppingIndexThatDoesNotExist() throws Exception {
    // given
    IndexDescriptor index;
    {
        SchemaWrite statement = schemaWriteInNewTransaction();
        index = statement.indexCreate(schema, "my index");
        commit();
    }
    {
        SchemaWrite statement = schemaWriteInNewTransaction();
        statement.indexDrop(index);
        commit();
    }
    var e = assertThrows(SchemaKernelException.class, () -> {
        SchemaWrite statement = schemaWriteInNewTransaction();
        statement.indexDrop(index);
    });
    assertThat(e.getMessage()).containsSubsequence("Unable to drop index", "Index does not exist").contains("Index(", "id=", "name='my index'", "type='GENERAL BTREE'", "schema=(:Label {prop})", "indexProvider='native-btree-1.0'");
    commit();
}
Also used : SchemaWrite(org.neo4j.internal.kernel.api.SchemaWrite) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)

Example 17 with SchemaWrite

use of org.neo4j.internal.kernel.api.SchemaWrite in project neo4j by neo4j.

the class SchemaReadWriteTestBase method setUp.

@BeforeEach
void setUp() throws Exception {
    try (KernelTransaction transaction = beginTransaction()) {
        SchemaRead schemaRead = transaction.schemaRead();
        SchemaWrite schemaWrite = transaction.schemaWrite();
        Iterator<ConstraintDescriptor> constraints = schemaRead.constraintsGetAll();
        while (constraints.hasNext()) {
            schemaWrite.constraintDrop(constraints.next());
        }
        Iterator<IndexDescriptor> indexes = schemaRead.indexesGetAll();
        while (indexes.hasNext()) {
            schemaWrite.indexDrop(indexes.next());
        }
        TokenWrite tokenWrite = transaction.tokenWrite();
        label = tokenWrite.labelGetOrCreateForName("label");
        label2 = tokenWrite.labelGetOrCreateForName("label2");
        type = tokenWrite.relationshipTypeGetOrCreateForName("relationship");
        prop1 = tokenWrite.propertyKeyGetOrCreateForName("prop1");
        prop2 = tokenWrite.propertyKeyGetOrCreateForName("prop2");
        prop3 = tokenWrite.propertyKeyGetOrCreateForName("prop3");
        transaction.commit();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) SchemaWrite(org.neo4j.internal.kernel.api.SchemaWrite) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) TokenWrite(org.neo4j.internal.kernel.api.TokenWrite) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 18 with SchemaWrite

use of org.neo4j.internal.kernel.api.SchemaWrite in project neo4j by neo4j.

the class IndexCreateIT method shouldCreateWithSpecificExistingProviderName.

protected void shouldCreateWithSpecificExistingProviderName(IndexCreator creator) throws KernelException {
    int counter = 0;
    for (GraphDatabaseSettings.SchemaIndex indexSetting : GraphDatabaseSettings.SchemaIndex.values()) {
        // given
        TokenWrite tokenWrite = tokenWriteInNewTransaction();
        int labelId = tokenWrite.labelGetOrCreateForName("Label" + counter);
        int propId = tokenWrite.propertyKeyGetOrCreateForName("property");
        commit();
        SchemaWrite schemaWrite = schemaWriteInNewTransaction();
        LabelSchemaDescriptor descriptor = forLabel(labelId, propId);
        String provider = indexSetting.providerName();
        String indexName = "index-" + counter;
        creator.create(schemaWrite, descriptor, provider, indexName);
        IndexDescriptor index = transaction.kernelTransaction().schemaRead().indexGetForName(indexName);
        // when
        commit();
        // then
        assertEquals(provider, indexingService.getIndexProxy(index).getDescriptor().getIndexProvider().name());
        counter++;
    }
}
Also used : GraphDatabaseSettings(org.neo4j.configuration.GraphDatabaseSettings) SchemaWrite(org.neo4j.internal.kernel.api.SchemaWrite) TokenWrite(org.neo4j.internal.kernel.api.TokenWrite) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor)

Example 19 with SchemaWrite

use of org.neo4j.internal.kernel.api.SchemaWrite in project neo4j by neo4j.

the class KernelTransactionSecurityContextTest method shouldAllowSchemaWriteAccessInFullMode.

@Test
void shouldAllowSchemaWriteAccessInFullMode() throws Throwable {
    // Given
    KernelTransactionImplementation tx = newTransaction(AUTH_DISABLED);
    // When
    SchemaWrite writes = tx.schemaWrite();
    // Then
    assertNotNull(writes);
}
Also used : SchemaWrite(org.neo4j.internal.kernel.api.SchemaWrite) Test(org.junit.jupiter.api.Test)

Example 20 with SchemaWrite

use of org.neo4j.internal.kernel.api.SchemaWrite 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();
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) SchemaWrite(org.neo4j.internal.kernel.api.SchemaWrite) Resource(org.neo4j.graphdb.Resource) CountDownLatch(java.util.concurrent.CountDownLatch) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) AtomicLong(java.util.concurrent.atomic.AtomicLong) FutureTask(java.util.concurrent.FutureTask) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) SchemaReadCore(org.neo4j.internal.kernel.api.SchemaReadCore) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Aggregations

SchemaWrite (org.neo4j.internal.kernel.api.SchemaWrite)27 Test (org.junit.jupiter.api.Test)21 KernelIntegrationTest (org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)15 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)11 TokenWrite (org.neo4j.internal.kernel.api.TokenWrite)9 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)9 LabelSchemaDescriptor (org.neo4j.internal.schema.LabelSchemaDescriptor)5 ProcedureException (org.neo4j.internal.kernel.api.exceptions.ProcedureException)4 SchemaKernelException (org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException)4 ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)4 IndexPrototype (org.neo4j.internal.schema.IndexPrototype)4 SchemaRead (org.neo4j.internal.kernel.api.SchemaRead)3 FulltextSchemaDescriptor (org.neo4j.internal.schema.FulltextSchemaDescriptor)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 FutureTask (java.util.concurrent.FutureTask)2 Timeout (org.junit.jupiter.api.Timeout)2 KernelException (org.neo4j.exceptions.KernelException)2 Resource (org.neo4j.graphdb.Resource)2 SchemaDescriptor (org.neo4j.internal.schema.SchemaDescriptor)2 IndexBackedConstraintDescriptor (org.neo4j.internal.schema.constraints.IndexBackedConstraintDescriptor)2