[rhmessaging-commits] rhmessaging commits: r4033 - in store/trunk/cpp: tests/jrnl and 1 other directory.

rhmessaging-commits at lists.jboss.org rhmessaging-commits at lists.jboss.org
Thu Jun 17 13:35:13 EDT 2010


Author: kpvdr
Date: 2010-06-17 13:35:12 -0400 (Thu, 17 Jun 2010)
New Revision: 4033

Modified:
   store/trunk/cpp/lib/jrnl/enq_map.cpp
   store/trunk/cpp/lib/jrnl/enq_map.hpp
   store/trunk/cpp/lib/jrnl/jcntl.cpp
   store/trunk/cpp/lib/jrnl/jcntl.hpp
   store/trunk/cpp/lib/jrnl/rmgr.cpp
   store/trunk/cpp/lib/jrnl/wmgr.cpp
   store/trunk/cpp/tests/jrnl/_ut_enq_map.cpp
Log:
Refactor to remove exceptions from emap execution path

Modified: store/trunk/cpp/lib/jrnl/enq_map.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/enq_map.cpp	2010-06-17 13:47:29 UTC (rev 4032)
+++ store/trunk/cpp/lib/jrnl/enq_map.cpp	2010-06-17 17:35:12 UTC (rev 4033)
@@ -8,7 +8,7 @@
  *
  * \author Kim van der Riet
  *
- * Copyright (c) 2007, 2008, 2009 Red Hat Inc.
+ * Copyright (c) 2007, 2008, 2009, 2010 Red Hat Inc.
  *
  * This file is part of the Qpid async store library msgstore.so.
  *
@@ -43,6 +43,14 @@
 namespace journal
 {
 
+// static return/error codes
+int16_t enq_map::EMAP_DUP_RID = -3;
+int16_t enq_map::EMAP_LOCKED = -2;
+int16_t enq_map::EMAP_RID_NOT_FOUND = -1;
+int16_t enq_map::EMAP_OK = 0;
+int16_t enq_map::EMAP_FALSE = 0;
+int16_t enq_map::EMAP_TRUE = 1;
+
 enq_map::enq_map():
         _map(),
         _pfid_enq_cnt()
@@ -56,13 +64,14 @@
     _pfid_enq_cnt.set_size(num_jfiles);
 }
 
-void
+
+int16_t
 enq_map::insert_pfid(const u_int64_t rid, const u_int16_t pfid)
 {
-    insert_pfid(rid, pfid, false);
+    return insert_pfid(rid, pfid, false);
 }
 
-void
+int16_t
 enq_map::insert_pfid(const u_int64_t rid, const u_int16_t pfid, const bool locked)
 {
     std::pair<emap_itr, bool> ret;
@@ -72,51 +81,32 @@
         ret = _map.insert(emap_param(rid, rec));
     }
     if (ret.second == false)
-    {
-        std::ostringstream oss;
-        oss << std::hex << "rid=0x" << rid << " pfid=0x" << pfid;
-        throw jexception(jerrno::JERR_MAP_DUPLICATE, oss.str(), "enq_map", "insert_pfid");
-    }
+        return EMAP_DUP_RID;
     _pfid_enq_cnt.incr(pfid);
+    return EMAP_OK;
 }
 
-u_int16_t
+int16_t
 enq_map::get_pfid(const u_int64_t rid)
 {
     slock s(_mutex);
     emap_itr itr = _map.find(rid);
     if (itr == _map.end()) // not found in map
-    {
-        std::ostringstream oss;
-        oss << std::hex << "rid=0x" << rid;
-        throw jexception(jerrno::JERR_MAP_NOTFOUND, oss.str(), "enq_map", "get_pfid");
-    }
+        return EMAP_RID_NOT_FOUND;
     if (itr->second._lock)
-    {
-        std::ostringstream oss;
-        oss << std::hex << "rid=0x" << rid;
-        throw jexception(jerrno::JERR_MAP_LOCKED, oss.str(), "enq_map", "get_pfid");
-    }
+        return EMAP_LOCKED;
     return itr->second._pfid;
 }
 
-u_int16_t
+int16_t
 enq_map::get_remove_pfid(const u_int64_t rid, const bool txn_flag)
 {
     slock s(_mutex);
     emap_itr itr = _map.find(rid);
     if (itr == _map.end()) // not found in map
-    {
-        std::ostringstream oss;
-        oss << std::hex << "rid=0x" << rid;
-        throw jexception(jerrno::JERR_MAP_NOTFOUND, oss.str(), "enq_map", "get_remove_pfid");
-    }
+        return EMAP_RID_NOT_FOUND;
     if (itr->second._lock && !txn_flag) // locked, but not a commit/abort
-    {
-        std::ostringstream oss;
-        oss << std::hex << "rid=0x" << rid;
-        throw jexception(jerrno::JERR_MAP_LOCKED, oss.str(), "enq_map", "get_remove_pfid");
-    }
+        return EMAP_LOCKED;
     u_int16_t pfid = itr->second._pfid;
     _map.erase(itr);
     _pfid_enq_cnt.decr(pfid);
@@ -135,46 +125,36 @@
     return true;
 }
 
