Bug 3195: Cleanup on error paths and error handling
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / LocalTransactionContext.java
index e62d15b..276523e 100644 (file)
@@ -29,10 +29,14 @@ import scala.concurrent.Future;
  */
 abstract class LocalTransactionContext extends AbstractTransactionContext {
     private final DOMStoreTransaction txDelegate;
+    private final LocalTransactionReadySupport readySupport;
+    private Exception operationError;
 
-    LocalTransactionContext(DOMStoreTransaction txDelegate, TransactionIdentifier identifier) {
+    LocalTransactionContext(DOMStoreTransaction txDelegate, TransactionIdentifier identifier,
+            LocalTransactionReadySupport readySupport) {
         super(identifier);
         this.txDelegate = Preconditions.checkNotNull(txDelegate);
+        this.readySupport = readySupport;
     }
 
     protected abstract DOMStoreWriteTransaction getWriteDelegate();
@@ -42,19 +46,38 @@ abstract class LocalTransactionContext extends AbstractTransactionContext {
     @Override
     public void writeData(YangInstanceIdentifier path, NormalizedNode<?, ?> data) {
         incrementModificationCount();
-        getWriteDelegate().write(path, data);
+        if(operationError == null) {
+            try {
+                getWriteDelegate().write(path, data);
+            } catch (Exception e) {
+                operationError = e;
+            }
+        }
+
     }
 
     @Override
     public void mergeData(YangInstanceIdentifier path, NormalizedNode<?, ?> data) {
         incrementModificationCount();
-        getWriteDelegate().merge(path, data);
+        if(operationError == null) {
+            try {
+                getWriteDelegate().merge(path, data);
+            } catch (Exception e) {
+                operationError = e;
+            }
+        }
     }
 
     @Override
     public void deleteData(YangInstanceIdentifier path) {
         incrementModificationCount();
-        getWriteDelegate().delete(path);
+        if(operationError == null) {
+            try {
+                getWriteDelegate().delete(path);
+            } catch (Exception e) {
+                operationError = e;
+            }
+        }
     }
 
     @Override
@@ -89,7 +112,9 @@ abstract class LocalTransactionContext extends AbstractTransactionContext {
 
     private LocalThreePhaseCommitCohort ready() {
         logModificationCount();
-        return (LocalThreePhaseCommitCohort) getWriteDelegate().ready();
+        LocalThreePhaseCommitCohort cohort = readySupport.onTransactionReady(getWriteDelegate());
+        cohort.setOperationError(operationError);
+        return cohort;
     }
 
     @Override

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.