|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.derby.impl.store.raw.xact.TransactionTable
public class TransactionTable
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:
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!!
To allow thread-safe iteration over the values in the Hashtable, callers
must synchronize on the Hashtable while iterating. The method visitEntries(EntryVisitor)
abstracts the synchronization and iteration
so that the callers don't need to synchronize explicitly when they go
through the contents of the table. Methods that are only called during
recovery don't need to take MT considerations, and can safely use iterators
with no additional synchronization.
Nested Class Summary | |
---|---|
(package private) static interface |
TransactionTable.EntryVisitor
Interface for visiting entries in the transaction table. |
private static class |
TransactionTable.UpdateTransactionCounter
Visitor class that counts update transactions. |
Field Summary | |
---|---|
private TransactionId |
largestUpdateXactId
|
private TransactionMapFactory |
mapFactory
|
private java.util.Map |
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. |
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 that are recovered durring the recovery in the transaction table. |
boolean |
hasPreparedXact()
Is there a prepared transaction in the transaction table. |
private boolean |
hasPreparedXact(boolean recovered)
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)
remove the transaction Id an return false iff the transaction is found in the table and it doesn't need exclusion during quiesce state |
(package private) void |
removeUpdateTransaction(TransactionId id)
Change update transaction to non-update MT - MT safe, since vector is MT-safe. |
java.lang.String |
toString()
|
(package private) void |
visitEntries(TransactionTable.EntryVisitor visitor)
Visit all the entries in the transaction table. |
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 |
---|
private final TransactionMapFactory mapFactory
private final java.util.Map trans
private TransactionId largestUpdateXactId
Constructor Detail |
---|
public TransactionTable()
Method Detail |
---|
private TransactionTableEntry findTransactionEntry(TransactionId id)
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).
visitor
- the visitor to apply on each transaction table entryvoid add(Xact xact, boolean exclude)
boolean remove(TransactionId id)
public void addUpdateTransaction(TransactionId tid, RawTransaction tran, int transactionStatus)
tid
- the transaction idtran
- the transaction to be addedtransactionStatus
- the transaction status that is stored in the
BeginXact log recordvoid removeUpdateTransaction(TransactionId id)
MT - MT safe, since vector is MT-safe.
id
- the transaction Idvoid prepareTransaction(TransactionId id)
MT - unsafe, caller is recovery, which is single threaded.
id
- the transaction Idpublic ContextManager findTransactionContextByGlobalId(GlobalXactId global_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.
global_id
- The global transaction we are searching for.
boolean hasActiveUpdateTransaction()
MT - safe
public int getTypeFormatId()
getTypeFormatId
in interface TypedFormat
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
writeExternal
in interface java.io.Externalizable
java.io.IOException
- problem reading the transaction tablepublic void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException
readExternal
in interface java.io.Externalizable
java.io.IOException
- problem reading the transaction table
java.lang.ClassNotFoundException
- problem reading the transaction tablepublic TransactionId largestUpdateXactId()
MT - unsafe, caller is recovery, which is single threaded.
public boolean hasRollbackFirstTransaction()
MT - unsafe, caller is recovery, which is single threaded.
public boolean hasPreparedRecoveredXact()
MT - unsafe, caller is recovery, which is single threaded.
public boolean hasPreparedXact()
MT - unsafe, called during boot, which is single threaded.
private boolean hasPreparedXact(boolean recovered)
MT - unsafe, caller is recovery/at boot, which is single threaded.
recovered
- true
to search for transaction
that are in prepared during recovery.
recovered tranaction.
false > to search for just prepared
transactons.
- Returns:
true if there is a prepared transaction and
recovered when recovered
argument is
true
public boolean getMostRecentRollbackFirstTransaction(RawTransaction tran)
MT - unsafe, caller is recovery, which is single threaded.
public boolean getMostRecentTransactionForRollback(RawTransaction tran)
MT - unsafe, caller is recovery, which is single threaded.
public boolean getMostRecentPreparedRecoveredXact(RawTransaction tran)
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.
tran
- Newly allocated transaction to add to link to a entry.
public LogInstant getFirstLogInstant()
MT - safe, caller can be recovery or checkpoint
boolean findAndAssumeTransaction(TransactionId id, RawTransaction tran)
MT - unsafe, caller is recovery, which is single threaded.
id
- transaction Idtran
- the transaction that was made to assume the transactionID
and all other relavent information stored in the transaction table
public TransactionInfo[] getTransactionInfo()
public java.lang.String toString()
toString
in class java.lang.Object
|
Built on Thu 2011-03-10 11:54:14+0000, from revision ??? | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |