[jboss-svn-commits] JBL Code SVN: r37461 - in labs/jbosstm/trunk/rest-tx/tx/src/main/java/org/jboss/jbossts/star: service and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Sep 9 10:41:58 EDT 2011
Author: mmusgrov
Date: 2011-09-09 10:41:58 -0400 (Fri, 09 Sep 2011)
New Revision: 37461
Modified:
labs/jbosstm/trunk/rest-tx/tx/src/main/java/org/jboss/jbossts/star/resource/RESTRecord.java
labs/jbosstm/trunk/rest-tx/tx/src/main/java/org/jboss/jbossts/star/resource/Transaction.java
labs/jbosstm/trunk/rest-tx/tx/src/main/java/org/jboss/jbossts/star/service/Coordinator.java
labs/jbosstm/trunk/rest-tx/tx/src/main/java/org/jboss/jbossts/star/util/TxSupport.java
Log:
[BLACKTIE-377] Add support for rollback only and improve heuristic reporting to support blacktie
Modified: labs/jbosstm/trunk/rest-tx/tx/src/main/java/org/jboss/jbossts/star/resource/RESTRecord.java
===================================================================
--- labs/jbosstm/trunk/rest-tx/tx/src/main/java/org/jboss/jbossts/star/resource/RESTRecord.java 2011-09-08 21:35:50 UTC (rev 37460)
+++ labs/jbosstm/trunk/rest-tx/tx/src/main/java/org/jboss/jbossts/star/resource/RESTRecord.java 2011-09-09 14:41:58 UTC (rev 37461)
@@ -278,6 +278,8 @@
*/
public int topLevelOnePhaseCommit()
{
+ TxSupport txs = new TxSupport();
+
check_halt(Fault.commit_halt);
check_suspend(Fault.commit_suspend);
@@ -289,18 +291,30 @@
if (log.isTraceEnabled())
log.trace("committing " + this.terminateUrl);
- if (!TxSupport.isReadOnly(status))
- status = TxSupport.getStatus(new TxSupport().httpRequest(new int[] {HttpURLConnection.HTTP_OK}, this.terminateUrl, "PUT", TxSupport.STATUS_MEDIA_TYPE,
- TxSupport.toStatusContent(TxSupport.COMMITTED), null)); // ONE_PHASE_COMMIT_CONTENT
- else
+ if (!TxSupport.isReadOnly(status)) {
+ txs = new TxSupport();
+ String body = txs.httpRequest(new int[] {HttpURLConnection.HTTP_OK},
+ this.terminateUrl, "PUT", TxSupport.STATUS_MEDIA_TYPE,
+ TxSupport.toStatusContent(TxSupport.COMMITTED), null); // ONE_PHASE_COMMIT_CONTENT
+
+ status = txs.getStatus(body);
+
+ if (log.isTraceEnabled())
+ log.trace("commit http status: " + txs.getStatus() + " RTS status: " + status);
+ } else {
status = TxSupport.COMMITTED;
+ }
if (log.isTraceEnabled())
log.trace("COMMIT OK at terminateUrl: " + this.terminateUrl);
}
catch (HttpResponseException e)
{
+ if (log.isDebugEnabled())
+ log.debug("commit exception: " + e + " body: " + txs.getBody());
checkFinishError(e.getActualResponse(), true);
+
+ status = txs.getBody();
}
return statusToOutcome(status);
Modified: labs/jbosstm/trunk/rest-tx/tx/src/main/java/org/jboss/jbossts/star/resource/Transaction.java
===================================================================
--- labs/jbosstm/trunk/rest-tx/tx/src/main/java/org/jboss/jbossts/star/resource/Transaction.java 2011-09-08 21:35:50 UTC (rev 37460)
+++ labs/jbosstm/trunk/rest-tx/tx/src/main/java/org/jboss/jbossts/star/resource/Transaction.java 2011-09-09 14:41:58 UTC (rev 37461)
@@ -175,6 +175,17 @@
r = pendingList.peekNext(r);
}
}
+ public boolean isGone()
+ {
+ switch ( status() )
+ {
+ case ActionStatus.COMMITTED :
+ case ActionStatus.ABORTED :
+ return true;
+ default:
+ return false;
+ }
+ }
public boolean isFinished()
{
Modified: labs/jbosstm/trunk/rest-tx/tx/src/main/java/org/jboss/jbossts/star/service/Coordinator.java
===================================================================
--- labs/jbosstm/trunk/rest-tx/tx/src/main/java/org/jboss/jbossts/star/service/Coordinator.java 2011-09-08 21:35:50 UTC (rev 37460)
+++ labs/jbosstm/trunk/rest-tx/tx/src/main/java/org/jboss/jbossts/star/service/Coordinator.java 2011-09-09 14:41:58 UTC (rev 37461)
@@ -169,13 +169,17 @@
int timeout = TxSupport.getIntValue(content, TxSupport.TIMEOUT_PROPERTY, 0); // default is 0 - never timeout
String uid = tx.get_uid().fileStringForm();
+ log.trace("coordinator: timeout=" + timeout);
transactions.put(uid, tx);
// round up the timeout from milliseconds to seconds
if (timeout != 0) {
- timeout = timeout / 1000;
if (timeout == 0)
timeout = 1;
+ else if (timeout < 0)
+ timeout = 0;
+ else
+ timeout /= 1000;
}
int status = tx.begin(timeout);
@@ -186,10 +190,12 @@
URI uri1 = TxSupport.getUri(info, info.getPathSegments().size(), uid);
Response.ResponseBuilder builder = Response.created(uri1);
- TxSupport.addLinkHeader(builder, info, TxSupport.TERMINATOR_LINK, TxSupport.TERMINATOR_LINK, uid, "terminate");
- TxSupport.addLinkHeader(builder, info, TxSupport.PARTICIPANT_LINK, TxSupport.PARTICIPANT_LINK, uid);
+ TxSupport.addLinkHeader(builder, info, TxSupport.TERMINATOR_LINK,
+ TxSupport.TERMINATOR_LINK, uid, "terminate");
+ TxSupport.addLinkHeader(builder, info, TxSupport.PARTICIPANT_LINK,
+ TxSupport.PARTICIPANT_LINK, uid);
- return builder.build();
+ return builder.build();
}
throw new TransactionStatusException("Transaction failed to start: " + status);
@@ -251,29 +257,47 @@
@Path(TxSupport.TX_SEGMENT + "/{TxId}/terminate")
public Response terminateTransaction(@PathParam("TxId")String txId, @QueryParam("fault") @DefaultValue("")String fault, String content)
{
- log.trace("coordinator: commit: transaction-manager/" + txId + "/terminate");
+ log.trace("coordinator: commit: transaction-manager/" + txId + "/terminate : content: " + content);
Transaction tx = getTransaction(txId);
Collection<String> enlistmentIds = new ArrayList<String>();
String how = TxSupport.getStringValue(content, TxSupport.STATUS_PROPERTY);
String status;
- int aaRes;
int scRes;
- boolean commit;
+ int ihow;
tx.getParticipants(enlistmentIds);
+ /*
+ ABORT_ONLY is not in the spec for the same reasons as it's not in the WS-TX and WS-CAF where
+ it is assumed that only the txn originator can end the tx:
+ - simply register a synchronization in the transaction that prevented a commit from happening;
+ and I haven't implemented synchronisations yet.
+ It is unclear why allowing similar functionality via synchronisations doesn't open up a similar
+ security hole.
+ */
+
if (TxSupport.COMMITTED.equals(how))
- commit = true;
+ ihow = 0;
else if (TxSupport.ABORTED.equals(how))
- commit = false;
+ ihow = 1;
+ else if (TxSupport.ABORT_ONLY.equals(how))
+ ihow = 2;
else
return Response.status(HttpURLConnection.HTTP_BAD_REQUEST).build();
tx.setFault(fault);
AtomicAction.resume(tx);
- aaRes = commit ? tx.commit(true) : tx.abort();
- status = tx.getStatus(aaRes);
+
+ if (ihow == 0) {
+ status = tx.getStatus(tx.commit(true));
+ } else if (ihow == 1) {
+ status = tx.getStatus(tx.abort());
+ } else {
+ tx.preventCommit();
+ status = tx.getStatus();
+ }
+
AtomicAction.suspend();
log.trace("terminate result: " + status);
@@ -289,7 +313,7 @@
i.remove();
} else if (tx.isFinishing()) {
// TODO who cleans up in this case
- log.debug("transaction is still terminating: " + aaRes);
+ log.debug("transaction is still terminating: " + status);
}
if (status.length() == 0)
Modified: labs/jbosstm/trunk/rest-tx/tx/src/main/java/org/jboss/jbossts/star/util/TxSupport.java
===================================================================
--- labs/jbosstm/trunk/rest-tx/tx/src/main/java/org/jboss/jbossts/star/util/TxSupport.java 2011-09-08 21:35:50 UTC (rev 37460)
+++ labs/jbosstm/trunk/rest-tx/tx/src/main/java/org/jboss/jbossts/star/util/TxSupport.java 2011-09-09 14:41:58 UTC (rev 37461)
@@ -228,12 +228,22 @@
addLocationHeader(connection, linkHeaders);
}
+ if (log.isTraceEnabled())
+ log.trace("httpRequest:" +
+ "\n\turl: " + url +
+ "\n\tmethod: " + method +
+ "\n\tmediaType: " + mediaType +
+ "\n\tcontent: " + content +
+ "\n\tresponse code: " + status +
+ "\n\tresponse body: " + body
+ );
+
if (expect != null && expect.length != 0) {
for (int sc : expect)
if (sc == status)
return body;
- throw new HttpResponseException(null, "", expect, status);
+ throw new HttpResponseException(null, body, expect, status);
} else {
return body;
}
More information about the jboss-svn-commits
mailing list