Globals.getLogger().log(Logger.DEBUG,
getPrefix() + " replayTransactionEvent");
}
ClusterTransactionEvent clusterTxnEvent = (ClusterTransactionEvent) txnEvent;
// replay to store on commit
ClusterTransaction clusterTxn = clusterTxnEvent.clusterTransaction;
int state = clusterTxn.getState();
TransactionUID tid = clusterTxn.getTid();
if (clusterTxnEvent.getSubType() == ClusterTransactionEvent.Type2PPrepareEvent) {
// 2-phase prepare
// check if it is stored
// (this should only be the case if a failure occurred between saving
// in prepared txn store and resetting the transaction log
if (incompleteStored.containsKey(tid)) {
if (Store.getDEBUG()) {
String msg = getPrefix()
+ " found matching txn in prepared store on replay "
+ clusterTxn;
Globals.getLogger().log(Logger.DEBUG, msg);
}
} else {
addToIncompleteUnstored(clusterTxn);
}
} else if (clusterTxnEvent.getSubType() == ClusterTransactionEvent.Type2PCompleteEvent) {
// we are completing a transaction
// the transaction could be
// a) unstored (prepare replayed earlier)
// b) stored incomplete (prepare occurred before last checkpoint,
// completion not written to prepared store yet)
// This should therefore be the last entry in log.
// c) stored complete (prepare occurred before last checkpoint,
// and failure occurred after completion stored in prepared store
BaseTransaction existingWork = null;
if (incompleteUnstored.containsKey(tid)) {
// a) unstored (prepare replayed earlier)
if (state == TransactionState.ROLLEDBACK) {
existingWork = removeFromIncompleteUnstored(tid);
} else if (state == TransactionState.COMMITTED) {
existingWork = incompleteUnstored.get(tid);
existingWork.getTransactionDetails().setState(state);
existingWork.getTransactionState().setState(state);
}
} else if (incompleteStored.containsKey(tid)) {
// b) stored incomplete (prepare occurred before last checkpoint,
// completion not written to prepared store yet)
existingWork = removeFromIncompleteStored(tid);
updateStoredState(tid, state);
addToCompleteStored(existingWork);
} else if (completeStored.containsKey(tid)) {
// c) stored complete (prepare occurred before last checkpoint,
// and failure occurred after completion stored in prepared store
existingWork = completeStored.get(tid);
}
if (existingWork != null) {
if (state == TransactionState.COMMITTED) {
transactionLogManager.transactionLogReplayer.replayTransactionWork(existingWork
.getTransactionWork(), tid, dstLoadedSet);
}
} else {
logger.log(Logger.ERROR,
"Could not find prepared work for completing two-phase transaction "
+ clusterTxn.getTid());
}
}
}