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.util.concurrent.ListenableFuture;
13 import java.util.Collection;
14 import java.util.concurrent.Callable;
15 import java.util.concurrent.ExecutionException;
16 import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
17 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
18 import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
22 class ShardPreCommitCoordinationTask implements Callable<Void>{
24 private static final Logger LOG = LoggerFactory.getLogger(ShardPreCommitCoordinationTask.class);
26 private final DOMDataTreeIdentifier rootShardPrefix;
27 private final Collection<DOMStoreThreePhaseCommitCohort> cohorts;
29 ShardPreCommitCoordinationTask(final DOMDataTreeIdentifier rootShardPrefix,
30 final Collection<DOMStoreThreePhaseCommitCohort> cohorts) {
31 this.rootShardPrefix = rootShardPrefix;
32 this.cohorts = cohorts;
36 public Void call() throws TransactionCommitFailedException {
39 LOG.debug("Shard {}, preCommit started", rootShardPrefix);
43 } catch (TransactionCommitFailedException e) {
44 LOG.warn("Shard: {} Submit Error during phase {}, starting Abort", rootShardPrefix, e);
50 void preCommitBlocking() throws TransactionCommitFailedException {
51 for (final ListenableFuture<?> preCommit : preCommitAll()) {
54 } catch (InterruptedException | ExecutionException e) {
55 throw new TransactionCommitFailedException("PreCommit failed", e);
60 private ListenableFuture<?>[] preCommitAll() {
61 final ListenableFuture<?>[] ops = new ListenableFuture<?>[cohorts.size()];
63 for (final DOMStoreThreePhaseCommitCohort cohort : cohorts) {
64 ops[i++] = cohort.preCommit();