BUG-8372: fix abort message confusion
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / databroker / actors / dds / RemoteProxyTransaction.java
index 1429ec5a7896734e6cf624c6663b1748e5209b78..d14b7bda666790f7268875c4dead378d77e70b31 100644 (file)
@@ -29,6 +29,7 @@ import org.opendaylight.controller.cluster.access.commands.TransactionDoCommitRe
 import org.opendaylight.controller.cluster.access.commands.TransactionMerge;
 import org.opendaylight.controller.cluster.access.commands.TransactionModification;
 import org.opendaylight.controller.cluster.access.commands.TransactionPreCommitRequest;
+import org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest;
 import org.opendaylight.controller.cluster.access.commands.TransactionRequest;
 import org.opendaylight.controller.cluster.access.commands.TransactionSuccess;
 import org.opendaylight.controller.cluster.access.commands.TransactionWrite;
@@ -63,6 +64,7 @@ final class RemoteProxyTransaction extends AbstractProxyTransaction {
     private static final int REQUEST_MAX_MODIFICATIONS = 1000;
 
     private final ModifyTransactionRequestBuilder builder;
+    private final boolean sendReadyOnSeal;
     private final boolean snapshotOnly;
 
     private boolean builderBusy;
@@ -70,9 +72,10 @@ final class RemoteProxyTransaction extends AbstractProxyTransaction {
     private volatile Exception operationFailure;
 
     RemoteProxyTransaction(final ProxyHistory parent, final TransactionIdentifier identifier,
-            final boolean snapshotOnly) {
+            final boolean snapshotOnly, final boolean sendReadyOnSeal) {
         super(parent);
         this.snapshotOnly = snapshotOnly;
+        this.sendReadyOnSeal = sendReadyOnSeal;
         builder = new ModifyTransactionRequestBuilder(identifier, localActor());
     }
 
@@ -131,12 +134,12 @@ final class RemoteProxyTransaction extends AbstractProxyTransaction {
 
     @Override
     void doAbort() {
-        ensureInitializedBuider();
+        ensureInitializedBuilder();
         builder.setAbort();
         flushBuilder();
     }
 
-    private void ensureInitializedBuider() {
+    private void ensureInitializedBuilder() {
         if (!builderBusy) {
             builder.setSequence(nextSequence());
             builderBusy = true;
@@ -186,7 +189,7 @@ final class RemoteProxyTransaction extends AbstractProxyTransaction {
 
     private void appendModification(final TransactionModification modification) {
         if (operationFailure == null) {
-            ensureInitializedBuider();
+            ensureInitializedBuilder();
 
             builder.addModification(modification);
             if (builder.size() >= REQUEST_MAX_MODIFICATIONS) {
@@ -255,7 +258,7 @@ final class RemoteProxyTransaction extends AbstractProxyTransaction {
 
     @Override
     ModifyTransactionRequest commitRequest(final boolean coordinated) {
-        ensureInitializedBuider();
+        ensureInitializedBuilder();
         builder.setCommit(coordinated);
 
         final ModifyTransactionRequest ret = builder.build();
@@ -265,7 +268,11 @@ final class RemoteProxyTransaction extends AbstractProxyTransaction {
 
     @Override
     void doSeal() {
-        // No-op
+        if (sendReadyOnSeal) {
+            ensureInitializedBuilder();
+            builder.setReady();
+            flushBuilder();
+        }
     }
 
     @Override
@@ -291,11 +298,15 @@ final class RemoteProxyTransaction extends AbstractProxyTransaction {
 
             final java.util.Optional<PersistenceProtocol> maybeProto = req.getPersistenceProtocol();
             if (maybeProto.isPresent()) {
-                seal();
+                ensureSealed();
 
                 switch (maybeProto.get()) {
                     case ABORT:
-                        sendAbort(callback);
+                        ensureInitializedBuilder();
+                        builder.setAbort();
+                        final ModifyTransactionRequest newReq = builder.build();
+                        builderBusy = false;
+                        sendRequest(newReq, callback);
                         break;
                     case SIMPLE:
                         sendRequest(commitRequest(false), callback);
@@ -303,6 +314,9 @@ final class RemoteProxyTransaction extends AbstractProxyTransaction {
                     case THREE_PHASE:
                         sendRequest(commitRequest(true), callback);
                         break;
+                    case READY:
+                        //no op
+                        break;
                     default:
                         throw new IllegalArgumentException("Unhandled protocol " + maybeProto.get());
                 }
@@ -324,6 +338,8 @@ final class RemoteProxyTransaction extends AbstractProxyTransaction {
         } else if (request instanceof TransactionAbortRequest) {
             ensureFlushedBuider();
             sendAbort(callback);
+        } else if (request instanceof TransactionPurgeRequest) {
+            purge();
         } else {
             throw new IllegalArgumentException("Unhandled request {}" + request);
         }