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;
15 import java.util.concurrent.RejectedExecutionException;
16 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
17 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
18 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
19 import org.opendaylight.controller.sal.core.spi.data.DOMStore;
20 import org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort;
21 import org.opendaylight.yangtools.util.DurationStatisticsTracker;
22 import org.opendaylight.yangtools.util.concurrent.MappingCheckedFuture;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
27 * Implementation of blocking three phase commit coordinator, which which
28 * supports coordination on multiple {@link DOMStoreThreePhaseCommitCohort}.
30 * This implementation does not support cancellation of commit,
32 * In order to advance to next phase of three phase commit all subtasks of
33 * previous step must be finish.
35 * This executor does not have an upper bound on subtask timeout.
37 public class SerializedDOMDataBroker extends AbstractDOMDataBroker {
38 private static final Logger LOG = LoggerFactory.getLogger(SerializedDOMDataBroker.class);
39 private final DurationStatisticsTracker commitStatsTracker = DurationStatisticsTracker.createConcurrent();
40 private final ListeningExecutorService executor;
44 * Construct DOMDataCommitCoordinator which uses supplied executor to
45 * process commit coordinations.
49 public SerializedDOMDataBroker(final Map<LogicalDatastoreType, DOMStore> datastores, final ListeningExecutorService executor) {
51 this.executor = Preconditions.checkNotNull(executor, "executor must not be null.");
54 public DurationStatisticsTracker getCommitStatsTracker() {
55 return commitStatsTracker;
59 protected CheckedFuture<Void,TransactionCommitFailedException> submit(final DOMDataWriteTransaction transaction,
60 final Iterable<DOMStoreThreePhaseCommitCohort> cohorts) {
61 Preconditions.checkArgument(transaction != null, "Transaction must not be null.");
62 Preconditions.checkArgument(cohorts != null, "Cohorts must not be null.");
63 LOG.debug("Tx: {} is submitted for execution.", transaction.getIdentifier());
65 ListenableFuture<Void> commitFuture = null;
67 commitFuture = executor.submit(new CommitCoordinationTask(transaction, cohorts,
69 } catch(RejectedExecutionException e) {
70 LOG.error("The commit executor's queue is full - submit task was rejected. \n" +
72 return Futures.immediateFailedCheckedFuture(
73 new TransactionCommitFailedException(
74 "Could not submit the commit task - the commit queue capacity has been exceeded.", e));
77 return MappingCheckedFuture.create(commitFuture,
78 TransactionCommitFailedExceptionMapper.COMMIT_ERROR_MAPPER);