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

rhmessaging-commits at lists.jboss.org rhmessaging-commits at lists.jboss.org
Thu Mar 6 10:17:50 EST 2008


Author: kpvdr
Date: 2008-03-06 10:17:49 -0500 (Thu, 06 Mar 2008)
New Revision: 1762

Modified:
   store/trunk/cpp/lib/jrnl/wrfc.cpp
   store/trunk/cpp/tests/jrnl/_st_basic.cpp
   store/trunk/cpp/tests/jrnl/_st_helper_fns.hpp
Log:
Fixed bug in enqueue threshold calculations, fixed enqueue threshold and journal overflow tests in _st_basic

Modified: store/trunk/cpp/lib/jrnl/wrfc.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/wrfc.cpp	2008-03-05 15:22:53 UTC (rev 1761)
+++ store/trunk/cpp/lib/jrnl/wrfc.cpp	2008-03-06 15:17:49 UTC (rev 1762)
@@ -28,6 +28,7 @@
 * The GNU Lesser General Public License is available in the file COPYING.
 */
 
+#include <cmath>
 #include <jrnl/wrfc.hpp>
 #include <jrnl/jerrno.hpp>
 #include <jrnl/jexception.hpp>
@@ -76,7 +77,8 @@
     }
     _fsize_sblks = fsize_sblks;
     _fsize_dblks = fsize_sblks * JRNL_SBLK_SIZE;
-    _enq_cap_offs_dblks = _fsize_dblks * _nfiles * (100 - JRNL_ENQ_THRESHOLD) / 100;
+    _enq_cap_offs_dblks = (u_int32_t)::ceil(_fsize_dblks * _nfiles *
+            (100.0 - JRNL_ENQ_THRESHOLD) / 100);
     // Check the offset is at least one file; if not, make it so
     if (_enq_cap_offs_dblks < _fsize_dblks)
         _enq_cap_offs_dblks = _fsize_dblks;
@@ -104,17 +106,36 @@
     return _reset_ok;
 }
 
+
+/**
+* The following routine finds whether the next write will take the write pointer to beyond the
+* enqueue limit threshold. The following illustrates how this is achieved.
+*
+* Current file index: 4                         +---+----------+
+* X's mark still-enqueued records               |msg| 1-thresh |
+* msg = current msg size + unwritten cache      +---+----------+
+* thresh = JRNL_ENQ_THRESHOLD as a fraction     ^              V
+*            +-------+-------+-------+-------+--+----+-------+-+-----+-------+
+* file num ->|   0   |   1   |   2   |   3   |   4   |   5   |   6   |   7   |
+* enq recs ->| X  XX |XX XXX |XX XXXX|XXXXXXX|XX     |       |       |     X |
+*            +-------+-------+-------+-------+--+----+-------+-+-----+-------+
+*                                               ^        ^       ^
+*                                  subm_dblks --+        |       |
+*                                                      These files must be free of enqueues
+*                                                      If not, return true.
+*/
 const bool
 wrfc::enq_threshold(const u_int32_t enq_dsize_dblks) const
 {
-    u_int32_t subm_dblks = subm_cnt_dblks();
+    u_int32_t subm_dblks = subm_cnt_dblks(); // includes file hdr if > 0
     // This compensates for new files which don't have their file headers written yet,
     // as file header space cannot be included in this calculation.
-    if (subm_dblks == 0)
-        subm_dblks = 4;
+    if (subm_dblks != 0)
+        subm_dblks -= 4;
     u_int32_t fwd_dblks = subm_dblks + enq_dsize_dblks + _enq_cap_offs_dblks;
     u_int16_t findex = _fh_index;
     nlfh* fhp = _curr_fh;
+    bool in_use = false;
     while (fwd_dblks && !(findex != _fh_index && fhp->enqcnt()))
     {
         fwd_dblks -= fwd_dblks > _fsize_dblks ? _fsize_dblks : fwd_dblks;
@@ -124,7 +145,9 @@
                 findex = 0;
             fhp = _fh_arr[findex];
         }
+        in_use |= fhp->enqcnt() > 0;
     }
+    // Return true if threshold exceeded
     return findex != _fh_index && fhp->enqcnt() > 0;
 }
 

