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