activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1537089 - in /activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src: main/csharp/NetTxTransactionContext.cs test/csharp/DtcConsumerTransactionsTest.cs test/csharp/DtcProducerTransactionsTest.cs
Date Wed, 30 Oct 2013 13:52:50 GMT
Author: tabish
Date: Wed Oct 30 13:52:50 2013
New Revision: 1537089

URL: http://svn.apache.org/r1537089
Log:
https://issues.apache.org/jira/browse/AMQNET-417

Modified:
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/NetTxTransactionContext.cs
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/DtcConsumerTransactionsTest.cs
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/DtcProducerTransactionsTest.cs

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/NetTxTransactionContext.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/NetTxTransactionContext.cs?rev=1537089&r1=1537088&r2=1537089&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/NetTxTransactionContext.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/NetTxTransactionContext.cs
Wed Oct 30 13:52:50 2013
@@ -32,11 +32,22 @@ namespace Apache.NMS.ActiveMQ
         private const int XA_READONLY = 3;
 
         private Enlistment currentEnlistment;
+        private static readonly Dictionary<string, bool> recoveredResourceManagerIds
= new Dictionary<string, bool>();
 
         public NetTxTransactionContext(Session session) : base(session)
         {
         }
 
+        /// <summary>
+        /// DTC recovery is performed once for each AppDomain per default. In case you want
to perform
+        /// it again during execution of the application you can call this method before.
+        /// But ensure in this case that no connection is active anymore.
+        /// </summary>
+        public static void ResetDtcRecovery()
+        {
+            recoveredResourceManagerIds.Clear();
+        }
+
         public override bool InLocalTransaction
         {
             get { return this.transactionId != null && this.currentEnlistment ==
null; }
@@ -500,62 +511,74 @@ namespace Apache.NMS.ActiveMQ
         /// </summary>
         public void InitializeDtcTxContext()
         {
+            string resourceManagerId = ResourceManagerId;
+
             // initialize the logger with the current Resource Manager Id
-            RecoveryLogger.Initialize(ResourceManagerId);
+            RecoveryLogger.Initialize(resourceManagerId);
 
-            KeyValuePair<XATransactionId, byte[]>[] localRecoverables = RecoveryLogger.GetRecoverables();
-            if (localRecoverables.Length == 0)
+            lock (recoveredResourceManagerIds)
             {
-                Tracer.Debug("Did not detect any open DTC transaction records on disk.");
-                // No local data so anything stored on the broker can't be recovered here.
-                return;
-            }
+                if (recoveredResourceManagerIds.ContainsKey(resourceManagerId))
+                {
+                    return;
+                }
 
-            XATransactionId[] recoverables = TryRecoverBrokerTXIds();
-            if (recoverables.Length == 0)
-            {
-                Tracer.Debug("Did not detect any recoverable transactions at Broker.");
-                // Broker has no recoverable data so nothing to do here, delete the
-                // old recovery log as its stale.
-                RecoveryLogger.Purge();
-                return;
-            }
+                recoveredResourceManagerIds[resourceManagerId] = true;
 
-            List<KeyValuePair<XATransactionId, byte[]>> matches = new List<KeyValuePair<XATransactionId,
byte[]>>();
+                KeyValuePair<XATransactionId, byte[]>[] localRecoverables = RecoveryLogger.GetRecoverables();
+                if (localRecoverables.Length == 0)
+                {
+                    Tracer.Debug("Did not detect any open DTC transaction records on disk.");
+                    // No local data so anything stored on the broker can't be recovered
here.
+                    return;
+                }
 
-            foreach (XATransactionId recoverable in recoverables)
-            {
-                foreach (KeyValuePair<XATransactionId, byte[]> entry in localRecoverables)
+                XATransactionId[] recoverables = TryRecoverBrokerTXIds();
+                if (recoverables.Length == 0)
                 {
-                    if (entry.Key.Equals(recoverable))
+                    Tracer.Debug("Did not detect any recoverable transactions at Broker.");
+                    // Broker has no recoverable data so nothing to do here, delete the 
+                    // old recovery log as its stale.
+                    RecoveryLogger.Purge();
+                    return;
+                }
+
+                List<KeyValuePair<XATransactionId, byte[]>> matches = new List<KeyValuePair<XATransactionId,
byte[]>>();
+
+                foreach (XATransactionId recoverable in recoverables)
+                {
+                    foreach (KeyValuePair<XATransactionId, byte[]> entry in localRecoverables)
                     {
-                        Tracer.DebugFormat("Found a matching TX on Broker to stored Id: {0}
reenlisting.", entry.Key);
-                        matches.Add(entry);
+                        if (entry.Key.Equals(recoverable))
+                        {
+                            Tracer.DebugFormat("Found a matching TX on Broker to stored Id:
{0} reenlisting.", entry.Key);
+                            matches.Add(entry);
+                        }
                     }
                 }
-            }
-
-            if (matches.Count != 0)
-            {
-                this.recoveryComplete = new CountDownLatch(matches.Count);
 
-                foreach (KeyValuePair<XATransactionId, byte[]> recoverable in matches)
+                if (matches.Count != 0)
                 {
-                    this.transactionId = recoverable.Key;
-                    Tracer.Info("Reenlisting recovered TX with Id: " + this.transactionId);
-                    this.currentEnlistment =
-                        TransactionManager.Reenlist(ResourceManagerGuid, recoverable.Value,
this);
+                    this.recoveryComplete = new CountDownLatch(matches.Count);
+
+                    foreach (KeyValuePair<XATransactionId, byte[]> recoverable in matches)
+                    {
+                        this.transactionId = recoverable.Key;
+                        Tracer.Info("Reenlisting recovered TX with Id: " + this.transactionId);
+                        this.currentEnlistment =
+                            TransactionManager.Reenlist(ResourceManagerGuid, recoverable.Value,
this);
+                    }
+
+                    this.recoveryComplete.await();
+                    Tracer.Debug("All Recovered TX enlistments Reports complete, Recovery
Complete.");
+                    TransactionManager.RecoveryComplete(ResourceManagerGuid);
+                    return;
                 }
 
-                this.recoveryComplete.await();
-                Tracer.Debug("All Recovered TX enlistments Reports complete, Recovery Complete.");
-                TransactionManager.RecoveryComplete(ResourceManagerGuid);
-                return;
+                // The old recovery information doesn't match what's on the broker so we
+                // should discard it as its stale now.
+                RecoveryLogger.Purge();
             }
-
-            // The old recovery information doesn't match what's on the broker so we
-            // should discard it as its stale now.
-            RecoveryLogger.Purge();
         }
 
         private XATransactionId[] TryRecoverBrokerTXIds()

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/DtcConsumerTransactionsTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/DtcConsumerTransactionsTest.cs?rev=1537089&r1=1537088&r2=1537089&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/DtcConsumerTransactionsTest.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/DtcConsumerTransactionsTest.cs
Wed Oct 30 13:52:50 2013
@@ -447,6 +447,7 @@ namespace Apache.NMS.ActiveMQ.Test
             VerifyDatabaseTableIsFull();
 
             // check messages are NOT present in the queue
+            NetTxTransactionContext.ResetDtcRecovery();
             VerifyBrokerQueueCount(0, newConnectionUri);
 
             Assert.AreEqual(0, Directory.GetFiles(logLocation).Length);
@@ -473,6 +474,7 @@ namespace Apache.NMS.ActiveMQ.Test
             VerifyDatabaseTableIsEmpty();
 
             // check messages are present in the queue
+            NetTxTransactionContext.ResetDtcRecovery();
             VerifyBrokerQueueCount();
         }
 
@@ -502,6 +504,7 @@ namespace Apache.NMS.ActiveMQ.Test
             VerifyDatabaseTableIsEmpty();
 
             // check messages are recovered and present in the queue 
+            NetTxTransactionContext.ResetDtcRecovery();
             VerifyBrokerQueueCount();
         }
 
@@ -534,6 +537,7 @@ namespace Apache.NMS.ActiveMQ.Test
             VerifyDatabaseTableIsEmpty();
 
             // check messages are present in the queue
+            NetTxTransactionContext.ResetDtcRecovery();
             VerifyBrokerQueueCount();
         }
 
@@ -566,6 +570,7 @@ namespace Apache.NMS.ActiveMQ.Test
             VerifyDatabaseTableIsEmpty();
 
             // check messages are present in the queue
+            NetTxTransactionContext.ResetDtcRecovery();
             VerifyBrokerQueueCount();
         }
 

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/DtcProducerTransactionsTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/DtcProducerTransactionsTest.cs?rev=1537089&r1=1537088&r2=1537089&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/DtcProducerTransactionsTest.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/DtcProducerTransactionsTest.cs
Wed Oct 30 13:52:50 2013
@@ -66,6 +66,7 @@ namespace Apache.NMS.ActiveMQ.Test
             VerifyDatabaseTableIsEmpty();
 
             // check messages are present in the queue
+            NetTxTransactionContext.ResetDtcRecovery();
             VerifyBrokerQueueCount();
         }
 



Mime
View raw message