use of org.opendaylight.controller.md.sal.common.api.data.OptimisticLockFailedException in project genius by opendaylight.
the class MDSALManager method removeFlowInternal.
public CheckedFuture<Void, TransactionCommitFailedException> removeFlowInternal(FlowEntity flowEntity) {
WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
deleteFlowEntityInternal(flowEntity, tx);
CheckedFuture<Void, TransactionCommitFailedException> submitFuture = tx.submit();
Futures.addCallback(submitFuture, new FutureCallback<Void>() {
@Override
public void onSuccess(final Void result) {
// Committed successfully
LOG.debug("Delete Flow -- Committedsuccessfully ");
}
@Override
public void onFailure(final Throwable throwable) {
// Transaction failed
if (throwable instanceof OptimisticLockFailedException) {
// Failed because of concurrent transaction modifying same
// data
LOG.error("Delete Flow -- Failed because of concurrent transaction modifying same data");
} else {
// Some other type of TransactionCommitFailedException
LOG.error("Delete Flow -- Some other type of TransactionCommitFailedException", throwable);
}
}
});
return submitFuture;
}
use of org.opendaylight.controller.md.sal.common.api.data.OptimisticLockFailedException in project genius by opendaylight.
the class DataBrokerFailuresTest method testFailTwoReadWriteTransactionSubmit.
@Test
public void testFailTwoReadWriteTransactionSubmit() throws TransactionCommitFailedException {
dbFailures.failSubmits(2, new OptimisticLockFailedException("bada boum bam!"));
checkSubmitFails();
// Now make sure that it still fails again a 2nd time, and not just once:
checkSubmitFails();
// But now it should pass.. because we specified howManyTimes = 2 above
dataBroker.newReadWriteTransaction().submit().checkedGet();
dataBroker.newWriteOnlyTransaction().submit().checkedGet();
dataBroker.newReadWriteTransaction().submit().checkedGet();
}
use of org.opendaylight.controller.md.sal.common.api.data.OptimisticLockFailedException in project controller by opendaylight.
the class OpendaylightToaster method checkStatusAndMakeToast.
private void checkStatusAndMakeToast(final MakeToastInput input, final SettableFuture<RpcResult<Void>> futureResult, final int tries) {
// Read the ToasterStatus and, if currently Up, try to write the status to Down.
// If that succeeds, then we essentially have an exclusive lock and can proceed
// to make toast.
final ReadWriteTransaction tx = dataBroker.newReadWriteTransaction();
ListenableFuture<Optional<Toaster>> readFuture = tx.read(OPERATIONAL, TOASTER_IID);
final ListenableFuture<Void> commitFuture = Futures.transformAsync(readFuture, toasterData -> {
ToasterStatus toasterStatus = ToasterStatus.Up;
if (toasterData.isPresent()) {
toasterStatus = toasterData.get().getToasterStatus();
}
LOG.debug("Read toaster status: {}", toasterStatus);
if (toasterStatus == ToasterStatus.Up) {
if (outOfBread()) {
LOG.debug("Toaster is out of bread");
return Futures.immediateFailedCheckedFuture(new TransactionCommitFailedException("", makeToasterOutOfBreadError()));
}
LOG.debug("Setting Toaster status to Down");
// We're not currently making toast - try to update the status to Down
// to indicate we're going to make toast. This acts as a lock to prevent
// concurrent toasting.
tx.put(OPERATIONAL, TOASTER_IID, buildToaster(ToasterStatus.Down));
return tx.submit();
}
LOG.debug("Oops - already making toast!");
// TransactionStatus in the RpcResult as an error condition.
return Futures.immediateFailedCheckedFuture(new TransactionCommitFailedException("", makeToasterInUseError()));
});
Futures.addCallback(commitFuture, new FutureCallback<Void>() {
@Override
public void onSuccess(final Void result) {
// OK to make toast
currentMakeToastTask.set(executor.submit(new MakeToastTask(input, futureResult)));
}
@Override
public void onFailure(final Throwable ex) {
if (ex instanceof OptimisticLockFailedException) {
if (tries - 1 > 0) {
LOG.debug("Got OptimisticLockFailedException - trying again");
checkStatusAndMakeToast(input, futureResult, tries - 1);
} else {
futureResult.set(RpcResultBuilder.<Void>failed().withError(ErrorType.APPLICATION, ex.getMessage()).build());
}
} else if (ex instanceof TransactionCommitFailedException) {
LOG.debug("Failed to commit Toaster status", ex);
// Probably already making toast.
futureResult.set(RpcResultBuilder.<Void>failed().withRpcErrors(((TransactionCommitFailedException) ex).getErrorList()).build());
} else {
LOG.debug("Unexpected error committing Toaster status", ex);
futureResult.set(RpcResultBuilder.<Void>failed().withError(ErrorType.APPLICATION, "Unexpected error committing Toaster status", ex).build());
}
}
});
}
use of org.opendaylight.controller.md.sal.common.api.data.OptimisticLockFailedException in project genius by opendaylight.
the class RetryingManagedNewTransactionRunnerTest method testCallWithNewWriteOnlyTransactionOptimisticLockFailedException.
@Override
public void testCallWithNewWriteOnlyTransactionOptimisticLockFailedException() throws Exception {
// contrary to the super() test implementation for (just) ManagedNewTransactionRunnerImpl, in the parent class
// here we expect the x2 OptimisticLockFailedException to be retried, and then eventually succeed:
testableDataBroker.failSubmits(2, new OptimisticLockFailedException("bada boum bam!"));
managedNewTransactionRunner.callWithNewWriteOnlyTransactionAndSubmit(writeTx -> writeTx.put(LogicalDatastoreType.OPERATIONAL, TEST_PATH, newTestDataObject())).get();
singleTransactionDataBroker.syncRead(OPERATIONAL, TEST_PATH);
}
use of org.opendaylight.controller.md.sal.common.api.data.OptimisticLockFailedException in project genius by opendaylight.
the class MDSALManager method removeGroupInternal.
protected CheckedFuture<Void, TransactionCommitFailedException> removeGroupInternal(BigInteger dpnId, long groupId) {
WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
removeGroupInternal(dpnId, groupId, tx);
CheckedFuture<Void, TransactionCommitFailedException> submitFuture = tx.submit();
Futures.addCallback(submitFuture, new FutureCallback<Void>() {
@Override
public void onSuccess(final Void result) {
LOG.debug("Install Group -- Committedsuccessfully ");
}
@Override
public void onFailure(final Throwable throwable) {
if (throwable instanceof OptimisticLockFailedException) {
LOG.error("Install Group -- Failed because of concurrent transaction modifying same data");
} else {
LOG.error("Install Group -- Some other type of TransactionCommitFailedException", throwable);
}
}
});
return submitFuture;
}
Aggregations