-void
+int16_t
 enq_map::lock(const u_int64_t rid)
 {
     slock s(_mutex);
     emap_itr itr = _map.find(rid);
     if (itr == _map.end()) // not found in map
-    {
-        std::ostringstream oss;
-        oss << std::hex << "rid=0x" << rid;
-        throw jexception(jerrno::JERR_MAP_NOTFOUND, oss.str(), "enq_map", "lock");
-    }
+        return EMAP_RID_NOT_FOUND;
     itr->second._lock = true;
+    return EMAP_OK;
 }
 
-void
+int16_t
 enq_map::unlock(const u_int64_t rid)
 {
     slock s(_mutex);
     emap_itr itr = _map.find(rid);
     if (itr == _map.end()) // not found in map
-    {
-        std::ostringstream oss;
-        oss << std::hex << "rid=0x" << rid;
-        throw jexception(jerrno::JERR_MAP_NOTFOUND, oss.str(), "enq_map", "unlock");
-    }
+        return EMAP_RID_NOT_FOUND;
     itr->second._lock = false;
+    return EMAP_OK;
 }
 
-bool
+int16_t
 enq_map::is_locked(const u_int64_t rid)
 {
     slock s(_mutex);
     emap_itr itr = _map.find(rid);
     if (itr == _map.end()) // not found in map
-    {
-        std::ostringstream oss;
-        oss << std::hex << "rid=0x" << rid;
-        throw jexception(jerrno::JERR_MAP_NOTFOUND, oss.str(), "enq_map", "is_locked");
-    }
-    return itr->second._lock;
+        return EMAP_RID_NOT_FOUND;
+    return itr->second._lock ? EMAP_TRUE : EMAP_FALSE;
 }
 
 void

Modified: store/trunk/cpp/lib/jrnl/enq_map.hpp
===================================================================
--- store/trunk/cpp/lib/jrnl/enq_map.hpp	2010-06-17 13:47:29 UTC (rev 4032)
+++ store/trunk/cpp/lib/jrnl/enq_map.hpp	2010-06-17 17:35:12 UTC (rev 4033)
@@ -8,7 +8,7 @@
  *
  * \author Kim van der Riet
  *
- * Copyright (c) 2007, 2008, 2009 Red Hat Inc.
+ * Copyright (c) 2007, 2008, 2009, 2010 Red Hat Inc.
  *
  * This file is part of the Qpid async store library msgstore.so.
  *
@@ -75,6 +75,15 @@
     */
     class enq_map
     {
+    public:
+        // return/error codes
+        static int16_t EMAP_DUP_RID;
+        static int16_t EMAP_LOCKED;
+        static int16_t EMAP_RID_NOT_FOUND;
+        static int16_t EMAP_OK;
+        static int16_t EMAP_FALSE;
+        static int16_t EMAP_TRUE;
+
     private:
 
         struct emap_data_struct
@@ -98,14 +107,14 @@
         void set_num_jfiles(const u_int16_t num_jfiles);
         inline u_int32_t get_enq_cnt(const u_int16_t pfid) const { return _pfid_enq_cnt.cnt(pfid); };
 
-        void insert_pfid(const u_int64_t rid, const u_int16_t pfid);
-        void insert_pfid(const u_int64_t rid, const u_int16_t pfid, const bool locked);
-        u_int16_t get_pfid(const u_int64_t rid);
-        u_int16_t get_remove_pfid(const u_int64_t rid, const bool txn_flag = false);
+        int16_t insert_pfid(const u_int64_t rid, const u_int16_t pfid); // 0=ok; -3=duplicate rid;
+        int16_t insert_pfid(const u_int64_t rid, const u_int16_t pfid, const bool locked); // 0=ok; -3=duplicate rid;
+        int16_t get_pfid(const u_int64_t rid); // >=0=pfid; -1=rid not found; -2=locked
+        int16_t get_remove_pfid(const u_int64_t rid, const bool txn_flag = false); // >=0=pfid; -1=rid not found; -2=locked
         bool is_enqueued(const u_int64_t rid, bool ignore_lock = false);
-        void lock(const u_int64_t rid);
-        void unlock(const u_int64_t rid);
-        bool is_locked(const u_int64_t rid);
+        int16_t lock(const u_int64_t rid); // 0=ok; -1=rid not found
+        int16_t unlock(const u_int64_t rid); // 0=ok; -1=rid not found
+        int16_t is_locked(const u_int64_t rid); // 1=true; 0=false; -1=rid not found
         inline void clear() { _map.clear(); }
         inline bool empty() const { return _map.empty(); }
         inline u_int32_t size() const { return u_int32_t(_map.size()); }

Modified: store/trunk/cpp/lib/jrnl/jcntl.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/jcntl.cpp	2010-06-17 13:47:29 UTC (rev 4032)
+++ store/trunk/cpp/lib/jrnl/jcntl.cpp	2010-06-17 17:35:12 UTC (rev 4033)
@@ -630,7 +630,16 @@
                         if (i->_enq_flag) // enq op - decrement enqueue count
                             rd._enq_cnt_list[i->_pfid]--;
                         else if (_emap.is_enqueued(i->_drid, true)) // deq op - unlock enq record
-                            _emap.unlock(i->_drid);
+                        {
+                            int16_t ret = _emap.unlock(i->_drid);
+                            if (ret < enq_map::EMAP_OK) // fail
+                            {
+                                // enq_map::unlock()'s only error is enq_map::EMAP_RID_NOT_FOUND
+                                std::ostringstream oss;
+                                oss << std::hex << "_emap.unlock(): drid=0x\"" << i->_drid;
+                                throw jexception(jerrno::JERR_MAP_NOTFOUND, oss.str(), "jcntl", "rcvr_janalyze");
+                            }
+                        }
                     }
                 }
             }
