org.infinispan.distribution
Class TransactionLoggerImpl

java.lang.Object
  extended by org.infinispan.distribution.TransactionLoggerImpl
All Implemented Interfaces:
RemoteTransactionLogger, TransactionLogger

public class TransactionLoggerImpl
extends Object
implements TransactionLogger

A transaction logger to log ongoing transactions in an efficient and thread-safe manner while a rehash is going on.

Transaction logs can then be replayed after the state transferred during a rehash has been written.

Since:
4.0
Author:
Manik Surtani, Dan Berindei

Constructor Summary
TransactionLoggerImpl(CommandsFactory cf, Configuration config)
           
 
Method Summary
 void afterCommand(InvocationContext ctx, WriteCommand command)
          Logs a write command (if needed).
 void afterCommand(TxInvocationContext ctx, CommitCommand command)
          Logs a CommitCommand if needed.
 void afterCommand(TxInvocationContext ctx, LockControlCommand command)
          Notify the transaction logger after a lock control command.
 void afterCommand(TxInvocationContext ctx, PrepareCommand command)
          Logs a PrepareCommand if needed.
 void afterCommand(TxInvocationContext ctx, RollbackCommand command)
          Logs a RollbackCommand if needed.
 boolean areTransactionsBlocked()
           
 boolean beforeCommand(InvocationContext ctx, WriteCommand command)
          Notify the transaction logger before a write command, potentially blocking.
 boolean beforeCommand(TxInvocationContext ctx, CommitCommand command)
          Notify the transaction logger before a commit command, potentially blocking.
 boolean beforeCommand(TxInvocationContext ctx, LockControlCommand cmd)
          Notify the transaction logger before a lock control command, potentially blocking
 boolean beforeCommand(TxInvocationContext ctx, PrepareCommand command)
          Notify the transaction logger before a prepare command, potentially blocking.
 boolean beforeCommand(TxInvocationContext ctx, RollbackCommand command)
          Notify the transaction logger before a rollback command, potentially blocking.
 void blockNewTransactions()
          Causes new transactions to block when calling beforeCommand().
 List<WriteCommand> drain()
          Drains the transaction log and returns a list of what has been drained.
 List<WriteCommand> drainAndLock()
          Similar to RemoteTransactionLogger.drain() except that relevant locks are acquired so that no more commands are added to the transaction log during this process, and transaction logging is disabled after draining.
 void enable()
          Enables transaction logging
 Collection<PrepareCommand> getPendingPrepares()
          Drains pending prepares.
 boolean isEnabled()
          Checks whether transaction logging is enabled
 void resumeTransactionLock(InvocationContext ctx)
          Re-acquire the transaction lock when a remote call returns.
 boolean shouldDrainWithoutLock()
          Tests whether the drain() method can be called without a lock.
 void suspendTransactionLock(InvocationContext ctx)
          Use before synchronous remote calls, as the remote call will also try to acquire the transaction lock on that node.
 String toString()
           
 void unblockNewTransactions()
          Unblocks anything blocking on beforeCommand().
 void unlockAndDisable()
          Unlocks and disables the transaction logger.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TransactionLoggerImpl

public TransactionLoggerImpl(CommandsFactory cf,
                             Configuration config)
Method Detail

enable

public void enable()
Description copied from interface: TransactionLogger
Enables transaction logging

Specified by:
enable in interface TransactionLogger

drain

public List<WriteCommand> drain()
Description copied from interface: RemoteTransactionLogger
Drains the transaction log and returns a list of what has been drained.

Specified by:
drain in interface RemoteTransactionLogger
Returns:
a list of drained commands

drainAndLock

public List<WriteCommand> drainAndLock()
                                throws InterruptedException
Description copied from interface: RemoteTransactionLogger
Similar to RemoteTransactionLogger.drain() except that relevant locks are acquired so that no more commands are added to the transaction log during this process, and transaction logging is disabled after draining.

Specified by:
drainAndLock in interface RemoteTransactionLogger
Returns:
list of drained commands
Throws:
InterruptedException

unlockAndDisable

public void unlockAndDisable()
Description copied from interface: RemoteTransactionLogger
Unlocks and disables the transaction logger. Should only be called after RemoteTransactionLogger.drainAndLock().

Specified by:
unlockAndDisable in interface RemoteTransactionLogger

afterCommand

public void afterCommand(InvocationContext ctx,
                         WriteCommand command)
                  throws InterruptedException
Description copied from interface: TransactionLogger
Logs a write command (if needed).

Specified by:
afterCommand in interface TransactionLogger
command - command to log
Throws:
InterruptedException

afterCommand

public void afterCommand(TxInvocationContext ctx,
                         PrepareCommand command)
                  throws InterruptedException
Description copied from interface: TransactionLogger
Logs a PrepareCommand if needed.

Specified by:
afterCommand in interface TransactionLogger
command - PrepoareCommand to log
Throws:
InterruptedException

afterCommand

public void afterCommand(TxInvocationContext ctx,
                         CommitCommand command)
                  throws InterruptedException
Description copied from interface: TransactionLogger
Logs a CommitCommand if needed.

Specified by:
afterCommand in interface TransactionLogger
command - CommitCommand to log
Throws:
InterruptedException

