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

rhmessaging-commits at lists.jboss.org rhmessaging-commits at lists.jboss.org
Thu Sep 24 12:51:53 EDT 2009


Author: kpvdr
Date: 2009-09-24 12:51:53 -0400 (Thu, 24 Sep 2009)
New Revision: 3648

Modified:
   store/trunk/cpp/lib/jrnl/wmgr.cpp
   store/trunk/cpp/lib/jrnl/wmgr.hpp
Log:
Refactor of wmgr to clean up duplicate code

Modified: store/trunk/cpp/lib/jrnl/wmgr.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/wmgr.cpp	2009-09-23 18:04:02 UTC (rev 3647)
+++ store/trunk/cpp/lib/jrnl/wmgr.cpp	2009-09-24 16:51:53 UTC (rev 3648)
@@ -204,50 +204,8 @@
         else
             dtokp->set_wstate(data_tok::ENQ_PART);
 
-        // Has the file header been written (i.e. write pointers still at 0)?
-        if (_wrfc.is_void())
-        {
-            u_int32_t rec_dblks_rem = _enq_rec.rec_size_dblks() - data_offs_dblks;
-            bool file_fit = rec_dblks_rem <= _jfsize_dblks;
-            bool file_full = rec_dblks_rem == _jfsize_dblks;
-            std::size_t fro = 0;
-            if (cont)
-            {
-                if (file_fit && !file_full)
-                    fro = (rec_dblks_rem + JRNL_SBLK_SIZE) * JRNL_DBLK_SIZE;
-            }
-            else
-                fro = JRNL_SBLK_SIZE * JRNL_DBLK_SIZE;
-            write_fhdr(rid, _wrfc.index(), _wrfc.index(), fro);
-        }
-
-        // Is the page full? If so, flush.
-        if (_pg_offset_dblks >= _cache_pgsize_sblks * JRNL_SBLK_SIZE)
-        {
-            res = write_flush();
-            assert(res == RHM_IORES_SUCCESS);
-
-            if (_page_cb_arr[_pg_index]._state == AIO_PENDING && !done)
-            {
-                res = RHM_IORES_PAGE_AIOWAIT;
-                done = true;
-            }
-
-            // File full?
-            if (_pg_cntr >= _jfsize_pgs)
-            {
-                iores rfres = rotate_file();
-                if (rfres != RHM_IORES_SUCCESS)
-                    res = rfres;
-                if (!done)
-                {
-                    if (rfres == RHM_IORES_SUCCESS)
-                        cont = true;
-                    else
-                        done = true;
-                }
-            }
-        }
+        file_header_check(rid, cont, _enq_rec.rec_size_dblks() - data_offs_dblks);
+        flush_check(res, cont, done);
     }
     if (dtokp->wstate() >= data_tok::ENQ_SUBM)
         _enq_busy = false;
@@ -345,50 +303,8 @@
         else
             dtokp->set_wstate(data_tok::DEQ_PART);
 