@@ -701,7 +710,15 @@
                         std::free(xidp);
                     }
                     else
-                        _emap.insert_pfid(h._rid, start_fid);
+                    {
+                        if (_emap.insert_pfid(h._rid, start_fid) < enq_map::EMAP_OK) // fail
+                        {
+                            // The only error code emap::insert_pfid() returns is enq_map::EMAP_DUP_RID.
+                            std::ostringstream oss;
+                            oss << std::hex << "rid=0x" << h._rid << " _pfid=0x" << start_fid;
+                            throw jexception(jerrno::JERR_MAP_DUPLICATE, oss.str(), "jcntl", "rcvr_get_next_record");
+                        }
+                    }
                 }
             }
             break;
@@ -714,11 +731,7 @@
                 if (dr.xid_size())
                 {
                     // If the enqueue is part of a pending txn, it will not yet be in emap
-                    try { _emap.lock(dr.deq_rid()); }
-                    catch(const jexception& e)
-                    {
-                        if (e.err_code() != jerrno::JERR_MAP_NOTFOUND) throw;
-                    }
+                    _emap.lock(dr.deq_rid()); // ignore not found error
                     dr.get_xid(&xidp);
                     assert(xidp != 0);
                     std::string xid((char*)xidp, dr.xid_size());
@@ -735,15 +748,18 @@
                 }
                 else
                 {
-                    try
+                    int16_t enq_fid = _emap.get_remove_pfid(dr.deq_rid(), true);
+                    if (enq_fid < enq_map::EMAP_OK) // fail
                     {
-                        u_int16_t enq_fid = _emap.get_remove_pfid(dr.deq_rid(), true);
+                        if (enq_fid == enq_map::EMAP_RID_NOT_FOUND)
+                        {
+                            std::ostringstream oss;
+                            oss << std::hex << "_emap.get_remove_pfid(): drid=0x" << dr.deq_rid();
+                            throw jexception(jerrno::JERR_MAP_NOTFOUND, oss.str(), "jcntl", "rcvr_get_next_record");
+                        }
+                    }
+                    else
                         rd._enq_cnt_list[enq_fid]--;
-                    }
-                    catch(const jexception& e)
-                    {
-                        if (e.err_code() != jerrno::JERR_MAP_NOTFOUND) throw;
-                    }
                 }
             }
             break;
@@ -756,27 +772,14 @@
                 ar.get_xid(&xidp);
                 assert(xidp != 0);
                 std::string xid((char*)xidp, ar.xid_size());
-                try
+                txn_data_list tdl = _tmap.get_remove_tdata_list(xid); // tdl will be empty if xid not found
+                for (tdl_itr itr = tdl.begin(); itr != tdl.end(); itr++)
                 {
-                    txn_data_list tdl = _tmap.get_remove_tdata_list(xid); // tdl will be empty if xid not found
-                    for (tdl_itr itr = tdl.begin(); itr != tdl.end(); itr++)
-                    {
-                        if (itr->_enq_flag)
-                            rd._enq_cnt_list[itr->_pfid]--;
-                        else
-                        {
-                            try { _emap.unlock(itr->_drid); }
-                            catch(const jexception& e)
-                            {
-                                if (e.err_code() != jerrno::JERR_MAP_NOTFOUND) throw;
-                            }
-                        }
-                    }
+                    if (itr->_enq_flag)
+                        rd._enq_cnt_list[itr->_pfid]--;
+                    else
+                        _emap.unlock(itr->_drid); // ignore not found error
                 }
-                catch (const jexception& e)
-                {
-                    if (e.err_code() != jerrno::JERR_MAP_NOTFOUND) throw;
-                }
                 std::free(xidp);
             }
             break;
