activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1339363 - in /activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core: ActiveMQConnection.cpp ActiveMQTransactionContext.cpp kernels/ActiveMQSessionKernel.cpp
Date Wed, 16 May 2012 21:07:40 GMT
Author: tabish
Date: Wed May 16 21:07:39 2012
New Revision: 1339363

URL: http://svn.apache.org/viewvc?rev=1339363&view=rev
Log:
Better handle exceptions that occurs during local transactions including the potential for
an TX to fail during failover because commit state is in doubt.

Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnection.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQTransactionContext.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/kernels/ActiveMQSessionKernel.cpp

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnection.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnection.cpp?rev=1339363&r1=1339362&r2=1339363&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnection.cpp
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnection.cpp
Wed May 16 21:07:39 2012
@@ -1037,6 +1037,7 @@ Pointer<Response> ActiveMQConnection::sy
 
         return response;
     }
+    AMQ_CATCH_RETHROW( cms::CMSException )
     AMQ_CATCH_RETHROW( ActiveMQException )
     AMQ_CATCH_EXCEPTION_CONVERT( IOException, ActiveMQException )
     AMQ_CATCH_EXCEPTION_CONVERT( decaf::lang::exceptions::UnsupportedOperationException,
ActiveMQException )

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQTransactionContext.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQTransactionContext.cpp?rev=1339363&r1=1339362&r2=1339363&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQTransactionContext.cpp
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQTransactionContext.cpp
Wed May 16 21:07:39 2012
@@ -19,6 +19,7 @@
 #include <cms/Xid.h>
 #include <cms/XAException.h>
 #include <cms/TransactionInProgressException.h>
+#include <cms/TransactionRolledBackException.h>
 #include <activemq/core/kernels/ActiveMQSessionKernel.h>
 #include <activemq/core/ActiveMQConnection.h>
 #include <activemq/core/ActiveMQConstants.h>
@@ -162,22 +163,20 @@ void ActiveMQTransactionContext::begin()
                 this->synchronizations.clear();
             }
 
-            // Create the Id
             Pointer<LocalTransactionId> id(new LocalTransactionId());
             id->setConnectionId(this->connection->getConnectionInfo().getConnectionId());
             id->setValue(this->connection->getNextLocalTransactionId());
 
-            // Create and Populate the Info Command.
             Pointer<TransactionInfo> transactionInfo(new TransactionInfo());
             transactionInfo->setConnectionId(id->getConnectionId());
             transactionInfo->setTransactionId(id);
             transactionInfo->setType(ActiveMQConstants::TRANSACTION_STATE_BEGIN);
 
             this->connection->oneway(transactionInfo);
-
-            this->context->transactionId = id.dynamicCast<TransactionId> ();
+            this->context->transactionId = id.dynamicCast<TransactionId>();
         }
     }
+    AMQ_CATCH_RETHROW( cms::CMSException )
     AMQ_CATCH_RETHROW( ActiveMQException )
     AMQ_CATCH_EXCEPTION_CONVERT( Exception, ActiveMQException )
     AMQ_CATCHALL_THROW( ActiveMQException )