-        // Has the file header been written (i.e. write pointers still at 0)?
-        if (_wrfc.is_void())
-        {
-            u_int32_t rec_dblks_rem = _deq_rec.rec_size_dblks() - data_offs_dblks;
-            bool file_fit = rec_dblks_rem <= _jfsize_dblks;
-            bool file_full = rec_dblks_rem == _jfsize_dblks;
-            std::size_t fro = 0;
-            if (cont)
-            {
-                if (file_fit && !file_full)
-                    fro = (rec_dblks_rem + JRNL_SBLK_SIZE) * JRNL_DBLK_SIZE;
-            }
-            else
-                fro = JRNL_SBLK_SIZE * JRNL_DBLK_SIZE;
-            write_fhdr(rid, _wrfc.index(), _wrfc.index(), fro);
-        }
-
-        // Is the page full? If so, flush.
-        if (_pg_offset_dblks >= _cache_pgsize_sblks * JRNL_SBLK_SIZE)
-        {
-            res = write_flush();
-            assert(res == RHM_IORES_SUCCESS);
-
-            if (_page_cb_arr[_pg_index]._state == AIO_PENDING && !done)
-            {
-                res = RHM_IORES_PAGE_AIOWAIT;
-                done = true;
-            }
-
-            // File full?
-            if (_pg_cntr >= _jfsize_pgs)
-            {
-                iores rfres = rotate_file();
-                if (rfres != RHM_IORES_SUCCESS)
-                    res = rfres;
-                if (!done)
-                {
-                    if (rfres == RHM_IORES_SUCCESS)
-                        cont = true;
-                    else
-                        done = true;
-                }
-            }
-        }
+        file_header_check(rid, cont, _deq_rec.rec_size_dblks() - data_offs_dblks);
+        flush_check(res, cont, done);
     }
     if (dtokp->wstate() >= data_tok::DEQ_SUBM)
         _deq_busy = false;
@@ -484,50 +400,8 @@
         else
             dtokp->set_wstate(data_tok::ABORT_PART);
 
-        // Has the file header been written (i.e. write pointers still at 0)?
-        if (_wrfc.is_void())
-        {
-            u_int32_t rec_dblks_rem = _txn_rec.rec_size_dblks() - data_offs_dblks;
-            bool file_fit = rec_dblks_rem <= _jfsize_dblks;
-            bool file_full = rec_dblks_rem == _jfsize_dblks;
-            std::size_t fro = 0;
-            if (cont)
-            {
-                if (file_fit && !file_full)
-                    fro = (rec_dblks_rem + JRNL_SBLK_SIZE) * JRNL_DBLK_SIZE;
-            }
-            else
-                fro = JRNL_SBLK_SIZE * JRNL_DBLK_SIZE;
-            write_fhdr(rid, _wrfc.index(), _wrfc.index(), fro);
-        }
-
-        // Is the page full? If so, flush.
-        if (_pg_offset_dblks >= _cache_pgsize_sblks * JRNL_SBLK_SIZE)
-        {
-            res = write_flush();
-            assert(res == RHM_IORES_SUCCESS);
-
-            if (_page_cb_arr[_pg_index]._state == AIO_PENDING && !done)
-            {
-                res = RHM_IORES_PAGE_AIOWAIT;
-                done = true;
-            }
-
-            // File full?
-            if (_pg_cntr >= _jfsize_pgs)
-            {
-                iores rfres = rotate_file();
-                if (rfres != RHM_IORES_SUCCESS)
-                    res = rfres;
-                if (!done)
-                {
-                    if (rfres == RHM_IORES_SUCCESS)
-                        cont = true;
-                    else
-                        done = true;
-                }
-            }
-        }
+        file_header_check(rid, cont, _txn_rec.rec_size_dblks() - data_offs_dblks);
+        flush_check(res, cont, done);
     }
     if (dtokp->wstate() >= data_tok::ABORT_SUBM)
         _abort_busy = false;
@@ -619,54 +493,64 @@
         else
             dtokp->set_wstate(data_tok::COMMIT_PART);
 
