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
8 package org.opendaylight.controller.md.sal.dom.broker.impl;
10 import static com.google.common.base.Preconditions.checkArgument;
11 import static java.util.Objects.requireNonNull;
13 import com.google.common.base.Supplier;
14 import com.google.common.util.concurrent.Futures;
15 import com.google.common.util.concurrent.ListenableFuture;
16 import com.google.common.util.concurrent.ListeningExecutorService;
17 import java.util.Collection;
19 import java.util.concurrent.RejectedExecutionException;
20 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
21 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
22 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
23 import org.opendaylight.controller.sal.core.spi.data.DOMStore;
24 import org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort;
25 import org.opendaylight.yangtools.util.DurationStatisticsTracker;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
30 * Implementation of blocking three phase commit coordinator, which which
31 * supports coordination on multiple {@link DOMStoreThreePhaseCommitCohort}.
34 * This implementation does not support cancellation of commit,
37 * In order to advance to next phase of three phase commit all subtasks of
38 * previous step must be finish.
41 * This executor does not have an upper bound on subtask timeout.
44 public class SerializedDOMDataBroker extends AbstractDOMDataBroker {
45 private static final Logger LOG = LoggerFactory.getLogger(SerializedDOMDataBroker.class);
46 private final DurationStatisticsTracker commitStatsTracker = DurationStatisticsTracker.createConcurrent();
47 private final ListeningExecutorService executor;
50 * Construct DOMDataCommitCoordinator which uses supplied executor to
51 * process commit coordinations.
53 * @param datastores data stores
54 * @param executor executor service
56 public SerializedDOMDataBroker(final Map<LogicalDatastoreType, DOMStore> datastores,
57 final ListeningExecutorService executor) {
59 this.executor = requireNonNull(executor, "executor must not be null.");
62 public DurationStatisticsTracker getCommitStatsTracker() {
63 return commitStatsTracker;
67 protected <T> ListenableFuture<T> commit(final DOMDataWriteTransaction transaction,
68 final Collection<DOMStoreThreePhaseCommitCohort> cohorts, final Supplier<T> futureValueSupplier) {
69 checkArgument(transaction != null, "Transaction must not be null.");
70 checkArgument(cohorts != null, "Cohorts must not be null.");
71 LOG.debug("Tx: {} is submitted for execution.", transaction.getIdentifier());
73 ListenableFuture<T> commitFuture;
75 commitFuture = executor.submit(new CommitCoordinationTask<>(transaction, cohorts, commitStatsTracker,
76 futureValueSupplier));
77 } catch (RejectedExecutionException e) {
78 LOG.error("The commit executor {} queue is full - submit task was rejected. \n", executor, e);
79 commitFuture = Futures.immediateFailedFuture(new TransactionCommitFailedException(
80 "Could not submit the commit task - the commit queue capacity has been exceeded.", e));