afterCommand

public void afterCommand(TxInvocationContext ctx,
                         RollbackCommand command)
Description copied from interface: TransactionLogger
Logs a RollbackCommand if needed.

Specified by:
afterCommand in interface TransactionLogger
command - RollbackCommand to log

afterCommand

public void afterCommand(TxInvocationContext ctx,
                         LockControlCommand command)
Description copied from interface: TransactionLogger
Notify the transaction logger after a lock control command.

Specified by:
afterCommand in interface TransactionLogger

beforeCommand

public boolean beforeCommand(InvocationContext ctx,
                             WriteCommand command)
                      throws InterruptedException,
                             TimeoutException
Description copied from interface: TransactionLogger
Notify the transaction logger before a write command, potentially blocking.

Specified by:
beforeCommand in interface TransactionLogger
Returns:
true if the transaction can proceed, false otherwise
Throws:
InterruptedException
TimeoutException

beforeCommand

public boolean beforeCommand(TxInvocationContext ctx,
                             PrepareCommand command)
                      throws InterruptedException,
                             TimeoutException
Description copied from interface: TransactionLogger
Notify the transaction logger before a prepare command, potentially blocking.

Specified by:
beforeCommand in interface TransactionLogger
Returns:
true if the transaction can proceed, false otherwise
Throws:
InterruptedException
TimeoutException

beforeCommand

public boolean beforeCommand(TxInvocationContext ctx,
                             CommitCommand command)
                      throws InterruptedException,
                             TimeoutException
Description copied from interface: TransactionLogger
Notify the transaction logger before a commit command, potentially blocking. If transaction logging was not enabled during the prepare command, use the context to extract the list of modifications.

Specified by:
beforeCommand in interface TransactionLogger
Returns:
true if the transaction can proceed, false otherwise
Throws:
InterruptedException
TimeoutException

beforeCommand

public boolean beforeCommand(TxInvocationContext ctx,
                             RollbackCommand command)
                      throws InterruptedException,
                             TimeoutException
Description copied from interface: TransactionLogger
Notify the transaction logger before a rollback command, potentially blocking.

Specified by:
beforeCommand in interface TransactionLogger
Returns:
true if the transaction can proceed, false otherwise
Throws:
InterruptedException
TimeoutException

beforeCommand

public boolean beforeCommand(TxInvocationContext ctx,
                             LockControlCommand cmd)
                      throws TimeoutException,
                             InterruptedException
Description copied from interface: TransactionLogger
Notify the transaction logger before a lock control command, potentially blocking

Specified by:
beforeCommand in interface TransactionLogger
Returns:
true if the transaction can proceed, false otherwise
Throws:
TimeoutException
InterruptedException

suspendTransactionLock

public void suspendTransactionLock(InvocationContext ctx)
Description copied from interface: TransactionLogger
Use before synchronous remote calls, as the remote call will also try to acquire the transaction lock on that node. Since the rehashing process may try to acquire the same locks in reverse order, this could lead to deadlocks.

Specified by:
suspendTransactionLock in interface TransactionLogger

resumeTransactionLock

public void resumeTransactionLock(InvocationContext ctx)
                           throws TimeoutException,
                                  InterruptedException
Description copied from interface: TransactionLogger
Re-acquire the transaction lock when a remote call returns.

Specified by:
resumeTransactionLock in interface TransactionLogger
Throws:
TimeoutException
InterruptedException

isEnabled

public boolean isEnabled()
Description copied from interface: TransactionLogger
Checks whether transaction logging is enabled

Specified by:
isEnabled in interface TransactionLogger
Returns:
true if enabled, false otherwise.

shouldDrainWithoutLock

public boolean shouldDrainWithoutLock()
Description copied from interface: RemoteTransactionLogger
Tests whether the drain() method can be called without a lock. This is usually true if there is a lot of stuff to drain. After a certain threshold (once there are relatively few entries in the tx log) this will return false after which you should call drainAndLock() to clear the final parts of the log.

Specified by:
shouldDrainWithoutLock in interface RemoteTransactionLogger
Returns:
true if drain() should be called, false if drainAndLock() should be called.

getPendingPrepares

public Collection<PrepareCommand> getPendingPrepares()
Description copied from interface: RemoteTransactionLogger
Drains pending prepares. Note that this should *only* be done after calling drainAndLock() to prevent race conditions

Specified by:
getPendingPrepares in interface RemoteTransactionLogger
Returns:
a list of prepares pending commit or rollback

blockNewTransactions

public void blockNewTransactions()
                          throws InterruptedException
Description copied from interface: TransactionLogger
Causes new transactions to block when calling beforeCommand().

Specified by:
blockNewTransactions in interface TransactionLogger
Throws:
InterruptedException

unblockNewTransactions

public void unblockNewTransactions()
Description copied from interface: TransactionLogger
Unblocks anything blocking on beforeCommand().

Specified by:
unblockNewTransactions in interface TransactionLogger

areTransactionsBlocked

public boolean areTransactionsBlocked()
Specified by:
areTransactionsBlocked in interface TransactionLogger
Returns:
true if new transactions are blocked and false otherwise.

toString

public String toString()
Overrides:
toString in class Object

-->

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