X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatabroker%2FConcurrentDOMDataBroker.java;h=1199fbf7bca4a4c5f60485690b4e82eb37ca062f;hb=02d2891da4b71fe01ea8027a88ac6ddd353c2bcd;hp=71cd2dc7fe2df10fa9b7f3a6e4ea037ea419f217;hpb=677caabe6a1144ab43dd231fcea7037a5cb4bb64;p=controller.git 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 71cd2dc7fe..1199fbf7bc 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,10 +7,14 @@ */ package org.opendaylight.controller.cluster.databroker; +import static org.opendaylight.mdsal.dom.broker.TransactionCommitFailedExceptionMapper.CAN_COMMIT_ERROR_MAPPER; +import static org.opendaylight.mdsal.dom.broker.TransactionCommitFailedExceptionMapper.COMMIT_ERROR_MAPPER; +import static org.opendaylight.mdsal.dom.broker.TransactionCommitFailedExceptionMapper.PRE_COMMIT_MAPPER; + import com.google.common.annotations.Beta; import com.google.common.base.Preconditions; import com.google.common.util.concurrent.AbstractFuture; -import com.google.common.util.concurrent.CheckedFuture; +import com.google.common.util.concurrent.FluentFuture; import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; @@ -23,15 +27,15 @@ import java.util.Map; import java.util.concurrent.Executor; import org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException; import org.opendaylight.controller.cluster.datastore.exceptions.ShardLeaderNotRespondingException; -import org.opendaylight.controller.md.sal.common.api.data.DataStoreUnavailableException; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; -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.common.api.CommitInfo; +import org.opendaylight.mdsal.common.api.DataStoreUnavailableException; +import org.opendaylight.mdsal.common.api.LogicalDatastoreType; +import org.opendaylight.mdsal.common.api.TransactionCommitFailedException; +import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction; +import org.opendaylight.mdsal.dom.broker.TransactionCommitFailedExceptionMapper; +import org.opendaylight.mdsal.dom.spi.store.DOMStore; +import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort; import org.opendaylight.yangtools.util.DurationStatisticsTracker; -import org.opendaylight.yangtools.util.concurrent.MappingCheckedFuture; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -57,12 +61,12 @@ public class ConcurrentDOMDataBroker extends AbstractDOMBroker { 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); @@ -73,15 +77,15 @@ public class ConcurrentDOMDataBroker extends AbstractDOMBroker { } @Override - protected CheckedFuture submit(DOMDataWriteTransaction transaction, - Collection cohorts) { + protected FluentFuture commit( + final DOMDataTreeWriteTransaction transaction, final Collection cohorts) { Preconditions.checkArgument(transaction != null, "Transaction must not be null."); Preconditions.checkArgument(cohorts != null, "Cohorts must not be null."); LOG.debug("Tx: {} is submitted for execution.", transaction.getIdentifier()); if (cohorts.isEmpty()) { - return Futures.immediateCheckedFuture(null); + return CommitInfo.emptyFluentFuture(); } final AsyncNotifyingSettableFuture clientSubmitFuture = @@ -89,12 +93,12 @@ public class ConcurrentDOMDataBroker extends AbstractDOMBroker { doCanCommit(clientSubmitFuture, transaction, cohorts); - return MappingCheckedFuture.create(clientSubmitFuture, - TransactionCommitFailedExceptionMapper.COMMIT_ERROR_MAPPER); + return FluentFuture.from(clientSubmitFuture).transform(ignored -> CommitInfo.empty(), + MoreExecutors.directExecutor()); } private void doCanCommit(final AsyncNotifyingSettableFuture clientSubmitFuture, - final DOMDataWriteTransaction transaction, + final DOMDataTreeWriteTransaction transaction, final Collection cohorts) { final long startTime = System.nanoTime(); @@ -104,27 +108,21 @@ public class ConcurrentDOMDataBroker extends AbstractDOMBroker { // 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); } }; @@ -133,7 +131,7 @@ public class ConcurrentDOMDataBroker extends AbstractDOMBroker { } private void doPreCommit(final long startTime, final AsyncNotifyingSettableFuture clientSubmitFuture, - final DOMDataWriteTransaction transaction, + final DOMDataTreeWriteTransaction transaction, final Collection cohorts) { final Iterator cohortIterator = cohorts.iterator(); @@ -141,7 +139,7 @@ public class ConcurrentDOMDataBroker extends AbstractDOMBroker { // 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); @@ -152,9 +150,8 @@ public class ConcurrentDOMDataBroker extends AbstractDOMBroker { } @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); } }; @@ -163,7 +160,7 @@ public class ConcurrentDOMDataBroker extends AbstractDOMBroker { } private void doCommit(final long startTime, final AsyncNotifyingSettableFuture clientSubmitFuture, - final DOMDataWriteTransaction transaction, + final DOMDataTreeWriteTransaction transaction, final Collection cohorts) { final Iterator cohortIterator = cohorts.iterator(); @@ -171,7 +168,7 @@ public class ConcurrentDOMDataBroker extends AbstractDOMBroker { // 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); @@ -184,9 +181,8 @@ public class ConcurrentDOMDataBroker extends AbstractDOMBroker { } @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); } }; @@ -199,7 +195,7 @@ public class ConcurrentDOMDataBroker extends AbstractDOMBroker { + "uncomfirmed cast but the generic type in TransactionCommitFailedExceptionMapper is " + "TransactionCommitFailedException and thus should be deemed as confirmed.") private static void handleException(final AsyncNotifyingSettableFuture clientSubmitFuture, - final DOMDataWriteTransaction transaction, + final DOMDataTreeWriteTransaction transaction, final Collection cohorts, final String phase, final TransactionCommitFailedExceptionMapper exMapper, final Throwable throwable) { @@ -209,7 +205,8 @@ public class ConcurrentDOMDataBroker extends AbstractDOMBroker { return; } - LOG.warn("Tx: {} Error during phase {}, starting Abort", transaction.getIdentifier(), phase, throwable); + // 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") @@ -233,13 +230,13 @@ public class ConcurrentDOMDataBroker extends AbstractDOMBroker { 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. 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); } }, MoreExecutors.directExecutor()); @@ -264,7 +261,7 @@ public class ConcurrentDOMDataBroker extends AbstractDOMBroker { private final Executor listenerExecutor; - AsyncNotifyingSettableFuture(Executor listenerExecutor) { + AsyncNotifyingSettableFuture(final Executor listenerExecutor) { this.listenerExecutor = Preconditions.checkNotNull(listenerExecutor); } @@ -292,7 +289,7 @@ public class ConcurrentDOMDataBroker extends AbstractDOMBroker { } @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);