Search in sources :

Example 1 with KernelException

use of org.neo4j.kernel.api.exceptions.KernelException in project neo4j by neo4j.

the class GraphDbStructureGuide method showStructure.

private void showStructure(Statement statement, DbStructureVisitor visitor) {
    ReadOperations read = statement.readOperations();
    try {
        showTokens(visitor, read);
        showSchema(visitor, read);
        showStatistics(visitor, read);
    } catch (KernelException e) {
        throw new IllegalStateException("Kernel exception when traversing database schema structure and statistics.  This is not expected to happen.", e);
    }
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) KernelException(org.neo4j.kernel.api.exceptions.KernelException)

Example 2 with KernelException

use of org.neo4j.kernel.api.exceptions.KernelException in project neo4j by neo4j.

the class IndexStatisticsTest method repeatCreateNamedPeopleFor.

private long[] repeatCreateNamedPeopleFor(int totalNumberOfPeople) throws Exception {
    // Parallelize the creation of persons
    final long[] nodes = new long[totalNumberOfPeople];
    final int threads = 100;
    final int peoplePerThread = totalNumberOfPeople / threads;
    final ExecutorService service = Executors.newFixedThreadPool(threads);
    final AtomicReference<KernelException> exception = new AtomicReference<>();
    final List<Callable<Void>> jobs = new ArrayList<>(threads);
    // Start threads that creates these people, relying on batched writes to speed things up
    for (int i = 0; i < threads; i++) {
        final int finalI = i;
        jobs.add(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                int offset = finalI * peoplePerThread;
                while (offset < (finalI + 1) * peoplePerThread) {
                    try {
                        offset += createNamedPeople(nodes, offset);
                    } catch (KernelException e) {
                        exception.compareAndSet(null, e);
                        throw new RuntimeException(e);
                    }
                }
                return null;
            }
        });
    }
    for (Future<?> job : service.invokeAll(jobs)) {
        job.get();
    }
    service.awaitTermination(1, TimeUnit.SECONDS);
    service.shutdown();
    // Make any KernelException thrown from a creation thread visible in the main thread
    Exception ex = exception.get();
    if (ex != null) {
        throw ex;
    }
    return nodes;
}
Also used : ArrayList(java.util.ArrayList) AtomicReference(java.util.concurrent.atomic.AtomicReference) Callable(java.util.concurrent.Callable) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException) KernelException(org.neo4j.kernel.api.exceptions.KernelException) ExecutorService(java.util.concurrent.ExecutorService) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) KernelException(org.neo4j.kernel.api.exceptions.KernelException)

Example 3 with KernelException

use of org.neo4j.kernel.api.exceptions.KernelException in project neo4j by neo4j.

the class GraphDatabaseFacade method nodesByLabelAndProperty.

private ResourceIterator<Node> nodesByLabelAndProperty(Label myLabel, String key, Object value) {
    Statement statement = spi.currentStatement();
    ReadOperations readOps = statement.readOperations();
    int propertyId = readOps.propertyKeyGetForName(key);
    int labelId = readOps.labelGetForName(myLabel.name());
    if (propertyId == NO_SUCH_PROPERTY_KEY || labelId == NO_SUCH_LABEL) {
        statement.close();
        return emptyIterator();
    }
    NewIndexDescriptor descriptor = findAnyIndexByLabelAndProperty(readOps, propertyId, labelId);
    try {
        if (null != descriptor) {
            // Ha! We found an index - let's use it to find matching nodes
            IndexQuery.ExactPredicate query = IndexQuery.exact(descriptor.schema().getPropertyId(), value);
            return map2nodes(readOps.indexQuery(descriptor, query), statement);
        }
    } catch (KernelException e) {
    // weird at this point but ignore and fallback to a label scan
    }
    return getNodesByLabelAndPropertyWithoutIndex(propertyId, value, statement, labelId);
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) KeyReadOperations(org.neo4j.kernel.impl.api.operations.KeyReadOperations) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) IndexQuery(org.neo4j.kernel.api.schema_new.IndexQuery) Statement(org.neo4j.kernel.api.Statement) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) InvalidTransactionTypeKernelException(org.neo4j.kernel.api.exceptions.InvalidTransactionTypeKernelException) KernelException(org.neo4j.kernel.api.exceptions.KernelException) SchemaKernelException(org.neo4j.kernel.api.exceptions.schema.SchemaKernelException)

Example 4 with KernelException

use of org.neo4j.kernel.api.exceptions.KernelException in project neo4j by neo4j.

the class ExceptionRepresentationTest method shouldRenderErrorsWithNeo4jStatusCode.

@Test
public void shouldRenderErrorsWithNeo4jStatusCode() throws Exception {
    // Given
    ExceptionRepresentation rep = new ExceptionRepresentation(new KernelException(UnknownError, "Hello") {
    });
    // When
    JsonNode out = serialize(rep);
    // Then
    assertThat(out.get("errors").get(0).get("code").asText(), equalTo("Neo.DatabaseError.General.UnknownError"));
    assertThat(out.get("errors").get(0).get("message").asText(), equalTo("Hello"));
}
Also used : JsonNode(org.codehaus.jackson.JsonNode) KernelException(org.neo4j.kernel.api.exceptions.KernelException) Test(org.junit.Test)

Example 5 with KernelException

use of org.neo4j.kernel.api.exceptions.KernelException in project neo4j by neo4j.

the class ExceptionRepresentationTest method shoudExcludeLegacyFormatIfAsked.

@Test
public void shoudExcludeLegacyFormatIfAsked() throws Exception {
    // Given
    ExceptionRepresentation rep = new ExceptionRepresentation(new KernelException(UnknownError, "Hello") {
    }, /*legacy*/
    false);
    // When
    JsonNode out = serialize(rep);
    // Then
    assertThat(out.get("errors").get(0).get("code").asText(), equalTo("Neo.DatabaseError.General.UnknownError"));
    assertThat(out.get("errors").get(0).get("message").asText(), equalTo("Hello"));
    assertThat(out.has("message"), equalTo(false));
}
Also used : JsonNode(org.codehaus.jackson.JsonNode) KernelException(org.neo4j.kernel.api.exceptions.KernelException) Test(org.junit.Test)

Aggregations

KernelException (org.neo4j.kernel.api.exceptions.KernelException)13 ArrayList (java.util.ArrayList)5 Log (org.neo4j.logging.Log)5 List (java.util.List)4 Optional (java.util.Optional)4 Stream (java.util.stream.Stream)4 RawIterator (org.neo4j.collection.RawIterator)4 Status (org.neo4j.kernel.api.exceptions.Status)4 CallableProcedure (org.neo4j.kernel.api.proc.CallableProcedure)4 CallableUserAggregationFunction (org.neo4j.kernel.api.proc.CallableUserAggregationFunction)4 CallableUserFunction (org.neo4j.kernel.api.proc.CallableUserFunction)4 MethodHandle (java.lang.invoke.MethodHandle)3 MethodHandles (java.lang.invoke.MethodHandles)3 Method (java.lang.reflect.Method)3 Modifier (java.lang.reflect.Modifier)3 Arrays (java.util.Arrays)3 Collections.emptyIterator (java.util.Collections.emptyIterator)3 Collections.emptyList (java.util.Collections.emptyList)3 Comparator (java.util.Comparator)3 Iterator (java.util.Iterator)3