Top Description Inners Fields Constructors Methods
org.apache.derby.impl.store.raw.xact

public Class TransactionTable

extends Object
implements Formatable
Class Inheritance
All Implemented Interfaces
org.apache.derby.iapi.services.io.Formatable, org.apache.derby.iapi.services.io.TypedFormat, java.io.Externalizable, java.io.Serializable
Imports
org.apache.derby.iapi.services.context.ContextManager, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.iapi.services.io.Formatable, .StoredFormatIds, .CompressedNumber, org.apache.derby.iapi.store.access.TransactionInfo, org.apache.derby.iapi.store.raw.GlobalTransactionId, org.apache.derby.iapi.store.raw.log.LogInstant, org.apache.derby.iapi.store.raw.xact.RawTransaction, .TransactionId, java.util.ArrayList, java.util.concurrent.ConcurrentHashMap, java.io.ObjectOutput, .ObjectInput, .IOException

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)

Methods that are only called during recovery don't need to take MT considerations, and can safely use iterators with no additional synchronization.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static interface
TransactionTable.EntryVisitor

Interface for visiting entries in the transaction table.

Field Summary

Modifier and TypeField and Description
private TransactionId
private final ConcurrentHashMap<TransactionId, TransactionTableEntry>

Constructor Summary

AccessConstructor and Description
public
TransactionTable()

MT - not needed for constructor

Method Summary

Modifier and TypeMethod and Description
pack-priv void
add(Xact xact, boolean exclude)

public void
addUpdateTransaction(TransactionId
the transaction id
tid
,
RawTransaction
the transaction to be added
tran
,
int
the transaction status that is stored in the BeginXact log record
transactionStatus
)

Change a transaction to update or add an update transaction to this table.

pack-priv boolean

Returns:

true if transaction can be found, false otherwise
findAndAssumeTransaction
(TransactionId
transaction Id
id
,
RawTransaction
the transaction that was made to assume the transactionID and all other relevant information stored in the transaction table
tran
)

Find a transaction using the transaction id, and make the passed in transaction assume the identity and properties of that transaction.

public ContextManager

Returns:

The ContextManager of the transaction being searched for.
findTransactionContextByGlobalId
(final GlobalXactId
The global transaction we are searching for.
global_id
)

Find a transaction in the table by Global transaction id.

This routine use to be only called during offline recovery so performance was not critical.

private TransactionTableEntry
findTransactionEntry(TransactionId id)

generic methods called by all clients of transaction table Must be MT -safe

public LogInstant

Returns:

the RawTransaction's first log instant

MT - safe, caller can be recovery or checkpoint

getFirstLogInstant
()

Get the least recently added (oldest) transaction

public boolean

Returns:

true if a candidate transaction has been found. false if no prepared/recovery transactions found in the table.
getMostRecentPreparedRecoveredXact
(RawTransaction
Newly allocated transaction to add to link to a entry.
tran
)

Get the most recent recovered prepared transaction.

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.

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.

public TransactionInfo[]
getTransactionInfo()

Get a printable version of the transaction table

public int
pack-priv boolean
hasActiveUpdateTransaction()

Return true if there is no transaction actively updating the database.

public boolean
hasPreparedRecoveredXact()

Is there a prepared transaction that are recovered durring the recovery in the transaction table.

public boolean
hasPreparedXact()

Is there a prepared transaction in the transaction table.

private boolean

Returns:

true if there is a prepared transaction and recovered when recovered argument is true
hasPreparedXact
(boolean
true to search for transaction that are in prepared during recovery. recovered tranaction. false > to search for just prepared transactons.
recovered
)

Is there a prepared transaction in the transaction table.

public boolean
hasRollbackFirstTransaction()

Is there an active internal transaction in the transaction table.

public TransactionId
largestUpdateXactId()

Return the largest update transactionId I have seen so far.

pack-priv void
prepareTransaction(TransactionId
the transaction Id
id
)

Change transaction to prepared.

public void
readExternal(ObjectInput
the stream to read data from in order to restore the object
in
)

Implements java.io.Externalizable.readExternal.

The object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays.

pack-priv boolean
remove(TransactionId id)

remove the transaction Id an return false iff the transaction is found in the table and it doesn't need exclusion during quiesce state

pack-priv void
removeUpdateTransaction(TransactionId
the transaction Id
id
)

Change update transaction to non-update

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

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

pack-priv void
visitEntries(TransactionTable.EntryVisitor
the visitor to apply on each transaction table entry
visitor
)

Visit all the entries in the transaction table.

public void
writeExternal(final ObjectOutput
the stream to write the object to
out
)

Implements java.io.Externalizable.writeExternal.

The object implements the writeExternal method to save its contents by calling the methods of DataOutput for its primitive values or calling the writeObject method of ObjectOutput for objects, strings, and arrays.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

largestUpdateXactIdback to summary
private TransactionId largestUpdateXactId
transback to summary
private final ConcurrentHashMap<TransactionId, TransactionTableEntry> trans

Constructor Detail

TransactionTableback to summary
public TransactionTable()

MT - not needed for constructor

Method Detail

addback to summary
pack-priv void add(Xact xact, boolean exclude)
addUpdateTransactionback to summary
public void addUpdateTransaction(TransactionId tid, RawTransaction tran, int transactionStatus)

Change a transaction to update or add an update transaction to this table.

Parameters
tid:TransactionId

the transaction id

tran:RawTransaction

the transaction to be added

transactionStatus:int

the transaction status that is stored in the BeginXact log record

findAndAssumeTransactionback to summary
pack-priv 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:TransactionId

transaction Id

tran:RawTransaction

the transaction that was made to assume the transactionID and all other relevant information stored in the transaction table

Returns:boolean

true if transaction can be found, false otherwise

