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%2FTransactionProxy.java;h=59c9298499c4ed0a58961b57fe40019f15214de1;hp=0b863623b4b9877cfc1553456994d241008f35ab;hb=78527e81f8cc82140af5cb2649863a597f380291;hpb=dc10cce59fd3f2e11af715605f094dfeabc4c73a diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionProxy.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionProxy.java index 0b863623b4..59c9298499 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionProxy.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionProxy.java @@ -12,8 +12,6 @@ import akka.actor.ActorSelection; import akka.dispatch.Mapper; import akka.dispatch.OnComplete; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.FinalizablePhantomReference; -import com.google.common.base.FinalizableReferenceQueue; import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.common.collect.Lists; @@ -24,7 +22,6 @@ import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; @@ -33,7 +30,6 @@ import javax.annotation.concurrent.GuardedBy; import org.opendaylight.controller.cluster.datastore.compat.PreLithiumTransactionContextImpl; import org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException; import org.opendaylight.controller.cluster.datastore.identifiers.TransactionIdentifier; -import org.opendaylight.controller.cluster.datastore.messages.CloseTransaction; import org.opendaylight.controller.cluster.datastore.messages.CreateTransaction; import org.opendaylight.controller.cluster.datastore.messages.CreateTransactionReply; import org.opendaylight.controller.cluster.datastore.shardstrategy.ShardStrategyFactory; @@ -106,72 +102,6 @@ public class TransactionProxy extends AbstractDOMStoreTransaction phantomReferenceCache = - new ConcurrentHashMap<>(); - - /** - * A PhantomReference that closes remote transactions for a TransactionProxy when it's - * garbage collected. This is used for read-only transactions as they're not explicitly closed - * by clients. So the only way to detect that a transaction is no longer in use and it's safe - * to clean up is when it's garbage collected. It's inexact as to when an instance will be GC'ed - * but TransactionProxy instances should generally be short-lived enough to avoid being moved - * to the old generation space and thus should be cleaned up in a timely manner as the GC - * runs on the young generation (eden, swap1...) space much more frequently. - */ - private static class TransactionProxyCleanupPhantomReference - extends FinalizablePhantomReference { - - private final List remoteTransactionActors; - private final AtomicBoolean remoteTransactionActorsMB; - private final ActorContext actorContext; - private final TransactionIdentifier identifier; - - protected TransactionProxyCleanupPhantomReference(TransactionProxy referent) { - super(referent, phantomReferenceQueue); - - // Note we need to cache the relevant fields from the TransactionProxy as we can't - // have a hard reference to the TransactionProxy instance itself. - - remoteTransactionActors = referent.remoteTransactionActors; - remoteTransactionActorsMB = referent.remoteTransactionActorsMB; - actorContext = referent.actorContext; - identifier = referent.getIdentifier(); - } - - @Override - public void finalizeReferent() { - LOG.trace("Cleaning up {} Tx actors for TransactionProxy {}", - remoteTransactionActors.size(), identifier); - - phantomReferenceCache.remove(this); - - // Access the memory barrier volatile to ensure all previous updates to the - // remoteTransactionActors list are visible to this thread. - - if(remoteTransactionActorsMB.get()) { - for(ActorSelection actor : remoteTransactionActors) { - LOG.trace("Sending CloseTransaction to {}", actor); - actorContext.sendOperationAsync(actor, CloseTransaction.INSTANCE.toSerializable()); - } - } - } - } - /** * Stores the remote Tx actors for each requested data store path to be used by the * PhantomReference to close the remote Tx's. This is only used for read-only Tx's. The @@ -179,8 +109,8 @@ public class TransactionProxy extends AbstractDOMStoreTransaction remoteTransactionActors; - private volatile AtomicBoolean remoteTransactionActorsMB; + List remoteTransactionActors; + volatile AtomicBoolean remoteTransactionActorsMB; /** * Stores the create transaction results per shard. @@ -188,7 +118,7 @@ public class TransactionProxy extends AbstractDOMStoreTransaction txFutureCallbackMap = new HashMap<>(); private final TransactionType transactionType; - private final ActorContext actorContext; + final ActorContext actorContext; private final String transactionChainId; private final SchemaContext schemaContext; private TransactionState state = TransactionState.OPEN; @@ -735,9 +665,7 @@ public class TransactionProxy extends AbstractDOMStoreTransaction