-        // Has the file header been written (i.e. write pointers still at 0)?
-        if (_wrfc.is_void())
+        file_header_check(rid, cont, _txn_rec.rec_size_dblks() - data_offs_dblks);
+        flush_check(res, cont, done);
+    }
+    if (dtokp->wstate() >= data_tok::COMMIT_SUBM)
+        _commit_busy = false;
+    return res;
+}
+
+void
+wmgr::file_header_check(const u_int64_t rid, const bool cont, const u_int32_t rec_dblks_rem)
+{
+    // Has the file header been written (i.e. write pointers still at 0)?
+    if (_wrfc.is_void())
+    {
+        bool file_fit = rec_dblks_rem <= _jfsize_dblks;
+        bool file_full = rec_dblks_rem == _jfsize_dblks;
+        std::size_t fro = 0;
+        if (cont)
         {
-            u_int32_t rec_dblks_rem = _txn_rec.rec_size_dblks() - data_offs_dblks;
-            bool file_fit = rec_dblks_rem <= _jfsize_dblks;
-            bool file_full = rec_dblks_rem == _jfsize_dblks;
-            std::size_t fro = 0;
-            if (cont)
-            {
-                if (file_fit && !file_full)
-                    fro = (rec_dblks_rem + JRNL_SBLK_SIZE) * JRNL_DBLK_SIZE;
-            }
-            else
-                fro = JRNL_SBLK_SIZE * JRNL_DBLK_SIZE;
-            write_fhdr(rid, _wrfc.index(), _wrfc.index(), fro);
+            if (file_fit && !file_full)
+                fro = (rec_dblks_rem + JRNL_SBLK_SIZE) * JRNL_DBLK_SIZE;
         }
+        else
+            fro = JRNL_SBLK_SIZE * JRNL_DBLK_SIZE;
+        write_fhdr(rid, _wrfc.index(), _wrfc.index(), fro);
+    }
+}
 
-        // Is the page full? If so, flush.
-        if (_pg_offset_dblks >= _cache_pgsize_sblks * JRNL_SBLK_SIZE)
+void
+wmgr::flush_check(iores& res, bool& cont, bool& done)
+{
+    // Is page is full, flush
+    if (_pg_offset_dblks >= _cache_pgsize_sblks * JRNL_SBLK_SIZE)
+    {
+        res = write_flush();
+        assert(res == RHM_IORES_SUCCESS);
+
+        if (_page_cb_arr[_pg_index]._state == AIO_PENDING && !done)
         {
-            res = write_flush();
-            assert(res == RHM_IORES_SUCCESS);
+            res = RHM_IORES_PAGE_AIOWAIT;
+            done = true;
+        }
 
-            if (_page_cb_arr[_pg_index]._state == AIO_PENDING && !done)
+        // If file is full, rotate to next file
+        if (_pg_cntr >= _jfsize_pgs)
+        {
+            iores rfres = rotate_file();
+            if (rfres != RHM_IORES_SUCCESS)
+                res = rfres;
+            if (!done)
             {
-                res = RHM_IORES_PAGE_AIOWAIT;
-                done = true;
+                if (rfres == RHM_IORES_SUCCESS)
+                    cont = true;
+                else
+                    done = true;
             }
-
-            // File full?
-            if (_pg_cntr >= _jfsize_pgs)
-            {
-                iores rfres = rotate_file();
-                if (rfres != RHM_IORES_SUCCESS)
-                    res = rfres;
-                if (!done)
-                {
-                    if (rfres == RHM_IORES_SUCCESS)
-                        cont = true;
-                    else
-                        done = true;
-                }
-            }
         }
     }
-    if (dtokp->wstate() >= data_tok::COMMIT_SUBM)
-        _commit_busy = false;
-    return res;
 }
 
 iores

Modified: store/trunk/cpp/lib/jrnl/wmgr.hpp
===================================================================
--- store/trunk/cpp/lib/jrnl/wmgr.hpp	2009-09-23 18:04:02 UTC (rev 3647)
+++ store/trunk/cpp/lib/jrnl/wmgr.hpp	2009-09-24 16:51:53 UTC (rev 3648)
@@ -131,6 +131,8 @@
                 const std::size_t xidsize = 0, const std::size_t dsize = 0, const bool external = false)
                 const;
         void dequeue_check(const std::string& xid, const u_int64_t drid);
+        void file_header_check(const u_int64_t rid, const bool cont, const u_int32_t rec_dblks_rem);
+        void flush_check(iores& res, bool& cont, bool& done);
         iores write_flush();
         iores rotate_file();
         void dblk_roundup();



More information about the rhmessaging-commits mailing list