2 * Copyright (c) 2016 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.store.inmemory;
11 import static java.util.Objects.requireNonNull;
13 import com.google.common.annotations.Beta;
14 import com.google.common.util.concurrent.ListenableFuture;
15 import java.util.Collection;
16 import java.util.concurrent.Callable;
17 import java.util.concurrent.ExecutionException;
18 import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
19 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
20 import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
25 * Task that coordinates the Commit phase of the provided {@link DOMStoreThreePhaseCommitCohort}'s.
28 public class ShardCommitCoordinationTask implements Callable<Void> {
30 private static final Logger LOG = LoggerFactory.getLogger(ShardCommitCoordinationTask.class);
32 private final DOMDataTreeIdentifier rootShardPrefix;
33 private final Collection<DOMStoreThreePhaseCommitCohort> cohorts;
34 private InmemoryDOMDataTreeShardWriteTransaction transaction;
36 public ShardCommitCoordinationTask(final DOMDataTreeIdentifier rootShardPrefix,
37 final Collection<DOMStoreThreePhaseCommitCohort> cohorts,
38 final InmemoryDOMDataTreeShardWriteTransaction transaction) {
39 this.rootShardPrefix = requireNonNull(rootShardPrefix);
40 this.cohorts = requireNonNull(cohorts);
41 this.transaction = requireNonNull(transaction);
45 public Void call() throws TransactionCommitFailedException {
48 LOG.debug("Shard {}, commit started", rootShardPrefix);
50 transaction.transactionCommited(transaction);
53 } catch (final TransactionCommitFailedException e) {
54 LOG.warn("Shard: {} Submit Error during phase Commit, starting Abort", rootShardPrefix, e);
60 void commitBlocking() throws TransactionCommitFailedException {
61 for (final ListenableFuture<?> commit : commitAll()) {
64 } catch (InterruptedException | ExecutionException e) {
65 throw new TransactionCommitFailedException("Commit failed", e);
70 private ListenableFuture<?>[] commitAll() {
71 final ListenableFuture<?>[] ops = new ListenableFuture<?>[cohorts.size()];
73 for (final DOMStoreThreePhaseCommitCohort cohort : cohorts) {
74 ops[index++] = cohort.commit();