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

rhmessaging-commits at lists.jboss.org rhmessaging-commits at lists.jboss.org
Mon Sep 29 09:35:20 EDT 2008


Author: kpvdr
Date: 2008-09-29 09:35:20 -0400 (Mon, 29 Sep 2008)
New Revision: 2550

Modified:
   store/trunk/cpp/lib/jrnl/fcntl.cpp
   store/trunk/cpp/lib/jrnl/fcntl.hpp
   store/trunk/cpp/lib/jrnl/jcntl.cpp
Log:
Added lid to class fcntl; removed some unneeded methods, made initialize() protected.

Modified: store/trunk/cpp/lib/jrnl/fcntl.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/fcntl.cpp	2008-09-26 21:00:58 UTC (rev 2549)
+++ store/trunk/cpp/lib/jrnl/fcntl.cpp	2008-09-29 13:35:20 UTC (rev 2550)
@@ -45,24 +45,11 @@
 namespace journal
 {
 
-fcntl::fcntl(const u_int32_t jfsize_sblks, const u_int16_t fid):
-        _fname(),
-        _fid(fid),
-        _ffull_dblks(JRNL_SBLK_SIZE * (jfsize_sblks + 1)),
-        _rd_fh(-1),
-        _wr_fh(-1),
-        _rec_enqcnt(0),
-        _rd_subm_cnt_dblks(0),
-        _rd_cmpl_cnt_dblks(0),
-        _wr_subm_cnt_dblks(0),
-        _wr_cmpl_cnt_dblks(0),
-        _aio_cnt(0)
-{}
-
-fcntl::fcntl(const std::string& fbasename, const u_int16_t fid, const u_int32_t jfsize_sblks,
+fcntl::fcntl(const std::string& fbasename, const u_int16_t fid, const u_int16_t lid, const u_int32_t jfsize_sblks,
         const rcvdat* const ro):
         _fname(),
         _fid(fid),
+        _lid(lid),
         _ffull_dblks(JRNL_SBLK_SIZE * (jfsize_sblks + 1)),
         _rd_fh(-1),
         _wr_fh(-1),
@@ -73,7 +60,7 @@
         _wr_cmpl_cnt_dblks(0),
         _aio_cnt(0)
 {
-    initialize(fbasename, fid, jfsize_sblks, ro);
+    initialize(fbasename, fid, lid, jfsize_sblks, ro);
     open_fh();
 }
 
@@ -82,46 +69,6 @@
     close_fh();
 }
 
-void
-fcntl::initialize(const std::string& fbasename, const u_int16_t fid,
-        const u_int32_t jfsize_sblks, const rcvdat* const ro)
-{
-    _fid = fid;
-    _fname = filename(fbasename, fid);
-
-#ifdef RHM_JOWRITE
-    // In test mode, only create file if it does not exist
-    struct stat s;
-    if (::stat(_fname.c_str(), &s))
-    {
-#endif
-        if (ro) // Recovery initialization: set counters only
-        {
-            if (!ro->_jempty)
-            {
-                // For last file only, set write counters to end of last record (the
-                // continuation point); for all others, set to eof.
-                if (ro->_lfid == _fid)
-                {
-                    _wr_subm_cnt_dblks = ro->_eo/JRNL_DBLK_SIZE;
-                    _wr_cmpl_cnt_dblks = ro->_eo/JRNL_DBLK_SIZE;
-                }
-                else
-                {
-                    _wr_subm_cnt_dblks = _ffull_dblks;
-                    _wr_cmpl_cnt_dblks = _ffull_dblks;
-                }
-                // Set the number of enqueued records for this file.
-                _rec_enqcnt = ro->_enq_cnt_list[_fid];
-            }
-        }
-        else // Normal initialization: create empty journal files
-            create_jfile(jfsize_sblks);
-#ifdef RHM_JOWRITE
-    }
-#endif
-}
-
 bool
 fcntl::reset(const rcvdat* const ro)
 {
@@ -273,9 +220,50 @@
     return oss.str();
 }
 
-// Private functions
+// Protected functions
 
 void
+fcntl::initialize(const std::string& fbasename, const u_int16_t fid, const u_int16_t lid, const u_int32_t jfsize_sblks,
+        const rcvdat* const ro)
+{
+    _fid = fid;
+    _lid = lid;
+    _fname = filename(fbasename, fid);
+
+#ifdef RHM_JOWRITE
+    // In test mode, only create file if it does not exist
+    struct stat s;
+    if (::stat(_fname.c_str(), &s))
+    {
+#endif
+        if (ro) // Recovery initialization: set counters only
+        {
+            if (!ro->_jempty)
+            {
+                // For last file only, set write counters to end of last record (the
+                // continuation point); for all others, set to eof.
+                if (ro->_lfid == _fid)
+                {
+                    _wr_subm_cnt_dblks = ro->_eo/JRNL_DBLK_SIZE;
+                    _wr_cmpl_cnt_dblks = ro->_eo/JRNL_DBLK_SIZE;
+                }
+                else
+                {
+                    _wr_subm_cnt_dblks = _ffull_dblks;
+                    _wr_cmpl_cnt_dblks = _ffull_dblks;
+                }
+                // Set the number of enqueued records for this file.
+                _rec_enqcnt = ro->_enq_cnt_list[_fid];
+            }
+        }
+        else // Normal initialization: create empty journal files
+            create_jfile(jfsize_sblks);
+#ifdef RHM_JOWRITE
+    }
+#endif
+}
+
+void
 fcntl::open_fh()
 {
     _rd_fh = ::open(_fname.c_str(), O_RDONLY | O_DIRECT);
@@ -387,23 +375,5 @@
     clean_file(jfsize_sblks);
 }
 
-void
-fcntl::get_jfile()
-{
-    // Step 1: stat _pool_dir, locate first available file, check file size matches
-    // Step 2: move file to current directory
-}
-
-void return_jfile()
-{
-    // Step 1: Clean file (if req'd)
-    // Step 2: Move file to _pool_dir
-}
-
-
-// Static declarations
-
-std::string fcntl::_pool_dir;
-
 } // namespace journal
 } // namespace mrg