@@ -789,31 +792,35 @@
                 cr.get_xid(&xidp);
                 assert(xidp != 0);
                 std::string xid((char*)xidp, cr.xid_size());
-                try
+                txn_data_list tdl = _tmap.get_remove_tdata_list(xid); // tdl will be empty if xid not found
+                for (tdl_itr itr = tdl.begin(); itr != tdl.end(); itr++)
                 {
-                    txn_data_list tdl = _tmap.get_remove_tdata_list(xid); // tdl will be empty if xid not found
-                    for (tdl_itr itr = tdl.begin(); itr != tdl.end(); itr++)
+                    if (itr->_enq_flag) // txn enqueue
                     {
-                        if (itr->_enq_flag) // txn enqueue
-                            _emap.insert_pfid(itr->_rid, itr->_pfid);
-                        else // txn dequeue
+                        if (_emap.insert_pfid(itr->_rid, itr->_pfid) < enq_map::EMAP_OK) // fail
                         {
-                            try
+                            // The only error code emap::insert_pfid() returns is enq_map::EMAP_DUP_RID.
+                            std::ostringstream oss;
+                            oss << std::hex << "rid=0x" << itr->_rid << " _pfid=0x" << itr->_pfid;
+                            throw jexception(jerrno::JERR_MAP_DUPLICATE, oss.str(), "jcntl", "rcvr_get_next_record");
+                        }
+                    }
+                    else // txn dequeue
+                    {
+                        int16_t fid = _emap.get_remove_pfid(itr->_drid, true);
+                        if (fid < 0)
+                        {
+                            if (fid == enq_map::EMAP_RID_NOT_FOUND)
                             {
-                                u_int16_t fid = _emap.get_remove_pfid(itr->_drid, true);
-                                rd._enq_cnt_list[fid]--;
+                                std::ostringstream oss;
+                                oss << std::hex << "_emap.get_remove_pfid(): drid=0x" << itr->_drid;
+                                throw jexception(jerrno::JERR_MAP_NOTFOUND, oss.str(), "jcntl", "rcvr_get_next_record");
                             }
-                            catch (const jexception& e)
-                            {
-                                if (e.err_code() != jerrno::JERR_MAP_NOTFOUND) throw;
-                            }
                         }
+                        else
+                            rd._enq_cnt_list[fid]--;
                     }
                 }
-                catch (const jexception& e)
-                {
-                    if (e.err_code() != jerrno::JERR_MAP_NOTFOUND) throw;
-                }
                 std::free(xidp);
             }
             break;

Modified: store/trunk/cpp/lib/jrnl/jcntl.hpp
===================================================================
--- store/trunk/cpp/lib/jrnl/jcntl.hpp	2010-06-17 13:47:29 UTC (rev 4032)
+++ store/trunk/cpp/lib/jrnl/jcntl.hpp	2010-06-17 17:35:12 UTC (rev 4033)
@@ -8,7 +8,7 @@
  *
  * \author Kim van der Riet
  *
- * Copyright (c) 2007, 2008, 2009 Red Hat, Inc.
+ * Copyright (c) 2007, 2008, 2009, 2010 Red Hat, Inc.
  *
  * This file is part of the Qpid async store library msgstore.so.
  *
@@ -584,7 +584,7 @@
         inline bool is_enqueued(const u_int64_t rid, bool ignore_lock = false)
                 { return _emap.is_enqueued(rid, ignore_lock); }
         inline bool is_locked(const u_int64_t rid)
-                { if (_emap.is_enqueued(rid, true)) return _emap.is_locked(rid); return false; }
+                { if (_emap.is_enqueued(rid, true) < enq_map::EMAP_OK) return false; return _emap.is_locked(rid) == enq_map::EMAP_TRUE; }
         inline void enq_rid_list(std::vector<u_int64_t>& rids) { _emap.rid_list(rids); }
         inline void enq_xid_list(std::vector<std::string>& xids) { _tmap.xid_list(xids); }
         inline u_int32_t get_open_txn_cnt() const { return _tmap.size(); }

Modified: store/trunk/cpp/lib/jrnl/rmgr.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/rmgr.cpp	2010-06-17 13:47:29 UTC (rev 4032)
+++ store/trunk/cpp/lib/jrnl/rmgr.cpp	2010-06-17 17:35:12 UTC (rev 4033)
@@ -8,7 +8,7 @@
  *
  * \author Kim van der Riet
  *
- * Copyright (c) 2007, 2008, 2009 Red Hat, Inc.
+ * Copyright (c) 2007, 2008, 2009, 2010 Red Hat, Inc.
  *
  * This file is part of the Qpid async store library msgstore.so.
  *
