Package org.infinispan.transaction.xa

Examples of org.infinispan.transaction.xa.DeadlockDetectingGlobalTransaction


      return false;
   }

   private void localVsLocalDld(InvocationContext ctx, DeadlockDetectingGlobalTransaction lockOwnerTx) {
      if (trace) log.trace("Looking for local vs local deadlocks");
      DeadlockDetectingGlobalTransaction thisThreadsTx = (DeadlockDetectingGlobalTransaction) ctx.getLockOwner();
      boolean weOwnLock = ownsLock(lockOwnerTx.getLockInterntion(), thisThreadsTx);
      if (trace) {
         log.trace("Other owner's intention is " + lockOwnerTx.getLockInterntion() + ". Do we(" + thisThreadsTx + ") own lock for it? " + weOwnLock + ". Lock owner is " + getOwner(lockOwnerTx.getLockInterntion()));
      }
      if (weOwnLock) {
         boolean iShouldInterrupt = thisThreadsTx.thisWillInterrupt(lockOwnerTx);
         if (trace)
            log.trace("deadlock situation detected. Shall I interrupt?" + iShouldInterrupt );
         if (iShouldInterrupt) {
            lockOwnerTx.interruptProcessingThread();
            if (exposeJmxStats) detectedLocalDeadlocks.incrementAndGet();
View Full Code Here


   }

   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

      }
   }

   private Object handleDataCommand(InvocationContext ctx, DataCommand command) throws Throwable {
      if (ctx.isInTxScope()) {
         DeadlockDetectingGlobalTransaction gtx = (DeadlockDetectingGlobalTransaction) ctx.getLockOwner();
         gtx.setLockInterntion(command.getKey());
         gtx.setProcessingThread(Thread.currentThread());
      }
      try {
         return invokeNextInterceptor(ctx, command);
      } catch (InterruptedException ie) {
         if (ctx.isInTxScope()) {
            lockManager.releaseLocks(ctx);
            if (ctx.isOriginLocal()) {
               Transaction transaction = txManager.getTransaction();
               if (trace)
                  log.trace("Marking the transaction for rollback! : " + transaction);
               if (transaction == null) {
                  throw new IllegalStateException("We're running in a local transaction, there MUST be one " +
                        "associated witht the local thread but none found! (null)");
               }
               transaction.setRollbackOnly();
               txTable.removeLocalTransaction(transaction);
               throw new DeadlockDetectedException("Deadlock request was detected for locally originated tx " + transaction +
                     "; it was marked for rollback");
            } else {
               DeadlockDetectingGlobalTransaction gtx = (DeadlockDetectingGlobalTransaction) ctx.getLockOwner();
               gtx.setMarkedForRollback(true);
               throw new DeadlockDetectedException("Deadlock request was detected for remotely originated tx " + gtx +
                     "; it was marked for rollback");
            }
         } else {
            if (trace)
View Full Code Here

      return handleDataCommand(ctx, command);
   }

   @Override
   public Object visitPrepareCommand(TxInvocationContext ctx, PrepareCommand command) throws Throwable {
      DeadlockDetectingGlobalTransaction globalTransaction = (DeadlockDetectingGlobalTransaction) ctx.getGlobalTransaction();
      globalTransaction.setProcessingThread(Thread.currentThread());
      if (ctx.isOriginLocal()) {
         if (configuration.getCacheMode().isDistributed()) {
            globalTransaction.setReplicatingTo(new HashSet<Address>(distributionManager.getAffectedNodes(ctx.getAffectedKeys())));
         } else {
            globalTransaction.setReplicatingTo(null);
         }
         if (trace) log.trace("Deadlock detection information was added to " + globalTransaction);
      }
      try {
         return invokeNextInterceptor(ctx, command);
      } catch (Throwable dde) {
         if (ctx.isOriginLocal()) {
            globalTransaction.setMarkedForRollback(true);
            boolean wasInterrupted = Thread.interrupted();
            if (trace)
               log.trace("Deadlock was detected on the remote side, marking the tx for rollback. Was this thread interrupted? " + wasInterrupted);
         }
         throw dde;
View Full Code Here

   }

   @Override
   public Object visitRollbackCommand(TxInvocationContext ctx, RollbackCommand command) throws Throwable {
      if (!ctx.isOriginLocal()) {
         DeadlockDetectingGlobalTransaction globalTransaction = (DeadlockDetectingGlobalTransaction) ctx.getGlobalTransaction();
         globalTransaction.interruptProcessingThread();
      }
      return invokeNextInterceptor(ctx, command);
   }
View Full Code Here

      }
   }

   private Object handleDataCommand(InvocationContext ctx, DataCommand command) throws Throwable {
      if (ctx.isInTxScope()) {
         DeadlockDetectingGlobalTransaction gtx = (DeadlockDetectingGlobalTransaction) ctx.getLockOwner();
         gtx.setLockInterntion(command.getKey());
         gtx.setProcessingThread(Thread.currentThread());
      }
      try {
         return invokeNextInterceptor(ctx, command);
      } catch (InterruptedException ie) {
         if (ctx.isInTxScope()) {
            lockManager.releaseLocks(ctx);
            if (ctx.isOriginLocal()) {
               Transaction transaction = txManager.getTransaction();
               if (trace)
                  log.trace("Marking the transaction for rollback! : " + transaction);
               if (transaction == null) {
                  throw new IllegalStateException("We're running in a local transaction, there MUST be one " +
                        "associated witht the local thread but none found! " + transaction);
               }
               transaction.setRollbackOnly();
               txTable.removeLocalTransaction(transaction);
               throw new DeadlockDetectedException("Deadlock request was detected for locally originated tx " + transaction +
                     "; it was marked for rollback");
            } else {
               DeadlockDetectingGlobalTransaction gtx = (DeadlockDetectingGlobalTransaction) ctx.getLockOwner();
               gtx.setMarkedForRollback(true);
               throw new DeadlockDetectedException("Deadlock request was detected for remotely originated tx " + gtx +
                     "; it was marked for rollback");
            }
         } else {
            if (trace)
View Full Code Here

      return handleDataCommand(ctx, command);
   }

   @Override
   public Object visitPrepareCommand(TxInvocationContext ctx, PrepareCommand command) throws Throwable {
      DeadlockDetectingGlobalTransaction globalTransaction = (DeadlockDetectingGlobalTransaction) ctx.getGlobalTransaction();
      globalTransaction.setProcessingThread(Thread.currentThread());
      if (ctx.isOriginLocal()) {
         if (configuration.getCacheMode().isDistributed()) {
            Set<Address> transactionParticipants = ctx.getTransactionParticipants();
            globalTransaction.setReplicatingTo(transactionParticipants);
         } else {
            globalTransaction.setReplicatingTo(null);
         }
         if (trace) log.trace("Deadlock detection information was added to " + globalTransaction);
      }
      try {
         return invokeNextInterceptor(ctx, command);
      } catch (Throwable dde) {
         if (ctx.isOriginLocal()) {
            globalTransaction.setMarkedForRollback(true);
            boolean wasInterrupted = Thread.interrupted();
            if (trace)
               log.trace("Deadlock was detected on the remote side, marking the tx for rollback. Was this thread interrupted? " + wasInterrupted);
         }
         throw dde;
View Full Code Here

   }

   @Override
   public Object visitRollbackCommand(TxInvocationContext ctx, RollbackCommand command) throws Throwable {
      if (!ctx.isOriginLocal()) {
         DeadlockDetectingGlobalTransaction globalTransaction = (DeadlockDetectingGlobalTransaction) ctx.getGlobalTransaction();
         globalTransaction.interruptProcessingThread();
      }
      return invokeNextInterceptor(ctx, command);
   }
View Full Code Here

      }
   }

   private Object handleDataCommand(InvocationContext ctx, DataCommand command) throws Throwable {
      if (ctx.isInTxScope()) {
         DeadlockDetectingGlobalTransaction gtx = (DeadlockDetectingGlobalTransaction) ctx.getLockOwner();
         gtx.setLockIntention(command.getKey());
         gtx.setProcessingThread(Thread.currentThread());
      }
      try {
         return invokeNextInterceptor(ctx, command);
      } catch (InterruptedException ie) {
         if (ctx.isInTxScope()) {
            lockManager.releaseLocks(ctx);
            if (ctx.isOriginLocal()) {
               Transaction transaction = txManager.getTransaction();
               if (trace)
                  log.trace("Marking the transaction for rollback! : " + transaction);
               if (transaction == null) {
                  throw new IllegalStateException("We're running in a local transaction, there MUST be one " +
                        "associated witht the local thread but none found! (null)");
               }
               transaction.setRollbackOnly();
               txTable.removeLocalTransaction(transaction);
               throw new DeadlockDetectedException("Deadlock request was detected for locally originated tx " + transaction +
                     "; it was marked for rollback");
            } else {
               DeadlockDetectingGlobalTransaction gtx = (DeadlockDetectingGlobalTransaction) ctx.getLockOwner();
               gtx.setMarkedForRollback(true);
               throw new DeadlockDetectedException("Deadlock request was detected for remotely originated tx " + gtx +
                     "; it was marked for rollback");
            }
         } else {
            if (trace)
View Full Code Here

      return handleDataCommand(ctx, command);
   }

   @Override
   public Object visitPrepareCommand(TxInvocationContext ctx, PrepareCommand command) throws Throwable {
      DeadlockDetectingGlobalTransaction globalTransaction = (DeadlockDetectingGlobalTransaction) ctx.getGlobalTransaction();
      globalTransaction.setProcessingThread(Thread.currentThread());
      if (ctx.isOriginLocal()) {
         if (configuration.getCacheMode().isDistributed()) {
            globalTransaction.setReplicatingTo(new HashSet<Address>(distributionManager.getAffectedNodes(ctx.getAffectedKeys())));
         } else {
            globalTransaction.setReplicatingTo(null);
         }
         if (trace) log.trace("Deadlock detection information was added to " + globalTransaction);
      }
      try {
         return invokeNextInterceptor(ctx, command);
      } catch (Throwable dde) {
         if (ctx.isOriginLocal()) {
            globalTransaction.setMarkedForRollback(true);
            boolean wasInterrupted = Thread.interrupted();
            if (trace)
               log.trace("Deadlock was detected on the remote side, marking the tx for rollback. Was this thread interrupted? " + wasInterrupted);
         }
         throw dde;
View Full Code Here

TOP

Related Classes of org.infinispan.transaction.xa.DeadlockDetectingGlobalTransaction

Copyright © 2018 www.massapicom. 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.