teiid SVN: r4545 - in branches/7.7.x/engine/src: main/java/org/teiid/query/processor/proc and 2 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2013-01-17 13:36:23 -0500 (Thu, 17 Jan 2013)
New Revision: 4545
Modified:
branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/process/Request.java
branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/process/TransactionServerImpl.java
branches/7.7.x/engine/src/main/java/org/teiid/query/processor/proc/ProcedurePlan.java
branches/7.7.x/engine/src/test/java/org/teiid/dqp/internal/process/TestRequest.java
branches/7.7.x/engine/src/test/java/org/teiid/query/processor/proc/TestProcedureProcessor.java
Log:
TEIID-2205 fix for procedure/block/local connection txn issues
Modified: branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/process/Request.java
===================================================================
--- branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/process/Request.java 2013-01-15 16:56:56 UTC (rev 4544)
+++ branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/process/Request.java 2013-01-17 18:36:23 UTC (rev 4545)
@@ -266,7 +266,6 @@
this.context.setRequestId(this.requestId);
this.context.setDQPWorkContext(this.workContext);
this.context.setTransactionService(this.transactionService);
- this.context.setTransactionContext(this.transactionContext);
}
@Override
@@ -374,6 +373,7 @@
tc.setIsolationLevel(requestMsg.getTransactionIsolation());
this.transactionContext = tc;
+ this.context.setTransactionContext(tc);
this.processor = new QueryProcessor(processPlan, context, bufferManager, processorDataManager);
}
Modified: branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
===================================================================
--- branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java 2013-01-15 16:56:56 UTC (rev 4544)
+++ branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java 2013-01-17 18:36:23 UTC (rev 4545)
@@ -349,13 +349,13 @@
}
private void resume() throws XATransactionException {
- if (this.transactionState == TransactionState.ACTIVE && isSuspendable()) {
+ if (this.transactionState == TransactionState.ACTIVE) {
this.transactionService.resume(this.transactionContext);
}
}
private boolean isSuspendable() {
- return !this.useCallingThread && this.transactionContext.getTransaction() != null;
+ return this.transactionContext.getTransaction() != null && !(this.useCallingThread && this.transactionContext.getTransactionType() == Scope.GLOBAL);
}
private void suspend() {
Modified: branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/process/TransactionServerImpl.java
===================================================================
--- branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/process/TransactionServerImpl.java 2013-01-15 16:56:56 UTC (rev 4544)
+++ branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/process/TransactionServerImpl.java 2013-01-17 18:36:23 UTC (rev 4545)
@@ -60,6 +60,10 @@
import org.teiid.query.QueryPlugin;
+/**
+ * Note that the begin methods do not leave the transaction associated with the
+ * calling thread. This is by design and requires explicit resumes for association.
+ */
public class TransactionServerImpl implements TransactionService {
private static class TransactionMapping {
@@ -425,8 +429,17 @@
}
public void resume(TransactionContext context) throws XATransactionException {
- try {
- this.transactionManager.resume(context.getTransaction());
+ try {
+ //if we're already associated, just return
+ if (this.transactionManager.getTransaction() == context.getTransaction()) {
+ return;
+ }
+ } catch (SystemException e) {
+ }
+ try {
+ this.transactionManager.resume(context.getTransaction());
+ } catch (IllegalStateException e) {
+ throw new XATransactionException(e);
} catch (InvalidTransactionException e) {
throw new XATransactionException(e);
} catch (SystemException e) {
Modified: branches/7.7.x/engine/src/main/java/org/teiid/query/processor/proc/ProcedurePlan.java
===================================================================
--- branches/7.7.x/engine/src/main/java/org/teiid/query/processor/proc/ProcedurePlan.java 2013-01-15 16:56:56 UTC (rev 4544)
+++ branches/7.7.x/engine/src/main/java/org/teiid/query/processor/proc/ProcedurePlan.java 2013-01-17 18:36:23 UTC (rev 4545)
@@ -140,7 +140,6 @@
private boolean requiresTransaction = true;
private TransactionContext blockContext;
- private boolean inTxn;
/**
* Resources cannot be held open across the txn boundary. This list is a hack at ensuring the resources are closed.
*/
@@ -219,7 +218,6 @@
beginBatch = 1;
batchRows = null;
lastBatch = false;
- inTxn = false;
//reset program stack
programs.clear();
LogManager.logTrace(org.teiid.logging.LogConstants.CTX_DQP, "ProcedurePlan reset"); //$NON-NLS-1$
@@ -277,15 +275,13 @@
@Override
public TupleBatch nextBatch() throws BlockedException,
TeiidComponentException, TeiidProcessingException {
- if (blockContext != null && !this.inTxn) {
+ if (blockContext != null) {
this.getContext().getTransactionServer().resume(blockContext);
- this.inTxn = true;
}
try {
return nextBatchDirect();
} finally {
if (blockContext != null) {
- this.inTxn = false;
this.getContext().getTransactionServer().suspend(blockContext);
}
}
@@ -606,9 +602,7 @@
TransactionContext tc = this.blockContext;
this.blockContext = null;
try {
- if (!inTxn) {
- this.getContext().getTransactionServer().resume(tc);
- }
+ this.getContext().getTransactionServer().resume(tc);
for (WeakReference<DataTierTupleSource> ref : txnTupleSources) {
DataTierTupleSource dtts = ref.get();
if (dtts != null) {
@@ -642,9 +636,8 @@
if (tc != null && tc.getTransactionType() == Scope.NONE) {
//start a transaction
this.getContext().getTransactionServer().begin(tc);
- this.inTxn = true;
this.blockContext = tc;
- this.peek().setStartedTxn(true);
+ program.setStartedTxn(true);
}
}
}
Modified: branches/7.7.x/engine/src/test/java/org/teiid/dqp/internal/process/TestRequest.java
===================================================================
--- branches/7.7.x/engine/src/test/java/org/teiid/dqp/internal/process/TestRequest.java 2013-01-15 16:56:56 UTC (rev 4544)
+++ branches/7.7.x/engine/src/test/java/org/teiid/dqp/internal/process/TestRequest.java 2013-01-17 18:36:23 UTC (rev 4545)
@@ -45,7 +45,6 @@
import org.teiid.query.tempdata.TempTableStore;
import org.teiid.query.tempdata.TempTableStore.TransactionMode;
import org.teiid.query.unittest.RealMetadataFactory;
-import org.teiid.query.util.ContextProperties;
@@ -126,6 +125,7 @@
Request request = helpProcessMessage(message, null, workContext);
assertEquals("1", request.context.getConnectionID()); //$NON-NLS-1$
+ assertNotNull(request.context.getTransactionContext());
}
private Request helpProcessMessage(RequestMessage message, SessionAwareCache<PreparedPlan> cache, DQPWorkContext workContext) throws TeiidComponentException,
Modified: branches/7.7.x/engine/src/test/java/org/teiid/query/processor/proc/TestProcedureProcessor.java
===================================================================
--- branches/7.7.x/engine/src/test/java/org/teiid/query/processor/proc/TestProcedureProcessor.java 2013-01-15 16:56:56 UTC (rev 4544)
+++ branches/7.7.x/engine/src/test/java/org/teiid/query/processor/proc/TestProcedureProcessor.java 2013-01-17 18:36:23 UTC (rev 4545)
@@ -2523,7 +2523,7 @@
}
Mockito.verify(ts).begin(tc);
- Mockito.verify(ts).resume(tc);
+ Mockito.verify(ts, Mockito.times(2)).resume(tc);
Mockito.verify(ts, Mockito.times(0)).commit(tc);
Mockito.verify(ts).rollback(tc);
}