Search in sources :

Example 1 with ShardLeaderNotRespondingException

use of org.opendaylight.controller.cluster.datastore.exceptions.ShardLeaderNotRespondingException in project controller by opendaylight.

the class ConcurrentDOMDataBroker method handleException.

@SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST_OF_RETURN_VALUE", justification = "Pertains to the assignment of the 'clientException' var. FindBugs flags this as an " + "uncomfirmed cast but the generic type in TransactionCommitFailedExceptionMapper is " + "TransactionCommitFailedException and thus should be deemed as confirmed.")
private static void handleException(final AsyncNotifyingSettableFuture clientSubmitFuture, final DOMDataTreeWriteTransaction transaction, final Collection<DOMStoreThreePhaseCommitCohort> cohorts, final String phase, final TransactionCommitFailedExceptionMapper exMapper, final Throwable throwable) {
    if (clientSubmitFuture.isDone()) {
        // We must have had failures from multiple cohorts.
        return;
    }
    // Use debug instead of warn level here because this exception gets propagate back to the caller via the Future
    LOG.debug("Tx: {} Error during phase {}, starting Abort", transaction.getIdentifier(), phase, throwable);
    // Transaction failed - tell all cohorts to abort.
    @SuppressWarnings("unchecked") ListenableFuture<Void>[] canCommitFutures = new ListenableFuture[cohorts.size()];
    int index = 0;
    for (DOMStoreThreePhaseCommitCohort cohort : cohorts) {
        canCommitFutures[index++] = cohort.abort();
    }
    // Propagate the original exception
    final Exception e;
    if (throwable instanceof NoShardLeaderException || throwable instanceof ShardLeaderNotRespondingException) {
        e = new DataStoreUnavailableException(throwable.getMessage(), throwable);
    } else if (throwable instanceof Exception) {
        e = (Exception) throwable;
    } else {
        e = new RuntimeException("Unexpected error occurred", throwable);
    }
    clientSubmitFuture.setException(exMapper.apply(e));
    ListenableFuture<List<Void>> combinedFuture = Futures.allAsList(canCommitFutures);
    Futures.addCallback(combinedFuture, new FutureCallback<List<Void>>() {

        @Override
        public void onSuccess(final List<Void> notUsed) {
            // Propagate the original exception to the client.
            LOG.debug("Tx: {} aborted successfully", transaction.getIdentifier());
        }

        @Override
        public void onFailure(final Throwable failure) {
            LOG.error("Tx: {} Error during Abort.", transaction.getIdentifier(), failure);
        }
    }, MoreExecutors.directExecutor());
}
Also used : DataStoreUnavailableException(org.opendaylight.mdsal.common.api.DataStoreUnavailableException) DOMStoreThreePhaseCommitCohort(org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort) ShardLeaderNotRespondingException(org.opendaylight.controller.cluster.datastore.exceptions.ShardLeaderNotRespondingException) DataStoreUnavailableException(org.opendaylight.mdsal.common.api.DataStoreUnavailableException) NoShardLeaderException(org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException) TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) NoShardLeaderException(org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException) ShardLeaderNotRespondingException(org.opendaylight.controller.cluster.datastore.exceptions.ShardLeaderNotRespondingException) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) List(java.util.List) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 2 with ShardLeaderNotRespondingException

use of org.opendaylight.controller.cluster.datastore.exceptions.ShardLeaderNotRespondingException in project controller by opendaylight.

the class RemoteTransactionContextSupport method createTransactionContext.

