org.infinispan.interceptors.locking
Class AbstractTxLockingInterceptor

java.lang.Object
  extended by org.infinispan.commands.AbstractVisitor
      extended by org.infinispan.interceptors.base.CommandInterceptor
          extended by org.infinispan.interceptors.locking.AbstractLockingInterceptor
              extended by org.infinispan.interceptors.locking.AbstractTxLockingInterceptor
All Implemented Interfaces:
Visitor
Direct Known Subclasses:
OptimisticLockingInterceptor, PessimisticLockingInterceptor

public abstract class AbstractTxLockingInterceptor
extends AbstractLockingInterceptor

Base class for transaction based locking interceptors.

Since:
5.1
Author:
Mircea.Markus@jboss.com

Field Summary
protected  RpcManager rpcManager
           
protected  TransactionTable txTable
           
 
Fields inherited from class org.infinispan.interceptors.base.CommandInterceptor
configuration
 
Constructor Summary
AbstractTxLockingInterceptor()
           
 
Method Summary
protected  void abortIfRemoteTransactionInvalid(TxInvocationContext ctx, AbstractTransactionBoundaryCommand c)
           
protected  Object invokeNextAndCommitIf1Pc(TxInvocationContext ctx, PrepareCommand command)
           
protected  void lockAndRegisterBackupLock(TxInvocationContext ctx, Object key)
          The backup (non-primary) owners keep a "backup lock" for each key they received in a lock/prepare command.
protected  void lockKeyAndCheckOwnership(InvocationContext ctx, Object key)
          Besides acquiring a lock, this method also handles the following situation: 1.
 void setDependencies(TransactionTable txTable, RpcManager rpcManager)
           
 Object visitCommitCommand(TxInvocationContext ctx, CommitCommand command)
           
 Object visitEvictCommand(InvocationContext ctx, EvictCommand command)
           
 Object visitGetKeyValueCommand(InvocationContext ctx, GetKeyValueCommand command)
           
 Object visitRollbackCommand(TxInvocationContext ctx, RollbackCommand command)
           
 
Methods inherited from class org.infinispan.interceptors.locking.AbstractLockingInterceptor
cleanLocksAndRethrow, lockKey, setDependencies, visitInvalidateCommand, visitInvalidateL1Command
 
Methods inherited from class org.infinispan.interceptors.base.CommandInterceptor
getLog, getNext, handleDefault, hasNext, invokeNextInterceptor, setNext
 
Methods inherited from class org.infinispan.commands.AbstractVisitor
visitApplyDeltaCommand, visitClearCommand, visitCollection, visitDistributedExecuteCommand, visitEntrySetCommand, visitKeySetCommand, visitLockControlCommand, visitPrepareCommand, visitPutKeyValueCommand, visitPutMapCommand, visitRemoveCommand, visitReplaceCommand, visitSizeCommand, visitUnknownCommand, visitValuesCommand
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

txTable

protected TransactionTable txTable

rpcManager

protected RpcManager rpcManager
Constructor Detail

AbstractTxLockingInterceptor

public AbstractTxLockingInterceptor()
Method Detail

setDependencies

public void setDependencies(TransactionTable txTable,
                            RpcManager rpcManager)

visitRollbackCommand

public Object visitRollbackCommand(TxInvocationContext ctx,
                                   RollbackCommand command)
                            throws Throwable
Specified by:
visitRollbackCommand in interface Visitor
Overrides:
visitRollbackCommand in class AbstractVisitor
Throws:
Throwable

visitEvictCommand

public final Object visitEvictCommand(InvocationContext ctx,
                                      EvictCommand command)
                               throws Throwable
Specified by:
visitEvictCommand in interface Visitor
Overrides:
visitEvictCommand in class AbstractVisitor
Throws:
Throwable

visitGetKeyValueCommand

public Object visitGetKeyValueCommand(InvocationContext ctx,
                                      GetKeyValueCommand command)
                               throws Throwable
Specified by:
visitGetKeyValueCommand in interface Visitor
Overrides:
visitGetKeyValueCommand in class AbstractVisitor
Throws:
Throwable

visitCommitCommand

public Object visitCommitCommand(TxInvocationContext ctx,
                                 CommitCommand command)
                          throws Throwable
Specified by:
visitCommitCommand in interface Visitor
Overrides:
visitCommitCommand in class AbstractVisitor
Throws:
Throwable

abortIfRemoteTransactionInvalid

protected final void abortIfRemoteTransactionInvalid(TxInvocationContext ctx,
                                                     AbstractTransactionBoundaryCommand c)

invokeNextAndCommitIf1Pc

protected final Object invokeNextAndCommitIf1Pc(TxInvocationContext ctx,
                                                PrepareCommand command)
                                         throws Throwable
Throws:
Throwable

lockAndRegisterBackupLock

protected final void lockAndRegisterBackupLock(TxInvocationContext ctx,
                                               Object key)
                                        throws InterruptedException
The backup (non-primary) owners keep a "backup lock" for each key they received in a lock/prepare command. Normally there can be many transactions holding the backup lock at the same time, but when the secondary owner becomes a primary owner a new transaction trying to obtain the "real" lock will have to wait for all backup locks to be released. The backup lock will be released either by a commit/rollback/unlock command or by the originator leaving the cluster (if recovery is disabled).

Throws:
InterruptedException

lockKeyAndCheckOwnership

protected final void lockKeyAndCheckOwnership(InvocationContext ctx,
                                              Object key)
                                       throws InterruptedException
Besides acquiring a lock, this method also handles the following situation: 1. consistentHash("k") == {A, B}, tx1 prepared on A and B. Then node A crashed (A == single lock owner) 2. at this point tx2 which also writes "k" tries to prepare on B. 3. tx2 has to determine that "k" is already locked by another tx (i.e. tx1) and it has to wait for that tx to finish before acquiring the lock. The algorithm used at step 3 is: - the transaction table(TT) associates the current view id with every remote and local transaction it creates - TT also keeps track of the minimal value of all the view ids of all the transactions still present in the cache (minViewId) - when a tx wants to acquire lock "k": - if tx.viewId > TT.minViewId then "k" might be a key whose owner crashed. If so: - obtain the list LT of transactions that started in a previous view (txTable.getTransactionsPreparedBefore) - for each t in LT: - if t wants to to write "k" then block until t finishes (CacheTransaction.waitForTransactionsToFinishIfItWritesToKey) - only then try to acquire lock on "k" - if tx.viewId == TT.minViewId try to acquire lock straight away. Note: The algorithm described below only when nodes leave the cluster, so it doesn't add a performance burden when the cluster is stable.

Throws:
InterruptedException

-->

Copyright © 2012 JBoss, a division of Red Hat. All Rights Reserved.