You can use the wsadmin tool and scripting to manage active
and prepared transactions that might need administrator action.
Before you begin
Before starting this task, the wsadmin tool
must be running.
About this task
In normal circumstances, transactions
should run and complete (commit or roll back) automatically, without
the need for intervention. However, in some circumstances, you might
have to resolve a transaction manually. For example, you might want
to roll back a transaction that is stuck polling a resource manager
that you know will not become available again in the required time
frame.
In normal circumstances, every effort
is made to finish a transaction. However, because of Resource Recovery
Services (RRS) and native contexts finishing, it might not be possible
to finish the transaction. In this case, the transaction is marked rollback_only so
that it rolls back at the next available window. In other situations,
you might have to finish a transaction manually. For example, you
might want to finish a transaction that is stuck polling a resource
manager that you know will not become available again in the required
time frame.
Note: If you choose to complete a transaction
on an application server, it is recorded as having completed in the
transaction service logs for that server, so it is not eligible for
recovery during server start up. If you complete a transaction, you
are responsible for cleaning up any in-doubt transactions on the resource
managers affected.
For more information about the TransactionService
and Transaction MBeans, see the application programming interface
(API) documentation.
Procedure
- You can use the TransactionService MBean to list transactions
in various states by invoking one of the following methods:
- listOfTransactions
- Lists all non-completed transactions. Never attempt to alter the
state of active transactions (for example, by using commit or rollback).
- listManualTransactions
- Lists transactions waiting for administrative completion. You
can commit or roll back transactions in this state.
- listRetryTransactions
- Lists transactions with some resources being retried. You can
finish (stop retrying) transactions in this state.
- listHeuristicTransactions
- Lists transactions that have completed heuristically. You can
clear these transactions from the list.
- listImportedPreparedTransactions
- Lists transactions that have been imported and prepared but not
yet committed. You can commit or roll back transactions in this state.
-
Each entry in the returned list contains the following
attributes:
- Local Transaction Identifier
- Status, which can be interpreted by calling getPrintableStatus on
the Transaction MBean
- Global Transaction Identifier
- Heuristic Outcome, which can take one of
the following values:
- 8 (HEURISTIC_COMMIT)
- 9 (HEURISTIC_ROLLBACK)
- 10 (HEURISTIC_MIXED)
- 11 (HEURISTIC_HAZARD)
- You can use the TransactionService MBean to gather more
information about the properties of the transaction service, by obtaining
the following attributes:
- transactionLogDirectory
- The directory for this server where the transaction service stores
log files for recovery.
- totalTranLifetimeTimeout
- The default maximum time, in seconds, allowed for a transaction
that is started on this server before the transaction service initiates
timeout completion. Any transaction that does not begin completion
processing before this timeout occurs is rolled back. This value applies
only to container-managed transaction (CMT) beans.
- asyncResponseTimeout
- The time, in seconds, that the server waits for an inbound Web
Services Atomic Transaction (WS-AT) protocol response before resending
the previous WS-AT protocol message.
- enableFileLocking
- Specifies whether the use of file locks is enabled when opening
the transaction service recovery log.
- enableProtocolSecurity
- Specifies whether the secure exchange of transaction service protocol
messages is enabled.
- maximumTransactionTimeout
- The maximum transaction timeout allowed for imported transactions.
This value applies to Container Managed Transaction (CMT) beans, Bean
Managed Transaction (BMT) beans, and imported transactions.
- clientInactivityTimeout
- The maximum duration, in seconds, between transactional requests
from a remote client. Any period of client inactivity that exceeds
this timeout results in the transaction being rolled back in this
application server.
- heuristicRetryLimit
- The number of times that the application server retries a completion
signal, such as commit or rollback. Retries occur after a transient
exception from a resource manager or remote partner, or if the configured
asynchronous response timeout expires before all Web Services Atomic
Transaction (WS-AT) partners have responded.
- heuristicRetryWait
- The number of seconds that the application server waits before
retrying a completion signal, such as commit or rollback, after a
transient exception from a resource manager or remote partner.
- httpProxyPrefix
- The HTTP prefix for WS-Transaction port SOAP addresses.
- httpsProxyPrefix
- The HTTPS prefix for WS-Transaction port SOAP addresses.
- propogatedOrBMTTranLifetimeTimeout
- The upper limit of the transaction timeout, in seconds, for transactions
that run in this server. This value should be greater than or equal
to the total transaction timeout.
- LPSHeuristicCompletion
- The action to use to complete a transaction that has an heuristic
outcome. Either the application server commits or rolls back the transaction,
or the administrator must complete the transaction manually.
- You can use the Transaction MBean to commit, roll back,
or finish a transaction, or remove a transaction from the list of
heuristically completed transactions, depending on the state of the
transaction, by invoking one of the following methods:
- commit
- Heuristically commits the transaction.
- rollback
- Heuristically rolls back the transaction.
- finish
- Stops retrying resources for the transaction.
- removeHeuristic
- Clears the transaction from the list.
- You can use the Transaction MBean to gather more information
about a transaction, by invoking the following methods:
- getPrintableStatus
- Return the transaction status.
- getGlobalTranName
- Get the global identifier for the transaction.
- listResources
- List the resources for the transaction.
-
Example
The following script is an example of how to use the TransactionService
and Transaction MBeans to work with manual transactions. Run the script
only against an application server, and not against the deployment
manager or node agent.
Example Jacl script:
# get the TransactionService MBean
set servicembean [$AdminControl queryNames type=TransactionService,*]
# get the Transaction MBean
set mbean [$AdminControl queryNames type=Transaction,*]
set input 0
while {$input >= 0} {
# invoke the listManualTransactions method
set tranManualList [$AdminControl invoke $servicembean listManualTransactions]
if {[llength $tranManualList] > 0} {
puts "----Manual Transaction details---------------"
set index 0
foreach tran $tranManualList {
puts " Index= $index tran= $tran"
incr index
}
puts "----End of Manual Transactions ---------------"
puts "Select index of transaction to commit/rollback:"
set input [gets stdin]
if {$input < 0} {
puts "No index selected, exiting."
} else {
set tran [lindex $tranManualList $input]
set commaPos [expr [string first "," $tran ]-1]
set localTID [string range $tran 0 $commaPos]
puts "Enter c to commit or r to rollback Transaction $localTID"
set input [gets stdin]
if {$input=="c"} {
puts "Committing transaction=$localTID"
$AdminControl invoke $mbean commit $localTID
}
if {$input=="r"} {
puts "Rolling back transaction=$localTID"
$AdminControl invoke $mbean rollback $localTID
}
}
} else {
puts "No Manual transactions found, exiting"
set input -1
}
puts " "
}
Working with manual transactions: example Jython script.
import sys
def wsadminToList(inStr):
outList=[]
if (len(inStr)>0 and inStr[0]=='[' and inStr[-1]==']'):
tmpList = inStr[1:-1].split(" ")
else:
tmpList = inStr.split("\n") #splits for Windows or Linux
for item in tmpList:
item = item.rstrip(); #removes any Windows "\r"
if (len(item)>0):
outList.append(item)
return outList
#endDef
servicembean = AdminControl.queryNames("type=TransactionService,*" )
mbean = AdminControl.queryNames("type=Transaction,*" )
input = 0
while (input >= 0):
tranList = wsadminToList(AdminControl.invoke(servicembean, "listManualTransactions" ))
tranLength = len(tranList)
if (tranLength > 0):
print "----Manual Transaction details---------------"
index = 0
for tran in tranList:
print " Index=" , index , " tran=" , tran
index = index+1
#endFor
print "----End of Manual Transactions ---------------"
print "Select index of transaction to commit/rollback:"
input = sys.stdin.readline().strip()
if (input == ""):
print "No index selected, exiting."
input = -1
else:
tran = tranList[int(input)]
commaPos = (tran.find(",") -1)
localTID = tran[0:commaPos+1]
print "Enter c to commit or r to rollback transaction ", localTID
input = sys.stdin.readline().strip()
if (input == "c"):
print "Committing transaction=", localTID
AdminControl.invoke(mbean, "commit", localTID )
#endIf
elif (input == "r"):
print "Rolling back transaction=", localTID
AdminControl.invoke(mbean, "rollback", localTID )
#endIf
else:
input = -1
#endelse
#endElse
else:
print "No transactions found, exiting"
input = -1
#endElse
print " "
#endWhile