Modified: store/trunk/cpp/tests/jrnl/_st_basic.cpp
===================================================================
--- store/trunk/cpp/tests/jrnl/_st_basic.cpp	2008-03-05 15:22:53 UTC (rev 1761)
+++ store/trunk/cpp/tests/jrnl/_st_basic.cpp	2008-03-06 15:17:49 UTC (rev 1762)
@@ -336,9 +336,9 @@
     cout << "ok" << endl;
 }
 
-QPID_AUTO_TEST_CASE(journal_threshold_block)
+QPID_AUTO_TEST_CASE(journal_threshold)
 {
-    string test_name = get_test_name(test_filename, "journal_threshold_block");
+    string test_name = get_test_name(test_filename, "journal_threshold");
     try
     {
         string msg;
@@ -351,58 +351,27 @@
         u_int32_t t = num_msgs_to_threshold(NUM_DEFAULT_JFILES,
                 DEFAULT_JFSIZE_SBLKS * JRNL_SBLK_SIZE, LARGE_MSG_REC_SIZE_DBLKS);
         for (m=0; m<t; m++)
-            enq_msg(jc, m, create_msg(msg, m, LARGE_MSG_SIZE), true);
+            enq_msg(jc, m, create_msg(msg, m, LARGE_MSG_SIZE), false);
         // This enqueue should exceed the threshold
-        enq_msg(jc, m, create_msg(msg, m, LARGE_MSG_SIZE), true, RHM_IORES_ENQCAPTHRESH);
+        BOOST_CHECK_EQUAL(jc.get_enq_cnt(), t);
+        enq_msg(jc, m, create_msg(msg, m, LARGE_MSG_SIZE), false, RHM_IORES_ENQCAPTHRESH);
+        BOOST_CHECK_EQUAL(jc.get_enq_cnt(), t);
 
         // Dequeue all msgs
         for (m=0; m<t; m++)
             deq_msg(jc, m);
+        BOOST_CHECK_EQUAL(jc.get_enq_cnt(), u_int32_t(0));
 
-        cout << "[NOTE: Partially disabled until outstanding issue(s) resolved.] ";
-//         // Fill journal to just below threshold
-//         for (m=2*t; m<3*t; m++)
-//             enq_msg(jc, m, create_msg(msg, m, LARGE_MSG_SIZE), true);
-//         // This enqueue should exceed the threshold
-//         enq_msg(jc, m, create_msg(msg, m, LARGE_MSG_SIZE), true, RHM_IORES_ENQCAPTHRESH);
+        // Check we can still enqueue and dequeue
+        for (m=2*t; m<2*t + NUM_MSGS; m++)
+            enq_msg(jc, m, create_msg(msg, m, LARGE_MSG_SIZE), false);
+        for (m=2*t; m<2*t + NUM_MSGS; m++)
+            deq_msg(jc, m);
     }
     catch(const exception& e) { BOOST_FAIL(e.what()); }
     cout << "ok" << endl;
 }
 
