BUG-5280: TransactionAbortRequest is used for user aborts 30/48830/2
authorRobert Varga <rovarga@cisco.com>
Wed, 30 Nov 2016 14:24:51 +0000 (15:24 +0100)
committerRobert Varga <rovarga@cisco.com>
Wed, 30 Nov 2016 15:22:01 +0000 (16:22 +0100)
TransactionAbortRequest is used to indicate both user abort
and 3PC abort, whereas current backend code assumed it is
only used for 3PC -- hence it required a cohort to be present.

Teach handleTransactionAbort to use a direct transaction abort
if it receives a request without having a cohort present.

Change-Id: Ia469d907edb575d5f1ee5e4f630fe1a19204032f
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/FrontendTransaction.java

index 1b15c72..a825a4d 100644 (file)
@@ -170,8 +170,7 @@ final class FrontendTransaction {
             handleTransactionDoCommit((TransactionDoCommitRequest) request, envelope, now);
             return null;
         } else if (request instanceof TransactionAbortRequest) {
-            handleTransactionAbort((TransactionAbortRequest) request, envelope, now);
-            return null;
+            return handleTransactionAbort((TransactionAbortRequest) request, envelope, now);
         } else {
             throw new UnsupportedRequestException(request);
         }
@@ -239,8 +238,13 @@ final class FrontendTransaction {
         });
     }
 
-    private void handleTransactionAbort(final TransactionAbortRequest request, final RequestEnvelope envelope,
-            final long now) throws RequestException {
+    private TransactionSuccess<?> handleTransactionAbort(final TransactionAbortRequest request,
+            final RequestEnvelope envelope, final long now) throws RequestException {
+        if (readyCohort == null) {
+            openTransaction.abort();
+            return new TransactionAbortSuccess(id, request.getSequence());
+        }
+
         readyCohort.abort(new FutureCallback<Void>() {
             @Override
             public void onSuccess(final Void result) {
@@ -256,6 +260,7 @@ final class FrontendTransaction {
                 recordAndSendFailure(envelope, now, new RuntimeRequestException("Abort failed", failure));
             }
         });
+        return null;
     }
 
     private void coordinatedCommit(final RequestEnvelope envelope, final long now) {