@@ -154,18 +154,13 @@
             {
                 _enq_rec.reset(); // sets enqueue rec size
                 // Check if RID of this rec is still enqueued, if so read it, else skip
-                u_int16_t fid = 0;
                 bool is_enq = false;
-                try
+                int16_t fid = _emap.get_pfid(_hdr._rid);
+                if (fid < enq_map::EMAP_OK)
                 {
-                    fid = _emap.get_pfid(_hdr._rid); // If locked, will throw JERR_MAP_LOCKED
-                    is_enq = true;
-                }
-                catch (const jexception& e)
-                {
                     bool enforce_txns = !_jc->is_read_only() && !ignore_pending_txns;
                     // Block read for transactionally locked record (only when not recovering)
-                    if (e.err_code() == jerrno::JERR_MAP_LOCKED && enforce_txns)
+                    if (fid == enq_map::EMAP_LOCKED && enforce_txns)
                         return RHM_IORES_TXPENDING;
 
                     // (Recover mode only) Ok, not in emap - now search tmap, if present then read
@@ -173,6 +168,8 @@
                     if (enforce_txns && is_enq)
                         return RHM_IORES_TXPENDING;
                 }
+                else
+                    is_enq = true;
 
                 if (is_enq) // ok, this record is enqueued, check it, then read it...
                 {

Modified: store/trunk/cpp/lib/jrnl/wmgr.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/wmgr.cpp	2010-06-17 13:47:29 UTC (rev 4032)
+++ store/trunk/cpp/lib/jrnl/wmgr.cpp	2010-06-17 17:35:12 UTC (rev 4033)
@@ -197,7 +197,15 @@
                 _tmap.insert_txn_data(xid, txn_data(rid, 0, dtokp->fid(), true));
             }
             else
-                _emap.insert_pfid(rid, dtokp->fid());
+            {
+                if (_emap.insert_pfid(rid, dtokp->fid()) < enq_map::EMAP_OK) // fail
+                {
+                    // The only error code emap::insert_pfid() returns is enq_map::EMAP_DUP_RID.
+                    std::ostringstream oss;
+                    oss << std::hex << "rid=0x" << rid << " _pfid=0x" << dtokp->fid();
+                    throw jexception(jerrno::JERR_MAP_DUPLICATE, oss.str(), "wmgr", "enqueue");
+                }
+            }
 
             done = true;
         }
@@ -284,17 +292,28 @@
             if (xid_len) // If part of transaction, add to transaction map
             {
                 // If the enqueue is part of a pending txn, it will not yet be in emap
-                try { _emap.lock(dequeue_rid); }
-                catch(const jexception& e)
-                {
-                    if (e.err_code() != jerrno::JERR_MAP_NOTFOUND) throw;
-                }
+                _emap.lock(dequeue_rid); // ignore rid not found error
                 std::string xid((char*)xid_ptr, xid_len);
                 _tmap.insert_txn_data(xid, txn_data(rid, dequeue_rid, dtokp->fid(), false));
             }
             else
             {
-                u_int16_t fid = _emap.get_remove_pfid(dtokp->dequeue_rid());
+                int16_t fid = _emap.get_remove_pfid(dtokp->dequeue_rid());
+                if (fid < enq_map::EMAP_OK) // fail
+                {
+                    if (fid == enq_map::EMAP_RID_NOT_FOUND)
+                    {
+                        std::ostringstream oss;
+                        oss << std::hex << "rid=0x" << rid;
+                        throw jexception(jerrno::JERR_MAP_NOTFOUND, oss.str(), "wmgr", "dequeue");
+                    }
+                    if (fid == enq_map::EMAP_LOCKED)
+                    {
+                        std::ostringstream oss;
+                        oss << std::hex << "rid=0x" << rid;
+                        throw jexception(jerrno::JERR_MAP_LOCKED, oss.str(), "wmgr", "dequeue");
+                    }
+                }
                 _wrfc.decr_enqcnt(fid);
             }
 
@@ -375,15 +394,8 @@
             txn_data_list tdl = _tmap.get_remove_tdata_list(xid); // tdl will be empty if xid not found
             for (tdl_itr itr = tdl.begin(); itr != tdl.end(); itr++)
             {
-                try
-				{
-					if (!itr->_enq_flag)
-						_emap.unlock(itr->_drid);
-				}
-                catch(const jexception& e)
-                {
-                    if (e.err_code() != jerrno::JERR_MAP_NOTFOUND) throw;
-                }
+				if (!itr->_enq_flag)
+				    _emap.unlock(itr->_drid); // ignore rid not found error
                 if (itr->_enq_flag)
                     _wrfc.decr_enqcnt(itr->_pfid);
             }
