BUG-8494: propagate submit failure immediately
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / databroker / ConcurrentDOMDataBroker.java
index b978147bcb77898dc6d7a4412846fa129d513bae..71cd2dc7fe2df10fa9b7f3a6e4ea037ea419f217 100644 (file)
@@ -30,10 +30,6 @@ import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
 import org.opendaylight.controller.md.sal.dom.broker.impl.TransactionCommitFailedExceptionMapper;
 import org.opendaylight.controller.sal.core.spi.data.DOMStore;
 import org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort;
-import org.opendaylight.mdsal.dom.api.DOMDataTreeCommitCohort;
-import org.opendaylight.mdsal.dom.api.DOMDataTreeCommitCohortRegistration;
-import org.opendaylight.mdsal.dom.api.DOMDataTreeCommitCohortRegistry;
-import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
 import org.opendaylight.yangtools.util.DurationStatisticsTracker;
 import org.opendaylight.yangtools.util.concurrent.MappingCheckedFuture;
 import org.slf4j.Logger;
@@ -47,7 +43,7 @@ import org.slf4j.LoggerFactory;
  * @author Thomas Pantelis
  */
 @Beta
-public class ConcurrentDOMDataBroker extends AbstractDOMBroker implements DOMDataTreeCommitCohortRegistry {
+public class ConcurrentDOMDataBroker extends AbstractDOMBroker {
     private static final Logger LOG = LoggerFactory.getLogger(ConcurrentDOMDataBroker.class);
     private static final String CAN_COMMIT = "CAN_COMMIT";
     private static final String PRE_COMMIT = "PRE_COMMIT";
@@ -214,19 +210,8 @@ public class ConcurrentDOMDataBroker extends AbstractDOMBroker implements DOMDat
         }
 
         LOG.warn("Tx: {} Error during phase {}, starting Abort", transaction.getIdentifier(), phase, throwable);
-        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);
-        }
-
-        final TransactionCommitFailedException clientException = exMapper.apply(e);
 
         // Transaction failed - tell all cohorts to abort.
-
         @SuppressWarnings("unchecked")
         ListenableFuture<Void>[] canCommitFutures = new ListenableFuture[cohorts.size()];
         int index = 0;
@@ -234,21 +219,28 @@ public class ConcurrentDOMDataBroker extends AbstractDOMBroker implements DOMDat
             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(List<Void> notUsed) {
                 // Propagate the original exception to the client.
-                clientSubmitFuture.setException(clientException);
+                LOG.debug("Tx: {} aborted successfully", transaction.getIdentifier());
             }
 
             @Override
             public void onFailure(Throwable failure) {
                 LOG.error("Tx: {} Error during Abort.", transaction.getIdentifier(), failure);
-
-                // Propagate the original exception as that is what caused the Tx to fail and is
-                // what's interesting to the client.
-                clientSubmitFuture.setException(clientException);
             }
         }, MoreExecutors.directExecutor());
     }
@@ -335,27 +327,6 @@ public class ConcurrentDOMDataBroker extends AbstractDOMBroker implements DOMDat
         }
     }
 
-    @Override
-    public <T extends DOMDataTreeCommitCohort> DOMDataTreeCommitCohortRegistration<T> registerCommitCohort(
-            DOMDataTreeIdentifier path, T cohort) {
-        DOMStore store = getTxFactories().get(toLegacy(path.getDatastoreType()));
-        if (store instanceof DOMDataTreeCommitCohortRegistry) {
-            return ((DOMDataTreeCommitCohortRegistry) store).registerCommitCohort(path, cohort);
-        }
-        throw new UnsupportedOperationException("Commit cohort is not supported for " + path);
-    }
-
-    private static LogicalDatastoreType toLegacy(org.opendaylight.mdsal.common.api.LogicalDatastoreType datastoreType) {
-        switch (datastoreType) {
-            case CONFIGURATION:
-                return LogicalDatastoreType.CONFIGURATION;
-            case OPERATIONAL:
-                return LogicalDatastoreType.OPERATIONAL;
-            default:
-                throw new IllegalArgumentException("Unsupported data store type: " + datastoreType);
-        }
-    }
-
     @Override
     public String toString() {
         return "Clustered ConcurrentDOMDataBroker";