[rhmessaging-commits] rhmessaging commits: r2145 - store/trunk/cpp/lib.

rhmessaging-commits at lists.jboss.org rhmessaging-commits at lists.jboss.org
Tue Jun 10 07:25:32 EDT 2008


Author: gordonsim
Date: 2008-06-10 07:25:32 -0400 (Tue, 10 Jun 2008)
New Revision: 2145

Modified:
   store/trunk/cpp/lib/BdbMessageStore.cpp
   store/trunk/cpp/lib/TxnCtxt.h
Log:
Fixes to construction of tid for use in journal:
* increment of count was unsafe due to per-instance lock; use pointer value instead as this is unique for the lifetime of the TxnCtxt object
* construction of string by adding an int value is not safe; use string stream instead

(These are believed to be fixes to BZ450280)



Modified: store/trunk/cpp/lib/BdbMessageStore.cpp
===================================================================
--- store/trunk/cpp/lib/BdbMessageStore.cpp	2008-06-06 19:03:42 UTC (rev 2144)
+++ store/trunk/cpp/lib/BdbMessageStore.cpp	2008-06-10 11:25:32 UTC (rev 2145)
@@ -54,7 +54,6 @@
 bool BdbMessageStore::useAsync;
 qpid::sys::Duration BdbMessageStore::defJournalGetEventsTimeout(10 * qpid::sys::TIME_MSEC); // 10ms
 qpid::sys::Duration BdbMessageStore::defJournalFlushTimeout(500 * qpid::sys::TIME_MSEC); // 0.5s
-unsigned int TxnCtxt::count = 0;
 qpid::sys::Mutex TxnCtxt::globalSerialiser;
 
 BdbMessageStore::BdbMessageStore(const char* envpath) : env(0), 

Modified: store/trunk/cpp/lib/TxnCtxt.h
===================================================================
--- store/trunk/cpp/lib/TxnCtxt.h	2008-06-06 19:03:42 UTC (rev 2144)
+++ store/trunk/cpp/lib/TxnCtxt.h	2008-06-10 11:25:32 UTC (rev 2145)
@@ -28,6 +28,7 @@
 #include <qpid/broker/MessageStore.h>
 #include <qpid/sys/Mutex.h>
 #include <boost/shared_ptr.hpp>
+#include <sstream>
 #include <memory>
 #include <vector>
 #include "JournalImpl.h"
@@ -53,15 +54,10 @@
     static qpid::sys::Mutex globalSerialiser;
 
     ipqdef impactedQueues; // list of Queues used in the txn
-    static unsigned int count;
     mutable qpid::sys::Mutex Lock;
     IdSequence* loggedtx;
     AutoScopedLock globalHolder;
-    
-    unsigned int getCount() {
-    	qpid::sys::Mutex::ScopedLock locker(Lock);
-        return ++count;
-    }
+
     /**
      * local txn id, if non XA.
      */
@@ -97,7 +93,11 @@
 public:
 	
     TxnCtxt(IdSequence* _loggedtx=NULL) : loggedtx(_loggedtx), txn(0)  {
-        if (loggedtx){ tid.assign( "rhm-tid"); tid+=getCount(); }
+        if (loggedtx){ 
+	  std::stringstream s;
+	  s << "rhm-tid" << this;
+	  tid.assign(s.str());
+	}
     }
 	
     /**
@@ -137,8 +137,20 @@
         env.txn_begin(0, &txn, 0);  
         if (sync) globalHolder = AutoScopedLock(new qpid::sys::Mutex::ScopedLock(globalSerialiser)); 
     }
-    void commit(){ txn->commit(0); completeTXN(true); txn = 0; globalHolder.reset(); }
-    void abort(){ txn->abort(); completeTXN(false); txn = 0; globalHolder.reset(); }
+    void commit(){ 
+        txn->commit(0); 
+        txn = 0; 
+        completeTXN(true); 
+        globalHolder.reset(); 
+    }
+    void abort(){ 
+        if (txn) {
+	    txn->abort();
+	    txn = 0; 
+	    completeTXN(false); 
+	    globalHolder.reset(); 
+	}
+    }
     DbTxn* get(){ return txn; }
     virtual bool isTPC() { return false; }
     virtual const std::string& getXid() { return tid; }




More information about the rhmessaging-commits mailing list