X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FShardDataTreeCohort.java;h=77b8db92099df0a2e3b014530de87f288983a1cb;hp=11b3ca8ed707e12f8456650fb423ca468a845660;hb=118cd0216b0c6b0ec1a01689ec2025a13e090861;hpb=56c1339ee7dbd85bc567fc44f21ecfd322c9e803 diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTreeCohort.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTreeCohort.java index 11b3ca8ed7..77b8db9209 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTreeCohort.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTreeCohort.java @@ -7,72 +7,70 @@ */ package org.opendaylight.controller.cluster.datastore; -import com.google.common.base.Preconditions; -import com.google.common.util.concurrent.Futures; -import com.google.common.util.concurrent.ListenableFuture; -import org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.MoreObjects; +import com.google.common.base.MoreObjects.ToStringHelper; +import com.google.common.primitives.UnsignedLong; +import com.google.common.util.concurrent.FutureCallback; +import java.util.Optional; +import java.util.SortedSet; +import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; +import org.opendaylight.yangtools.concepts.Identifiable; +import org.opendaylight.yangtools.yang.common.Empty; +import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate; +import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateTip; +import org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification; -final class ShardDataTreeCohort implements DOMStoreThreePhaseCommitCohort { - private static final Logger LOG = LoggerFactory.getLogger(ShardDataTreeCohort.class); - private static final ListenableFuture TRUE_FUTURE = Futures.immediateFuture(Boolean.TRUE); - private static final ListenableFuture VOID_FUTURE = Futures.immediateFuture(null); - private final DataTreeModification transaction; - private final ShardDataTree dataTree; - private DataTreeCandidateTip candidate; +@VisibleForTesting +public abstract class ShardDataTreeCohort implements Identifiable { + public enum State { + READY, + CAN_COMMIT_PENDING, + CAN_COMMIT_COMPLETE, + PRE_COMMIT_PENDING, + PRE_COMMIT_COMPLETE, + COMMIT_PENDING, - ShardDataTreeCohort(final ShardDataTree dataTree, final DataTreeModification transaction) { - this.dataTree = Preconditions.checkNotNull(dataTree); - this.transaction = Preconditions.checkNotNull(transaction); + ABORTED, + COMMITTED, + FAILED, } - @Override - public ListenableFuture canCommit() { - try { - dataTree.getDataTree().validate(transaction); - LOG.debug("Transaction {} validated", transaction); - return TRUE_FUTURE; - } catch (Exception e) { - return Futures.immediateFailedFuture(e); - } + ShardDataTreeCohort() { + // Prevent foreign instantiation } - @Override - public ListenableFuture preCommit() { - try { - candidate = dataTree.getDataTree().prepare(transaction); - /* - * FIXME: this is the place where we should be interacting with persistence, specifically by invoking - * persist on the candidate (which gives us a Future). - */ - LOG.debug("Transaction {} prepared candidate {}", transaction, candidate); - return VOID_FUTURE; - } catch (Exception e) { - LOG.debug("Transaction {} failed to prepare", transaction, e); - return Futures.immediateFailedFuture(e); - } - } + // FIXME: This leaks internal state generated in preCommit, + // should be result of canCommit + abstract DataTreeCandidateTip getCandidate(); - @Override - public ListenableFuture abort() { - // No-op, really - return VOID_FUTURE; - } + abstract DataTreeModification getDataTreeModification(); + + abstract Optional> getParticipatingShardNames(); + + // FIXME: Should return rebased DataTreeCandidateTip + @VisibleForTesting + public abstract void canCommit(FutureCallback callback); + + @VisibleForTesting + public abstract void preCommit(FutureCallback callback); + + @VisibleForTesting + public abstract void abort(FutureCallback callback); + + @VisibleForTesting + public abstract void commit(FutureCallback callback); + + public abstract boolean isFailed(); + + public abstract State getState(); @Override - public ListenableFuture commit() { - try { - dataTree.getDataTree().commit(candidate); - } catch (Exception e) { - LOG.error("Transaction {} failed to commit", transaction, e); - return Futures.immediateFailedFuture(e); - } + public final String toString() { + return addToStringAttributes(MoreObjects.toStringHelper(this).omitNullValues()).toString(); + } - LOG.debug("Transaction {} committed, proceeding to notify", transaction); - dataTree.notifyListeners(candidate); - return VOID_FUTURE; + ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) { + return toStringHelper.add("id", getIdentifier()).add("state", getState()); } }