Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.apache.derby.impl.store.raw.xact
Class TransactionTable  view TransactionTable download TransactionTable.java

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

public class TransactionTable
extends java.lang.Object
implements org.apache.derby.iapi.services.io.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!!


Field Summary
private  org.apache.derby.iapi.store.raw.xact.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(org.apache.derby.iapi.store.raw.xact.TransactionId tid, org.apache.derby.iapi.store.raw.xact.RawTransaction tran, int transactionStatus)
          Change a transaction to update or add an update transaction to this table.
(package private)  boolean findAndAssumeTransaction(org.apache.derby.iapi.store.raw.xact.TransactionId id, org.apache.derby.iapi.store.raw.xact.RawTransaction tran)
          Find a transaction using the transaction id, and make the passed in transaction assume the identity and properties of that transaction.
 org.apache.derby.iapi.services.context.ContextManager findTransactionContextByGlobalId(GlobalXactId global_id)
          Find a transaction in the table by Global transaction id.
private  TransactionTableEntry findTransactionEntry(org.apache.derby.iapi.store.raw.xact.TransactionId id)
          generic methods called by all clients of transaction table Must be MT -safe
 org.apache.derby.iapi.store.raw.log.LogInstant getFirstLogInstant()
          Get the least recently added (oldest) transaction
 boolean getMostRecentPreparedRecoveredXact(org.apache.derby.iapi.store.raw.xact.RawTransaction tran)
          Get the most recent recovered prepared transaction.
 boolean getMostRecentRollbackFirstTransaction(org.apache.derby.iapi.store.raw.xact.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(org.apache.derby.iapi.store.raw.xact.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.
 org.apache.derby.iapi.store.access.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.
 org.apache.derby.iapi.store.raw.xact.TransactionId largestUpdateXactId()
          Return the largest update transactionId I have seen so far.
(package private)  void prepareTransaction(org.apache.derby.iapi.store.raw.xact.TransactionId id)
          Change transaction to prepared.
 void readExternal(java.io.ObjectInput in)
          This method restores an object's state by reading in the instance data for the object from the passed in stream.
(package private)  boolean remove(org.apache.derby.iapi.store.raw.xact.TransactionId id)
           
(package private)  void removeUpdateTransaction(org.apache.derby.iapi.store.raw.xact.TransactionId id)
          Change update transaction to non-update
 java.lang.String toString()
          Convert this Object to a human-readable String.
 void writeExternal(java.io.ObjectOutput out)
          This method is responsible for writing the instance data of an object to the passed in stream.
 
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 org.apache.derby.iapi.store.raw.xact.TransactionId largestUpdateXactId
Constructor Detail

TransactionTable

public TransactionTable()
MT - not needed for constructor

Method Detail

findTransactionEntry

private TransactionTableEntry findTransactionEntry(org.apache.derby.iapi.store.raw.xact.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(org.apache.derby.iapi.store.raw.xact.TransactionId id)

addUpdateTransaction

public void addUpdateTransaction(org.apache.derby.iapi.store.raw.xact.TransactionId tid,
                                 org.apache.derby.iapi.store.raw.xact.RawTransaction tran,
                                 int transactionStatus)
Change a transaction to update or add an update transaction to this table.


removeUpdateTransaction

void removeUpdateTransaction(org.apache.derby.iapi.store.raw.xact.TransactionId id)
Change update transaction to non-update

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


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.


prepareTransaction

void prepareTransaction(org.apache.derby.iapi.store.raw.xact.TransactionId id)
Change transaction to prepared.

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


findTransactionContextByGlobalId

public org.apache.derby.iapi.services.context.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.


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 org.apache.derby.iapi.services.io.TypedFormat

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Description copied from interface: java.io.Externalizable
This method is responsible for writing the instance data of an object to the passed in stream. Note that this stream is not a subclass of OutputStream, but rather is a class that implements the ObjectOutput interface. That interface provides a number of methods for writing Java data values to a stream.

Not that the implementation of this method must be coordinated with the implementation of readExternal.

Specified by:
writeExternal in interface java.io.Externalizable

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Description copied from interface: java.io.Externalizable
This method restores an object's state by reading in the instance data for the object from the passed in stream. Note that this stream is not a subclass of InputStream, but rather is a class that implements the ObjectInput interface. That interface provides a mechanism for reading in Java data types from a stream.

Note that this method must be compatible with writeExternal. It must read back the exact same types that were written by that method in the exact order they were written.

If this method needs to read back an object instance, then the class for that object must be found and loaded. If that operation fails, then this method throws a ClassNotFoundException

Specified by:
readExternal in interface java.io.Externalizable

largestUpdateXactId

public org.apache.derby.iapi.store.raw.xact.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(org.apache.derby.iapi.store.raw.xact.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(org.apache.derby.iapi.store.raw.xact.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(org.apache.derby.iapi.store.raw.xact.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.


getFirstLogInstant

public org.apache.derby.iapi.store.raw.log.LogInstant getFirstLogInstant()
Get the least recently added (oldest) transaction


findAndAssumeTransaction

boolean findAndAssumeTransaction(org.apache.derby.iapi.store.raw.xact.TransactionId id,
                                 org.apache.derby.iapi.store.raw.xact.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.


getTransactionInfo

public org.apache.derby.iapi.store.access.TransactionInfo[] getTransactionInfo()
Get a printable version of the transaction table


toString

public java.lang.String toString()
Description copied from class: java.lang.Object
Convert this Object to a human-readable String. There are no limits placed on how long this String should be or what it should contain. We suggest you make it as intuitive as possible to be able to place it into System.out.println() 55 and such.

It is typical, but not required, to ensure that this method never completes abruptly with a java.lang.RuntimeException.

This method will be called when performing string concatenation with this object. If the result is null, string concatenation will instead use "null".

The default implementation returns getClass().getName() + "@" + Integer.toHexString(hashCode()).