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
8 package org.opendaylight.mdsal.dom.store.inmemory;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.annotations.Beta;
13 import com.google.common.util.concurrent.ListenableFuture;
14 import java.util.Collection;
15 import java.util.concurrent.Callable;
16 import java.util.concurrent.ExecutionException;
17 import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
18 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
19 import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
24 * Task that coordinates the PreCommit phase of the provided {@link DOMStoreThreePhaseCommitCohort}'s.
27 public class ShardPreCommitCoordinationTask implements Callable<Void> {
29 private static final Logger LOG = LoggerFactory.getLogger(ShardPreCommitCoordinationTask.class);
31 private final DOMDataTreeIdentifier rootShardPrefix;
32 private final Collection<DOMStoreThreePhaseCommitCohort> cohorts;
34 public ShardPreCommitCoordinationTask(final DOMDataTreeIdentifier rootShardPrefix,
35 final Collection<DOMStoreThreePhaseCommitCohort> cohorts) {
36 this.rootShardPrefix = requireNonNull(rootShardPrefix);
37 this.cohorts = requireNonNull(cohorts);
41 public Void call() throws TransactionCommitFailedException {
44 LOG.debug("Shard {}, preCommit started", rootShardPrefix);
48 } catch (final TransactionCommitFailedException e) {
49 LOG.warn("Shard: {} Submit Error during phase PreCommit, starting Abort", rootShardPrefix, e);
55 void preCommitBlocking() throws TransactionCommitFailedException {
56 for (final ListenableFuture<?> preCommit : preCommitAll()) {
59 } catch (InterruptedException | ExecutionException e) {
60 throw new TransactionCommitFailedException("PreCommit failed", e);
65 private ListenableFuture<?>[] preCommitAll() {
66 final ListenableFuture<?>[] ops = new ListenableFuture<?>[cohorts.size()];
68 for (final DOMStoreThreePhaseCommitCohort cohort : cohorts) {
69 ops[index++] = cohort.preCommit();