Search in sources :

Example 1 with DatabaseShutdownException

use of org.neo4j.graphdb.DatabaseShutdownException in project neo4j by neo4j.

the class Neo4jErrorTest method shouldSetStatusToDatabaseUnavailableOnDatabaseShutdownException.

@Test
public void shouldSetStatusToDatabaseUnavailableOnDatabaseShutdownException() {
    // Given
    DatabaseShutdownException ex = new DatabaseShutdownException();
    // When
    Neo4jError error = Neo4jError.from(ex);
    // Then
    assertThat(error.status(), equalTo(Status.General.DatabaseUnavailable));
    assertThat(error.cause(), equalTo(ex));
}
Also used : DatabaseShutdownException(org.neo4j.graphdb.DatabaseShutdownException) Test(org.junit.Test)

Example 2 with DatabaseShutdownException

use of org.neo4j.graphdb.DatabaseShutdownException in project neo4j by neo4j.

the class Cluster method leaderTx.

/**
     * Perform a transaction against the leader of the core cluster, retrying as necessary.
     */
private CoreClusterMember leaderTx(BiConsumer<CoreGraphDatabase, Transaction> op, int timeout, TimeUnit timeUnit) throws Exception {
    ThrowingSupplier<CoreClusterMember, Exception> supplier = () -> {
        CoreClusterMember member = awaitLeader(timeout, timeUnit);
        CoreGraphDatabase db = member.database();
        if (db == null) {
            throw new DatabaseShutdownException();
        }
        try (Transaction tx = db.beginTx()) {
            op.accept(db, tx);
            return member;
        } catch (Throwable e) {
            if (isTransientFailure(e)) {
                // this is not the best, but it helps in debugging
                System.err.println("Transient failure in leader transaction, trying again.");
                e.printStackTrace();
                return null;
            } else {
                throw e;
            }
        }
    };
    return awaitEx(supplier, notNull()::test, timeout, timeUnit);
}
Also used : Transaction(org.neo4j.graphdb.Transaction) DatabaseShutdownException(org.neo4j.graphdb.DatabaseShutdownException) CoreGraphDatabase(org.neo4j.causalclustering.core.CoreGraphDatabase) TimeoutException(java.util.concurrent.TimeoutException) TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) IdGenerationException(org.neo4j.causalclustering.core.state.machines.id.IdGenerationException) ExecutionException(java.util.concurrent.ExecutionException) NoLeaderFoundException(org.neo4j.causalclustering.core.consensus.NoLeaderFoundException) WriteOperationsNotAllowedException(org.neo4j.graphdb.security.WriteOperationsNotAllowedException) DatabaseShutdownException(org.neo4j.graphdb.DatabaseShutdownException) AcquireLockTimeoutException(org.neo4j.storageengine.api.lock.AcquireLockTimeoutException)

Example 3 with DatabaseShutdownException

use of org.neo4j.graphdb.DatabaseShutdownException in project neo4j by neo4j.

the class WorkLoad method doWork.

@Override
protected void doWork() {
    GraphDatabaseService db = dbRef.get();
    try (Transaction tx = db.beginTx()) {
        Node node = db.createNode(label);
        for (int i = 1; i <= 8; i++) {
            node.setProperty(prop(i), "let's add some data here so the transaction logs rotate more often...");
        }
        tx.success();
    } catch (DatabaseShutdownException | TransactionFailureException e) {
    // whatever let's go on with the workload
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) DatabaseShutdownException(org.neo4j.graphdb.DatabaseShutdownException)

Example 4 with DatabaseShutdownException

use of org.neo4j.graphdb.DatabaseShutdownException in project neo4j by neo4j.

the class Cluster method dataOnMemberEventuallyLooksLike.

/**
     * Waits for {@link #DEFAULT_TIMEOUT_MS} for the <code>memberThatChanges</code> to match the contents of
     * <code>memberToLookLike</code>. After calling this method, changes both in <code>memberThatChanges</code> and
     * <code>memberToLookLike</code> are picked up.
     */
public static void dataOnMemberEventuallyLooksLike(CoreClusterMember memberThatChanges, CoreClusterMember memberToLookLike) throws TimeoutException, InterruptedException {
    await(() -> {
        try {
            // We recalculate the DbRepresentation of both source and target, so changes can be picked up
            DbRepresentation representationToLookLike = DbRepresentation.of(memberToLookLike.database());
            DbRepresentation representationThatChanges = DbRepresentation.of(memberThatChanges.database());
            return representationToLookLike.equals(representationThatChanges);
        } catch (DatabaseShutdownException e) {
        /*
                     * This can happen if the database is still in the process of starting. Yes, the naming
                     * of the exception is unfortunate, since it is thrown when the database lifecycle is not
                     * in RUNNING state and therefore signals general unavailability (e.g still starting) and not
                     * necessarily a database that is shutting down.
                     */
        }
        return false;
    }, DEFAULT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
}
Also used : DatabaseShutdownException(org.neo4j.graphdb.DatabaseShutdownException) DbRepresentation(org.neo4j.test.DbRepresentation)

Example 5 with DatabaseShutdownException

use of org.neo4j.graphdb.DatabaseShutdownException in project neo4j by neo4j.

the class TestNeo4jApiExceptions method shouldGiveNiceErrorWhenShutdownLegacy.

@Test
public void shouldGiveNiceErrorWhenShutdownLegacy() {
    GraphDatabaseService graphDb = graph;
    Node node = graphDb.createNode();
    commit();
    graphDb.shutdown();
    try {
        node.getRelationships();
        fail("Did not get a nice exception");
    } catch (DatabaseShutdownException e) {
    // good
    }
    try {
        graphDb.createNode();
        fail("Create node did not produce expected error");
    } catch (DatabaseShutdownException e) {
    // good
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Node(org.neo4j.graphdb.Node) DatabaseShutdownException(org.neo4j.graphdb.DatabaseShutdownException) Test(org.junit.Test)

Aggregations

DatabaseShutdownException (org.neo4j.graphdb.DatabaseShutdownException)6 Test (org.junit.Test)3 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)3 Node (org.neo4j.graphdb.Node)3 Transaction (org.neo4j.graphdb.Transaction)2 TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)2 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 CoreGraphDatabase (org.neo4j.causalclustering.core.CoreGraphDatabase)1 NoLeaderFoundException (org.neo4j.causalclustering.core.consensus.NoLeaderFoundException)1 IdGenerationException (org.neo4j.causalclustering.core.state.machines.id.IdGenerationException)1 WriteOperationsNotAllowedException (org.neo4j.graphdb.security.WriteOperationsNotAllowedException)1 AcquireLockTimeoutException (org.neo4j.storageengine.api.lock.AcquireLockTimeoutException)1 DbRepresentation (org.neo4j.test.DbRepresentation)1