Search in sources :

Example 46 with SchemaRead

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

the class SchemaImpl method awaitIndexesOnline.

private boolean awaitIndexesOnline(Iterable<IndexDescriptor> indexes, Function<IndexDescriptor, String> describe, long duration, TimeUnit unit, boolean bubbleNotFound) {
    Stopwatch startTime = Stopwatch.start();
    do {
        boolean allOnline = true;
        SchemaRead schemaRead = transaction.schemaRead();
        for (IndexDescriptor index : indexes) {
            if (index == IndexDescriptor.NO_INDEX) {
                allOnline = false;
                break;
            }
            try {
                InternalIndexState indexState = schemaRead.indexGetState(index);
                if (indexState == InternalIndexState.POPULATING) {
                    allOnline = false;
                    break;
                }
                if (indexState == InternalIndexState.FAILED) {
                    String cause = schemaRead.indexGetFailure(index);
                    String message = "Index " + describe.apply(index) + " entered a " + indexState + " state. Please see database logs.";
                    message = IndexPopulationFailure.appendCauseOfFailure(message, cause);
                    throw new IllegalStateException(message);
                }
            } catch (IndexNotFoundKernelException e) {
                if (bubbleNotFound) {
                    throw newIndexNotFoundException(descriptorToDefinition(transaction.tokenRead(), index), e);
                }
                // Weird that the index vanished, but we'll just wait and see if it comes back until we time out.
                allOnline = false;
                break;
            }
        }
        if (allOnline) {
            return false;
        }
        sleepIgnoreInterrupt();
    } while (!startTime.hasTimedOut(duration, unit));
    return true;
}
Also used : InternalIndexState(org.neo4j.internal.kernel.api.InternalIndexState) SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) Stopwatch(org.neo4j.time.Stopwatch) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor)

Example 47 with SchemaRead

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

the class SchemaImpl method getIndexState.

@Override
public IndexState getIndexState(final IndexDefinition index) {
    try {
        transaction.assertOpen();
        SchemaRead schemaRead = transaction.schemaRead();
        IndexDescriptor reference = getIndexReference(schemaRead, transaction.tokenRead(), (IndexDefinitionImpl) index);
        InternalIndexState indexState = schemaRead.indexGetState(reference);
        switch(indexState) {
            case POPULATING:
                return POPULATING;
            case ONLINE:
                return ONLINE;
            case FAILED:
                return FAILED;
            default:
                throw new IllegalArgumentException(String.format("Illegal index state %s", indexState));
        }
    } catch (KernelException e) {
        throw newIndexNotFoundException(index, e);
    }
}
Also used : InternalIndexState(org.neo4j.internal.kernel.api.InternalIndexState) SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) InvalidTransactionTypeKernelException(org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) TokenCapacityExceededKernelException(org.neo4j.internal.kernel.api.exceptions.schema.TokenCapacityExceededKernelException) SchemaKernelException(org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException) KernelException(org.neo4j.exceptions.KernelException)

Example 48 with SchemaRead

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

the class SchemaImpl method getIndexes.

@Override
public Iterable<IndexDefinition> getIndexes(RelationshipType relationshipType) {
    transaction.assertOpen();
    TokenRead tokenRead = transaction.tokenRead();
    SchemaRead schemaRead = transaction.schemaRead();
    List<IndexDefinition> definitions = new ArrayList<>();
    int relationshipTypeId = tokenRead.relationshipType(relationshipType.name());
    if (relationshipTypeId == TokenRead.NO_TOKEN) {
        return emptyList();
    }
    Iterator<IndexDescriptor> indexes = schemaRead.indexesGetForRelationshipType(relationshipTypeId);
    addDefinitions(definitions, tokenRead, IndexDescriptor.sortByType(indexes));
    return definitions;
}
Also used : SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) ArrayList(java.util.ArrayList) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) TokenRead(org.neo4j.internal.kernel.api.TokenRead)

Example 49 with SchemaRead

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

the class KernelTransactionAssertOpenTest method shouldThrowNotInTransactionWhenTransactionClosedAndAttemptingOperations.

@ParameterizedTest
@MethodSource("parameters")
void shouldThrowNotInTransactionWhenTransactionClosedAndAttemptingOperations(String name, Operation transactionOperation) throws KernelException {
    KernelTransaction transaction = newTransaction(AnonymousContext.write());
    Read read = transaction.dataRead();
    Write write = transaction.dataWrite();
    SchemaRead schemaRead = transaction.schemaRead();
    transaction.commit();
    assertThrows(NotInTransactionException.class, () -> transactionOperation.operate(read, write, schemaRead));
}
Also used : Read(org.neo4j.internal.kernel.api.Read) SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) Write(org.neo4j.internal.kernel.api.Write) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 50 with SchemaRead

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

the class IndexIT method addIndexRuleInATransaction.

@Test
void addIndexRuleInATransaction() throws Exception {
    // GIVEN
    SchemaWrite schemaWriteOperations = schemaWriteInNewTransaction();
    // WHEN
    IndexDescriptor expectedRule = schemaWriteOperations.indexCreate(schema, "my index");
    commit();
    // THEN
    SchemaRead schemaRead = newTransaction().schemaRead();
    assertEquals(asSet(expectedRule), asSet(schemaRead.indexesGetForLabel(labelId)));
    assertEquals(expectedRule, Iterators.single(schemaRead.index(schema)));
    commit();
}
Also used : SchemaWrite(org.neo4j.internal.kernel.api.SchemaWrite) SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)

Aggregations

SchemaRead (org.neo4j.internal.kernel.api.SchemaRead)52 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)36 Test (org.junit.jupiter.api.Test)28 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)26 ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)22 TokenRead (org.neo4j.internal.kernel.api.TokenRead)12 SchemaReadCore (org.neo4j.internal.kernel.api.SchemaReadCore)9 IndexNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException)8 ArrayList (java.util.ArrayList)7 Read (org.neo4j.internal.kernel.api.Read)5 HashMap (java.util.HashMap)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 Arrays (java.util.Arrays)3 Iterator (java.util.Iterator)3 List (java.util.List)3 Map (java.util.Map)3 EntityType (org.neo4j.common.EntityType)3 KernelException (org.neo4j.exceptions.KernelException)3 Transaction (org.neo4j.graphdb.Transaction)3 Iterators (org.neo4j.internal.helpers.collection.Iterators)3