-QPID_AUTO_TEST_CASE(journal_threshold_interleaved)
-{
-    string test_name = get_test_name(test_filename, "journal_threshold_interleaved");
-    try
-    {
-        string msg;
-
-        jcntl jc(test_name, JRNL_DIR, test_name, NUM_DEFAULT_JFILES, DEFAULT_JFSIZE_SBLKS);
-        jrnl_init(jc);
-        unsigned m;
-        
-        // Fill journal to just below threshold
-        u_int32_t t = num_msgs_to_threshold(NUM_DEFAULT_JFILES,
-                DEFAULT_JFSIZE_SBLKS * JRNL_SBLK_SIZE, LARGE_MSG_REC_SIZE_DBLKS);
-        for (m=0; m<t; m++)
-            enq_msg(jc, m, create_msg(msg, m, LARGE_MSG_SIZE), true);
-        // This enqueue should exceed the threshold
-        enq_msg(jc, m, create_msg(msg, m, LARGE_MSG_SIZE), true, RHM_IORES_ENQCAPTHRESH);
-
-        cout << "[NOTE: Partially disabled until outstanding issue(s) resolved.] ";
-        // Interleave dequeues and enqueues
-//         for (m=0; m<t; m++)
-//         {
-//             u_int64_t msg_num = deq_msg(jc, m) + 1;
-//             enq_msg(jc, msg_num, create_msg(msg, msg_num, LARGE_MSG_SIZE), true);
-//             enq_msg(jc, msg_num + 1, create_msg(msg, msg_num + 1, LARGE_MSG_SIZE), true,
-//                     RHM_IORES_ENQCAPTHRESH);
-//         }
-    }
-    catch(const exception& e) { BOOST_FAIL(e.what()); }
-    cout << "ok" << endl;
-}
-
 QPID_AUTO_TEST_CASE(journal_overflow)
 {
     string test_name = get_test_name(test_filename, "journal_overflow");
@@ -415,18 +384,18 @@
         unsigned m;
         
         // Fill journal to just below threshold
-        cout << "[NOTE: Partially disabled until outstanding issue(s) resolved.] ";
-        u_int32_t t = 10;
-//         u_int32_t t = num_msgs_to_threshold(NUM_DEFAULT_JFILES,
-//                 DEFAULT_JFSIZE_SBLKS * JRNL_SBLK_SIZE, MSG_REC_SIZE_DBLKS);
+        u_int32_t t = num_msgs_to_threshold(NUM_DEFAULT_JFILES,
+                DEFAULT_JFSIZE_SBLKS * JRNL_SBLK_SIZE, MSG_REC_SIZE_DBLKS);
+        u_int32_t d = num_dequeues_rem(NUM_DEFAULT_JFILES, DEFAULT_JFSIZE_SBLKS * JRNL_SBLK_SIZE);
         for (m=0; m<t; m++)
-            enq_msg(jc, m, create_msg(msg, m, MSG_SIZE), true);
+            enq_msg(jc, m, create_msg(msg, m, MSG_SIZE), false);
         // This enqueue should exceed the threshold
-//         enq_msg(jc, m, create_msg(msg, m, MSG_SIZE), true, RHM_IORES_ENQCAPTHRESH);
+        enq_msg(jc, m, create_msg(msg, m, MSG_SIZE), false, RHM_IORES_ENQCAPTHRESH);
 
-        // Dequeue all msgs except first
-        for (m=1; m<t; m++)
+        // Dequeue as many msgs as possible except first
+        for (m=1; m<=d; m++)
             deq_msg(jc, m);
+        deq_msg(jc, d+1, RHM_IORES_FULL);
     }
     catch(const exception& e) { BOOST_FAIL(e.what()); }
     cout << "ok" << endl;

Modified: store/trunk/cpp/tests/jrnl/_st_helper_fns.hpp
===================================================================
--- store/trunk/cpp/tests/jrnl/_st_helper_fns.hpp	2008-03-05 15:22:53 UTC (rev 1761)
+++ store/trunk/cpp/tests/jrnl/_st_helper_fns.hpp	2008-03-06 15:17:49 UTC (rev 1762)
@@ -236,20 +236,26 @@
 }
 
 const u_int32_t
-num_msgs_to_full(const u_int16_t num_files, const u_int32_t file_size_sblks,
+num_msgs_to_full(const u_int16_t num_files, const u_int32_t file_size_dblks,
         const u_int32_t msg_rec_size_dblks)
 {
-   return u_int32_t(::floor(1.0 * num_files * file_size_sblks / msg_rec_size_dblks));
+   return u_int32_t(::floor(1.0 * num_files * file_size_dblks / msg_rec_size_dblks));
 }
 
 const u_int32_t
-num_msgs_to_threshold(const u_int16_t num_files, const u_int32_t file_size_sblks,
+num_msgs_to_threshold(const u_int16_t num_files, const u_int32_t file_size_dblks,
         const u_int32_t msg_rec_size_dblks)
 {
-   return u_int32_t(::floor(1.0 * num_files * file_size_sblks * JRNL_ENQ_THRESHOLD /
+   return u_int32_t(::floor(1.0 * num_files * file_size_dblks * JRNL_ENQ_THRESHOLD /
            msg_rec_size_dblks / 100));
 }
 
+const u_int32_t
+num_dequeues_rem(const u_int16_t num_files, const u_int32_t file_size_sblks)
+{
+   return u_int32_t(::ceil(num_files * file_size_sblks * (1 - (1.0 * JRNL_ENQ_THRESHOLD / 100))));
+}
+
 const string&
 create_msg(string& s, const int msg_num, const int len)
 {




More information about the rhmessaging-commits mailing list