@@ -473,10 +485,33 @@
             for (tdl_itr itr = tdl.begin(); itr != tdl.end(); itr++)
             {
                 if (itr->_enq_flag) // txn enqueue
-                    _emap.insert_pfid(itr->_rid, itr->_pfid);
+                {
+                    if (_emap.insert_pfid(itr->_rid, itr->_pfid) < enq_map::EMAP_OK) // fail
+                    {
+                        // The only error code emap::insert_pfid() returns is enq_map::EMAP_DUP_RID.
+                        std::ostringstream oss;
+                        oss << std::hex << "rid=0x" << itr->_rid << " _pfid=0x" << itr->_pfid;
+                        throw jexception(jerrno::JERR_MAP_DUPLICATE, oss.str(), "wmgr", "commit");
+                    }
+                }
                 else // txn dequeue
                 {
-                    u_int16_t fid = _emap.get_remove_pfid(itr->_drid, true);
+                    int16_t fid = _emap.get_remove_pfid(itr->_drid, true);
+                    if (fid < enq_map::EMAP_OK) // fail
+                    {
+                        if (fid == enq_map::EMAP_RID_NOT_FOUND)
+                        {
+                            std::ostringstream oss;
+                            oss << std::hex << "rid=0x" << rid;
+                            throw jexception(jerrno::JERR_MAP_NOTFOUND, oss.str(), "wmgr", "dequeue");
+                        }
+                        if (fid == enq_map::EMAP_LOCKED)
+                        {
+                            std::ostringstream oss;
+                            oss << std::hex << "rid=0x" << rid;
+                            throw jexception(jerrno::JERR_MAP_LOCKED, oss.str(), "wmgr", "dequeue");
+                        }
+                    }
                     _wrfc.decr_enqcnt(fid);
                 }
             }