Modified: store/trunk/cpp/lib/jrnl/fcntl.hpp
===================================================================
--- store/trunk/cpp/lib/jrnl/fcntl.hpp	2008-09-26 21:00:58 UTC (rev 2549)
+++ store/trunk/cpp/lib/jrnl/fcntl.hpp	2008-09-29 13:35:20 UTC (rev 2550)
@@ -57,9 +57,9 @@
     class fcntl
     {
     protected:
-        static std::string _pool_dir;   ///< Directory containing unused file pool
         std::string _fname;             ///< File name
-        u_int16_t _fid;                 ///< File ID (ordinal number in ring buffer)
+        u_int16_t _fid;                 ///< File ID (file number in order of creation)
+        u_int16_t _lid;                 ///< Logical ID (ordinal number in ring store)
         const u_int32_t _ffull_dblks;   ///< File size in dblks (incl. file header)
         int _rd_fh;                     ///< Read file handle
         int _wr_fh;                     ///< Write file handle
@@ -71,23 +71,19 @@
         u_int16_t _aio_cnt;             ///< Outstanding AIO operations on this file
 
     public:
-        fcntl(const u_int32_t jfsize_sblks, const u_int16_t fid);
         // Constructors with implicit initialize() and open()
-        fcntl(const std::string& fbasename, const u_int16_t fid, const u_int32_t jfsize_sblks,
+        fcntl(const std::string& fbasename, const u_int16_t fid, const u_int16_t lid, const u_int32_t jfsize_sblks,
                 const rcvdat* const ro);
         virtual ~fcntl();
 
-        inline static std::string& pool_dir() { return _pool_dir; }
-        inline static void set_pool_dir(const std::string pool_dir) { _pool_dir = pool_dir; }
-        
-        virtual void initialize(const std::string& fbasename, const u_int16_t fid,
-                const u_int32_t jfsize_sblks, const rcvdat* const ro);
         virtual bool reset(const rcvdat* const ro = 0);
         virtual void rd_reset();
         virtual bool wr_reset(const rcvdat* const ro = 0);
 
         inline const std::string& fname() const { return _fname; }
         inline u_int16_t fid() const { return _fid; }
+        inline u_int16_t lid() const { return _lid; }
+        inline void set_lid(const u_int16_t lid) { _lid = lid; }
         inline int rd_fh() const { return _rd_fh; }
         inline int wr_fh() const { return _wr_fh; }
         inline u_int32_t enqcnt() const { return _rec_enqcnt; }
@@ -120,38 +116,32 @@
 
         inline bool rd_void() const { return _wr_cmpl_cnt_dblks == 0; }
         inline bool rd_empty() const { return _wr_cmpl_cnt_dblks <= JRNL_SBLK_SIZE; }
-        inline u_int32_t rd_remaining_dblks() const
-                { return _wr_cmpl_cnt_dblks - _rd_subm_cnt_dblks; }
+        inline u_int32_t rd_remaining_dblks() const { return _wr_cmpl_cnt_dblks - _rd_subm_cnt_dblks; }
         inline bool is_rd_full() const { return _wr_cmpl_cnt_dblks == _rd_subm_cnt_dblks; }
-        inline bool is_rd_compl() const
-                { return _wr_cmpl_cnt_dblks == _rd_cmpl_cnt_dblks; }
-        inline u_int32_t rd_aio_outstanding_dblks() const
-                { return _rd_subm_cnt_dblks - _rd_cmpl_cnt_dblks; }
+        inline bool is_rd_compl() const { return _wr_cmpl_cnt_dblks == _rd_cmpl_cnt_dblks; }
+        inline u_int32_t rd_aio_outstanding_dblks() const { return _rd_subm_cnt_dblks - _rd_cmpl_cnt_dblks; }
         inline bool rd_file_rotate() const { return is_rd_full() && is_wr_compl(); }
 
         inline bool wr_void() const { return _wr_subm_cnt_dblks == 0; }
         inline bool wr_empty() const { return _wr_subm_cnt_dblks <= JRNL_SBLK_SIZE; }
-        inline u_int32_t wr_remaining_dblks() const
-                { return _ffull_dblks - _wr_subm_cnt_dblks; }
+        inline u_int32_t wr_remaining_dblks() const { return _ffull_dblks - _wr_subm_cnt_dblks; }
         inline bool is_wr_full() const { return _ffull_dblks == _wr_subm_cnt_dblks; }
         inline bool is_wr_compl() const { return _ffull_dblks == _wr_cmpl_cnt_dblks; }
-        inline u_int32_t wr_aio_outstanding_dblks() const
-                { return _wr_subm_cnt_dblks - _wr_cmpl_cnt_dblks; }
+        inline u_int32_t wr_aio_outstanding_dblks() const { return _wr_subm_cnt_dblks - _wr_cmpl_cnt_dblks; }
         inline bool wr_file_rotate() const { return is_wr_full(); }
         
         // Debug aid
         const std::string status_str() const;
 
     protected:
+        virtual void initialize(const std::string& fbasename, const u_int16_t fid, const u_int16_t lid,
+                const u_int32_t jfsize_sblks, const rcvdat* const ro);
+
         virtual void open_fh();
         virtual void close_fh();
         static std::string filename(const std::string& fbasename, const u_int16_t fid);
         void clean_file(const u_int32_t jfsize_sblks);
         void create_jfile(const u_int32_t jfsize_sblks);
-        
-        // These functions for future use of file pool
-        void get_jfile();
-        void return_jfile();
     };
 
 } // namespace journal

