Examples of TxInvocationContext


Examples of org.infinispan.context.impl.TxInvocationContext

      try {
         retval = command.perform(ctx);
      }
      catch (Throwable t) {
         if (ctx.isInTxScope()) {
            TxInvocationContext txContext = (TxInvocationContext) ctx;
            if (txContext.isValidRunningTx()) {
               txContext.getRunningTransaction().setRollbackOnly();
            }
         }
         throw t;
      }
      return retval;
View Full Code Here

Examples of org.infinispan.context.impl.TxInvocationContext

      long lockTimeout = getLockAcquisitionTimeout(ctx);
      if (trace) log.tracef("Attempting to lock %s with acquisition timeout of %s millis", key, lockTimeout);
      if (lockContainer.acquireLock(key, lockTimeout, MILLISECONDS) != null) {
         // successfully locked!
         if (ctx instanceof TxInvocationContext) {
            TxInvocationContext tctx = (TxInvocationContext) ctx;
            if (!tctx.isTransactionValid()) {
               Transaction tx = tctx.getTransaction();
               log.debugf("Successfully acquired lock, but the transaction %s is no longer valid!  Releasing lock.", tx);
               lockContainer.releaseLock(key);
               throw new IllegalStateException("Transaction "+tx+" appears to no longer be valid!");
            }
         }
View Full Code Here

Examples of org.infinispan.context.impl.TxInvocationContext

         }
         //create a remote tx without any modifications (we do not know modifications ahead of time)
         transaction = txTable.createRemoteTransaction(globalTx);
      }
      ctxt.setRemoteTransaction(transaction);
      TxInvocationContext ctx = ctxt;
      if (flags != null && !flags.isEmpty()) {
         ctx = new TransactionalInvocationContextFlagsOverride(ctxt, flags);
      }
      return invoker.invoke(ctx, this);
   }
View Full Code Here

Examples of org.infinispan.context.impl.TxInvocationContext

         }
      }
   }

   private boolean remoteVsRemoteDld(Object key, InvocationContext ctx, long lockTimeout, long start, long now, DeadlockDetectingGlobalTransaction lockOwnerTx) throws InterruptedException {
      TxInvocationContext remoteTxContext = (TxInvocationContext) ctx;
      Address origin = remoteTxContext.getGlobalTransaction().getAddress();
      DeadlockDetectingGlobalTransaction remoteGlobalTransaction = (DeadlockDetectingGlobalTransaction) ctx.getLockOwner();
      boolean thisShouldInterrupt = remoteGlobalTransaction.thisWillInterrupt(lockOwnerTx);
      if (trace) log.trace("Should I interrupt other transaction ? " + thisShouldInterrupt);
      boolean isDeadLock = (configuration.getCacheMode().isReplicated() || lockOwnerTx.isReplicatingTo(origin)) && !lockOwnerTx.isRemote();
      if (thisShouldInterrupt && isDeadLock) {
         lockOwnerTx.interruptProcessingThread();
         if (exposeJmxStats) {
            detectedRemoteDeadlocks.incrementAndGet();
            locallyInterruptedTransactions.incrementAndGet();
         }
         return lockForTheRemainingTime(key, lockTimeout, start, now);
      } else if (!isDeadLock) {
         return lockForTheRemainingTime(key, lockTimeout, start, now);
      } else {
         if (trace)
            log.trace("Not trying to acquire lock anymore, as we're in deadlock and this will be rollback at origin");
         if (exposeJmxStats) {
            detectedRemoteDeadlocks.incrementAndGet();
         }
         remoteGlobalTransaction.setMarkedForRollback(true);
         throw new DeadlockDetectedException("Deadlock situation detected on tx: " + remoteTxContext.getLockOwner());
      }
   }
View Full Code Here

Examples of org.infinispan.context.impl.TxInvocationContext

         }
      }
   }

   private boolean remoteVsRemoteDld(Object key, InvocationContext ctx, long lockTimeout, long start, long now, DeadlockDetectingGlobalTransaction lockOwnerTx) throws InterruptedException {
      TxInvocationContext remoteTxContext = (TxInvocationContext) ctx;
      Address origin = remoteTxContext.getGlobalTransaction().getAddress();
      DeadlockDetectingGlobalTransaction remoteGlobalTransaction = (DeadlockDetectingGlobalTransaction) ctx.getLockOwner();
      boolean thisShouldInterrupt = remoteGlobalTransaction.thisWillInterrupt(lockOwnerTx);
      if (trace) log.trace("Should I interrupt other transaction ? " + thisShouldInterrupt);
      boolean isDeadLock = (configuration.getCacheMode().isReplicated() || lockOwnerTx.isReplicatingTo(origin)) && !lockOwnerTx.isRemote();
      if (thisShouldInterrupt && isDeadLock) {
         lockOwnerTx.interruptProcessingThread();
         if (exposeJmxStats) {
            detectedRemoteDeadlocks.incrementAndGet();
            locallyInterruptedTransactions.incrementAndGet();
         }
         return lockForTheRemainingTime(key, lockTimeout, start, now);
      } else if (!isDeadLock) {
         return lockForTheRemainingTime(key, lockTimeout, start, now);
      } else {
         if (trace)
            log.trace("Not trying to acquire lock anymore, as we're in deadlock and this will be rollback at origin");
         if (exposeJmxStats) {
            detectedRemoteDeadlocks.incrementAndGet();
         }
         remoteGlobalTransaction.setMarkedForRollback(true);
         throw new DeadlockDetectedException("Deadlock situation detected on tx: " + remoteTxContext.getLockOwner());
      }
   }