@@ -884,18 +919,23 @@
 {
     // First check emap
     bool found = false;
-    try
+    int16_t fid = _emap.get_pfid(drid);
+    if (fid < enq_map::EMAP_OK) // fail
     {
-        _emap.get_pfid(drid);
+        if (fid == enq_map::EMAP_RID_NOT_FOUND)
+        {
+            if (xid.size())
+                found = _tmap.data_exists(xid, drid);
+        }
+        else if (fid == enq_map::EMAP_LOCKED)
+        {
+            std::ostringstream oss;
+            oss << std::hex << "drid=0x" << drid;
+            throw jexception(jerrno::JERR_MAP_LOCKED, oss.str(), "wmgr", "dequeue_check");
+        }
+    }
+    else
         found = true;
-    }
-    catch(const jexception& e)
-    {
-        if (e.err_code() != jerrno::JERR_MAP_NOTFOUND)
-            throw;
-        if (xid.size())
-            found = _tmap.data_exists(xid, drid);
-    }
     if (!found)
     {
         std::ostringstream oss;

Modified: store/trunk/cpp/tests/jrnl/_ut_enq_map.cpp
===================================================================
--- store/trunk/cpp/tests/jrnl/_ut_enq_map.cpp	2010-06-17 13:47:29 UTC (rev 4032)
+++ store/trunk/cpp/tests/jrnl/_ut_enq_map.cpp	2010-06-17 17:35:12 UTC (rev 4033)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2008, 2009 Red Hat, Inc.
+ * Copyright (c) 2007, 2008, 2009, 2010 Red Hat, Inc.
  *
  * This file is part of the Qpid async store library msgstore.so.
  *
@@ -57,7 +57,7 @@
     u_int64_t rid_incr_1 = 4ULL;
     enq_map e2;
     for (rid = rid_begin, pfid = pfid_start; rid < rid_end; rid += rid_incr_1, pfid++)
-        e2.insert_pfid(rid, pfid);
+        BOOST_CHECK_EQUAL(e2.insert_pfid(rid, pfid), enq_map::EMAP_OK);
     BOOST_CHECK(!e2.empty());
     BOOST_CHECK_EQUAL(e2.size(), u_int32_t(128));
 
@@ -66,18 +66,18 @@
     for (u_int64_t rid = rid_begin; rid < rid_end; rid += rid_incr_2)
     {
         BOOST_CHECK_EQUAL(e2.is_enqueued(rid), (rid%rid_incr_1 ? false : true));
-        try
+        u_int16_t exp_pfid = pfid_start + (u_int16_t)((rid - rid_begin)/rid_incr_1);
+        int16_t ret_fid = e2.get_pfid(rid);
+        if (ret_fid < enq_map::EMAP_OK) // fail
         {
-            u_int16_t exp_pfid = pfid_start + (u_int16_t)((rid - rid_begin)/rid_incr_1);
-            u_int16_t ret_fid = e2.get_pfid(rid);
+            BOOST_CHECK_EQUAL(ret_fid, enq_map::EMAP_RID_NOT_FOUND);
+            BOOST_CHECK(rid%rid_incr_1);
+        }
+        else
+        {
             BOOST_CHECK_EQUAL(ret_fid, exp_pfid);
             BOOST_CHECK(rid%rid_incr_1 == 0);
         }
-        catch (const jexception& e)
-        {
-            BOOST_CHECK_EQUAL(e.err_code(), jerrno::JERR_MAP_NOTFOUND);
-            BOOST_CHECK(rid%rid_incr_1);
-        }
         if ((rid + rid_incr_2)%(8 * rid_incr_2) == 0)
             pfid++;
     }
@@ -85,16 +85,14 @@
     // insert with dups
     for (rid = rid_begin, pfid = pfid_start; rid < rid_end; rid += rid_incr_2, pfid++)
     {
-        try
+        int16_t res = e2.insert_pfid(rid, pfid);
+        if (res < enq_map::EMAP_OK) // fail
         {
-            e2.insert_pfid(rid, pfid);
-            BOOST_CHECK(rid%rid_incr_1);
-        }
-        catch (const jexception& e)
-        {
-            BOOST_CHECK_EQUAL(e.err_code(), jerrno::JERR_MAP_DUPLICATE);
+            BOOST_CHECK_EQUAL(res, enq_map::EMAP_DUP_RID);
             BOOST_CHECK(rid%rid_incr_1 == 0);
         }
+        else
+            BOOST_CHECK(rid%rid_incr_1);
     }
     BOOST_CHECK_EQUAL(e2.size(), u_int32_t(171));
     e2.clear();
@@ -116,24 +114,24 @@
     u_int64_t num_incr_1 = (rid_end - rid_begin)/rid_incr_1;
     enq_map e3;
     for (rid = rid_begin, pfid = pfid_start; rid < rid_end; rid += rid_incr_1, pfid++)
-        e3.insert_pfid(rid, pfid);
+        BOOST_CHECK_EQUAL(e3.insert_pfid(rid, pfid), enq_map::EMAP_OK);
     BOOST_CHECK_EQUAL(e3.size(), num_incr_1);
 
     u_int64_t rid_incr_2 = 6ULL;
     for (rid = rid_begin, pfid = pfid_start; rid < rid_end; rid += rid_incr_2, pfid++)
     {
-        try
+        u_int16_t exp_pfid = pfid_start + (u_int16_t)((rid - rid_begin)/rid_incr_1);
+        int16_t ret_fid = e3.get_remove_pfid(rid);
+        if (ret_fid < enq_map::EMAP_OK) // fail
         {
-            u_int16_t exp_pfid = pfid_start + (u_int16_t)((rid - rid_begin)/rid_incr_1);
-            u_int16_t ret_fid = e3.get_remove_pfid(rid);
+            BOOST_CHECK_EQUAL(ret_fid, enq_map::EMAP_RID_NOT_FOUND);
+            BOOST_CHECK(rid%rid_incr_1);
+        }
+        else
+        {
             BOOST_CHECK_EQUAL(ret_fid, exp_pfid);
             BOOST_CHECK(rid%rid_incr_1 == 0);
         }
-        catch (const jexception& e)
-        {
-            BOOST_CHECK_EQUAL(e.err_code(), jerrno::JERR_MAP_NOTFOUND);
-            BOOST_CHECK(rid%rid_incr_1);
-        }
     }
     BOOST_CHECK_EQUAL(e3.size(), u_int32_t(85));
     cout << "ok" << endl;
@@ -155,52 +153,46 @@
     enq_map e4;
     for (rid = rid_begin, pfid = pfid_start; rid < rid_end; rid += rid_incr_1, pfid++)
     {
-        e4.insert_pfid(rid, pfid, locked);
+        BOOST_CHECK_EQUAL(e4.insert_pfid(rid, pfid, locked), enq_map::EMAP_OK);
         locked = !locked;
     }
     BOOST_CHECK_EQUAL(e4.size(), num_incr_1);
 
     // unlock and lock non-existent rids
-    try
-    {
-        e4.lock(1ULL);
-        BOOST_ERROR("Failed to throw exception when locking non-existent rid.");
-    }
-    catch (const jexception& e) { BOOST_CHECK_EQUAL(e.err_code(), jerrno::JERR_MAP_NOTFOUND); }
-    try
-    {
-        e4.unlock(2ULL);
-        BOOST_ERROR("Failed to throw exception when locking non-existent rid.");
-    }
-    catch (const jexception& e) { BOOST_CHECK_EQUAL(e.err_code(), jerrno::JERR_MAP_NOTFOUND); }
+    int16_t res = e4.lock(1ULL);
+    if (res < enq_map::EMAP_OK)
+        BOOST_CHECK_EQUAL(res, enq_map::EMAP_RID_NOT_FOUND);
+    else
+        BOOST_ERROR("Failed to detect locking non-existent rid.");
+    res = e4.unlock(2ULL);
+    if (res < enq_map::EMAP_OK)
+        BOOST_CHECK_EQUAL(res, enq_map::EMAP_RID_NOT_FOUND);
+    else
+        BOOST_ERROR("Failed to detect unlocking non-existent rid.");
 
     // get / unlock
     for (u_int64_t rid = rid_begin; rid < rid_end; rid += rid_incr_1)
     {
-        try { e4.get_pfid(rid); }
-        catch(const jexception& e)
+        int16_t fid = e4.get_pfid(rid);
+        if (fid < enq_map::EMAP_OK) // fail
         {
-            BOOST_CHECK_EQUAL(e.err_code(), jerrno::JERR_MAP_LOCKED);
+            BOOST_CHECK_EQUAL(fid, enq_map::EMAP_LOCKED);
             BOOST_CHECK(rid%(2*rid_incr_1));
             // unlock, read, then relock
-            e4.unlock(rid);
-            e4.get_pfid(rid);
-            e4.lock(rid);
-            try
-            {
-               e4.get_pfid(rid);
-               BOOST_ERROR("Failed to throw exception when getting locked record");
-            }
-            catch(const jexception& e)
-            {
-                BOOST_CHECK_EQUAL(e.err_code(), jerrno::JERR_MAP_LOCKED);
-            }
+            BOOST_CHECK_EQUAL(e4.unlock(rid), enq_map::EMAP_OK);
+            BOOST_CHECK(e4.get_pfid(rid) >= enq_map::EMAP_OK);
+            BOOST_CHECK_EQUAL(e4.lock(rid), enq_map::EMAP_OK);
+            fid = e4.get_pfid(rid);
+            if (fid < enq_map::EMAP_OK) // fail
+                BOOST_CHECK_EQUAL(fid, enq_map::EMAP_LOCKED);
+            else
+                BOOST_ERROR("Failed to prevent getting locked record");
         }
     }
 
     // remove all; if locked, use with txn_flag true; should ignore all locked records
     for (u_int64_t rid = rid_begin; rid < rid_end; rid += rid_incr_1)
-        e4.get_remove_pfid(rid, true);
+        BOOST_CHECK(e4.get_remove_pfid(rid, true) >= enq_map::EMAP_OK);
     BOOST_CHECK(e4.empty());
     cout << "ok" << endl;
 }
