[Mulgara-svn] r563 - branches/mgr-73/src/jar/resolver/java/org/mulgara/resolver
andrae at mulgara.org
andrae at mulgara.org
Fri Nov 16 06:16:39 UTC 2007
Author: andrae
Date: 2007-11-16 00:16:39 -0600 (Fri, 16 Nov 2007)
New Revision: 563
Modified:
branches/mgr-73/src/jar/resolver/java/org/mulgara/resolver/MulgaraExternalTransaction.java
Log:
Added code to cleanup the transaction on transaction completion.
This primarally requires notifying the manager via the factory that the
transaction is over so it can release the writelock if it is held.
Modified: branches/mgr-73/src/jar/resolver/java/org/mulgara/resolver/MulgaraExternalTransaction.java
===================================================================
--- branches/mgr-73/src/jar/resolver/java/org/mulgara/resolver/MulgaraExternalTransaction.java 2007-11-16 06:14:01 UTC (rev 562)
+++ branches/mgr-73/src/jar/resolver/java/org/mulgara/resolver/MulgaraExternalTransaction.java 2007-11-16 06:16:39 UTC (rev 563)
@@ -50,11 +50,12 @@
private Set<EnlistableResource> committed;
private Set<EnlistableResource> rollbacked;
- private MulgaraXAResource resource;
+ private MulgaraExternalTransactionFactory factory;
+ private DatabaseOperationContext context;
- MulgaraExternalTransaction(Xid xid, MulgaraXAResource resource) {
- this.xid = xid;
- this.resource = resource;
+ MulgaraExternalTransaction(MulgaraExternalTransactionFactory resource, OperationContext context) {
+ this.factory = factory;
+ this.context = context;
this.enlisted = new HashSet<EnlistableResource>();
this.prepared = new HashSet<EnlistableResource>();
@@ -68,14 +69,18 @@
MulgaraTransactionException abortTransaction(String errorMessage, Throwable cause)
throws MulgaraTransactionException {
- if (resource.getStatus() == MulgaraXAResource.ACTIVE) {
- resource.setRollback(cause);
+ try {
+ if (resource.getStatus() == MulgaraXAResource.ACTIVE) {
+ resource.setRollback(cause);
+ }
+ for (EnlistableResource resource : resources) {
+ try {
+ resource.abort();
+ } catch (Throwable throw_away) {}
+ }
+ } finally {
+ cleanupTransaction();
}
- for (EnlistableResource resource : resources) {
- try {
- resource.abort();
- } catch (Throwable throw_away) {}
- }
}
@@ -120,6 +125,14 @@
// Methods used to manage transaction from XAResource.
//
+ void commit(Xid xid) throws XAException {
+ for (EnlistableResource er : xa.getEnlistedResources()) {
+ er.getXAResource().commit(xid, false);
+ committed.add(er);
+ }
+ cleanupTransaction();
+ }
+
boolean isHeuristicallyRollbacked() {
return false;
}
@@ -137,74 +150,78 @@
}
void rollback(Xid xid) throws XAException {
- Map<EnlistableResource, XAException> rollbackFailed = new HashMap<EnlistableResource, XAException>();
+ try {
+ Map<EnlistableResource, XAException> rollbackFailed = new HashMap<EnlistableResource, XAException>();
- assert exception != null;
+ assert exception != null;
- for (EnlistableResource er : xa.getEnlistedResources()) {
- try {
- if (!committed.contains(er)) {
- er.getXAResource().rollback(xid, false);
- rollbacked.add(er);
+ for (EnlistableResource er : xa.getEnlistedResources()) {
+ try {
+ if (!committed.contains(er)) {
+ er.getXAResource().rollback(xid, false);
+ rollbacked.add(er);
+ }
+ } catch (XAException ex) {
+ logger.error("Attempt to rollback resource failed", ex);
+ rollbackFailed.put(er, ex);
}
- } catch (XAException ex) {
- logger.error("Attempt to rollback resource failed", ex);
- rollbackFailed.put(er, ex);
}
- }
- if (rollbackFailed.isEmpty()) {
- if (committed.isEmpty()) { // Clean failure and rollback - rethrow cause
- // status = ROLLBACK_COMPLETED;
- } else { // No rollback-failure, but partial commit
- heurCode = XAException.XA_HEURMIX;
- throw new XAException(heurCode);
- }
- } else {
- // Something went wrong - start by assuming if one committed all committed
- heurCode = (committed.isEmpty()) ? 0 : XAException.XA_HEURCOM;
- // Then check every rollback failure code for a contradiction to all committed.
- for (XAException xaex : rollbackFailed.values()) {
- switch (xaex.errorCode) {
- case XAException.XA_HEURHAZ:
- case XAException.XAER_NOTA:
- case XAException.XAER_RMERR:
- case XAException.XAER_RMFAIL:
- case XAException.XAER_INVAL:
- case XAException.XAER_PROTO:
- // All these amount to not knowing the result - so we have a hazard
- // unless we already know we have a mixed result.
- if (heurCode != XAException.XA_HEURMIX) {
- XAException.XA_HEURHAZ;
- }
- break;
- case XAException.XA_HEURCOM:
- if (!rollbacked.isEmpty() || heurCode == XAException.XA_HEURRB) {
- // We know something else was rollbacked, so we know we have a mixed result.
+ if (rollbackFailed.isEmpty()) {
+ if (committed.isEmpty()) { // Clean failure and rollback - rethrow cause
+ // status = ROLLBACK_COMPLETED;
+ } else { // No rollback-failure, but partial commit
+ heurCode = XAException.XA_HEURMIX;
+ throw new XAException(heurCode);
+ }
+ } else {
+ // Something went wrong - start by assuming if one committed all committed
+ heurCode = (committed.isEmpty()) ? 0 : XAException.XA_HEURCOM;
+ // Then check every rollback failure code for a contradiction to all committed.
+ for (XAException xaex : rollbackFailed.values()) {
+ switch (xaex.errorCode) {
+ case XAException.XA_HEURHAZ:
+ case XAException.XAER_NOTA:
+ case XAException.XAER_RMERR:
+ case XAException.XAER_RMFAIL:
+ case XAException.XAER_INVAL:
+ case XAException.XAER_PROTO:
+ // All these amount to not knowing the result - so we have a hazard
+ // unless we already know we have a mixed result.
+ if (heurCode != XAException.XA_HEURMIX) {
+ XAException.XA_HEURHAZ;
+ }
+ break;
+ case XAException.XA_HEURCOM:
+ if (!rollbacked.isEmpty() || heurCode == XAException.XA_HEURRB) {
+ // We know something else was rollbacked, so we know we have a mixed result.
+ heurCode = XAException.XA_HEURMIX;
+ } else if (heurCode == 0) {
+ heurCode = XAException.XA_HEURCOM;
+ } // else it's a HEURHAZ or a HEURCOM and stays that way.
+ break;
+ case XAException.XA_HEURRB:
+ if (!committed.isEmpty() || heurCode == XAException.XA_HEURCOM) {
+ heurCode = XAException.XA_HEURMIX;
+ } else if (heurCode == 0) {
+ heurCode = XAException.XA_HEURRB;
+ } // else it's a HEURHAZ or a HEURRB and stays that way.
+ break;
+ case XAException.XA_HEURMIX:
+ // It can't get worse than, we know we have a mixed result.
heurCode = XAException.XA_HEURMIX;
- } else if (heurCode == 0) {
- heurCode = XAException.XA_HEURCOM;
- } // else it's a HEURHAZ or a HEURCOM and stays that way.
- break;
- case XAException.XA_HEURRB:
- if (!committed.isEmpty() || heurCode == XAException.XA_HEURCOM) {
- heurCode = XAException.XA_HEURMIX;
- } else if (heurCode == 0) {
- heurCode = XAException.XA_HEURRB;
- } // else it's a HEURHAZ or a HEURRB and stays that way.
- break;
- case XAException.XA_HEURMIX:
- // It can't get worse than, we know we have a mixed result.
- heurCode = XAException.XA_HEURMIX;
- break;
- default:
- // The codes above are the only codes permitted from a rollback() so
- // anything else indicates a serious error in the resource-manager.
- throw new XAException(XAException.XAER_RMERR);
+ break;
+ default:
+ // The codes above are the only codes permitted from a rollback() so
+ // anything else indicates a serious error in the resource-manager.
+ throw new XAException(XAException.XAER_RMERR);
+ }
}
- }
- throw new XAException(heurCode);
+ throw new XAException(heurCode);
+ }
+ } finally {
+ cleanupTransaction();
}
}
@@ -212,48 +229,7 @@
return rollbackOnly;
}
- private void doOnePhaseCommit(Xid xid, MulgaraExternalTransaction xa) throws XAException {
- try {
- boolean success = true;
- XAException exception = null;
- Set<EnlistableResource> prepared = new HashSet<EnlistableResource>();
-
- try {
- for (EnlistableResource er : xa.getEnlistedResources()) {
- er.getXAResource().prepare(xid);
- prepared.add(er);
- }
- } catch (XAResource ex) {
- exception = ex;
- success = false;
- } catch (Throwable th) {
- logger.error("Error preparing transaction in onePhase commit", th);
- exception = new XAException(XAException.XAER_RMERR);
- success = false;
- }
-
- Set<EnlistableResource> committed = new HashSet<EnlistableResource>();
-
- if (success) {
- try {
- for (EnlistableResource er : xa.getEnlistedResources()) {
- er.getXAResource().commit(xid, false);
- committed.add(er);
- }
- } catch (XAResource ex) {
- logger.error("Error committing resource in onePhase commit", ex);
- exception = ex;
- success = false;
- }
- }
-
- }
- } catch (XAException ex) {
- logger.error("Attempt to perform one-phase-commit failed", ex);
- throw ex;
- } catch (Throwable th) {
- logger.error("Exception while performing one-phase-commit", th);
- throw new XAException(XAException.XAER_RMERR);
- }
+ private void cleanupTransaction() {
+ factory.transactionComplete(this);
}
}
More information about the Mulgara-svn
mailing list