X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatabroker%2FConcurrentDOMDataBroker.java;h=b80a6050fc958da681cad6cef79bbc557b22c822;hp=b978147bcb77898dc6d7a4412846fa129d513bae;hb=1c717bbf117d3486196a0fdd73ac650721f9c557;hpb=057b787289f7b909d7013c22ac73a1c91c860af8 diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/ConcurrentDOMDataBroker.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/ConcurrentDOMDataBroker.java index b978147bcb..b80a6050fc 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/ConcurrentDOMDataBroker.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/ConcurrentDOMDataBroker.java @@ -7,6 +7,10 @@ */ package org.opendaylight.controller.cluster.databroker; +import static org.opendaylight.controller.md.sal.dom.broker.impl.TransactionCommitFailedExceptionMapper.CAN_COMMIT_ERROR_MAPPER; +import static org.opendaylight.controller.md.sal.dom.broker.impl.TransactionCommitFailedExceptionMapper.COMMIT_ERROR_MAPPER; +import static org.opendaylight.controller.md.sal.dom.broker.impl.TransactionCommitFailedExceptionMapper.PRE_COMMIT_MAPPER; + import com.google.common.annotations.Beta; import com.google.common.base.Preconditions; import com.google.common.util.concurrent.AbstractFuture; @@ -30,12 +34,8 @@ 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.mdsal.common.api.MappingCheckedFuture; import org.opendaylight.yangtools.util.DurationStatisticsTracker; -import org.opendaylight.yangtools.util.concurrent.MappingCheckedFuture; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -47,7 +47,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"; @@ -61,12 +61,12 @@ public class ConcurrentDOMDataBroker extends AbstractDOMBroker implements DOMDat private final Executor clientFutureCallbackExecutor; public ConcurrentDOMDataBroker(final Map datastores, - Executor listenableFutureExecutor) { + final Executor listenableFutureExecutor) { this(datastores, listenableFutureExecutor, DurationStatisticsTracker.createConcurrent()); } public ConcurrentDOMDataBroker(final Map datastores, - Executor listenableFutureExecutor, DurationStatisticsTracker commitStatsTracker) { + final Executor listenableFutureExecutor, final DurationStatisticsTracker commitStatsTracker) { super(datastores); this.clientFutureCallbackExecutor = Preconditions.checkNotNull(listenableFutureExecutor); this.commitStatsTracker = Preconditions.checkNotNull(commitStatsTracker); @@ -77,8 +77,8 @@ public class ConcurrentDOMDataBroker extends AbstractDOMBroker implements DOMDat } @Override - protected CheckedFuture submit(DOMDataWriteTransaction transaction, - Collection cohorts) { + protected CheckedFuture submit(final DOMDataWriteTransaction transaction, + final Collection cohorts) { Preconditions.checkArgument(transaction != null, "Transaction must not be null."); Preconditions.checkArgument(cohorts != null, "Cohorts must not be null."); @@ -93,8 +93,7 @@ public class ConcurrentDOMDataBroker extends AbstractDOMBroker implements DOMDat doCanCommit(clientSubmitFuture, transaction, cohorts); - return MappingCheckedFuture.create(clientSubmitFuture, - TransactionCommitFailedExceptionMapper.COMMIT_ERROR_MAPPER); + return MappingCheckedFuture.create(clientSubmitFuture, COMMIT_ERROR_MAPPER); } private void doCanCommit(final AsyncNotifyingSettableFuture clientSubmitFuture, @@ -108,27 +107,21 @@ public class ConcurrentDOMDataBroker extends AbstractDOMBroker implements DOMDat // Not using Futures.allAsList here to avoid its internal overhead. FutureCallback futureCallback = new FutureCallback() { @Override - public void onSuccess(Boolean result) { + public void onSuccess(final Boolean result) { if (result == null || !result) { - handleException(clientSubmitFuture, transaction, cohorts, - CAN_COMMIT, TransactionCommitFailedExceptionMapper.CAN_COMMIT_ERROR_MAPPER, - new TransactionCommitFailedException( - "Can Commit failed, no detailed cause available.")); + handleException(clientSubmitFuture, transaction, cohorts, CAN_COMMIT, CAN_COMMIT_ERROR_MAPPER, + new TransactionCommitFailedException("Can Commit failed, no detailed cause available.")); + } else if (!cohortIterator.hasNext()) { + // All cohorts completed successfully - we can move on to the preCommit phase + doPreCommit(startTime, clientSubmitFuture, transaction, cohorts); } else { - if (!cohortIterator.hasNext()) { - // All cohorts completed successfully - we can move on to the preCommit phase - doPreCommit(startTime, clientSubmitFuture, transaction, cohorts); - } else { - ListenableFuture canCommitFuture = cohortIterator.next().canCommit(); - Futures.addCallback(canCommitFuture, this, MoreExecutors.directExecutor()); - } + Futures.addCallback(cohortIterator.next().canCommit(), this, MoreExecutors.directExecutor()); } } @Override - public void onFailure(Throwable failure) { - handleException(clientSubmitFuture, transaction, cohorts, CAN_COMMIT, - TransactionCommitFailedExceptionMapper.CAN_COMMIT_ERROR_MAPPER, failure); + public void onFailure(final Throwable failure) { + handleException(clientSubmitFuture, transaction, cohorts, CAN_COMMIT, CAN_COMMIT_ERROR_MAPPER, failure); } }; @@ -145,7 +138,7 @@ public class ConcurrentDOMDataBroker extends AbstractDOMBroker implements DOMDat // Not using Futures.allAsList here to avoid its internal overhead. FutureCallback futureCallback = new FutureCallback() { @Override - public void onSuccess(Void notUsed) { + public void onSuccess(final Void notUsed) { if (!cohortIterator.hasNext()) { // All cohorts completed successfully - we can move on to the commit phase doCommit(startTime, clientSubmitFuture, transaction, cohorts); @@ -156,9 +149,8 @@ public class ConcurrentDOMDataBroker extends AbstractDOMBroker implements DOMDat } @Override - public void onFailure(Throwable failure) { - handleException(clientSubmitFuture, transaction, cohorts, PRE_COMMIT, - TransactionCommitFailedExceptionMapper.PRE_COMMIT_MAPPER, failure); + public void onFailure(final Throwable failure) { + handleException(clientSubmitFuture, transaction, cohorts, PRE_COMMIT, PRE_COMMIT_MAPPER, failure); } }; @@ -175,7 +167,7 @@ public class ConcurrentDOMDataBroker extends AbstractDOMBroker implements DOMDat // Not using Futures.allAsList here to avoid its internal overhead. FutureCallback futureCallback = new FutureCallback() { @Override - public void onSuccess(Void notUsed) { + public void onSuccess(final Void notUsed) { if (!cohortIterator.hasNext()) { // All cohorts completed successfully - we're done. commitStatsTracker.addDuration(System.nanoTime() - startTime); @@ -188,9 +180,8 @@ public class ConcurrentDOMDataBroker extends AbstractDOMBroker implements DOMDat } @Override - public void onFailure(Throwable throwable) { - handleException(clientSubmitFuture, transaction, cohorts, COMMIT, - TransactionCommitFailedExceptionMapper.COMMIT_ERROR_MAPPER, throwable); + public void onFailure(final Throwable throwable) { + handleException(clientSubmitFuture, transaction, cohorts, COMMIT, COMMIT_ERROR_MAPPER, throwable); } }; @@ -213,20 +204,10 @@ public class ConcurrentDOMDataBroker extends AbstractDOMBroker implements DOMDat return; } - 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); + // Use debug instead of warn level here because this exception gets propagate back to the caller via the Future + LOG.debug("Tx: {} Error during phase {}, starting Abort", transaction.getIdentifier(), phase, throwable); // Transaction failed - tell all cohorts to abort. - @SuppressWarnings("unchecked") ListenableFuture[] canCommitFutures = new ListenableFuture[cohorts.size()]; int index = 0; @@ -234,21 +215,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> combinedFuture = Futures.allAsList(canCommitFutures); Futures.addCallback(combinedFuture, new FutureCallback>() { @Override - public void onSuccess(List notUsed) { + public void onSuccess(final List notUsed) { // Propagate the original exception to the client. - clientSubmitFuture.setException(clientException); + LOG.debug("Tx: {} aborted successfully", transaction.getIdentifier()); } @Override - public void onFailure(Throwable failure) { + public void onFailure(final 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()); } @@ -272,7 +260,7 @@ public class ConcurrentDOMDataBroker extends AbstractDOMBroker implements DOMDat private final Executor listenerExecutor; - AsyncNotifyingSettableFuture(Executor listenerExecutor) { + AsyncNotifyingSettableFuture(final Executor listenerExecutor) { this.listenerExecutor = Preconditions.checkNotNull(listenerExecutor); } @@ -300,7 +288,7 @@ public class ConcurrentDOMDataBroker extends AbstractDOMBroker implements DOMDat } @Override - protected boolean setException(Throwable throwable) { + protected boolean setException(final Throwable throwable) { ON_TASK_COMPLETION_THREAD_TL.set(Boolean.TRUE); try { return super.setException(throwable); @@ -335,27 +323,6 @@ public class ConcurrentDOMDataBroker extends AbstractDOMBroker implements DOMDat } } - @Override - public DOMDataTreeCommitCohortRegistration 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";