2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.mdsal.dom.broker;
11 import org.opendaylight.mdsal.dom.spi.store.DOMStore;
12 import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
14 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
15 import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
16 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
17 import com.google.common.base.Preconditions;
18 import com.google.common.util.concurrent.CheckedFuture;
19 import com.google.common.util.concurrent.Futures;
20 import com.google.common.util.concurrent.ListenableFuture;
21 import com.google.common.util.concurrent.ListeningExecutorService;
22 import java.util.Collection;
24 import java.util.concurrent.RejectedExecutionException;
25 import org.opendaylight.yangtools.util.DurationStatisticsTracker;
26 import org.opendaylight.yangtools.util.concurrent.MappingCheckedFuture;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
31 * Implementation of blocking three phase commit coordinator, which which
32 * supports coordination on multiple {@link DOMStoreThreePhaseCommitCohort}.
34 * This implementation does not support cancellation of commit,
36 * In order to advance to next phase of three phase commit all subtasks of
37 * previous step must be finish.
39 * This executor does not have an upper bound on subtask timeout.
41 public class SerializedDOMDataBroker extends AbstractDOMDataBroker {
42 private static final Logger LOG = LoggerFactory.getLogger(SerializedDOMDataBroker.class);
43 private final DurationStatisticsTracker commitStatsTracker = DurationStatisticsTracker.createConcurrent();
44 private final ListeningExecutorService executor;
48 * Construct DOMDataCommitCoordinator which uses supplied executor to
49 * process commit coordinations.
53 public SerializedDOMDataBroker(final Map<LogicalDatastoreType, DOMStore> datastores, final ListeningExecutorService executor) {
55 this.executor = Preconditions.checkNotNull(executor, "executor must not be null.");
58 public DurationStatisticsTracker getCommitStatsTracker() {
59 return commitStatsTracker;
63 protected CheckedFuture<Void,TransactionCommitFailedException> submit(final DOMDataTreeWriteTransaction transaction,
64 final Collection<DOMStoreThreePhaseCommitCohort> cohorts) {
65 Preconditions.checkArgument(transaction != null, "Transaction must not be null.");
66 Preconditions.checkArgument(cohorts != null, "Cohorts must not be null.");
67 LOG.debug("Tx: {} is submitted for execution.", transaction.getIdentifier());
69 ListenableFuture<Void> commitFuture = null;
71 commitFuture = executor.submit(new CommitCoordinationTask(transaction, cohorts,
73 } catch(RejectedExecutionException e) {
74 LOG.error("The commit executor's queue is full - submit task was rejected. \n" +
76 return Futures.immediateFailedCheckedFuture(
77 new TransactionCommitFailedException(
78 "Could not submit the commit task - the commit queue capacity has been exceeded.", e));
81 return MappingCheckedFuture.create(commitFuture,
82 TransactionCommitFailedExceptionMapper.COMMIT_ERROR_MAPPER);