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 com.google.common.util.concurrent.ListenableFuture;
12 import java.util.Collection;
13 import java.util.concurrent.Callable;
14 import java.util.concurrent.ExecutionException;
15 import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
16 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
17 import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
21 class ShardCommitCoordinationTask implements Callable<Void> {
23 private static final Logger LOG = LoggerFactory.getLogger(ShardCommitCoordinationTask.class);
25 private final DOMDataTreeIdentifier rootShardPrefix;
26 private final Collection<DOMStoreThreePhaseCommitCohort> cohorts;
28 ShardCommitCoordinationTask(final DOMDataTreeIdentifier rootShardPrefix,
29 final Collection<DOMStoreThreePhaseCommitCohort> cohorts) {
30 this.rootShardPrefix = rootShardPrefix;
31 this.cohorts = cohorts;
35 public Void call() throws TransactionCommitFailedException {
38 LOG.debug("Shard {}, commit started", rootShardPrefix);
42 } catch (TransactionCommitFailedException e) {
43 LOG.warn("Shard: {} Submit Error during phase Commit, starting Abort", rootShardPrefix, e);
49 void commitBlocking() throws TransactionCommitFailedException {
50 for (final ListenableFuture<?> commit : commitAll()) {
53 } catch (InterruptedException | ExecutionException e) {
54 throw new TransactionCommitFailedException("Commit failed", e);
59 private ListenableFuture<?>[] commitAll() {
60 final ListenableFuture<?>[] ops = new ListenableFuture<?>[cohorts.size()];
62 for (final DOMStoreThreePhaseCommitCohort cohort : cohorts) {
63 ops[i++] = cohort.commit();