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());
}
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);
}
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);
}
}
}
Aggregations