View Full Code Here

Examples of org.infinispan.context.impl.TxInvocationContext

   public Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand command) throws Throwable {
      // needed by the stat transfer.
      if (command.hasFlag(Flag.SKIP_LOCKING))
         return invokeNextInterceptor(ctx, command);

      final TxInvocationContext txContext = (TxInvocationContext) ctx;
      try {
         // The primary owner check doesn't work for preload, as we don't have a topology yet
         boolean localOnly = command.hasFlag(Flag.CACHE_MODE_LOCAL);
         boolean localLock = localOnly || cdl.localNodeIsPrimaryOwner(command.getKey());
         acquireRemoteIfNeeded(ctx, command, localLock);
         if (localLock) {
            boolean skipLocking = hasSkipLocking(command);
            long lockTimeout = getLockAcquisitionTimeout(command, skipLocking);
            lockKeyAndCheckOwnership(ctx, command.getKey(), lockTimeout, skipLocking);
         } else if (cdl.localNodeIsOwner(command.getKey())) {
            txContext.getCacheTransaction().addBackupLockForKey(command.getKey());
         }
         return invokeNextInterceptor(ctx, command);
      } catch (Throwable te) {
         releaseLocksOnFailureBeforePrepare(ctx);
         throw te;
View Full Code Here

Examples of org.infinispan.context.impl.TxInvocationContext

   @Override
   public Object visitPutMapCommand(InvocationContext ctx, PutMapCommand command) throws Throwable {
      try {
         acquireRemoteIfNeeded(ctx, command.getMap().keySet(), command);
         final TxInvocationContext txContext = (TxInvocationContext) ctx;
         boolean skipLocking = hasSkipLocking(command);
         long lockTimeout = getLockAcquisitionTimeout(command, skipLocking);
         for (Object key : command.getMap().keySet()) {
            lockAndRegisterBackupLock(txContext, key, lockTimeout, skipLocking);
         }
View Full Code Here

Examples of org.infinispan.context.impl.TxInvocationContext

   @Override
   public Object visitRemoveCommand(InvocationContext ctx, RemoveCommand command) throws Throwable {
      try {
         final boolean localNodeOwnsLock = cdl.localNodeIsPrimaryOwner(command.getKey());
         acquireRemoteIfNeeded(ctx, command, localNodeOwnsLock);
         final TxInvocationContext txContext = (TxInvocationContext) ctx;
         boolean skipLocking = hasSkipLocking(command);
         long lockTimeout = getLockAcquisitionTimeout(command, skipLocking);
         lockAndRegisterBackupLock(txContext, command.getKey(),
               localNodeOwnsLock, lockTimeout, skipLocking);
         return invokeNextInterceptor(ctx, command);
View Full Code Here

Examples of org.infinispan.context.impl.TxInvocationContext

   @Override
   public Object visitReplaceCommand(InvocationContext ctx, ReplaceCommand command) throws Throwable {
      try {
         final boolean localNodeOwnsLock = cdl.localNodeIsPrimaryOwner(command.getKey());
         acquireRemoteIfNeeded(ctx, command, localNodeOwnsLock);
         final TxInvocationContext txContext = (TxInvocationContext) ctx;
         boolean skipLocking = hasSkipLocking(command);
         long lockTimeout = getLockAcquisitionTimeout(command, skipLocking);
         lockAndRegisterBackupLock(txContext, command.getKey(),
               localNodeOwnsLock, lockTimeout, skipLocking);
         return invokeNextInterceptor(ctx, command);
View Full Code Here

Examples of org.infinispan.context.impl.TxInvocationContext

      }
   }

   private void acquireRemoteIfNeeded(InvocationContext ctx, Set<Object> keys, FlagAffectedCommand command) throws Throwable {
      if (ctx.isOriginLocal() && !command.hasFlag(Flag.CACHE_MODE_LOCAL)) {
         final TxInvocationContext txContext = (TxInvocationContext) ctx;
         LocalTransaction localTransaction = (LocalTransaction) txContext.getCacheTransaction();
         if (localTransaction.getAffectedKeys().containsAll(keys)) {
            log.tracef("We already have lock for keys %s, skip remote lock acquisition", keys);
            return;
         } else {
            LockControlCommand lcc = cf.buildLockControlCommand(keys,
                  command.getFlags(), txContext.getGlobalTransaction());
            invokeNextInterceptor(ctx, lcc);
         }
      }
      ((TxInvocationContext) ctx).addAllAffectedKeys(keys);
   }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.