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
10 package org.opendaylight.mdsal.dom.store.inmemory;
12 import com.google.common.annotations.Beta;
13 import com.google.common.base.Preconditions;
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 PreCommit phase of the provided {@link DOMStoreThreePhaseCommitCohort}'s
28 public class ShardPreCommitCoordinationTask implements Callable<Void>{
30 private static final Logger LOG = LoggerFactory.getLogger(ShardPreCommitCoordinationTask.class);
32 private final DOMDataTreeIdentifier rootShardPrefix;
33 private final Collection<DOMStoreThreePhaseCommitCohort> cohorts;
35 public ShardPreCommitCoordinationTask(final DOMDataTreeIdentifier rootShardPrefix,
36 final Collection<DOMStoreThreePhaseCommitCohort> cohorts) {
37 this.rootShardPrefix = Preconditions.checkNotNull(rootShardPrefix);
38 this.cohorts = Preconditions.checkNotNull(cohorts);
42 public Void call() throws TransactionCommitFailedException {
45 LOG.debug("Shard {}, preCommit started", rootShardPrefix);
49 } catch (final TransactionCommitFailedException e) {
50 LOG.warn("Shard: {} Submit Error during phase {}, starting Abort", rootShardPrefix, e);
56 void preCommitBlocking() throws TransactionCommitFailedException {
57 for (final ListenableFuture<?> preCommit : preCommitAll()) {
60 } catch (InterruptedException | ExecutionException e) {
61 throw new TransactionCommitFailedException("PreCommit failed", e);
66 private ListenableFuture<?>[] preCommitAll() {
67 final ListenableFuture<?>[] ops = new ListenableFuture<?>[cohorts.size()];
69 for (final DOMStoreThreePhaseCommitCohort cohort : cohorts) {
70 ops[i++] = cohort.preCommit();