@@ -222,7 +214,7 @@
     enq_map e5;
     for (rid = rid_begin, pfid = pfid_start; rid < rid_end; rid += rid_incr_1, pfid++)
     {
-        e5.insert_pfid(rid, pfid);
+        BOOST_CHECK_EQUAL(e5.insert_pfid(rid, pfid), enq_map::EMAP_OK);
         rid_list.push_back(rid);
         pfid_list.push_back(pfid);
     }
@@ -260,7 +252,7 @@
     for (u_int16_t pfid=0; pfid<4; pfid++)
         BOOST_CHECK_EQUAL(e6.get_enq_cnt(pfid), u_int32_t(0));
     for (u_int64_t rid=0; rid<100; rid++)
-        e6.insert_pfid(rid, 1);
+        BOOST_CHECK_EQUAL(e6.insert_pfid(rid, 1), enq_map::EMAP_OK);
     for (u_int16_t pfid=0; pfid<4; pfid++)
     {
         if (pfid == 1)
@@ -271,7 +263,8 @@
 
     // Now remove 10 from file 1, check that the counts match
     for (u_int64_t rid=0; rid<100; rid+=10)
-        e6.get_remove_pfid(rid);
+        //e6.Xget_remove_pfid(rid);
+        BOOST_CHECK(e6.get_remove_pfid(rid) >= enq_map::EMAP_OK);
     for (u_int16_t pfid=0; pfid<4; pfid++)
     {
         if (pfid == 1)
@@ -305,17 +298,18 @@
 
     // insert even rids with no dups
     for (rid = rid_begin, rid_cnt = u_int64_t(0); rid_cnt < num_rid; rid += 2ULL, rid_cnt++)
-        e7.insert_pfid(rid, u_int16_t(0));
+        BOOST_CHECK_EQUAL(e7.insert_pfid(rid, u_int16_t(0)), enq_map::EMAP_OK);
     BOOST_CHECK_EQUAL(e7.size(), num_rid);
 
     // insert odd rids with no dups
     for (rid = rid_begin + 1, rid_cnt = u_int64_t(0); rid_cnt < num_rid; rid += 2ULL, rid_cnt++)
-        e7.insert_pfid(rid, u_int16_t(0));
+        BOOST_CHECK_EQUAL(e7.insert_pfid(rid, u_int16_t(0)), enq_map::EMAP_OK);
     BOOST_CHECK_EQUAL(e7.size(), num_rid * 2);
 
     // remove even rids
     for (rid = rid_begin, rid_cnt = u_int64_t(0); rid_cnt < num_rid; rid += 2ULL, rid_cnt++)
-        e7.get_remove_pfid(rid);
+//        e7.Xget_remove_pfid(rid);
+        BOOST_CHECK(e7.get_remove_pfid(rid) >= enq_map::EMAP_OK);
     BOOST_CHECK_EQUAL(e7.size(), num_rid);
 
     cout << "ok" << endl;



More information about the rhmessaging-commits mailing list