findTransactionContextByGlobalIdback to summary
public ContextManager findTransactionContextByGlobalId(final GlobalXactId global_id)

Find a transaction in the table by Global transaction id.

This routine use to be only called during offline recovery so performance was not critical. Since that time more calls have been made, including one in startGlobalTransaction() so a linear search may no longer be appropriate. See DERBY-828.

Parameters
global_id:GlobalXactId

The global transaction we are searching for.

Returns:ContextManager

The ContextManager of the transaction being searched for.

findTransactionEntryback to summary
private TransactionTableEntry findTransactionEntry(TransactionId id)

generic methods called by all clients of transaction table Must be MT -safe

getFirstLogInstantback to summary
public LogInstant getFirstLogInstant()

Get the least recently added (oldest) transaction

Returns:LogInstant

the RawTransaction's first log instant

MT - safe, caller can be recovery or checkpoint

getMostRecentPreparedRecoveredXactback to summary
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:RawTransaction

Newly allocated transaction to add to link to a entry.

Returns:boolean

true if a candidate transaction has been found. false if no prepared/recovery transactions found in the table.

getMostRecentRollbackFirstTransactionback to summary
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.

getMostRecentTransactionForRollbackback to summary
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.

getTransactionInfoback to summary
public TransactionInfo[] getTransactionInfo()

Get a printable version of the transaction table

getTypeFormatIdback to summary
public int getTypeFormatId()

Implements org.apache.derby.iapi.services.io.TypedFormat.getTypeFormatId.

Return my format identifier.

Returns:int

Doc from org.apache.derby.iapi.services.io.TypedFormat.getTypeFormatId.

The identifier. (A UUID stuffed in an array of 16 bytes).

hasActiveUpdateTransactionback to summary
pack-priv 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

hasPreparedRecoveredXactback to summary
public boolean hasPreparedRecoveredXact()

Is there a prepared transaction that are recovered durring the recovery in the transaction table.

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

hasPreparedXactback to summary
public boolean hasPreparedXact()

Is there a prepared transaction in the transaction table.

MT - unsafe, called during boot, which is single threaded.

hasPreparedXactback to summary
private boolean hasPreparedXact(boolean recovered)

Is there a prepared transaction in the transaction table.

MT - unsafe, caller is recovery/at boot, which is single threaded.

Parameters
recovered:boolean

true to search for transaction that are in prepared during recovery. recovered tranaction. false > to search for just prepared transactons.

Returns:boolean

true if there is a prepared transaction and recovered when recovered argument is true

hasRollbackFirstTransactionback to summary
public boolean hasRollbackFirstTransaction()

Is there an active internal transaction in the transaction table.

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

largestUpdateXactIdback to summary
public TransactionId largestUpdateXactId()

Return the largest update transactionId I have seen so far.

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

prepareTransactionback to summary
pack-priv void prepareTransaction(TransactionId id)

Change transaction to prepared.

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

Parameters
id:TransactionId

the transaction Id

readExternalback to summary
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException

Implements java.io.Externalizable.readExternal.

Doc from java.io.Externalizable.readExternal.

The object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays. The readExternal method must read the values in the same sequence and with the same types as were written by writeExternal.

Parameters
in:ObjectInput

the stream to read data from in order to restore the object

Exceptions
IOException:
problem reading the transaction table
ClassNotFoundException:
problem reading the transaction table
removeback to summary
pack-priv boolean remove(TransactionId id)

remove the transaction Id an return false iff the transaction is found in the table and it doesn't need exclusion during quiesce state

removeUpdateTransactionback to summary
pack-priv void removeUpdateTransaction(TransactionId id)

Change update transaction to non-update

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

Parameters
id:TransactionId

the transaction Id

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

visitEntriesback to summary
pack-priv void visitEntries(TransactionTable.EntryVisitor visitor)

Visit all the entries in the transaction table.

MT - MT safe

Entries that are added to or removed from the transaction table while it's being traversed, may or may not be visited. All the entries that are present in the map when this method is called, and have not been removed when the method returns, will have been visited exactly once (except if the visit() method returns false before all entries have been visited, in which case the traversal of the map will stop earlier).

Note however that this method does not guarantee that a single TransactionTableEntry is not accessed concurrently by multiple threads. If the visitor accesses some of the entry's mutable state, the caller must ensure that appropriate synchronization protection is in place. For example, if accessing the update state of the entry, the caller must synchronize on "this" (the TransactionTable instance).

Parameters
visitor:TransactionTable.EntryVisitor

the visitor to apply on each transaction table entry

writeExternalback to summary
public void writeExternal(final ObjectOutput out) throws IOException

Implements java.io.Externalizable.writeExternal.

Doc from java.io.Externalizable.writeExternal.

The object implements the writeExternal method to save its contents by calling the methods of DataOutput for its primitive values or calling the writeObject method of ObjectOutput for objects, strings, and arrays.

Parameters
out:ObjectOutput

the stream to write the object to

Exceptions
IOException:
problem reading the transaction table
org.apache.derby.impl.store.raw.xact back to summary

pack-priv Interface TransactionTable.EntryVisitor


Interface for visiting entries in the transaction table.
See Also
visitEntries(EntryVisitor)

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the scan of the transaction table should continue, or false if the visitor has completed its work and no more entries need to be visited
visit
(TransactionTableEntry
the TransactionTableEntry being visited
entry
)

Visit an entry.

Method Detail

visitback to summary
public boolean visit(TransactionTableEntry entry)

Visit an entry. visitEntries(EntryVisitor) will call this method once for each entry in the transaction table, or until false is returned by this method.

Parameters
entry:TransactionTableEntry

the TransactionTableEntry being visited

Returns:boolean

true if the scan of the transaction table should continue, or false if the visitor has completed its work and no more entries need to be visited