Class BasicAction
java.lang.Object
com.arjuna.ats.arjuna.StateManager
com.arjuna.ats.arjuna.coordinator.BasicAction
- Direct Known Subclasses:
TwoPhaseCoordinator
BasicAction does most of the work of an atomic action, but does not manage
thread scoping. This is the responsibility of any derived classes.
- Since:
- JTS 1.0.
- Version:
- $Id: BasicAction.java 2342 2006-03-30 13:06:17Z $
- Author:
- Mark Little (mark@arjuna.com)
-
Field Summary
Modifier and TypeFieldDescriptionprotected RecordList
protected RecordList
protected RecordList
protected RecordList
protected RecordList
protected boolean
protected boolean
protected final List
<com.arjuna.ats.arjuna.coordinator.StackTraceCapture> Fields inherited from class com.arjuna.ats.arjuna.StateManager
modifyingActions, objectModel, objectUid, synchronizationLock, usingActions
-
Constructor Summary
ModifierConstructorDescriptionprotected
BasicAction
(int at) Create a transaction of the specified type.BasicAction
(Uid objUid) BasicAction constructor with a Uid.protected
BasicAction
(Uid u, int at) Recreate the specified transaction. -
Method Summary
Modifier and TypeMethodDescriptionprotected int
Abort()
This is the user callable abort operation.protected int
Abort
(boolean applicationAbort) This is the user callable abort operation.protected int
boolean
activate()
Overloaded version of activate -- sets up the store, performs read_state followed by restore_state.boolean
Overloaded version of activate -- sets up the store, performs read_state followed by restore_state.final int
final int
Add a record to the atomic action.final boolean
Add a new child action to the atomic action.final boolean
Add the current thread to the list of threads associated with this transaction.final boolean
Add the specified thread to the list of threads associated with this transaction.protected final void
Add the specified abstract record to the transaction.protected int
async_prepare
(boolean reportHeuristics) protected int
Begin
(BasicAction parentAct) Atomic action Begin operation.protected boolean
Do we want to check that a transaction can only be terminated by a thread that has it as its current transaction? The base class has this check enabled (i.e., we check), but some implementations may wish to override this.final Object[]
protected int
protected final void
Defines the end of a critical region by resetting the critical flag.protected final void
Defines the start of a critical region by setting the critical flag.static BasicAction
Current()
boolean
This operation deactivates a persistent object.boolean
destroy()
OverloadsStateManager.destroy
to prevent destroy being called on a BasicAction.protected int
doAbort
(boolean reportHeuristics, AbstractRecord record) protected int
doAbort
(RecordList list_toprocess, boolean reportHeuristics) protected int
doCommit
(boolean reportHeuristics, AbstractRecord record) protected int
doCommit
(RecordList rl, boolean reportHeuristics) Walk down a record list extracting records and calling the appropriate commit function.protected int
doPrepare
(boolean reportHeuristics, AbstractRecord record) protected int
End
(boolean reportHeuristics) End the atomic action by committing it.boolean
void
BasicAction destructor.protected boolean
Forget any heuristics we may have received, and tell the resources which generated them to forget too.Get any Throwable that was caught during commit processing but not directly rethrown.protected final int
final ActionHierarchy
Return the action hierarchy for this transaction.getStore()
Set up an object store and assign it to the participantStore variable.int
hashCode()
final int
protected AbstractRecord
insertRecord
(RecordList reclist, AbstractRecord record) final boolean
isAncestor
(Uid ancestor) boolean function that checks whether the Uid passed as an argument is the Uid for an ancestor of the current atomic action.static boolean
If heuristic outcomes are returned, by default we will not save the state once the forget method has been called on them (which happens as soon as we have received all outcomes from registered resources).protected void
onePhaseCommit
(boolean reportHeuristics) There is only one record on the intentions list.protected void
onePhaseCommit
(boolean reportHeuristics, boolean permitReportStatistics) SeeonePhaseCommit(boolean)
This method may be called during 2PC prepare when the first resource returns read-only.protected void
final BasicAction
parent()
protected final void
phase2Abort
(boolean reportHeuristics) Second phase of the two phase commit protocol for aborting actions.protected final void
Cleanup phase for actions.protected final void
phase2Commit
(boolean reportHeuristics) Second phase of the two-phase commit protocol for committing actions.protected final int
prepare
(boolean reportHeuristics) Phase one of a two phase commit protocol.protected int
final boolean
Force the only outcome for the transaction to be to rollback.protected void
final boolean
Remove a child action.final boolean
Remove a child thread.final boolean
removeChildThread
(String threadId) Remove the specified thread from the transaction.boolean
restore_state
(InputObjectState os, int ot) This assumes the various lists are zero length when it is called.boolean
save_state
(OutputObjectState os, int ot) Redefined version of save_state and restore_state from StateManager.protected final void
Add the specified CheckedAction object to this transaction.protected final void
setHeuristicDecision
(int p) WARNING: use with extreme care!final int
status()
final BasicAction
final Uid
The following function returns the Uid of the top-level atomic action.toString()
Overloads Object.toString()type()
Overloads StateManager.type()final int
protected final void
updateHeuristic
(int p, boolean commit) protected void
Methods inherited from class com.arjuna.ats.arjuna.StateManager
cleanup, createLists, deactivate, deactivate, disable, forgetAction, get_uid, getCreationTimeMillis, getMutex, getObjectModel, getStoreRoot, loadObjectState, lockMutex, modified, objectType, packHeader, persist, print, rememberAction, setStatus, setupStore, setupStore, setupStore, terminate, tryLockMutex, unlockMutex, unpackHeader
-
Field Details
-
pendingList
-
preparedList
-
readonlyList
-
failedList
-
heuristicList
-
savedIntentionList
protected boolean savedIntentionList -
subordinate
protected boolean subordinate -
threadStackTraceHistoryList
protected final List<com.arjuna.ats.arjuna.coordinator.StackTraceCapture> threadStackTraceHistoryList
-
-
Constructor Details
-
BasicAction
public BasicAction() -
BasicAction
BasicAction constructor with a Uid. This constructor is for recreating an BasicAction, typically during crash recovery. -
BasicAction
protected BasicAction(int at) Create a transaction of the specified type. -
BasicAction
Recreate the specified transaction. Used for crash recovery purposes.
-
-
Method Details
-
finalizeInternal
public void finalizeInternal()BasicAction destructor. Under normal circumstances we do very little. However there exists the possibility that this action is being deleted while still running (user forgot to commit/abort) - in which case we do an abort for him and mark all our parents as unable to commit. Additionally due to scoping we may not be the current action - but in that case the current action must be one of our nested actions so by applying abort to it we should end up at ourselves! -
getHierarchy
Return the action hierarchy for this transaction. -
preventCommit
public final boolean preventCommit()Force the only outcome for the transaction to be to rollback. Only possible if this transaction has not (or is not) terminated.- Returns:
true
if successful,false
otherwise.
-
activeThreads
public final int activeThreads()- Returns:
- the number of threads associated with this transaction.
-
add
Add a record to the atomic action. This function returns AR_ADDED if the record is added. AR_REJECTED if the record cannot be added because the action is past the prepare phase, and IGNORED otherwise.- Returns:
AddOutcome
indicating outcome.
-
hierarchyDepth
public final int hierarchyDepth()- Returns:
- the depth of the current transaction hierarchy.
-
isAncestor
boolean function that checks whether the Uid passed as an argument is the Uid for an ancestor of the current atomic action.- Returns:
true
if the parameter represents an ancestor,false
otherwise.
-
parent
- Returns:
- a reference to the parent BasicAction
-
typeOfAction
public final int typeOfAction() -
status
public final int status()- Overrides:
status
in classStateManager
- Returns:
- the status of the BasicAction
-
getStore
Set up an object store and assign it to the participantStore variable.- Overrides:
getStore
in classStateManager
- Returns:
- the object store implementation to use.
- See Also:
-
topLevelActionUid
The following function returns the Uid of the top-level atomic action. If this is the top-level transaction then it is equivalent to calling get_uid().- Returns:
- the top-level transaction's
Uid
.
-
topLevelAction
- Returns:
- a reference to the top-level transaction. If this is the top-level transaction then a reference to itself will be returned.
-
activate
public boolean activate()Overloaded version of activate -- sets up the store, performs read_state followed by restore_state. The store root isnull
.- Overrides:
activate
in classStateManager
- Returns:
true
if successful,false
otherwise.- See Also:
-
activate
Overloaded version of activate -- sets up the store, performs read_state followed by restore_state. The root of the object store to use is specified in theroot
parameter.- Overrides:
activate
in classStateManager
- Returns:
true
if successful,false
otherwise.- See Also:
-
deactivate
public boolean deactivate()This operation deactivates a persistent object. It behaves in a similar manner to the activate operation, but has an extra argument which defines whether the object's state should be committed or written as a shadow. The root of the object store isnull
. It is assumed that this is being called during a transaction commit.- Overrides:
deactivate
in classStateManager
- Returns:
true
on success,false
otherwise.
-
addChildThread
public final boolean addChildThread()Add the current thread to the list of threads associated with this transaction.- Returns:
true
if successful,false
otherwise.
-
addChildThread
Add the specified thread to the list of threads associated with this transaction.- Returns:
true
if successful,false
otherwise.
-
removeChildThread
public final boolean removeChildThread()Remove a child thread. The current thread is removed.- Returns:
true
if successful,false
otherwise.
-
removeChildThread
Remove the specified thread from the transaction.- Returns:
true
if successful,false
otherwise.
-
addChildAction
Add a new child action to the atomic action.- Returns:
true
if successful,false
otherwise.
-
save_state
Redefined version of save_state and restore_state from StateManager. Normal operation (no crashes): BasicAction.save_state is called after a successful prepare. This causes and BasicAction object to be saved in the object store. This object contains primarily the "intentions list" of the BasicAction. After successfully completing phase 2 of the commit protocol, the BasicAction object is deleted from the store. Failure cases: If a server crashes after successfully preparing, then upon recovery the action must be resolved (either committed or aborted) depending upon whether the co-ordinating atomic action committed or aborted. Upon server recovery, the crash recovery mechanism detects ServerBasicAction objects in the object store and attempts to activate the BasicAction object of the co-ordinating action. If this is successful then the SAA is committed else aborted. If, when processing phase 2 of the commit protocol, the co-ordinator experiences a failure to commit from one of the records then the BasicAction object is NOT deleted. It is rewritten when a new state which contains a list of the records that failed during phase 2 commit. This list is called the "failedList". The crash recovery manager will detect local BasicAction objects in addition to SAA objects in the objectstore. An attempt will be made to commit these actions. If the action contained a call to a now dead server, this action can never be resolved and the AA object can never be removed. However, if the action is purely local then after the processing is complete the removed by crash recovery.- Overrides:
save_state
in classStateManager
- Returns:
true
if successful,false
otherwise.
-
removeChildAction
Remove a child action.- Returns:
true
if successful,false
otherwise.
-
setCheckedAction
Add the specified CheckedAction object to this transaction.- See Also:
-
getSavingUid
- Returns:
- the Uid that the transaction's intentions list will be saved under.
-
toString
Overloads Object.toString() -
restore_state
This assumes the various lists are zero length when it is called.- Overrides:
restore_state
in classStateManager
- Returns:
true
if successful,false
otherwise.
-
type
Overloads StateManager.type()- Overrides:
type
in classStateManager
-
Current
- Returns:
- the thread's notion of the current transaction.
-
maintainHeuristics
public static boolean maintainHeuristics()If heuristic outcomes are returned, by default we will not save the state once the forget method has been called on them (which happens as soon as we have received all outcomes from registered resources). By specifying otherwise, we will always maintain the heuristic information, which may prove useful for logging and off-line resolution.- Returns:
true
if the transaction should save its heuristic information,false
otherwise.
-
destroy
public boolean destroy()OverloadsStateManager.destroy
to prevent destroy being called on a BasicAction. Could be a *very* bad idea!!- Overrides:
destroy
in classStateManager
- Returns:
false
.- See Also:
-
childTransactions
- Returns:
- the list of child transactions. Currently only their ids are given.
- Since:
- JTS 2.2.
-
getDeferredThrowables
Get any Throwable that was caught during commit processing but not directly rethrown.- Returns:
- a list of ThrowableS, if any
-
equals
-
hashCode
public int hashCode() -
forgetHeuristics
protected boolean forgetHeuristics()Forget any heuristics we may have received, and tell the resources which generated them to forget too.- Returns:
true
if heuristic information (if any) was successfully forgotten,false
otherwise.
-
Begin
Atomic action Begin operation. Does not change the calling thread's notion of the current transaction.- Returns:
ActionStatus
indicating outcome.
-
End
protected int End(boolean reportHeuristics) End the atomic action by committing it. This invokes the prepare() operation. If this succeeds then the pendingList should be empty and the records that were formally on it will have been distributed between the preparedList and the readonlyList, also if the action is topLevel then the intention list will have been written to the object store. Then invoke phase2Commit and clean up the object store if necessary If prepare() fails invoke phase2Abort. In this case the pendingList may still contain records but phase2Abort takes care of these. Also in this case no intention list has been written. Does not change the calling thread's notion of the current transaction. Any heuristic outcomes will only be reported if the parameter istrue
.- Returns:
ActionStatus
indicating outcome.
-
Abort
protected int Abort()This is the user callable abort operation. It is invoked prior to the start of two-phase commit and hence only processes records in the pendingList (the other lists should be empty). Does not change the calling thread's notion of the current transaction.- Returns:
ActionStatus
indicating outcome.
-
Abort
protected int Abort(boolean applicationAbort) This is the user callable abort operation. It is invoked prior to the start of two-phase commit and hence only processes records in the pendingList (the other lists should be empty). Does not change the calling thread's notion of the current transaction.- Parameters:
applicationAbort
- indicates whether or not this is an application abort- Returns:
ActionStatus
indicating outcome.
-
criticalStart
protected final void criticalStart()Defines the start of a critical region by setting the critical flag. If the signal handler is called the class variable abortAndExit is set. The value of this variable is checked in the corresponding operation to end the critical region. -
criticalEnd
protected final void criticalEnd()Defines the end of a critical region by resetting the critical flag. If the signal handler is called the class variable abortAndExit is set. The value of this variable is checked when ending the critical region. -
phase2Cleanup
protected final void phase2Cleanup()Cleanup phase for actions. If an action is in the PREPARED state when a terminate signal is delivered (ie the coordinator node has crashed) then we need to cleanup. This is essentially the same as phase2Abort but we call cleanup ops rather than abort ops and let the records take care of appropriate cleanup. The pendingList is processed because it may not be empty - since prepare() stops processing the list at the first PREPARE_NOTOK result. The read_only list is processed to ensure that actions are aborted immediately and any servers killed at that point since they need not hang around. This contrasts with commit where readonlyList entries are simply merged with the parent list or discarded -
phase2Commit
Second phase of the two-phase commit protocol for committing actions. Phase 2 should only be called if phase 1 has completed successfully. This operation first invokes the doCommit operation on the preparedList. This ensures that the appropriate commit operation is performed on each entry which is then either deleted (top_level) or merged into the parent's pendingList. Processing of the readonlyList is different in that if the action is top_level then all records in the readonlyList are deleted without further processing. If nested the records must be merged. This is an optimisation to avoid unnecessary processing. Note that at this point the pendingList SHOULD be empty due to the prior invocation of prepare().- Throws:
Error
- JBTM-895 tests, byteman limitation
-
phase2Abort
protected final void phase2Abort(boolean reportHeuristics) Second phase of the two phase commit protocol for aborting actions. Actions are aborted by invoking the doAbort operation on the preparedList, the readonlyList, and the pendingList. The pendingList is processed because it may not be empty - since prepare() stops processing the list at the first PREPARE_NOTOK result. By default, records that responsed PREPARE_READONLY will not be contacted during second-phase abort, just as they are not during second-phase commit. This can be overridden at runtime using the READONLY_OPTIMISATION variable. -
async_prepare
protected int async_prepare(boolean reportHeuristics) -
prepare
protected final int prepare(boolean reportHeuristics) Phase one of a two phase commit protocol. This function returns the ouctome of the prepare operation. If all goes well it will be PREPARE_OK, if not PREPARE_NOTOK. The value PREPARE_READONLY may also be returned if all the records indicate that they are readonly records. Such records do not take part in the second phase commit processing.- Returns:
TwoPhaseOutcome
indicating outcome. Note that if 1PC optimisation is enabled then it is possible for prepare to dynamically optimise and commit if the first N-1 participants return read-only, causing the protcol to commit the last participant rather than go through prepare.
-
onePhaseCommit
protected void onePhaseCommit(boolean reportHeuristics) There is only one record on the intentions list. Only called from synchronized methods. Don't bother about creating separate threads here! -
onePhaseCommit
protected void onePhaseCommit(boolean reportHeuristics, boolean permitReportStatistics) SeeonePhaseCommit(boolean)
This method may be called during 2PC prepare when the first resource returns read-only. -
getHeuristicDecision
protected final int getHeuristicDecision()- Returns:
- the current heuristic decision. Each time a heuristic outcome is received, we need to merge it with any previous outcome to determine what the overall heuristic decision is (e.g., a heuristic rollback followed by a heuristic commit means the overall decision is heuristic mixed.)
-
setHeuristicDecision
protected final void setHeuristicDecision(int p) WARNING: use with extreme care! -
addRecord
Add the specified abstract record to the transaction. Does not do any of the runtime checking of BasicAction.add, so should be used with care. Currently used by crash recovery. -
preparedStatus
protected int preparedStatus()- Returns:
- the transaction's prepared status.
- Since:
- JTS 2.0.
-
abortStatus
protected int abortStatus() -
commitStatus
protected int commitStatus() -
doPrepare
-
doCommit
Walk down a record list extracting records and calling the appropriate commit function. Discard or merge records as appropriate -
doCommit
-
doAbort
-
doAbort
-
insertRecord
-
checkForCurrent
protected boolean checkForCurrent()Do we want to check that a transaction can only be terminated by a thread that has it as its current transaction? The base class has this check enabled (i.e., we check), but some implementations may wish to override this.- Returns:
false
to disable checking.
-
updateHeuristic
protected final void updateHeuristic(int p, boolean commit) -
updateState
protected void updateState() -
recordStackTraces
protected void recordStackTraces() -
outputCapturedStackTraces
protected void outputCapturedStackTraces() -
createStackTraces
-