X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatabroker%2Factors%2Fdds%2FAbstractClientHandle.java;h=003c073de8ea12a101e9542cd4dab9259a8ae946;hb=refs%2Fchanges%2F49%2F85749%2F63;hp=90773359dcab9c47089f6bdd96c1675c4275d5b7;hpb=44d274e8a4282ef859a35369c563e4963cf2185a;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractClientHandle.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractClientHandle.java index 90773359dc..003c073de8 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractClientHandle.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractClientHandle.java @@ -12,7 +12,7 @@ import static java.util.Objects.requireNonNull; import com.google.common.annotations.Beta; import com.google.common.base.MoreObjects; -import java.util.Collection; +import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; import org.eclipse.jdt.annotation.NonNull; @@ -43,8 +43,8 @@ public abstract class AbstractClientHandle e private static final AtomicReferenceFieldUpdater STATE_UPDATER = AtomicReferenceFieldUpdater.newUpdater(AbstractClientHandle.class, State.class, "state"); - private final TransactionIdentifier transactionId; - private final AbstractClientHistory parent; + private final @NonNull TransactionIdentifier transactionId; + private final @NonNull AbstractClientHistory parent; private volatile State state = new State<>(); @@ -55,6 +55,7 @@ public abstract class AbstractClientHandle e } @Override + // Non-final for mocking public TransactionIdentifier getIdentifier() { return transactionId; } @@ -64,6 +65,7 @@ public abstract class AbstractClientHandle e * * @return True if this transaction became closed during this call */ + // Non-final for mocking public boolean abort() { if (commonAbort()) { parent.onTransactionAbort(this); @@ -74,12 +76,13 @@ public abstract class AbstractClientHandle e } private boolean commonAbort() { - final Collection toClose = ensureClosed(); + final Map toClose = ensureClosed(); if (toClose == null) { return false; } - toClose.forEach(AbstractProxyTransaction::abort); + toClose.values().forEach(AbstractProxyTransaction::abort); + parent.onTransactionShardsBound(transactionId, toClose.keySet()); return true; } @@ -93,13 +96,14 @@ public abstract class AbstractClientHandle e * Make sure this snapshot is closed. If it became closed as the effect of this call, return a collection of * {@link AbstractProxyTransaction} handles which need to be closed, too. * - * @return null if this snapshot has already been closed, otherwise a collection of proxies, which need to be + * @return null if this snapshot has already been closed, otherwise a State with of proxies, which need to be * closed, too. */ - final @Nullable Collection ensureClosed() { - @SuppressWarnings("unchecked") - final State local = STATE_UPDATER.getAndSet(this, null); - return local == null ? null : local.values(); + final @Nullable Map ensureClosed() { + // volatile read and a conditional CAS. This ends up being better in the typical case when we are invoked more + // than once (see ClientBackedTransaction) than performing a STATE_UPDATER.getAndSet(). + final State local = state; + return local != null && STATE_UPDATER.compareAndSet(this, local, null) ? local : null; } final T ensureProxy(final YangInstanceIdentifier path) {