org.apache.derby.impl.store.raw.xact
Class TransactionTable

java.lang.Object
  extended byorg.apache.derby.impl.store.raw.xact.TransactionTable
All Implemented Interfaces:
java.io.Externalizable, Formatable, java.io.Serializable, TypedFormat

public class TransactionTable
extends java.lang.Object
implements Formatable

The transaction table is used by the transaction factory to keep track of all transactions that are in the system.
The transction table serves the following purposes:

  1. checkpoint - when a checkpoint log record is written out, it writes out also all transactions that have updated the database. RESOLVE: this is actually not used right now - rather, the transaction table is reconstructed during the redo phase by traversing from the undo LWM. It is a goal to use this transaction table (and traversing from the redoLWM) instead of rebuilding it to speed up recovery.
  2. Quiesce State - when a system enters the quiesce state, it needs to account for all transactions in the system, even those which are just started and are in their IDLE state.
  3. TransactionTable VTI - we need to get a snapshot of all transactions in the system for diagnostic purposes.
In order to speed up the time it takes to look up a transaction from the transaction table, each transaction must have a unique transaction Id. This means newly coined transaction must also have a transaction Id.

During recovery, there is only one real xact object doing all the recovery work, but there could be many outstanding transactions that are gleamed from the log. Each of these "recovery transactions" have its on entry into the transaction table but they all share the same Xact object.

Multithreading considerations:
TransactionTable must be MT-safe it is called upon by many threads simultaneously (except during recovery)

This class depends on Hashtable synchronization!!

See Also:
Serialized Form

Field Summary
private  TransactionId largestUpdateXactId
           
private  java.util.Hashtable trans
           
 
Constructor Summary
TransactionTable()
          MT - not needed for constructor
 
Method Summary
(package private)  void add(Xact xact, boolean exclude)
           
 void addUpdateTransaction(TransactionId tid, RawTransaction tran, int transactionStatus)
          Change a transaction to update or add an update transaction to this table.
(package private)  boolean findAndAssumeTransaction(TransactionId id, RawTransaction tran)
          Find a transaction using the transaction id, and make the passed in transaction assume the identity and properties of that transaction.
 ContextManager findTransactionContextByGlobalId(GlobalXactId global_id)
          Find a transaction in the table by Global transaction id.
private  TransactionTableEntry findTransactionEntry(TransactionId id)
          generic methods called by all clients of transaction table Must be MT -safe
 LogInstant getFirstLogInstant()
          Get the least recently added (oldest) transaction
 boolean getMostRecentPreparedRecoveredXact(RawTransaction tran)
          Get the most recent recovered prepared transaction.
 boolean getMostRecentRollbackFirstTransaction(RawTransaction tran)
          Get the most recently added transaction that says it needs to be rolled back first (an InternalXact) from the transaction table and make the passed in transaction assume its identity.
 boolean getMostRecentTransactionForRollback(RawTransaction tran)
          Get the most recently non-prepared added transaction from the transaction table and make the passed in transaction assume its identity.
 java.util.Hashtable getTableForXA()
          Return the hash table to the XA layer.
 TransactionInfo[] getTransactionInfo()
          Get a printable version of the transaction table
 int getTypeFormatId()
          Return my format identifier.
(package private)  boolean hasActiveUpdateTransaction()
          Return true if there is no transaction actively updating the database.
 boolean hasPreparedRecoveredXact()
          Is there a prepared transaction in the transaction table.
 boolean hasRollbackFirstTransaction()
          Is there an active internal transaction in the transaction table.
 TransactionId largestUpdateXactId()
          Return the largest update transactionId I have seen so far.
(package private)  void prepareTransaction(TransactionId id)
          Change transaction to prepared.
 void readExternal(java.io.ObjectInput in)
           
(package private)  boolean remove(TransactionId id)
           
(package private)  void removeUpdateTransaction(TransactionId id)
          Change update transaction to non-update MT - MT safe, since vector is MT-safe.
 java.lang.String toString()
           
 void writeExternal(java.io.ObjectOutput out)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

trans

private java.util.Hashtable trans

largestUpdateXactId

private TransactionId largestUpdateXactId
Constructor Detail

TransactionTable

public TransactionTable()
MT - not needed for constructor

Method Detail

findTransactionEntry

private TransactionTableEntry findTransactionEntry(TransactionId id)
generic methods called by all clients of transaction table Must be MT -safe


add

void add(Xact xact,
         boolean exclude)

remove

boolean remove(TransactionId id)

addUpdateTransaction

public void addUpdateTransaction(TransactionId tid,
                                 RawTransaction tran,
                                 int transactionStatus)
Change a transaction to update or add an update transaction to this table.

Parameters:
tid - the transaction id
tran - the transaction to be added
transactionStatus - the transaction status that is stored in the BeginXact log record

removeUpdateTransaction

void removeUpdateTransaction(TransactionId id)
Change update transaction to non-update

MT - MT safe, since vector is MT-safe.

Parameters:
id - the transaction Id

getTableForXA

public java.util.Hashtable getTableForXA()
Return the hash table to the XA layer.

