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%2FCohortEntry.java;h=767749af29900a2c298758ec78e54e26768b8dc7;hp=06d3ec9d67381e3709617bc4535f40ac37378fc9;hb=a47dd7a5d21ca68804a6d0e2e3ca765f223c2ef4;hpb=23472d531aca7f695082a3d57719894bfa34d0ac diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/CohortEntry.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/CohortEntry.java index 06d3ec9d67..767749af29 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/CohortEntry.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/CohortEntry.java @@ -8,38 +8,22 @@ package org.opendaylight.controller.cluster.datastore; import akka.actor.ActorRef; -import akka.util.Timeout; import com.google.common.base.Preconditions; -import com.google.common.base.Stopwatch; +import com.google.common.primitives.UnsignedLong; +import com.google.common.util.concurrent.FutureCallback; import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; import org.opendaylight.controller.cluster.datastore.ShardCommitCoordinator.CohortDecorator; import org.opendaylight.controller.cluster.datastore.modification.Modification; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import scala.concurrent.duration.Duration; final class CohortEntry { - enum State { - PENDING, - CAN_COMMITTED, - PRE_COMMITTED, - COMMITTED, - ABORTED - } - - private static final Timeout COMMIT_STEP_TIMEOUT = new Timeout(Duration.create(5, TimeUnit.SECONDS)); - - private final Stopwatch lastAccessTimer = Stopwatch.createStarted(); private final ReadWriteShardDataTreeTransaction transaction; private final TransactionIdentifier transactionID; - private final CompositeDataTreeCohort userCohorts; private final short clientVersion; - private State state = State.PENDING; private RuntimeException lastBatchedModificationsException; private int totalBatchedModificationsReceived; private ShardDataTreeCohort cohort; @@ -47,36 +31,25 @@ final class CohortEntry { private ActorRef replySender; private Shard shard; - private CohortEntry(TransactionIdentifier transactionID, ReadWriteShardDataTreeTransaction transaction, - DataTreeCohortActorRegistry cohortRegistry, SchemaContext schema, short clientVersion) { + private CohortEntry(final ReadWriteShardDataTreeTransaction transaction, final short clientVersion) { this.transaction = Preconditions.checkNotNull(transaction); - this.transactionID = Preconditions.checkNotNull(transactionID); + this.transactionID = transaction.getId(); this.clientVersion = clientVersion; - this.userCohorts = new CompositeDataTreeCohort(cohortRegistry, transactionID, schema, COMMIT_STEP_TIMEOUT); } - private CohortEntry(TransactionIdentifier transactionID, ShardDataTreeCohort cohort, DataTreeCohortActorRegistry cohortRegistry, - SchemaContext schema, short clientVersion) { - this.transactionID = Preconditions.checkNotNull(transactionID); - this.cohort = cohort; + private CohortEntry(final ShardDataTreeCohort cohort, final short clientVersion) { + this.cohort = Preconditions.checkNotNull(cohort); + this.transactionID = cohort.getIdentifier(); this.transaction = null; this.clientVersion = clientVersion; - this.userCohorts = new CompositeDataTreeCohort(cohortRegistry, transactionID, schema, COMMIT_STEP_TIMEOUT); - } - - static CohortEntry createOpen(TransactionIdentifier transactionID, ReadWriteShardDataTreeTransaction transaction, - DataTreeCohortActorRegistry cohortRegistry, SchemaContext schema, short clientVersion) { - return new CohortEntry(transactionID, transaction, cohortRegistry, schema, clientVersion); } - static CohortEntry createReady(TransactionIdentifier transactionID, ShardDataTreeCohort cohort, - DataTreeCohortActorRegistry cohortRegistry, SchemaContext schema, short clientVersion) { - return new CohortEntry(transactionID, cohort, cohortRegistry, schema, clientVersion); + static CohortEntry createOpen(final ReadWriteShardDataTreeTransaction transaction, final short clientVersion) { + return new CohortEntry(transaction, clientVersion); } - void updateLastAccessTime() { - lastAccessTimer.reset(); - lastAccessTimer.start(); + static CohortEntry createReady(final ShardDataTreeCohort cohort, final short clientVersion) { + return new CohortEntry(cohort, clientVersion); } TransactionIdentifier getTransactionID() { @@ -87,12 +60,8 @@ final class CohortEntry { return clientVersion; } - State getState() { - return state; - } - - DataTreeCandidate getCandidate() { - return cohort.getCandidate(); + boolean isFailed() { + return cohort != null && cohort.isFailed(); } DataTreeModification getDataTreeModification() { @@ -111,7 +80,7 @@ final class CohortEntry { return lastBatchedModificationsException; } - void applyModifications(Iterable modifications) { + void applyModifications(final Iterable modifications) { totalBatchedModificationsReceived++; if(lastBatchedModificationsException == null) { for (Modification modification : modifications) { @@ -125,43 +94,25 @@ final class CohortEntry { } } - boolean canCommit() throws InterruptedException, ExecutionException { - state = State.CAN_COMMITTED; - - // We block on the future here (and also preCommit(), commit(), abort()) so we don't have to worry - // about possibly accessing our state on a different thread outside of our dispatcher. - // TODO: the ShardDataTreeCohort returns immediate Futures anyway which begs the question - why - // bother even returning Futures from ShardDataTreeCohort if we have to treat them synchronously - // anyway?. The Futures are really a remnant from when we were using the InMemoryDataBroker. - return cohort.canCommit().get(); + void canCommit(final FutureCallback callback) { + cohort.canCommit(callback); } - - - void preCommit() throws InterruptedException, ExecutionException, TimeoutException { - state = State.PRE_COMMITTED; - cohort.preCommit().get(); - userCohorts.canCommit(cohort.getCandidate()); - userCohorts.preCommit(); + void preCommit(final FutureCallback callback) { + cohort.preCommit(callback); } - void commit() throws InterruptedException, ExecutionException, TimeoutException { - state = State.COMMITTED; - cohort.commit().get(); - userCohorts.commit(); + void commit(final FutureCallback callback) { + cohort.commit(callback); } void abort() throws InterruptedException, ExecutionException, TimeoutException { - state = State.ABORTED; cohort.abort().get(); - userCohorts.abort(); } - void ready(CohortDecorator cohortDecorator, boolean doImmediateCommit) { + void ready(final CohortDecorator cohortDecorator) { Preconditions.checkState(cohort == null, "cohort was already set"); - setDoImmediateCommit(doImmediateCommit); - cohort = transaction.ready(); if(cohortDecorator != null) { @@ -170,19 +121,11 @@ final class CohortEntry { } } - boolean isReadyToCommit() { - return replySender != null; - } - - boolean isExpired(long expireTimeInMillis) { - return lastAccessTimer.elapsed(TimeUnit.MILLISECONDS) >= expireTimeInMillis; - } - boolean isDoImmediateCommit() { return doImmediateCommit; } - void setDoImmediateCommit(boolean doImmediateCommit) { + void setDoImmediateCommit(final boolean doImmediateCommit) { this.doImmediateCommit = doImmediateCommit; } @@ -190,7 +133,7 @@ final class CohortEntry { return replySender; } - void setReplySender(ActorRef replySender) { + void setReplySender(final ActorRef replySender) { this.replySender = replySender; } @@ -198,15 +141,10 @@ final class CohortEntry { return shard; } - void setShard(Shard shard) { + void setShard(final Shard shard) { this.shard = shard; } - - boolean isAborted() { - return state == State.ABORTED; - } - @Override public String toString() { final StringBuilder builder = new StringBuilder();