private void createTransactionContext(final Throwable failure, final Object response) {
    // Create the TransactionContext from the response or failure. Store the new
    // TransactionContext locally until we've completed invoking the
    // TransactionOperations. This avoids thread timing issues which could cause
    // out-of-order TransactionOperations. Eg, on a modification operation, if the
    // TransactionContext is non-null, then we directly call the TransactionContext.
    // However, at the same time, the code may be executing the cached
    // TransactionOperations. So to avoid thus timing, we don't publish the
    // TransactionContext until after we've executed all cached TransactionOperations.
    TransactionContext localTransactionContext;
    if (failure != null) {
        LOG.debug("Tx {} Creating NoOpTransaction because of error", getIdentifier(), failure);
        Throwable resultingEx = failure;
        if (failure instanceof AskTimeoutException) {
            resultingEx = new ShardLeaderNotRespondingException(String.format("Could not create a %s transaction on shard %s. The shard leader isn't responding.", parent.getType(), shardName), failure);
        } else if (!(failure instanceof NoShardLeaderException)) {
            resultingEx = new Exception(String.format("Error creating %s transaction on shard %s", parent.getType(), shardName), failure);
        }
        localTransactionContext = new NoOpTransactionContext(resultingEx, getIdentifier());
    } else if (CreateTransactionReply.isSerializedType(response)) {
        localTransactionContext = createValidTransactionContext(CreateTransactionReply.fromSerializable(response));
    } else {
        IllegalArgumentException exception = new IllegalArgumentException(String.format("Invalid reply type %s for CreateTransaction", response.getClass()));
        localTransactionContext = new NoOpTransactionContext(exception, getIdentifier());
    }
    transactionContextWrapper.executePriorTransactionOperations(localTransactionContext);
}
Also used : ShardLeaderNotRespondingException(org.opendaylight.controller.cluster.datastore.exceptions.ShardLeaderNotRespondingException) AskTimeoutException(akka.pattern.AskTimeoutException) ShardLeaderNotRespondingException(org.opendaylight.controller.cluster.datastore.exceptions.ShardLeaderNotRespondingException) NoShardLeaderException(org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException) AskTimeoutException(akka.pattern.AskTimeoutException) NoShardLeaderException(org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException)

Example 3 with ShardLeaderNotRespondingException

use of org.opendaylight.controller.cluster.datastore.exceptions.ShardLeaderNotRespondingException in project controller by opendaylight.

the class DistributedDataStoreRemotingIntegrationTest method testTransactionWithShardLeaderNotResponding.

@Test
public void testTransactionWithShardLeaderNotResponding() throws Exception {
    followerDatastoreContextBuilder.frontendRequestTimeoutInSeconds(2);
    followerDatastoreContextBuilder.shardElectionTimeoutFactor(50);
    initDatastoresWithCars("testTransactionWithShardLeaderNotResponding");
    // Do an initial read to get the primary shard info cached.
    final DOMStoreReadTransaction readTx = followerDistributedDataStore.newReadOnlyTransaction();
    readTx.read(CarsModel.BASE_PATH).checkedGet(5, TimeUnit.SECONDS);
    // Shutdown the leader and try to create a new tx.
    TestKit.shutdownActorSystem(leaderSystem, true);
    followerDatastoreContextBuilder.operationTimeoutInMillis(50).shardElectionTimeoutFactor(1);
    sendDatastoreContextUpdate(followerDistributedDataStore, followerDatastoreContextBuilder);
    final DOMStoreReadWriteTransaction rwTx = followerDistributedDataStore.newReadWriteTransaction();
    rwTx.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
    try {
        followerTestKit.doCommit(rwTx.ready());
        fail("Exception expected");
    } catch (final ExecutionException e) {
        final String msg = "Unexpected exception: " + Throwables.getStackTraceAsString(e.getCause());
        if (DistributedDataStore.class.equals(testParameter)) {
            assertTrue(msg, Throwables.getRootCause(e) instanceof NoShardLeaderException || e.getCause() instanceof ShardLeaderNotRespondingException);
        } else {
            assertTrue(msg, Throwables.getRootCause(e) instanceof RequestTimeoutException);
        }
    }
}
Also used : RequestTimeoutException(org.opendaylight.controller.cluster.access.client.RequestTimeoutException) ShardLeaderNotRespondingException(org.opendaylight.controller.cluster.datastore.exceptions.ShardLeaderNotRespondingException) DOMStoreReadTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction) DOMStoreReadWriteTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction) AddressFromURIString(akka.actor.AddressFromURIString) ExecutionException(java.util.concurrent.ExecutionException) NoShardLeaderException(org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException) Test(org.junit.Test)

Aggregations

NoShardLeaderException (org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException)3 ShardLeaderNotRespondingException (org.opendaylight.controller.cluster.datastore.exceptions.ShardLeaderNotRespondingException)3 AddressFromURIString (akka.actor.AddressFromURIString)1 AskTimeoutException (akka.pattern.AskTimeoutException)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 List (java.util.List)1 ExecutionException (java.util.concurrent.ExecutionException)1 Test (org.junit.Test)1 RequestTimeoutException (org.opendaylight.controller.cluster.access.client.RequestTimeoutException)1 DataStoreUnavailableException (org.opendaylight.mdsal.common.api.DataStoreUnavailableException)1 TransactionCommitFailedException (org.opendaylight.mdsal.common.api.TransactionCommitFailedException)1 DOMStoreReadTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction)1 DOMStoreReadWriteTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction)1 DOMStoreThreePhaseCommitCohort (org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort)1