The XA code will do linear read-only operations on the hash table, write operations are only done in this module. It is a little ugly to export the hash table, but I wanted to move the XA specific code into the XA module, so that we could configure out the XA code if necessary.

Must be MT -safe, depends on sync hash table, and must get synchronized(hash_table) for linear searches.

Returns:
The ContextManager of the transaction being searched for.

prepareTransaction

void prepareTransaction(TransactionId id)
Change transaction to prepared.

MT - unsafe, caller is recovery, which is single threaded.

Parameters:
id - the transaction Id

findTransactionContextByGlobalId

public ContextManager findTransactionContextByGlobalId(GlobalXactId global_id)
Find a transaction in the table by Global transaction id.

Only called by XactXAResourceManager.find() during offline recovery of in-doubt transactions, we do not expect this to be called often so performance is not critical. Just to linear search of id's.

Parameters:
global_id - The global transaction we are searching for.
Returns:
The ContextManager of the transaction being searched for.

hasActiveUpdateTransaction

boolean hasActiveUpdateTransaction()
Return true if there is no transaction actively updating the database. New transaction may be started or old transaction committed right afterward, the caller of this routine must have other ways to stop transactions from starting or ending.

MT - safe


getTypeFormatId

public int getTypeFormatId()
Return my format identifier.

Specified by:
getTypeFormatId in interface TypedFormat
Returns:
The identifier. (A UUID stuffed in an array of 16 bytes).

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Specified by:
writeExternal in interface java.io.Externalizable
Throws:
java.io.IOException - problem reading the transaction table

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Specified by:
readExternal in interface java.io.Externalizable
Throws:
java.io.IOException - problem reading the transaction table
java.lang.ClassNotFoundException - problem reading the transaction table

largestUpdateXactId

public TransactionId largestUpdateXactId()
Return the largest update transactionId I have seen so far.

MT - unsafe, caller is recovery, which is single threaded.


hasRollbackFirstTransaction

public boolean hasRollbackFirstTransaction()
Is there an active internal transaction in the transaction table.

MT - unsafe, caller is recovery, which is single threaded.


hasPreparedRecoveredXact

public boolean hasPreparedRecoveredXact()
Is there a prepared transaction in the transaction table.

MT - unsafe, caller is recovery, which is single threaded.


getMostRecentRollbackFirstTransaction

public boolean getMostRecentRollbackFirstTransaction(RawTransaction tran)
Get the most recently added transaction that says it needs to be rolled back first (an InternalXact) from the transaction table and make the passed in transaction assume its identity. Should only be used in recovery undo !! RESOLVE: (sku)I don't think even these internal transactions need to be rolled back in the reverse order, because they are physical in nature. But it won't hurt.

MT - unsafe, caller is recovery, which is single threaded.


getMostRecentTransactionForRollback

public boolean getMostRecentTransactionForRollback(RawTransaction tran)
Get the most recently non-prepared added transaction from the transaction table and make the passed in transaction assume its identity. Prepared transactions will not be undone. RESOLVE: (sku) I don't think normal user transactions needs to be rolled back in order, but it won't hurt. Should only be used in recovery undo !!

MT - unsafe, caller is recovery, which is single threaded.


getMostRecentPreparedRecoveredXact

public boolean getMostRecentPreparedRecoveredXact(RawTransaction tran)
Get the most recent recovered prepared transaction.

Get the most recently added transaction that says it is prepared during recovery the transaction table and make the passed in transaction assume its identity.

This routine, unlike the redo and rollback getMostRecent*() routines expects a brand new transaction to be passed in. If a candidate transaction is found, then upon return the transaction table will be altered such that the old entry no longer exists, and a new entry will exist pointing to the transaction passed in. The new entry will look the same as if the prepared transaction had been created during runtime rather than recovery. Should only be used in recovery handle prepare after undo !!

MT - unsafe, caller is recovery, which is single threaded.

Parameters:
tran - Newly allocated transaction to add to link to a entry.
Returns:
true if a candidate transaction has been found. false if no prepared/recovery transactions found in the table.

getFirstLogInstant

public LogInstant getFirstLogInstant()
Get the least recently added (oldest) transaction

Returns:
the RawTransaction's first log instant

MT - safe, caller can be recovery or checkpoint


findAndAssumeTransaction

boolean findAndAssumeTransaction(TransactionId id,
                                 RawTransaction tran)
Find a transaction using the transaction id, and make the passed in transaction assume the identity and properties of that transaction.

MT - unsafe, caller is recovery, which is single threaded.

Parameters:
id - transaction Id
tran - the transaction that was made to assume the transactionID and all other relavent information stored in the transaction table
Returns:
true if transaction can be found, false otherwise

getTransactionInfo

public TransactionInfo[] getTransactionInfo()
Get a printable version of the transaction table


toString

public java.lang.String toString()

Built on Mon 2007-06-04 09:58:47+0400, from revision ???

Apache Derby V10.1 Engine Documentation - Copyright © 1997,2005 The Apache Software Foundation or its licensors, as applicable.