* @throws HeuristicMixedException when some resources committed and some rolled back.
* @throws bitronix.tm.internal.BitronixSystemException when an internal error occured.
* @throws bitronix.tm.internal.BitronixRollbackException during 1PC when resource fails to commit
*/
public void commit(BitronixTransaction transaction, List<XAResourceHolderState> interestedResources) throws HeuristicMixedException, HeuristicRollbackException, BitronixSystemException, BitronixRollbackException {
XAResourceManager resourceManager = transaction.getResourceManager();
if (resourceManager.size() == 0) {
transaction.setStatus(Status.STATUS_COMMITTING); //TODO: there is a disk force here that could be avoided
transaction.setStatus(Status.STATUS_COMMITTED);
if (log.isDebugEnabled()) { log.debug("phase 2 commit succeeded with no interested resource"); }
return;
}
transaction.setStatus(Status.STATUS_COMMITTING);
this.interestedResources.clear();
this.interestedResources.addAll(interestedResources);
this.onePhase = resourceManager.size() == 1;
try {
executePhase(resourceManager, true);
} catch (PhaseException ex) {
logFailedResources(ex);
if (onePhase) {
transaction.setStatus(Status.STATUS_ROLLEDBACK);
throw new BitronixRollbackException("transaction failed during 1PC commit of " + transaction, ex);
} else {
transaction.setStatus(Status.STATUS_UNKNOWN);
throwException("transaction failed during commit of " + transaction, ex, interestedResources.size());
}
}
if (log.isDebugEnabled()) { log.debug("phase 2 commit executed on resources " + Decoder.collectResourcesNames(committedResources)); }
// Some resources might have failed the 2nd phase of 2PC.
// Only resources which successfully committed should be registered in the journal, the other
// ones should be picked up by the recoverer.
// Not interested resources have to be included as well since they returned XA_RDONLY and they
// don't participate in phase 2: the TX succeded for them.
Set<String> committedAndNotInterestedUniqueNames = new HashSet<String>();
committedAndNotInterestedUniqueNames.addAll(collectResourcesUniqueNames(committedResources));
List<XAResourceHolderState> notInterestedResources = collectNotInterestedResources(resourceManager.getAllResources(), interestedResources);
committedAndNotInterestedUniqueNames.addAll(collectResourcesUniqueNames(notInterestedResources));
if (log.isDebugEnabled()) {
List<XAResourceHolderState> committedAndNotInterestedResources = new ArrayList<XAResourceHolderState>();
committedAndNotInterestedResources.addAll(committedResources);