@@ -192,27 +191,32 @@ void ActiveMQTransactionContext::commit(
             throw cms::TransactionInProgressException("Cannot Commit a local transaction
while an XA Transaction is in progress.");
         }
 
-        if (this->context->transactionId.get() == NULL) {
-            throw InvalidStateException(__FILE__, __LINE__, "ActiveMQTransactionContext::commit
- "
-                "Commit called before transaction was started.");
+        try {
+            this->beforeEnd();
+        } catch (cms::CMSException& ex) {
+            rollback();
+            throw;
         }
 
-        this->beforeEnd();
-
-        // Create and Populate the Info Command.
-        Pointer<TransactionInfo> info(new TransactionInfo());
-        info->setConnectionId(this->connection->getConnectionInfo().getConnectionId());
-        info->setTransactionId(this->context->transactionId);
-        info->setType(ActiveMQConstants::TRANSACTION_STATE_COMMITONEPHASE);
-
-        // Before we send the command NULL the id in case of an exception.
-        this->context->transactionId.reset(NULL);
+        if (isInTransaction()) {
+            Pointer<TransactionInfo> info(new TransactionInfo());
+            info->setConnectionId(this->connection->getConnectionInfo().getConnectionId());
+            info->setTransactionId(this->context->transactionId);
+            info->setType(ActiveMQConstants::TRANSACTION_STATE_COMMITONEPHASE);
 
-        // Commit the current Transaction
-        this->connection->syncRequest(info);
+            // Before we send the command NULL the id in case of an exception.
+            this->context->transactionId.reset(NULL);
 
-        this->afterCommit();
+            try {
+                this->connection->syncRequest(info);
+                this->afterCommit();
+            } catch(cms::CMSException& ex) {
+                this->afterRollback();
+                throw;
+            }
+        }
     }
+    AMQ_CATCH_RETHROW( cms::CMSException )
     AMQ_CATCH_RETHROW( ActiveMQException )
     AMQ_CATCH_EXCEPTION_CONVERT( Exception, ActiveMQException )
     AMQ_CATCHALL_THROW( ActiveMQException )
@@ -227,27 +231,27 @@ void ActiveMQTransactionContext::rollbac
             throw cms::TransactionInProgressException("Cannot Rollback a local transaction
while an XA Transaction is in progress.");
         }
 
-        if (this->context->transactionId == NULL) {
-            throw InvalidStateException(__FILE__, __LINE__, "ActiveMQTransactionContext::rollback
- "
-                "Rollback called before transaction was started.");
+        try {
+            this->beforeEnd();
+        } catch (cms::TransactionRolledBackException& ex) {
+            // Ignore, can occur on failover if the last command was commit.
         }
 
-        this->beforeEnd();
-
-        // Create and Populate the Info Command.
-        Pointer<TransactionInfo> info(new TransactionInfo());
-        info->setConnectionId(this->connection->getConnectionInfo().getConnectionId());
-        info->setTransactionId(this->context->transactionId);
-        info->setType(ActiveMQConstants::TRANSACTION_STATE_ROLLBACK);
+        if (isInTransaction()) {
 
-        // Before we send the command NULL the id in case of an exception.
-        this->context->transactionId.reset(NULL);
+            Pointer<TransactionInfo> info(new TransactionInfo());
+            info->setConnectionId(this->connection->getConnectionInfo().getConnectionId());
+            info->setTransactionId(this->context->transactionId);
+            info->setType(ActiveMQConstants::TRANSACTION_STATE_ROLLBACK);
 
-        // Roll back the current Transaction
-        this->connection->syncRequest(info);
+            // Before we send the command NULL the id in case of an exception.
+            this->context->transactionId.reset(NULL);
 
-        this->afterRollback();
+            this->connection->syncRequest(info);
+            this->afterRollback();
+        }
     }
+    AMQ_CATCH_RETHROW( cms::CMSException )
     AMQ_CATCH_RETHROW( ActiveMQException )
     AMQ_CATCH_EXCEPTION_CONVERT( Exception, ActiveMQException )
     AMQ_CATCHALL_THROW( ActiveMQException )

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/kernels/ActiveMQSessionKernel.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/kernels/ActiveMQSessionKernel.cpp?rev=1339363&r1=1339362&r2=1339363&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/kernels/ActiveMQSessionKernel.cpp
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/kernels/ActiveMQSessionKernel.cpp
Wed May 16 21:07:39 2012
@@ -389,7 +389,8 @@ void ActiveMQSessionKernel::commit() {
         this->checkClosed();
 
         if (!this->isTransacted()) {
-            throw ActiveMQException(__FILE__, __LINE__, "ActiveMQSessionKernel::commit -
This Session is not Transacted");
+            throw ActiveMQException(
+                __FILE__, __LINE__, "ActiveMQSessionKernel::commit - This Session is not
Transacted");
         }
 
         // Commit the Transaction
@@ -406,7 +407,8 @@ void ActiveMQSessionKernel::rollback() {
         this->checkClosed();
 
         if (!this->isTransacted()) {
-            throw ActiveMQException(__FILE__, __LINE__, "ActiveMQSessionKernel::rollback
- This Session is not Transacted");
+            throw ActiveMQException(
+                __FILE__, __LINE__, "ActiveMQSessionKernel::rollback - This Session is not
Transacted");
         }
 
         // Roll back the Transaction



Mime
View raw message