2 * Copyright (c) 2014 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.controller.cluster.datastore;
11 import akka.actor.ActorSelection;
12 import akka.dispatch.Mapper;
13 import akka.dispatch.OnComplete;
14 import com.google.common.annotations.VisibleForTesting;
15 import com.google.common.base.FinalizablePhantomReference;
16 import com.google.common.base.FinalizableReferenceQueue;
17 import com.google.common.base.Optional;
18 import com.google.common.base.Preconditions;
19 import com.google.common.collect.Lists;
20 import com.google.common.util.concurrent.CheckedFuture;
21 import com.google.common.util.concurrent.FutureCallback;
22 import com.google.common.util.concurrent.Futures;
23 import com.google.common.util.concurrent.SettableFuture;
24 import java.util.ArrayList;
25 import java.util.Collection;
26 import java.util.HashMap;
27 import java.util.List;
29 import java.util.concurrent.ConcurrentHashMap;
30 import java.util.concurrent.Semaphore;
31 import java.util.concurrent.TimeUnit;
32 import java.util.concurrent.atomic.AtomicBoolean;
33 import java.util.concurrent.atomic.AtomicLong;
34 import javax.annotation.concurrent.GuardedBy;
35 import org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException;
36 import org.opendaylight.controller.cluster.datastore.identifiers.TransactionIdentifier;
37 import org.opendaylight.controller.cluster.datastore.messages.CloseTransaction;
38 import org.opendaylight.controller.cluster.datastore.messages.CreateTransaction;
39 import org.opendaylight.controller.cluster.datastore.messages.CreateTransactionReply;
40 import org.opendaylight.controller.cluster.datastore.shardstrategy.ShardStrategyFactory;
41 import org.opendaylight.controller.cluster.datastore.utils.ActorContext;
42 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
43 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction;
44 import org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort;
45 import org.opendaylight.yangtools.util.concurrent.MappingCheckedFuture;
46 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
47 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
48 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
49 import org.slf4j.Logger;
50 import org.slf4j.LoggerFactory;
51 import scala.concurrent.Future;
52 import scala.concurrent.Promise;
53 import scala.concurrent.duration.FiniteDuration;
56 * TransactionProxy acts as a proxy for one or more transactions that were created on a remote shard
58 * Creating a transaction on the consumer side will create one instance of a transaction proxy. If during
59 * the transaction reads and writes are done on data that belongs to different shards then a separate transaction will
60 * be created on each of those shards by the TransactionProxy
63 * The TransactionProxy does not make any guarantees about atomicity or order in which the transactions on the various
64 * shards will be executed.
67 public class TransactionProxy implements DOMStoreReadWriteTransaction {
69 public static enum TransactionType {
75 static final Mapper<Throwable, Throwable> SAME_FAILURE_TRANSFORMER =
76 new Mapper<Throwable, Throwable>() {
78 public Throwable apply(Throwable failure) {
83 private static final AtomicLong counter = new AtomicLong();
85 private static final Logger LOG = LoggerFactory.getLogger(TransactionProxy.class);
88 * Time interval in between transaction create retries.
90 private static final FiniteDuration CREATE_TX_TRY_INTERVAL =
91 FiniteDuration.create(1, TimeUnit.SECONDS);
94 * Used to enqueue the PhantomReferences for read-only TransactionProxy instances. The
95 * FinalizableReferenceQueue is safe to use statically in an OSGi environment as it uses some
96 * trickery to clean up its internal thread when the bundle is unloaded.
98 private static final FinalizableReferenceQueue phantomReferenceQueue =
99 new FinalizableReferenceQueue();
102 * This stores the TransactionProxyCleanupPhantomReference instances statically, This is
103 * necessary because PhantomReferences need a hard reference so they're not garbage collected.
104 * Once finalized, the TransactionProxyCleanupPhantomReference removes itself from this map
105 * and thus becomes eligible for garbage collection.
107 private static final Map<TransactionProxyCleanupPhantomReference,
108 TransactionProxyCleanupPhantomReference> phantomReferenceCache =
109 new ConcurrentHashMap<>();
112 * A PhantomReference that closes remote transactions for a TransactionProxy when it's
113 * garbage collected. This is used for read-only transactions as they're not explicitly closed
114 * by clients. So the only way to detect that a transaction is no longer in use and it's safe
115 * to clean up is when it's garbage collected. It's inexact as to when an instance will be GC'ed
116 * but TransactionProxy instances should generally be short-lived enough to avoid being moved
117 * to the old generation space and thus should be cleaned up in a timely manner as the GC
118 * runs on the young generation (eden, swap1...) space much more frequently.
120 private static class TransactionProxyCleanupPhantomReference
121 extends FinalizablePhantomReference<TransactionProxy> {
123 private final List<ActorSelection> remoteTransactionActors;
124 private final AtomicBoolean remoteTransactionActorsMB;
125 private final ActorContext actorContext;
126 private final TransactionIdentifier identifier;
128 protected TransactionProxyCleanupPhantomReference(TransactionProxy referent) {
129 super(referent, phantomReferenceQueue);
131 // Note we need to cache the relevant fields from the TransactionProxy as we can't
132 // have a hard reference to the TransactionProxy instance itself.
134 remoteTransactionActors = referent.remoteTransactionActors;
135 remoteTransactionActorsMB = referent.remoteTransactionActorsMB;
136 actorContext = referent.actorContext;
137 identifier = referent.identifier;
141 public void finalizeReferent() {
142 LOG.trace("Cleaning up {} Tx actors for TransactionProxy {}",
143 remoteTransactionActors.size(), identifier);
145 phantomReferenceCache.remove(this);
147 // Access the memory barrier volatile to ensure all previous updates to the
148 // remoteTransactionActors list are visible to this thread.
150 if(remoteTransactionActorsMB.get()) {
151 for(ActorSelection actor : remoteTransactionActors) {
152 LOG.trace("Sending CloseTransaction to {}", actor);
153 actorContext.sendOperationAsync(actor, CloseTransaction.INSTANCE.toSerializable());
160 * Stores the remote Tx actors for each requested data store path to be used by the
161 * PhantomReference to close the remote Tx's. This is only used for read-only Tx's. The
162 * remoteTransactionActorsMB volatile serves as a memory barrier to publish updates to the
163 * remoteTransactionActors list so they will be visible to the thread accessing the
166 private List<ActorSelection> remoteTransactionActors;
167 private AtomicBoolean remoteTransactionActorsMB;
170 * Stores the create transaction results per shard.
172 private final Map<String, TransactionFutureCallback> txFutureCallbackMap = new HashMap<>();
174 private final TransactionType transactionType;
175 private final ActorContext actorContext;
176 private final TransactionIdentifier identifier;
177 private final String transactionChainId;
178 private final SchemaContext schemaContext;
179 private boolean inReadyState;
180 private final Semaphore operationLimiter;
181 private final OperationCompleter operationCompleter;
183 public TransactionProxy(ActorContext actorContext, TransactionType transactionType) {
184 this(actorContext, transactionType, "");
187 public TransactionProxy(ActorContext actorContext, TransactionType transactionType,
188 String transactionChainId) {
189 this.actorContext = Preconditions.checkNotNull(actorContext,
190 "actorContext should not be null");
191 this.transactionType = Preconditions.checkNotNull(transactionType,
192 "transactionType should not be null");
193 this.schemaContext = Preconditions.checkNotNull(actorContext.getSchemaContext(),
194 "schemaContext should not be null");
195 this.transactionChainId = transactionChainId;
197 String memberName = actorContext.getCurrentMemberName();
198 if(memberName == null){
199 memberName = "UNKNOWN-MEMBER";
202 this.identifier = TransactionIdentifier.builder().memberName(memberName).counter(
203 counter.getAndIncrement()).build();
205 if(transactionType == TransactionType.READ_ONLY) {
206 // Read-only Tx's aren't explicitly closed by the client so we create a PhantomReference
207 // to close the remote Tx's when this instance is no longer in use and is garbage
210 remoteTransactionActors = Lists.newArrayList();
211 remoteTransactionActorsMB = new AtomicBoolean();
213 TransactionProxyCleanupPhantomReference cleanup =
214 new TransactionProxyCleanupPhantomReference(this);
215 phantomReferenceCache.put(cleanup, cleanup);
218 // Note : Currently mailbox-capacity comes from akka.conf and not from the config-subsystem
219 this.operationLimiter = new Semaphore(actorContext.getTransactionOutstandingOperationLimit());
220 this.operationCompleter = new OperationCompleter(operationLimiter);
222 LOG.debug("Created txn {} of type {} on chain {}", identifier, transactionType, transactionChainId);
226 List<Future<Object>> getRecordedOperationFutures() {
227 List<Future<Object>> recordedOperationFutures = Lists.newArrayList();
228 for(TransactionFutureCallback txFutureCallback : txFutureCallbackMap.values()) {
229 TransactionContext transactionContext = txFutureCallback.getTransactionContext();
230 if(transactionContext != null) {
231 recordedOperationFutures.addAll(transactionContext.getRecordedOperationFutures());
235 return recordedOperationFutures;
239 boolean hasTransactionContext() {
240 for(TransactionFutureCallback txFutureCallback : txFutureCallbackMap.values()) {
241 TransactionContext transactionContext = txFutureCallback.getTransactionContext();
242 if(transactionContext != null) {
251 public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read(final YangInstanceIdentifier path) {
253 Preconditions.checkState(transactionType != TransactionType.WRITE_ONLY,
254 "Read operation on write-only transaction is not allowed");
256 LOG.debug("Tx {} read {}", identifier, path);
260 TransactionFutureCallback txFutureCallback = getOrCreateTxFutureCallback(path);
261 return txFutureCallback.enqueueReadOperation(new ReadOperation<Optional<NormalizedNode<?, ?>>>() {
263 public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> invoke(
264 TransactionContext transactionContext) {
265 return transactionContext.readData(path);
271 public CheckedFuture<Boolean, ReadFailedException> exists(final YangInstanceIdentifier path) {
273 Preconditions.checkState(transactionType != TransactionType.WRITE_ONLY,
274 "Exists operation on write-only transaction is not allowed");
276 LOG.debug("Tx {} exists {}", identifier, path);
280 TransactionFutureCallback txFutureCallback = getOrCreateTxFutureCallback(path);
281 return txFutureCallback.enqueueReadOperation(new ReadOperation<Boolean>() {
283 public CheckedFuture<Boolean, ReadFailedException> invoke(TransactionContext transactionContext) {
284 return transactionContext.dataExists(path);
290 private void checkModificationState() {
291 Preconditions.checkState(transactionType != TransactionType.READ_ONLY,
292 "Modification operation on read-only transaction is not allowed");
293 Preconditions.checkState(!inReadyState,
294 "Transaction is sealed - further modifications are not allowed");
297 private void throttleOperation() {
298 throttleOperation(1);
301 private void throttleOperation(int acquirePermits) {
303 if(!operationLimiter.tryAcquire(acquirePermits, actorContext.getDatastoreContext().getOperationTimeoutInSeconds(), TimeUnit.SECONDS)){
304 LOG.warn("Failed to acquire operation permit for transaction {}", getIdentifier());
306 } catch (InterruptedException e) {
307 if(LOG.isDebugEnabled()) {
308 LOG.debug("Interrupted when trying to acquire operation permit for transaction " + getIdentifier().toString(), e);
310 LOG.warn("Interrupted when trying to acquire operation permit for transaction {}", getIdentifier());
317 public void write(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
319 checkModificationState();
321 LOG.debug("Tx {} write {}", identifier, path);
325 TransactionFutureCallback txFutureCallback = getOrCreateTxFutureCallback(path);
326 txFutureCallback.enqueueModifyOperation(new TransactionOperation() {
328 public void invoke(TransactionContext transactionContext) {
329 transactionContext.writeData(path, data);
335 public void merge(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
337 checkModificationState();
339 LOG.debug("Tx {} merge {}", identifier, path);
343 TransactionFutureCallback txFutureCallback = getOrCreateTxFutureCallback(path);
344 txFutureCallback.enqueueModifyOperation(new TransactionOperation() {
346 public void invoke(TransactionContext transactionContext) {
347 transactionContext.mergeData(path, data);
353 public void delete(final YangInstanceIdentifier path) {
355 checkModificationState();
357 LOG.debug("Tx {} delete {}", identifier, path);
361 TransactionFutureCallback txFutureCallback = getOrCreateTxFutureCallback(path);
362 txFutureCallback.enqueueModifyOperation(new TransactionOperation() {
364 public void invoke(TransactionContext transactionContext) {
365 transactionContext.deleteData(path);
371 public DOMStoreThreePhaseCommitCohort ready() {
373 checkModificationState();
375 throttleOperation(txFutureCallbackMap.size());
379 LOG.debug("Tx {} Readying {} transactions for commit", identifier,
380 txFutureCallbackMap.size());
382 List<Future<ActorSelection>> cohortFutures = Lists.newArrayList();
384 for(TransactionFutureCallback txFutureCallback : txFutureCallbackMap.values()) {
386 LOG.debug("Tx {} Readying transaction for shard {} chain {}", identifier,
387 txFutureCallback.getShardName(), transactionChainId);
389 Future<ActorSelection> future = txFutureCallback.enqueueFutureOperation(new FutureOperation<ActorSelection>() {
391 public Future<ActorSelection> invoke(TransactionContext transactionContext) {
392 return transactionContext.readyTransaction();
396 cohortFutures.add(future);
399 onTransactionReady(cohortFutures);
401 return new ThreePhaseCommitCohortProxy(actorContext, cohortFutures,
402 identifier.toString());
406 * Method for derived classes to be notified when the transaction has been readied.
408 * @param cohortFutures the cohort Futures for each shard transaction.
410 protected void onTransactionReady(List<Future<ActorSelection>> cohortFutures) {
414 * Method called to send a CreateTransaction message to a shard.
416 * @param shard the shard actor to send to
417 * @param serializedCreateMessage the serialized message to send
418 * @return the response Future
420 protected Future<Object> sendCreateTransaction(ActorSelection shard,
421 Object serializedCreateMessage) {
422 return actorContext.executeOperationAsync(shard, serializedCreateMessage);
426 public Object getIdentifier() {
427 return this.identifier;
431 public void close() {
432 for (TransactionFutureCallback txFutureCallback : txFutureCallbackMap.values()) {
433 txFutureCallback.enqueueModifyOperation(new TransactionOperation() {
435 public void invoke(TransactionContext transactionContext) {
436 transactionContext.closeTransaction();
441 txFutureCallbackMap.clear();
443 if(transactionType == TransactionType.READ_ONLY) {
444 remoteTransactionActors.clear();
445 remoteTransactionActorsMB.set(true);
449 private String shardNameFromIdentifier(YangInstanceIdentifier path){
450 return ShardStrategyFactory.getStrategy(path).findShard(path);
453 private TransactionFutureCallback getOrCreateTxFutureCallback(YangInstanceIdentifier path) {
454 String shardName = shardNameFromIdentifier(path);
455 TransactionFutureCallback txFutureCallback = txFutureCallbackMap.get(shardName);
456 if(txFutureCallback == null) {
457 Future<ActorSelection> findPrimaryFuture = actorContext.findPrimaryShardAsync(shardName);
459 final TransactionFutureCallback newTxFutureCallback =
460 new TransactionFutureCallback(shardName);
462 txFutureCallback = newTxFutureCallback;
463 txFutureCallbackMap.put(shardName, txFutureCallback);
465 findPrimaryFuture.onComplete(new OnComplete<ActorSelection>() {
467 public void onComplete(Throwable failure, ActorSelection primaryShard) {
468 if(failure != null) {
469 newTxFutureCallback.onComplete(failure, null);
471 newTxFutureCallback.setPrimaryShard(primaryShard);
474 }, actorContext.getActorSystem().dispatcher());
477 return txFutureCallback;
480 public String getTransactionChainId() {
481 return transactionChainId;
484 protected ActorContext getActorContext() {
489 * Interfaces for transaction operations to be invoked later.
491 private static interface TransactionOperation {
492 void invoke(TransactionContext transactionContext);
496 * This interface returns a Guava Future
498 private static interface ReadOperation<T> {
499 CheckedFuture<T, ReadFailedException> invoke(TransactionContext transactionContext);
503 * This interface returns a Scala Future
505 private static interface FutureOperation<T> {
506 Future<T> invoke(TransactionContext transactionContext);
510 * Implements a Future OnComplete callback for a CreateTransaction message. This class handles
511 * retries, up to a limit, if the shard doesn't have a leader yet. This is done by scheduling a
512 * retry task after a short delay.
514 * The end result from a completed CreateTransaction message is a TransactionContext that is
515 * used to perform transaction operations. Transaction operations that occur before the
516 * CreateTransaction completes are cache and executed once the CreateTransaction completes,
517 * successfully or not.
519 private class TransactionFutureCallback extends OnComplete<Object> {
522 * The list of transaction operations to execute once the CreateTransaction completes.
524 @GuardedBy("txOperationsOnComplete")
525 private final List<TransactionOperation> txOperationsOnComplete = Lists.newArrayList();
528 * The TransactionContext resulting from the CreateTransaction reply.
530 private volatile TransactionContext transactionContext;
533 * The target primary shard.
535 private volatile ActorSelection primaryShard;
537 private volatile int createTxTries = (int) (actorContext.getDatastoreContext().
538 getShardLeaderElectionTimeout().duration().toMillis() /
539 CREATE_TX_TRY_INTERVAL.toMillis());
541 private final String shardName;
543 TransactionFutureCallback(String shardName) {
544 this.shardName = shardName;
547 String getShardName() {
551 TransactionContext getTransactionContext() {
552 return transactionContext;
557 * Sets the target primary shard and initiates a CreateTransaction try.
559 void setPrimaryShard(ActorSelection primaryShard) {
560 LOG.debug("Tx {} Primary shard found - trying create transaction", identifier);
562 this.primaryShard = primaryShard;
563 tryCreateTransaction();
567 * Adds a TransactionOperation to be executed after the CreateTransaction completes.
569 void addTxOperationOnComplete(TransactionOperation operation) {
570 boolean invokeOperation = true;
571 synchronized(txOperationsOnComplete) {
572 if(transactionContext == null) {
573 LOG.debug("Tx {} Adding operation on complete {}", identifier);
575 invokeOperation = false;
576 txOperationsOnComplete.add(operation);
580 if(invokeOperation) {
581 operation.invoke(transactionContext);
586 <T> Future<T> enqueueFutureOperation(final FutureOperation<T> op) {
590 if (transactionContext != null) {
591 future = op.invoke(transactionContext);
593 // The shard Tx hasn't been created yet so add the Tx operation to the Tx Future
594 // callback to be executed after the Tx is created.
595 final Promise<T> promise = akka.dispatch.Futures.promise();
596 addTxOperationOnComplete(new TransactionOperation() {
598 public void invoke(TransactionContext transactionContext) {
599 promise.completeWith(op.invoke(transactionContext));
603 future = promise.future();
609 <T> CheckedFuture<T, ReadFailedException> enqueueReadOperation(final ReadOperation<T> op) {
611 CheckedFuture<T, ReadFailedException> future;
613 if (transactionContext != null) {
614 future = op.invoke(transactionContext);
616 // The shard Tx hasn't been created yet so add the Tx operation to the Tx Future
617 // callback to be executed after the Tx is created.
618 final SettableFuture<T> proxyFuture = SettableFuture.create();
619 addTxOperationOnComplete(new TransactionOperation() {
621 public void invoke(TransactionContext transactionContext) {
622 Futures.addCallback(op.invoke(transactionContext), new FutureCallback<T>() {
624 public void onSuccess(T data) {
625 proxyFuture.set(data);
629 public void onFailure(Throwable t) {
630 proxyFuture.setException(t);
636 future = MappingCheckedFuture.create(proxyFuture, ReadFailedException.MAPPER);
642 void enqueueModifyOperation(final TransactionOperation op) {
644 if (transactionContext != null) {
645 op.invoke(transactionContext);
647 // The shard Tx hasn't been created yet so add the Tx operation to the Tx Future
648 // callback to be executed after the Tx is created.
649 addTxOperationOnComplete(op);
654 * Performs a CreateTransaction try async.
656 private void tryCreateTransaction() {
657 Future<Object> createTxFuture = sendCreateTransaction(primaryShard,
658 new CreateTransaction(identifier.toString(),
659 TransactionProxy.this.transactionType.ordinal(),
660 getTransactionChainId()).toSerializable());
662 createTxFuture.onComplete(this, actorContext.getActorSystem().dispatcher());
666 public void onComplete(Throwable failure, Object response) {
667 if(failure instanceof NoShardLeaderException) {
668 // There's no leader for the shard yet - schedule and try again, unless we're out
669 // of retries. Note: createTxTries is volatile as it may be written by different
670 // threads however not concurrently, therefore decrementing it non-atomically here
672 if(--createTxTries > 0) {
673 LOG.debug("Tx {} Shard {} has no leader yet - scheduling create Tx retry",
674 identifier, shardName);
676 actorContext.getActorSystem().scheduler().scheduleOnce(CREATE_TX_TRY_INTERVAL,
680 tryCreateTransaction();
682 }, actorContext.getActorSystem().dispatcher());
687 // Create the TransactionContext from the response or failure. Store the new
688 // TransactionContext locally until we've completed invoking the
689 // TransactionOperations. This avoids thread timing issues which could cause
690 // out-of-order TransactionOperations. Eg, on a modification operation, if the
691 // TransactionContext is non-null, then we directly call the TransactionContext.
692 // However, at the same time, the code may be executing the cached
693 // TransactionOperations. So to avoid thus timing, we don't publish the
694 // TransactionContext until after we've executed all cached TransactionOperations.
695 TransactionContext localTransactionContext;
696 if(failure != null) {
697 LOG.debug("Tx {} Creating NoOpTransaction because of error: {}", identifier,
698 failure.getMessage());
700 localTransactionContext = new NoOpTransactionContext(failure, identifier, operationLimiter);
701 } else if (response.getClass().equals(CreateTransactionReply.SERIALIZABLE_CLASS)) {
702 localTransactionContext = createValidTransactionContext(
703 CreateTransactionReply.fromSerializable(response));
705 IllegalArgumentException exception = new IllegalArgumentException(String.format(
706 "Invalid reply type %s for CreateTransaction", response.getClass()));
708 localTransactionContext = new NoOpTransactionContext(exception, identifier, operationLimiter);
711 executeTxOperatonsOnComplete(localTransactionContext);
714 private void executeTxOperatonsOnComplete(TransactionContext localTransactionContext) {
716 // Access to txOperationsOnComplete and transactionContext must be protected and atomic
717 // (ie synchronized) with respect to #addTxOperationOnComplete to handle timing
718 // issues and ensure no TransactionOperation is missed and that they are processed
719 // in the order they occurred.
721 // We'll make a local copy of the txOperationsOnComplete list to handle re-entrancy
722 // in case a TransactionOperation results in another transaction operation being
723 // queued (eg a put operation from a client read Future callback that is notified
725 Collection<TransactionOperation> operationsBatch = null;
726 synchronized(txOperationsOnComplete) {
727 if(txOperationsOnComplete.isEmpty()) {
728 // We're done invoking the TransactionOperations so we can now publish the
729 // TransactionContext.
730 transactionContext = localTransactionContext;
734 operationsBatch = new ArrayList<>(txOperationsOnComplete);
735 txOperationsOnComplete.clear();
738 // Invoke TransactionOperations outside the sync block to avoid unnecessary blocking.
739 // A slight down-side is that we need to re-acquire the lock below but this should
741 for(TransactionOperation oper: operationsBatch) {
742 oper.invoke(localTransactionContext);
747 private TransactionContext createValidTransactionContext(CreateTransactionReply reply) {
748 String transactionPath = reply.getTransactionPath();
750 LOG.debug("Tx {} Received transaction actor path {}", identifier, transactionPath);
752 ActorSelection transactionActor = actorContext.actorSelection(transactionPath);
754 if (transactionType == TransactionType.READ_ONLY) {
755 // Add the actor to the remoteTransactionActors list for access by the
756 // cleanup PhantonReference.
757 remoteTransactionActors.add(transactionActor);
759 // Write to the memory barrier volatile to publish the above update to the
760 // remoteTransactionActors list for thread visibility.
761 remoteTransactionActorsMB.set(true);
764 // TxActor is always created where the leader of the shard is.
765 // Check if TxActor is created in the same node
766 boolean isTxActorLocal = actorContext.isPathLocal(transactionPath);
768 return new TransactionContextImpl(transactionPath, transactionActor, identifier,
769 actorContext, schemaContext, isTxActorLocal, reply.getVersion(), operationCompleter);