Modified: store/trunk/cpp/lib/jrnl/jcntl.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/jcntl.cpp	2008-09-26 21:00:58 UTC (rev 2549)
+++ store/trunk/cpp/lib/jrnl/jcntl.cpp	2008-09-29 13:35:20 UTC (rev 2550)
@@ -134,7 +134,8 @@
     {
         std::ostringstream oss;
         oss << _jdir << "/" << _base_filename;
-        _fc_arr[i] = new fcntl(oss.str(), i, _jfsize_sblks, 0);
+        // TODO: resolve fid/lid in following stmt:
+        _fc_arr[i] = new fcntl(oss.str(), i, i, _jfsize_sblks, 0);
     }
 
     _wrfc.initialize(_num_jfiles, _jfsize_sblks, _fc_arr);
@@ -200,7 +201,8 @@
     {
         std::ostringstream oss;
         oss << _jdir << "/" << _base_filename;
-        _fc_arr[i] = new fcntl(oss.str(), i, _jfsize_sblks, &_rcvdat);
+        // TODO: resolve fid/lid in following stmt:
+        _fc_arr[i] = new fcntl(oss.str(), i, i, _jfsize_sblks, &_rcvdat);
     }
 
     _wrfc.initialize(_num_jfiles, _jfsize_sblks, _fc_arr, &_rcvdat);




More information about the rhmessaging-commits mailing list