[rhmessaging-commits] rhmessaging commits: r1456 - in store/trunk/cpp: lib/jrnl and 1 other directories.
rhmessaging-commits at lists.jboss.org
rhmessaging-commits at lists.jboss.org
Tue Dec 11 16:04:27 EST 2007
Author: kpvdr
Date: 2007-12-11 16:04:27 -0500 (Tue, 11 Dec 2007)
New Revision: 1456
Added:
store/trunk/cpp/lib/jrnl/deq_hdr.hpp
store/trunk/cpp/lib/jrnl/enq_hdr.hpp
store/trunk/cpp/lib/jrnl/rec_hdr.hpp
store/trunk/cpp/lib/jrnl/rec_tail.hpp
store/trunk/cpp/lib/jrnl/txn_hdr.hpp
store/trunk/cpp/tests/jrnl/unit_test_rec_hdr.cpp
Removed:
store/trunk/cpp/lib/jrnl/file_hdr.cpp
store/trunk/cpp/tests/jrnl/unit_test_file_hdr.cpp
Modified:
store/trunk/cpp/lib/Makefile.am
store/trunk/cpp/lib/jrnl/deq_rec.cpp
store/trunk/cpp/lib/jrnl/deq_rec.hpp
store/trunk/cpp/lib/jrnl/enq_rec.cpp
store/trunk/cpp/lib/jrnl/enq_rec.hpp
store/trunk/cpp/lib/jrnl/file_hdr.hpp
store/trunk/cpp/lib/jrnl/jcntl.cpp
store/trunk/cpp/lib/jrnl/jcntl.hpp
store/trunk/cpp/lib/jrnl/jinf.cpp
store/trunk/cpp/lib/jrnl/jrec.cpp
store/trunk/cpp/lib/jrnl/jrec.hpp
store/trunk/cpp/lib/jrnl/nlfh.cpp
store/trunk/cpp/lib/jrnl/nlfh.hpp
store/trunk/cpp/lib/jrnl/rcvdat.hpp
store/trunk/cpp/lib/jrnl/rmgr.cpp
store/trunk/cpp/lib/jrnl/rmgr.hpp
store/trunk/cpp/lib/jrnl/rrfc.cpp
store/trunk/cpp/lib/jrnl/txn_rec.cpp
store/trunk/cpp/lib/jrnl/txn_rec.hpp
store/trunk/cpp/lib/jrnl/wmgr.cpp
store/trunk/cpp/lib/jrnl/wrfc.cpp
store/trunk/cpp/tests/jrnl/
store/trunk/cpp/tests/jrnl/Makefile.am
store/trunk/cpp/tests/jrnl/Makefile.rtest
store/trunk/cpp/tests/jrnl/unit_test_jinf.cpp
Log:
Reorg of the messy file_hdr.hpp file - used subclassing instead of agrigation for record headers, also split each struct out into its own file. Also inlined all functions and constructors.
Modified: store/trunk/cpp/lib/Makefile.am
===================================================================
--- store/trunk/cpp/lib/Makefile.am 2007-12-11 21:04:00 UTC (rev 1455)
+++ store/trunk/cpp/lib/Makefile.am 2007-12-11 21:04:27 UTC (rev 1456)
@@ -41,7 +41,6 @@
jrnl/deq_rec.cpp \
jrnl/enq_map.cpp \
jrnl/enq_rec.cpp \
- jrnl/file_hdr.cpp \
jrnl/jcntl.cpp \
jrnl/jdir.cpp \
jrnl/jerrno.cpp \
@@ -59,7 +58,9 @@
jrnl/wrfc.cpp \
jrnl/aio_cb.hpp \
jrnl/data_tok.hpp \
+ jrnl/deq_hdr.hpp \
jrnl/deq_rec.hpp \
+ jrnl/enq_hdr.hpp \
jrnl/enq_map.hpp \
jrnl/enq_rec.hpp \
jrnl/file_hdr.hpp \
@@ -74,9 +75,12 @@
jrnl/nlfh.hpp \
jrnl/pmgr.hpp \
jrnl/rcvdat.hpp \
+ jrnl/rec_hdr.hpp \
+ jrnl/rec_tail.hpp \
jrnl/rmgr.hpp \
jrnl/rrfc.hpp \
jrnl/slock.hpp \
+ jrnl/txn_hdr.hpp \
jrnl/txn_map.hpp \
jrnl/txn_rec.hpp \
jrnl/wmgr.hpp \
Added: store/trunk/cpp/lib/jrnl/deq_hdr.hpp
===================================================================
--- store/trunk/cpp/lib/jrnl/deq_hdr.hpp (rev 0)
+++ store/trunk/cpp/lib/jrnl/deq_hdr.hpp 2007-12-11 21:04:27 UTC (rev 1456)
@@ -0,0 +1,131 @@
+/**
+* \file deq_hdr.hpp
+*
+* Red Hat Messaging - Message Journal
+*
+* File containing code for class rhm::journal::deq_hdr (dequeue record),
+* used to dequeue a previously enqueued record.
+*
+* \author Kim van der Riet
+*
+* Copyright 2007 Red Hat, Inc.
+*
+* This file is part of Red Hat Messaging.
+*
+* Red Hat Messaging is free software; you can redistribute it and/or
+* modify it under the terms of the GNU Lesser General Public
+* License as published by the Free Software Foundation; either
+* version 2.1 of the License, or (at your option) any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this library; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+* USA
+*
+* The GNU Lesser General Public License is available in the file COPYING.
+*/
+
+#ifndef rhm_journal_deq_hdr_hpp
+#define rhm_journal_deq_hdr_hpp
+
+#include <jrnl/rec_hdr.hpp>
+//#include <jrnl/jcfg.hpp>
+//#include <sys/types.h>
+
+namespace rhm
+{
+namespace journal
+{
+
+#pragma pack(1)
+
+ /**
+ * \brief Struct for dequeue record.
+ *
+ * Struct for dequeue record. If this record has a non-zero xidsize field (i.e., there is a
+ * valid XID), then this header is followed by the XID of xidsize bytes and a rec_tail. If,
+ * on the other hand, this record has a zero xidsize (i.e., there is no XID), then the rec_tail
+ * is absent.
+ *
+ * Note that this record had its own rid distinct from the rid of the record it is dequeueing.
+ * The rid field below is the rid of the dequeue record itself; the deq-rid field is the rid of a
+ * previous enqueue record being dequeued by this record.
+ *
+ * Record header info in binary format (32 bytes):
+ * <pre>
+ * 0 7
+ * +---+---+---+---+---+---+---+---+ -+
+ * | magic | v | e | flags | |
+ * +---+---+---+---+---+---+---+---+ | struct hdr
+ * | rid | |
+ * +---+---+---+---+---+---+---+---+ -+
+ * | deq-rid |
+ * +---+---+---+---+---+---+---+---+
+ * | xidsize |
+ * +---+---+---+---+---+---+---+---+
+ * v = file version (If the format or encoding of this file changes, then this
+ * number should be incremented)
+ * e = endian flag, false (0x00) for little endian, true (0x01) for big endian
+ * </pre>
+ *
+ * Note that journal files should be transferable between 32- and 64-bit
+ * hardware of the same endianness, but not between hardware of opposite
+ * entianness without some sort of binary conversion utility. Thus buffering
+ * will be needed for types that change size between 32- and 64-bit compiles.
+ */
+ struct deq_hdr : rec_hdr
+ {
+ u_int64_t _deq_rid; ///< Record ID of dequeued record
+#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
+ u_int32_t _filler0; ///< Big-endian filler for 32-bit size_t
+#endif
+ size_t _xidsize; ///< XID size
+#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
+ u_int32_t _filler0; ///< Little-endian filler for 32-bit size_t
+#endif
+
+ /**
+ * \brief Default constructor, which sets all values to 0.
+ */
+ inline deq_hdr(): rec_hdr(), _deq_rid(0),
+#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
+ _filler0(0),
+#endif
+ _xidsize(0)
+#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
+ , _filler0(0)
+#endif
+ {}
+
+ /**
+ * \brief Convenience constructor which initializes values during construction.
+ */
+ inline deq_hdr(const u_int32_t magic, const u_int8_t version, const u_int64_t rid,
+ const u_int64_t deq_rid, const size_t xidsize, const bool owi):
+ rec_hdr(magic, version, rid, owi), _deq_rid(deq_rid),
+#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
+ _filler0(0),
+#endif
+ _xidsize(xidsize)
+#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
+ , _filler0(0)
+#endif
+ {}
+
+ /**
+ * \brief Returns the size of the header in bytes.
+ */
+ inline static const size_t size() { return sizeof(deq_hdr); }
+ };
+
+#pragma pack()
+
+} // namespace journal
+} // namespace rhm
+
+#endif // ifndef rhm_journal_deq_hdr_hpp
Modified: store/trunk/cpp/lib/jrnl/deq_rec.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/deq_rec.cpp 2007-12-11 21:04:00 UTC (rev 1455)
+++ store/trunk/cpp/lib/jrnl/deq_rec.cpp 2007-12-11 21:04:27 UTC (rev 1456)
@@ -48,7 +48,7 @@
_deq_hdr(RHM_JDAT_DEQ_MAGIC, RHM_JDAT_VERSION, 0, 0, 0, false),
_xidp(NULL),
_buff(NULL),
- _deq_tail(_deq_hdr._hdr)
+ _deq_tail(_deq_hdr)
{}
deq_rec::deq_rec(const u_int64_t rid, const u_int64_t drid, const void* const xidp,
@@ -56,7 +56,7 @@
_deq_hdr(RHM_JDAT_DEQ_MAGIC, RHM_JDAT_VERSION, rid, drid, xidlen, owi),
_xidp(xidp),
_buff(NULL),
- _deq_tail(_deq_hdr._hdr)
+ _deq_tail(_deq_hdr)
{}
deq_rec::~deq_rec()
@@ -67,7 +67,7 @@
void
deq_rec::reset()
{
- _deq_hdr._hdr._rid = 0;
+ _deq_hdr._rid = 0;
_deq_hdr._deq_rid = 0;
_deq_hdr._xidsize = 0;
_deq_tail._rid = 0;
@@ -79,7 +79,7 @@
deq_rec::reset(const u_int64_t rid, const u_int64_t drid, const void* const xidp,
const size_t xidlen, const bool owi)
{
- _deq_hdr._hdr._rid = rid;
+ _deq_hdr._rid = rid;
_deq_hdr.set_owi(owi);
_deq_hdr._deq_rid = drid;
_deq_hdr._xidsize = xidlen;
@@ -201,7 +201,7 @@
}
const u_int32_t
-deq_rec::decode(hdr& h, void* rptr, u_int32_t rec_offs_dblks, u_int32_t max_size_dblks)
+deq_rec::decode(rec_hdr& h, void* rptr, u_int32_t rec_offs_dblks, u_int32_t max_size_dblks)
{
assert(rptr != NULL);
assert(max_size_dblks > 0);
@@ -263,8 +263,8 @@
else // Start of record
{
// Get and check header
- _deq_hdr._hdr.copy(h);
- rd_cnt = sizeof(hdr);
+ _deq_hdr.hdr_copy(h);
+ rd_cnt = sizeof(rec_hdr);
_deq_hdr._deq_rid = *(u_int64_t*)((char*)rptr + rd_cnt);
rd_cnt += sizeof(u_int64_t);
#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
@@ -317,11 +317,11 @@
}
const bool
-deq_rec::rcv_decode(hdr h, std::ifstream* ifsp, size_t& rec_offs)
+deq_rec::rcv_decode(rec_hdr h, std::ifstream* ifsp, size_t& rec_offs)
{
if (rec_offs == 0)
{
- _deq_hdr._hdr.copy(h);
+ _deq_hdr.hdr_copy(h);
ifsp->read((char*)&_deq_hdr._deq_rid, sizeof(u_int64_t));
#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
ifsp->ignore(sizeof(u_int32_t)); // _filler0
@@ -387,9 +387,9 @@
deq_rec::str(std::string& str) const
{
std::stringstream ss;
- ss << "deq_rec: m=" << _deq_hdr._hdr._magic;
- ss << " v=" << (int)_deq_hdr._hdr._version;
- ss << " rid=" << _deq_hdr._hdr._rid;
+ ss << "deq_rec: m=" << _deq_hdr._magic;
+ ss << " v=" << (int)_deq_hdr._version;
+ ss << " rid=" << _deq_hdr._rid;
ss << " drid=" << _deq_hdr._deq_rid;
if (_xidp)
ss << " xid=\"" << _xidp << "\"";
@@ -412,14 +412,14 @@
void
deq_rec::chk_hdr() const
{
- jrec::chk_hdr(_deq_hdr._hdr);
- if (_deq_hdr._hdr._magic != RHM_JDAT_DEQ_MAGIC)
+ jrec::chk_hdr(_deq_hdr);
+ if (_deq_hdr._magic != RHM_JDAT_DEQ_MAGIC)
{
std::stringstream ss;
ss << std::hex << std::setfill('0');
- ss << "deq magic: rid=0x" << std::setw(16) << _deq_hdr._hdr._rid;
+ ss << "deq magic: rid=0x" << std::setw(16) << _deq_hdr._rid;
ss << ": expected=0x" << std::setw(8) << RHM_JDAT_DEQ_MAGIC;
- ss << " read=0x" << std::setw(2) << (int)_deq_hdr._hdr._magic;
+ ss << " read=0x" << std::setw(2) << (int)_deq_hdr._magic;
throw jexception(jerrno::JERR_JREC_BADRECHDR, ss.str().c_str(), "deq_rec", "chk_hdr");
}
}
@@ -428,13 +428,13 @@
deq_rec::chk_hdr(u_int64_t rid) const
{
chk_hdr();
- jrec::chk_rid(_deq_hdr._hdr, rid);
+ jrec::chk_rid(_deq_hdr, rid);
}
void
deq_rec::chk_tail() const
{
- jrec::chk_tail(_deq_tail, _deq_hdr._hdr);
+ jrec::chk_tail(_deq_tail, _deq_hdr);
}
void
Modified: store/trunk/cpp/lib/jrnl/deq_rec.hpp
===================================================================
--- store/trunk/cpp/lib/jrnl/deq_rec.hpp 2007-12-11 21:04:00 UTC (rev 1455)
+++ store/trunk/cpp/lib/jrnl/deq_rec.hpp 2007-12-11 21:04:27 UTC (rev 1456)
@@ -41,6 +41,7 @@
}
}
+#include <jrnl/deq_hdr.hpp>
#include <jrnl/jrec.hpp>
namespace rhm
@@ -74,12 +75,12 @@
void reset(const u_int64_t rid, const u_int64_t drid, const void* const xidp,
const size_t xidlen, const bool owi);
const u_int32_t encode(void* wptr, u_int32_t rec_offs_dblks, u_int32_t max_size_dblks);
- const u_int32_t decode(hdr& h, void* rptr, u_int32_t rec_offs_dblks,
+ const u_int32_t decode(rec_hdr& h, void* rptr, u_int32_t rec_offs_dblks,
u_int32_t max_size_dblks);
// Decode used for recover
- const bool rcv_decode(hdr h, std::ifstream* ifsp, size_t& rec_offs);
+ const bool rcv_decode(rec_hdr h, std::ifstream* ifsp, size_t& rec_offs);
- inline const u_int64_t rid() const { return _deq_hdr._hdr._rid; }
+ inline const u_int64_t rid() const { return _deq_hdr._rid; }
inline const u_int64_t deq_rid() const { return _deq_hdr._deq_rid; }
const size_t get_xid(void** const xidpp);
std::string& str(std::string& str) const;
Added: store/trunk/cpp/lib/jrnl/enq_hdr.hpp
===================================================================
--- store/trunk/cpp/lib/jrnl/enq_hdr.hpp (rev 0)
+++ store/trunk/cpp/lib/jrnl/enq_hdr.hpp 2007-12-11 21:04:27 UTC (rev 1456)
@@ -0,0 +1,164 @@
+/**
+* \file enq_hdr.hpp
+*
+* Red Hat Messaging - Message Journal
+*
+* File containing code for class rhm::journal::enq_hdr (enueue header),
+* used to start an enqueue record in the journal.
+*
+* \author Kim van der Riet
+*
+* Copyright 2007 Red Hat, Inc.
+*
+* This file is part of Red Hat Messaging.
+*
+* Red Hat Messaging is free software; you can redistribute it and/or
+* modify it under the terms of the GNU Lesser General Public
+* License as published by the Free Software Foundation; either
+* version 2.1 of the License, or (at your option) any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this library; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+* USA
+*
+* The GNU Lesser General Public License is available in the file COPYING.
+*/
+
+#ifndef rhm_journal_enq_hdr_hpp
+#define rhm_journal_enq_hdr_hpp
+
+#include <jrnl/rec_hdr.hpp>
+
+namespace rhm
+{
+namespace journal
+{
+
+#pragma pack(1)
+
+ /**
+ * \brief Struct for enqueue record.
+ *
+ * Struct for enqueue record. In addition to the common data, this header includes both the
+ * xid and data blob sizes.
+ *
+ * This header precedes all enqueue data in journal files.
+ *
+ * Record header info in binary format (32 bytes):
+ * <pre>
+ * 0 7
+ * +---+---+---+---+---+---+---+---+ -+
+ * | magic | v | e | flags | |
+ * +---+---+---+---+---+---+---+---+ | struct hdr
+ * | rid | |
+ * +---+---+---+---+---+---+---+---+ -+
+ * | xidsize |
+ * +---+---+---+---+---+---+---+---+
+ * | dsize |
+ * +---+---+---+---+---+---+---+---+
+ * v = file version (If the format or encoding of this file changes, then this
+ * number should be incremented)
+ * e = endian flag, false (0x00) for little endian, true (0x01) for big endian
+ * </pre>
+ *
+ * Note that journal files should be transferable between 32- and 64-bit
+ * hardware of the same endianness, but not between hardware of opposite
+ * entianness without some sort of binary conversion utility. Thus buffering
+ * will be needed for types that change size between 32- and 64-bit compiles.
+ */
+ struct enq_hdr : rec_hdr
+ {
+#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
+ u_int32_t _filler0; ///< Big-endian filler for 32-bit size_t
+#endif
+ size_t _xidsize; ///< XID size
+#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
+ u_int32_t _filler0; ///< Little-endian filler for 32-bit size_t
+#endif
+#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
+ u_int32_t _filler1; ///< Big-endian filler for 32-bit size_t
+#endif
+ size_t _dsize; ///< Record data size
+#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
+ u_int32_t _filler1; ///< Little-endian filler for 32-bit size_t
+#endif
+ static const u_int16_t ENQ_HDR_TRANSIENT_MASK = 0x10;
+ static const u_int16_t ENQ_HDR_EXTERNAL_MASK = 0x20;
+
+ /**
+ * \brief Default constructor, which sets all values to 0.
+ */
+ inline enq_hdr(): rec_hdr(),
+#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
+ _filler0(0),
+#endif
+ _xidsize(0),
+#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
+ _filler0(0),
+#endif
+#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
+ _filler1(0),
+#endif
+ _dsize(0)
+#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
+ , _filler1(0)
+#endif
+ {}
+
+ /**
+ * \brief Convenience constructor which initializes values during construction.
+ */
+ inline enq_hdr(const u_int32_t magic, const u_int8_t version, const u_int64_t rid,
+ const size_t xidsize, const size_t dsize, const bool owi,
+ const bool transient = false): rec_hdr(magic, version, rid, owi),
+#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
+ _filler0(0),
+#endif
+ _xidsize(xidsize),
+#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
+ _filler0(0),
+#endif
+#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
+ _filler1(0),
+#endif
+ _dsize(dsize)
+#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
+ , _filler1(0)
+#endif
+ { set_transient(transient); }
+
+
+ inline const bool is_transient() const { return _uflag & ENQ_HDR_TRANSIENT_MASK; }
+
+ inline void set_transient(const bool transient)
+ {
+ _uflag = transient ? _uflag | ENQ_HDR_TRANSIENT_MASK :
+ _uflag & (~ENQ_HDR_TRANSIENT_MASK);
+ }
+
+ inline const bool is_external() const { return _uflag & ENQ_HDR_EXTERNAL_MASK; }
+
+ inline void set_external(const bool external)
+ {
+ _uflag = external ? _uflag | ENQ_HDR_EXTERNAL_MASK :
+ _uflag & (~ENQ_HDR_EXTERNAL_MASK);
+ }
+
+ /**
+ * \brief Returns the size of the header in bytes.
+ */
+ inline static const size_t size() { return sizeof(enq_hdr); }
+ };
+
+#pragma pack()
+
+} // namespace journal
+} // namespace rhm
+
+#endif // ifndef rhm_journal_enq_hdr_hpp
Modified: store/trunk/cpp/lib/jrnl/enq_rec.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/enq_rec.cpp 2007-12-11 21:04:00 UTC (rev 1455)
+++ store/trunk/cpp/lib/jrnl/enq_rec.cpp 2007-12-11 21:04:27 UTC (rev 1456)
@@ -51,7 +51,7 @@
_xidp(NULL),
_data(NULL),
_buff(NULL),
- _enq_tail(_enq_hdr._hdr)
+ _enq_tail(_enq_hdr)
{}
// Constructor used for transactional write operations, where dbuf contains data to be written.
@@ -62,7 +62,7 @@
_xidp(xidp),
_data(dbuf),
_buff(NULL),
- _enq_tail(_enq_hdr._hdr)
+ _enq_tail(_enq_hdr)
{}
enq_rec::~enq_rec()
@@ -75,7 +75,7 @@
void
enq_rec::reset()
{
- _enq_hdr._hdr._rid = 0;
+ _enq_hdr._rid = 0;
_enq_hdr.set_owi(false);
_enq_hdr.set_transient(false);
_enq_hdr._xidsize = 0;
@@ -93,7 +93,7 @@
const void* const xidp, const size_t xidlen, const bool owi, const bool transient,
const bool external)
{
- _enq_hdr._hdr._rid = rid;
+ _enq_hdr._rid = rid;
_enq_hdr.set_owi(owi);
_enq_hdr.set_transient(transient);
_enq_hdr.set_external(external);
@@ -251,7 +251,7 @@
}
const u_int32_t
-enq_rec::decode(hdr& h, void* rptr, u_int32_t rec_offs_dblks, u_int32_t max_size_dblks)
+enq_rec::decode(rec_hdr& h, void* rptr, u_int32_t rec_offs_dblks, u_int32_t max_size_dblks)
{
assert(rptr != NULL);
assert(max_size_dblks > 0);
@@ -337,8 +337,8 @@
else // Start of record
{
// Get and check header
- _enq_hdr._hdr.copy(h);
- rd_cnt = sizeof(hdr);
+ _enq_hdr.hdr_copy(h);
+ rd_cnt = sizeof(rec_hdr);
#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
rd_cnt += sizeof(u_int32_t); // Filler 0
#endif
@@ -432,12 +432,12 @@
}
const bool
-enq_rec::rcv_decode(hdr h, std::ifstream* ifsp, size_t& rec_offs)
+enq_rec::rcv_decode(rec_hdr h, std::ifstream* ifsp, size_t& rec_offs)
{
if (rec_offs == 0)
{
// Read header, allocate (if req'd) for xid
- _enq_hdr._hdr.copy(h);
+ _enq_hdr.hdr_copy(h);
#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
ifsp->ignore(sizeof(u_int32_t)); // _filler0
#endif
@@ -474,7 +474,7 @@
}
if (!_enq_hdr.is_external())
{
- if (rec_offs < sizeof(hdr) + _enq_hdr._xidsize + _enq_hdr._dsize)
+ if (rec_offs < sizeof(rec_hdr) + _enq_hdr._xidsize + _enq_hdr._dsize)
{
// Ignore data (or continue ignoring data)
size_t offs = rec_offs - sizeof(_enq_hdr) - _enq_hdr._xidsize;
@@ -540,9 +540,9 @@
enq_rec::str(std::string& str) const
{
std::stringstream ss;
- ss << "enq_rec: m=" << _enq_hdr._hdr._magic;
- ss << " v=" << (int)_enq_hdr._hdr._version;
- ss << " rid=" << _enq_hdr._hdr._rid;
+ ss << "enq_rec: m=" << _enq_hdr._magic;
+ ss << " v=" << (int)_enq_hdr._version;
+ ss << " rid=" << _enq_hdr._rid;
if (_xidp)
ss << " xid=\"" << _xidp << "\"";
ss << " len=" << _enq_hdr._dsize;
@@ -573,21 +573,21 @@
void
enq_rec::set_rid(const u_int64_t rid)
{
- _enq_hdr._hdr._rid = rid;
+ _enq_hdr._rid = rid;
_enq_tail._rid = rid;
}
void
enq_rec::chk_hdr() const
{
- jrec::chk_hdr(_enq_hdr._hdr);
- if (_enq_hdr._hdr._magic != RHM_JDAT_ENQ_MAGIC)
+ jrec::chk_hdr(_enq_hdr);
+ if (_enq_hdr._magic != RHM_JDAT_ENQ_MAGIC)
{
std::stringstream ss;
ss << std::hex << std::setfill('0');
- ss << "enq magic: rid=0x" << std::setw(16) << _enq_hdr._hdr._rid;
+ ss << "enq magic: rid=0x" << std::setw(16) << _enq_hdr._rid;
ss << ": expected=0x" << std::setw(8) << RHM_JDAT_ENQ_MAGIC;
- ss << " read=0x" << std::setw(2) << (int)_enq_hdr._hdr._magic;
+ ss << " read=0x" << std::setw(2) << (int)_enq_hdr._magic;
throw jexception(jerrno::JERR_JREC_BADRECHDR, ss.str().c_str(), "enq_rec", "chk_hdr");
}
}
@@ -596,13 +596,13 @@
enq_rec::chk_hdr(u_int64_t rid) const
{
chk_hdr();
- jrec::chk_rid(_enq_hdr._hdr, rid);
+ jrec::chk_rid(_enq_hdr, rid);
}
void
enq_rec::chk_tail() const
{
- jrec::chk_tail(_enq_tail, _enq_hdr._hdr);
+ jrec::chk_tail(_enq_tail, _enq_hdr);
}
void
Modified: store/trunk/cpp/lib/jrnl/enq_rec.hpp
===================================================================
--- store/trunk/cpp/lib/jrnl/enq_rec.hpp 2007-12-11 21:04:00 UTC (rev 1455)
+++ store/trunk/cpp/lib/jrnl/enq_rec.hpp 2007-12-11 21:04:27 UTC (rev 1456)
@@ -41,6 +41,7 @@
}
}
+#include <jrnl/enq_hdr.hpp>
#include <jrnl/jrec.hpp>
namespace rhm
@@ -86,10 +87,10 @@
const bool external);
const u_int32_t encode(void* wptr, u_int32_t rec_offs_dblks, u_int32_t max_size_dblks);
- const u_int32_t decode(hdr& h, void* rptr, u_int32_t rec_offs_dblks,
+ const u_int32_t decode(rec_hdr& h, void* rptr, u_int32_t rec_offs_dblks,
u_int32_t max_size_dblks);
// Decode used for recover
- const bool rcv_decode(hdr h, std::ifstream* ifsp, size_t& rec_offs);
+ const bool rcv_decode(rec_hdr h, std::ifstream* ifsp, size_t& rec_offs);
const size_t get_xid(void** const xidpp);
const size_t get_data(void** const datapp);
@@ -99,7 +100,7 @@
const size_t data_size() const;
const size_t xid_size() const;
const size_t rec_size() const;
- inline const u_int64_t rid() const { return _enq_hdr._hdr._rid; }
+ inline const u_int64_t rid() const { return _enq_hdr._rid; }
void set_rid(const u_int64_t rid);
private:
Deleted: store/trunk/cpp/lib/jrnl/file_hdr.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/file_hdr.cpp 2007-12-11 21:04:00 UTC (rev 1455)
+++ store/trunk/cpp/lib/jrnl/file_hdr.cpp 2007-12-11 21:04:27 UTC (rev 1456)
@@ -1,354 +0,0 @@
-/**
-* \file file_hdr.cpp
-*
-* Red Hat Messaging - Message Journal
-*
-* File containing code for class rhm::journal::file_hdr (journal log file
-* handle), used for controlling journal log files. See comments in file
-* file_hdr.hpp for details.
-*
-* \author Kim van der Riet
-*
-* Copyright 2007 Red Hat, Inc.
-*
-* This file is part of Red Hat Messaging.
-*
-* Red Hat Messaging is free software; you can redistribute it and/or
-* modify it under the terms of the GNU Lesser General Public
-* License as published by the Free Software Foundation; either
-* version 2.1 of the License, or (at your option) any later version.
-*
-* This library is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this library; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
-* USA
-*
-* The GNU Lesser General Public License is available in the file COPYING.
-*/
-
-#include <jrnl/file_hdr.hpp>
-
-#include <cerrno>
-#include <sstream>
-#include <jrnl/jerrno.hpp>
-
-namespace rhm
-{
-namespace journal
-{
-
-// ***** struct hdr *****
-
-hdr::hdr():
- _magic(0),
- _version(0),
- _eflag(0),
- _uflag(0),
- _rid(0)
-{}
-
-hdr::hdr(const u_int32_t magic, const u_int8_t version, const u_int64_t rid, const bool owi):
- _magic(magic),
- _version(version),
-#if defined(JRNL_BIG_ENDIAN)
- _eflag(RHM_BENDIAN_FLAG),
-#else
- _eflag(RHM_LENDIAN_FLAG),
-#endif
- _uflag(owi ? HDR_OVERWRITE_INDICATOR_MASK : 0),
- _rid(rid)
-{}
-
-void
-hdr::copy(const hdr& h)
-{
- _magic = h._magic;
- _version = h._version;
- _eflag = h._eflag;
- _uflag = h._uflag;
- _rid = h._rid;
-}
-
-void
-hdr::reset()
-{
- _magic = 0;
- _version = 0;
- _eflag = 0;
- _uflag = 0;
- _rid = 0;
-}
-
-void
-hdr::set_owi(const bool owi)
-{
- if (owi)
- _uflag |= HDR_OVERWRITE_INDICATOR_MASK;
- else
- _uflag &= (~HDR_OVERWRITE_INDICATOR_MASK);
-}
-
-const u_int16_t hdr::HDR_OVERWRITE_INDICATOR_MASK = 0x1;
-
-
-// ***** struct rec_tail *****
-
-rec_tail::rec_tail():
- _xmagic(0xffffffff), // 1's complement of 0
- _rid(0)
-{}
-
-rec_tail::rec_tail(const hdr& _hdr):
- _xmagic(~_hdr._magic),
- _rid(_hdr._rid)
-{}
-
-rec_tail::rec_tail(const u_int32_t xmagic, const u_int64_t rid):
- _xmagic(xmagic),
- _rid(rid)
-{}
-
-
-// ***** struct file_hdr *****
-
-file_hdr::file_hdr():
- _hdr(),
- _fid(0),
- _res(0),
-#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
- _filler0(0),
-#endif
- _fro(0),
-#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
- _filler0(0),
-#endif
-#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
- _filler1(0),
-#endif
- _ts_sec(0),
-#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
- _filler1(0),
-#endif
-#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
- _filler2(0),
-#endif
- _ts_nsec(0)
-#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
- , _filler2(0)
-#endif
-{}
-
-file_hdr::file_hdr(const u_int32_t magic, const u_int8_t version, const u_int64_t rid,
- const u_int32_t fid, const size_t fro, const bool owi, const bool settime):
- _hdr(magic, version, rid, owi),
- _fid(fid),
- _res(0),
-#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
- _filler0(0),
-#endif
- _fro(fro),
-#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
- _filler0(0),
-#endif
-#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
- _filler1(0),
-#endif
- _ts_sec(0),
-#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
- _filler1(0),
-#endif
-#if defined(JRNL_BIG_ENDIAN)
- _filler2(0),
-#endif
- _ts_nsec(0)
-#if defined(JRNL_LITTLE_ENDIAN)
- , _filler2(0)
-#endif
-{
- if (settime)
- set_time();
-}
-
-void
-file_hdr::set_owi(const bool owi)
-{
- if (owi)
- _hdr._uflag |= hdr::HDR_OVERWRITE_INDICATOR_MASK;
- else
- _hdr._uflag &= (~hdr::HDR_OVERWRITE_INDICATOR_MASK);
-}
-
-void
-file_hdr::set_time()
-{
-// TODO: Standardize on a method for getting time that does not requrie a context switch.
- timespec ts;
- if (::clock_gettime(CLOCK_REALTIME, &ts))
- {
- std::stringstream ss;
- ss << "errno=" << errno;
- throw jexception(jerrno::JERR__RTCLOCK, ss.str().c_str(), "file_hdr", "set_time");
- }
- _ts_sec = ts.tv_sec;
- _ts_nsec = ts.tv_nsec;
-}
-
-void
-file_hdr::set_time(timespec& ts)
-{
- _ts_sec = ts.tv_sec;
- _ts_nsec = ts.tv_nsec;
-}
-
-
-// ***** struct enq_hdr *****
-
-enq_hdr::enq_hdr():
- _hdr(),
-#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
- _filler0(0),
-#endif
- _xidsize(0),
-#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
- _filler0(0),
-#endif
-#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
- _filler1(0),
-#endif
- _dsize(0)
-#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
- , _filler1(0)
-#endif
-{}
-
-enq_hdr::enq_hdr(const u_int32_t magic, const u_int8_t version, const u_int64_t rid,
- const size_t xidsize, const size_t dsize, const bool owi, const bool transient):
- _hdr(magic, version, rid, owi),
-#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
- _filler0(0),
-#endif
- _xidsize(xidsize),
-#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
- _filler0(0),
-#endif
-#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
- _filler1(0),
-#endif
- _dsize(dsize)
-#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
- , _filler1(0)
-#endif
-{
- set_transient(transient);
-}
-
-void
-enq_hdr::set_owi(const bool owi)
-{
- if (owi)
- _hdr._uflag |= hdr::HDR_OVERWRITE_INDICATOR_MASK;
- else
- _hdr._uflag &= (~hdr::HDR_OVERWRITE_INDICATOR_MASK);
-}
-
-void
-enq_hdr::set_transient(const bool transient)
-{
- if (transient)
- _hdr._uflag |= ENQ_HDR_TRANSIENT_MASK;
- else
- _hdr._uflag &= (~ENQ_HDR_TRANSIENT_MASK);
-}
-
-void
-enq_hdr::set_external(const bool external)
-{
- if (external)
- _hdr._uflag |= ENQ_HDR_EXTERNAL_MASK;
- else
- _hdr._uflag &= (~ENQ_HDR_EXTERNAL_MASK);
-}
-
-const u_int16_t enq_hdr::ENQ_HDR_TRANSIENT_MASK = 0x10;
-const u_int16_t enq_hdr::ENQ_HDR_EXTERNAL_MASK = 0x20;
-
-
-// ***** struct deq_hdr *****
-
-deq_hdr::deq_hdr():
- _hdr(),
- _deq_rid(0),
-#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
- _filler0(0),
-#endif
- _xidsize(0)
-#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
- , _filler0(0)
-#endif
-{}
-
-deq_hdr::deq_hdr(const u_int32_t magic, const u_int8_t version, const u_int64_t rid,
- const u_int64_t deq_rid, const size_t xidsize, const bool owi):
- _hdr(magic, version, rid, owi),
- _deq_rid(deq_rid),
-#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
- _filler0(0),
-#endif
- _xidsize(xidsize)
-#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
- , _filler0(0)
-#endif
-{}
-
-void
-deq_hdr::set_owi(const bool owi)
-{
- if (owi)
- _hdr._uflag |= hdr::HDR_OVERWRITE_INDICATOR_MASK;
- else
- _hdr._uflag &= (~hdr::HDR_OVERWRITE_INDICATOR_MASK);
-}
-
-
-// ***** struct txn_hdr *****
-
-
-txn_hdr::txn_hdr():
- _hdr(),
-#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
- _filler0(0),
-#endif
- _xidsize(0)
-#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
- , _filler0(0)
-#endif
-{}
-
-txn_hdr::txn_hdr(const u_int32_t magic, const u_int8_t version, const u_int64_t rid,
- const size_t xidsize, const bool owi):
- _hdr(magic, version, rid, owi),
-#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
- _filler0(0),
-#endif
- _xidsize(xidsize)
-#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
- , _filler0(0)
-#endif
-{}
-
-void
-txn_hdr::set_owi(const bool owi)
-{
- if (owi)
- _hdr._uflag |= hdr::HDR_OVERWRITE_INDICATOR_MASK;
- else
- _hdr._uflag &= (~hdr::HDR_OVERWRITE_INDICATOR_MASK);
-}
-
-} // namespace journal
-} // namespace rhm
Modified: store/trunk/cpp/lib/jrnl/file_hdr.hpp
===================================================================
--- store/trunk/cpp/lib/jrnl/file_hdr.hpp 2007-12-11 21:04:00 UTC (rev 1455)
+++ store/trunk/cpp/lib/jrnl/file_hdr.hpp 2007-12-11 21:04:27 UTC (rev 1456)
@@ -3,9 +3,9 @@
*
* Red Hat Messaging - Message Journal
*
-* File containing code for class rhm::journal::file_hdr (journal log file
-* handle), used for controlling journal log files. See class documentation
-* for details.
+* File containing code for class rhm::journal::file_hdr (file
+* record header), used to start a journal file. It contains some
+* file metadata and information to aid journal recovery.
*
* \author Kim van der Riet
*
@@ -34,18 +34,12 @@
#ifndef rhm_journal_file_hdr_hpp
#define rhm_journal_file_hdr_hpp
-namespace rhm
-{
-namespace journal
-{
-class file_hdr;
-}
-}
-
-#include <jrnl/jcfg.hpp>
-
-#include <sys/types.h>
+#include <errno.h>
+#include <jrnl/rec_hdr.hpp>
+#include <jrnl/jerrno.hpp>
#include <jrnl/jexception.hpp>
+#include <sstream>
+//#include <sys/types.h>
namespace rhm
{
@@ -55,119 +49,6 @@
#pragma pack(1)
/**
- * \brief Struct for data common to the head of all journal files and records.
- * This includes identification for the file type, the encoding version, endian
- * indicator and a record ID.
- *
- * File header info in binary format (16 bytes):
- * <pre>
- * 0 7
- * +---+---+---+---+---+---+---+---+
- * | magic | v | e | flags |
- * +---+---+---+---+---+---+---+---+
- * | rid |
- * +---+---+---+---+---+---+---+---+
- * v = file version (If the format or encoding of this file changes, then this
- * number should be incremented)
- * e = endian flag, false (0x00) for little endian, true (0x01) for big endian
- * </pre>
- *
- * Note that journal files should be transferable between 32- and 64-bit
- * hardware of the same endianness, but not between hardware of opposite
- * entianness without some sort of binary conversion utility. Thus buffering
- * will be needed for types that change size between 32- and 64-bit compiles.
- */
- struct hdr
- {
- u_int32_t _magic; ///< File type identifier (magic number)
- u_int8_t _version; ///< File encoding version
- u_int8_t _eflag; ///< Flag for determining endianness
- u_int16_t _uflag; ///< User-defined flags
- u_int64_t _rid; ///< Record ID (rotating 64-bit counter)
-
- // Global flags
- static const u_int16_t HDR_OVERWRITE_INDICATOR_MASK;
-
- // Convenience constructors and methods
- /**
- * \brief Default constructor, which sets all values to 0.
- */
- hdr();
-
- /**
- * \brief Convenience constructor which initializes values during construction.
- */
- hdr(const u_int32_t magic, const u_int8_t version, const u_int64_t rid, const bool owi);
-
- /**
- * \brief Convenience copy method.
- */
- void copy(const hdr& h);
-
- /**
- * \brief Resets all fields to 0
- */
- void reset();
-
- inline const bool get_owi() const { return _uflag & HDR_OVERWRITE_INDICATOR_MASK; }
- void set_owi(const bool owi);
-
- /**
- * \brief Returns the size of the header in bytes.
- */
- inline static const size_t size() { return sizeof(hdr); }
- }; // struct hdr
-
-
- /**
- * \brief Struct for data common to the tail of all records. The magic number
- * used here is the binary inverse (1's complement) of the magic used in the
- * record header; this minimizes possible confusion with other headers that may
- * be present during recovery.
- *
- * This header precedes all records in journal files.
- *
- * Record header info in binary format (12 bytes):
- * <pre>
- * 0 7
- * +---+---+---+---+---+---+---+---+
- * | ~(magic) | rid |
- * +---+---+---+---+---+---+---+---+
- * | rid (con't) |
- * +---+---+---+---+
- * </pre>
- */
- struct rec_tail
- {
- u_int32_t _xmagic; ///< Binary inverse (1's complement) of hdr magic number
- u_int64_t _rid; ///< ID (rotating 64-bit counter)
-
-
- /**
- * \brief Default constructor, which sets all values to 0.
- */
- rec_tail();
-
-
- /**
- * \brief Convenience constructor which initializes values during construction from
- * existing enq_hdr instance.
- */
- rec_tail(const hdr& _hdr);
-
- /**
- * \brief Convenience constructor which initializes values during construction.
- */
- rec_tail(const u_int32_t xmagic, const u_int64_t rid);
-
- /**
- * \brief Returns the size of the header in bytes.
- */
- inline static const size_t size() { return sizeof(rec_tail); }
- };
-
-
- /**
* \brief Struct for data common to the head of all journal files. In addition to
* the common data, this includes the record ID and offset of the first record in
* the file.
@@ -204,10 +85,9 @@
* entianness without some sort of binary conversion utility. Thus buffering
* will be needed for types that change size between 32- and 64-bit compiles.
*/
- struct file_hdr
+ struct file_hdr : rec_hdr
{
- hdr _hdr; ///< Common header
- u_int32_t _fid; ///< File ID
+ u_int32_t _fid; ///< File ID (fid)
u_int32_t _res; ///< Reserved (for alignment/flags)
#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
u_int32_t _filler0; ///< Big-endian filler for 32-bit size_t
@@ -234,240 +114,92 @@
/**
* \brief Default constructor, which sets all values to 0.
*/
- file_hdr();
-
- /**
- * \brief Convenience constructor which initializes values during construction.
- */
- file_hdr(const u_int32_t magic, const u_int8_t version, const u_int64_t rid,
- const u_int32_t fid, const size_t fro, const bool owi, const bool settime = false);
-
- inline const bool get_owi() const { return _hdr._uflag & hdr::HDR_OVERWRITE_INDICATOR_MASK; }
- void set_owi(const bool owi);
-
- /**
- * \brief Gets the current time from the system clock and sets the timestamp in the struct.
- */
- void set_time();
-
- /**
- * \brief Sets the timestamp in the struct to the provided value (in seconds and
- * nanoseconds).
- */
- void set_time(timespec& ts);
-
- /**
- * \brief Returns the size of the header in bytes.
- */
- inline static const size_t size() { return sizeof(file_hdr); }
- }; // struct file_hdr
-
-
- /**
- * \brief Struct for enqueue record.
- *
- * Struct for enqueue record. In addition to the common data, this header includes both the
- * xid and data blob sizes.
- *
- * This header precedes all enqueue data in journal files.
- *
- * Record header info in binary format (32 bytes):
- * <pre>
- * 0 7
- * +---+---+---+---+---+---+---+---+ -+
- * | magic | v | e | flags | |
- * +---+---+---+---+---+---+---+---+ | struct hdr
- * | rid | |
- * +---+---+---+---+---+---+---+---+ -+
- * | xidsize |
- * +---+---+---+---+---+---+---+---+
- * | dsize |
- * +---+---+---+---+---+---+---+---+
- * v = file version (If the format or encoding of this file changes, then this
- * number should be incremented)
- * e = endian flag, false (0x00) for little endian, true (0x01) for big endian
- * </pre>
- *
- * Note that journal files should be transferable between 32- and 64-bit
- * hardware of the same endianness, but not between hardware of opposite
- * entianness without some sort of binary conversion utility. Thus buffering
- * will be needed for types that change size between 32- and 64-bit compiles.
- */
- struct enq_hdr
- {
- hdr _hdr; ///< Common header
+ inline file_hdr(): rec_hdr(), _fid(0), _res(0),
#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
- u_int32_t _filler0; ///< Big-endian filler for 32-bit size_t
+ _filler0(0),
#endif
- size_t _xidsize; ///< XID size
+ _fro(0),
#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
- u_int32_t _filler0; ///< Little-endian filler for 32-bit size_t
+ _filler0(0),
#endif
#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
- u_int32_t _filler1; ///< Big-endian filler for 32-bit size_t
+ _filler1(0),
#endif
- size_t _dsize; ///< Record data size
+ _ts_sec(0),
#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
- u_int32_t _filler1; ///< Little-endian filler for 32-bit size_t
+ _filler1(0),
#endif
- static const u_int16_t ENQ_HDR_TRANSIENT_MASK;
- static const u_int16_t ENQ_HDR_EXTERNAL_MASK;
-
- /**
- * \brief Default constructor, which sets all values to 0.
- */
- enq_hdr();
-
- /**
- * \brief Convenience constructor which initializes values during construction.
- */
- enq_hdr(const u_int32_t magic, const u_int8_t version, const u_int64_t rid,
- const size_t xidsize, const size_t dsize, const bool owi,
- const bool transient = false);
-
- inline const bool get_owi() const { return _hdr._uflag & hdr::HDR_OVERWRITE_INDICATOR_MASK; }
- void set_owi(const bool owi);
- inline const bool is_transient() const { return _hdr._uflag & ENQ_HDR_TRANSIENT_MASK; }
- void set_transient(const bool transient);
- inline const bool is_external() const { return _hdr._uflag & ENQ_HDR_EXTERNAL_MASK; }
- void set_external(const bool external);
-
- /**
- * \brief Returns the size of the header in bytes.
- */
- inline static const size_t size() { return sizeof(enq_hdr); }
- };
-
-
- /**
- * \brief Struct for dequeue record.
- *
- * Struct for dequeue record. If this record has a non-zero xidsize field (i.e., there is a
- * valid XID), then this header is followed by the XID of xidsize bytes and a rec_tail. If,
- * on the other hand, this record has a zero xidsize (i.e., there is no XID), then the rec_tail
- * is absent.
- *
- * Note that this record had its own rid distinct from the rid of the record it is dequeueing.
- * The rid field below is the rid of the dequeue record itself; the deq-rid field is the rid of a
- * previous enqueue record being dequeued by this record.
- *
- * Record header info in binary format (32 bytes):
- * <pre>
- * 0 7
- * +---+---+---+---+---+---+---+---+ -+
- * | magic | v | e | flags | |
- * +---+---+---+---+---+---+---+---+ | struct hdr
- * | rid | |
- * +---+---+---+---+---+---+---+---+ -+
- * | deq-rid |
- * +---+---+---+---+---+---+---+---+
- * | xidsize |
- * +---+---+---+---+---+---+---+---+
- * v = file version (If the format or encoding of this file changes, then this
- * number should be incremented)
- * e = endian flag, false (0x00) for little endian, true (0x01) for big endian
- * </pre>
- *
- * Note that journal files should be transferable between 32- and 64-bit
- * hardware of the same endianness, but not between hardware of opposite
- * entianness without some sort of binary conversion utility. Thus buffering
- * will be needed for types that change size between 32- and 64-bit compiles.
- */
- struct deq_hdr
- {
- hdr _hdr; ///< Common header
- u_int64_t _deq_rid; ///< Record ID of dequeued record
#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
- u_int32_t _filler0; ///< Big-endian filler for 32-bit size_t
+ _filler2(0),
#endif
- size_t _xidsize; ///< XID size
+ _ts_nsec(0)
#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
- u_int32_t _filler0; ///< Little-endian filler for 32-bit size_t
+ , _filler2(0)
#endif
+ {}
/**
- * \brief Default constructor, which sets all values to 0.
- */
- deq_hdr();
-
- /**
* \brief Convenience constructor which initializes values during construction.
*/
- deq_hdr(const u_int32_t magic, const u_int8_t version, const u_int64_t rid,
- const u_int64_t deq_rid, const size_t xidsize, const bool owi);
-
- inline const bool get_owi() const { return _hdr._uflag & hdr::HDR_OVERWRITE_INDICATOR_MASK; }
- void set_owi(const bool owi);
-
- /**
- * \brief Returns the size of the header in bytes.
- */
- inline static const size_t size() { return sizeof(deq_hdr); }
- };
-
-
- /**
- * \brief Struct for transaction commit and abort records.
- *
- * Struct for DTX commit and abort records. Only the magic distinguishes between them. Since
- * this record must be used in the context of a valid XID, the xidsize field must not be zero.
- * Immediately following this record is the XID itself which is xidsize bytes long, followed by
- * a rec_tail.
- *
- * Note that this record had its own rid distinct from the rids of the record(s) making up the
- * transaction it is committing or aborting.
- *
- * Record header info in binary format (24 bytes):
- * <pre>
- * 0 7
- * +---+---+---+---+---+---+---+---+ -+
- * | magic | v | e | flags | |
- * +---+---+---+---+---+---+---+---+ | struct hdr
- * | rid | |
- * +---+---+---+---+---+---+---+---+ -+
- * | xidsize |
- * +---+---+---+---+---+---+---+---+
- * v = file version (If the format or encoding of this file changes, then this
- * number should be incremented)
- * e = endian flag, false (0x00) for little endian, true (0x01) for big endian
- * </pre>
- *
- * Note that journal files should be transferable between 32- and 64-bit
- * hardware of the same endianness, but not between hardware of opposite
- * entianness without some sort of binary conversion utility. Thus buffering
- * will be needed for types that change size between 32- and 64-bit compiles.
- */
- struct txn_hdr
- {
- hdr _hdr; ///< Common header
+ inline file_hdr(const u_int32_t magic, const u_int8_t version, const u_int64_t rid,
+ const u_int32_t fid, const size_t fro, const bool owi, const bool settime = false):
+ rec_hdr(magic, version, rid, owi), _fid(fid), _res(0),
#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
- u_int32_t _filler0; ///< Big-endian filler for 32-bit size_t
+ _filler0(0),
#endif
- size_t _xidsize; ///< XID size
+ _fro(fro),
#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
- u_int32_t _filler0; ///< Little-endian filler for 32-bit size_t
+ _filler0(0),
#endif
+#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
+ _filler1(0),
+#endif
+ _ts_sec(0),
+#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
+ _filler1(0),
+#endif
+#if defined(JRNL_BIG_ENDIAN)
+ _filler2(0),
+#endif
+ _ts_nsec(0)
+#if defined(JRNL_LITTLE_ENDIAN)
+ , _filler2(0)
+#endif
+ { if (settime) set_time(); }
/**
- * \brief Default constructor, which sets all values to 0.
+ * \brief Gets the current time from the system clock and sets the timestamp in the struct.
*/
- txn_hdr();
+ inline void set_time()
+ {
+ // TODO: Standardize on method for getting time that does not requrie a context switch.
+ timespec ts;
+ if (::clock_gettime(CLOCK_REALTIME, &ts))
+ {
+ std::stringstream ss;
+ ss << "errno=" << errno;
+ throw jexception(jerrno::JERR__RTCLOCK, ss.str().c_str(), "file_hdr", "set_time");
+ }
+ _ts_sec = ts.tv_sec;
+ _ts_nsec = ts.tv_nsec;
+ }
/**
- * \brief Convenience constructor which initializes values during construction.
+ * \brief Sets the timestamp in the struct to the provided value (in seconds and
+ * nanoseconds).
*/
- txn_hdr(const u_int32_t magic, const u_int8_t version, const u_int64_t rid,
- const size_t xidsize, const bool owi);
+ inline void set_time(timespec& ts)
+ {
+ _ts_sec = ts.tv_sec;
+ _ts_nsec = ts.tv_nsec;
+ }
- inline const bool get_owi() const { return _hdr._uflag & hdr::HDR_OVERWRITE_INDICATOR_MASK; }
- void set_owi(const bool owi);
-
/**
* \brief Returns the size of the header in bytes.
*/
- inline static const size_t size() { return sizeof(txn_hdr); }
- };
-
+ inline static const size_t size() { return sizeof(file_hdr); }
+ }; // struct file_hdr
+
#pragma pack()
} // namespace journal
Modified: store/trunk/cpp/lib/jrnl/jcntl.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/jcntl.cpp 2007-12-11 21:04:00 UTC (rev 1455)
+++ store/trunk/cpp/lib/jrnl/jcntl.cpp 2007-12-11 21:04:27 UTC (rev 1456)
@@ -37,6 +37,7 @@
#include <cerrno>
#include <fstream>
#include <iomanip>
+#include <jrnl/file_hdr.hpp>
#include <jrnl/jerrno.hpp>
#include <jrnl/jinf.hpp>
#include <sstream>
@@ -456,11 +457,11 @@
{
size_t cum_size_read = 0;
void* xidp = NULL;
- hdr h;
+ rec_hdr h;
if (!jfile_cycle(fid, ifsp, lowi, rd, true))
return false;
std::streampos read_pos = ifsp->tellg();
- ifsp->read((char*)&h, sizeof(hdr));
+ ifsp->read((char*)&h, sizeof(rec_hdr));
switch(h._magic)
{
case RHM_JDAT_ENQ_MAGIC:
@@ -569,8 +570,8 @@
break;
case RHM_JDAT_EMPTY_MAGIC:
{
- u_int32_t rec_dblks = jrec::size_dblks(sizeof(hdr));
- ifsp->ignore(rec_dblks * JRNL_DBLK_SIZE - sizeof(hdr));
+ u_int32_t rec_dblks = jrec::size_dblks(sizeof(rec_hdr));
+ ifsp->ignore(rec_dblks * JRNL_DBLK_SIZE - sizeof(rec_hdr));
}
break;
case 0:
@@ -595,7 +596,7 @@
}
const bool
-jcntl::decode(jrec& rec, u_int16_t& fid, std::ifstream* ifsp, size_t& cum_size_read, hdr& h,
+jcntl::decode(jrec& rec, u_int16_t& fid, std::ifstream* ifsp, size_t& cum_size_read, rec_hdr& h,
bool& lowi, rcvdat& rd, std::streampos& rec_offset)
{
if (!check_owi(fid, h, lowi, rd, rec_offset))
@@ -650,7 +651,7 @@
// Read file header
file_hdr fhdr;
ifsp->read((char*)&fhdr, sizeof(fhdr));
- if (fhdr._hdr._magic == RHM_JDAT_FILE_MAGIC)
+ if (fhdr._magic == RHM_JDAT_FILE_MAGIC)
{
assert(fhdr._fid == fid);
if (!rd._fro)
@@ -668,7 +669,7 @@
}
const bool
-jcntl::check_owi(const u_int16_t fid, hdr& h, bool& lowi, rcvdat& rd, std::streampos& read_pos)
+jcntl::check_owi(const u_int16_t fid, rec_hdr& h, bool& lowi, rcvdat& rd, std::streampos& read_pos)
{
if (rd._ffid ? h.get_owi() == lowi : h.get_owi() != lowi) // Overwrite indicator changed
{
Modified: store/trunk/cpp/lib/jrnl/jcntl.hpp
===================================================================
--- store/trunk/cpp/lib/jrnl/jcntl.hpp 2007-12-11 21:04:00 UTC (rev 1455)
+++ store/trunk/cpp/lib/jrnl/jcntl.hpp 2007-12-11 21:04:27 UTC (rev 1456)
@@ -647,12 +647,12 @@
rcvdat& rd);
const bool decode(jrec& rec, u_int16_t& fid, std::ifstream* ifsp, size_t& cum_size_read,
- hdr& h, bool& lowi, rcvdat& rd, std::streampos& rec_offset);
+ rec_hdr& h, bool& lowi, rcvdat& rd, std::streampos& rec_offset);
const bool jfile_cycle(u_int16_t& fid, std::ifstream* ifsp, bool& lowi, rcvdat& rd,
const bool jump_fro);
- const bool check_owi(const u_int16_t fid, hdr& h, bool& lowi, rcvdat& rd,
+ const bool check_owi(const u_int16_t fid, rec_hdr& h, bool& lowi, rcvdat& rd,
std::streampos& read_pos);
void check_journal_alignment(const u_int16_t fid, std::streampos& rec_offset);
Modified: store/trunk/cpp/lib/jrnl/jinf.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/jinf.cpp 2007-12-11 21:04:00 UTC (rev 1455)
+++ store/trunk/cpp/lib/jrnl/jinf.cpp 2007-12-11 21:04:27 UTC (rev 1456)
@@ -34,6 +34,7 @@
#include <jrnl/jinf.hpp>
#include <fstream>
+#include <jrnl/file_hdr.hpp>
#include <jrnl/jcntl.hpp>
#include <jrnl/jerrno.hpp>
#include <sstream>
@@ -173,7 +174,7 @@
throw jexception(jerrno::JERR__FILEIO, ss.str().c_str(), "jinf", "analyze");
file_hdr fhdr;
jifs.read((char*)&fhdr, sizeof(fhdr));
- if (fhdr._hdr._magic != RHM_JDAT_FILE_MAGIC)
+ if (fhdr._magic != RHM_JDAT_FILE_MAGIC)
break;
if (!fnum) // First file only
{
Modified: store/trunk/cpp/lib/jrnl/jrec.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/jrec.cpp 2007-12-11 21:04:00 UTC (rev 1455)
+++ store/trunk/cpp/lib/jrnl/jrec.cpp 2007-12-11 21:04:27 UTC (rev 1456)
@@ -32,10 +32,11 @@
#include <jrnl/jrec.hpp>
-#include <errno.h>
+// #include <errno.h>
#include <iomanip>
#include <sstream>
#include <jrnl/jerrno.hpp>
+#include <jrnl/jexception.hpp>
namespace rhm
{
@@ -46,7 +47,7 @@
jrec::~jrec() {}
void
-jrec::chk_hdr(const hdr& hdr)
+jrec::chk_hdr(const rec_hdr& hdr)
{
if (hdr._magic == 0)
{
@@ -81,7 +82,7 @@
}
void
-jrec::chk_rid(const hdr& hdr, const u_int64_t rid)
+jrec::chk_rid(const rec_hdr& hdr, const u_int64_t rid)
{
if (hdr._rid != rid)
{
@@ -94,7 +95,7 @@
}
void
-jrec::chk_tail(const rec_tail& tail, const hdr& hdr)
+jrec::chk_tail(const rec_tail& tail, const rec_hdr& hdr)
{
if (tail._xmagic != ~hdr._magic)
{
Modified: store/trunk/cpp/lib/jrnl/jrec.hpp
===================================================================
--- store/trunk/cpp/lib/jrnl/jrec.hpp 2007-12-11 21:04:00 UTC (rev 1455)
+++ store/trunk/cpp/lib/jrnl/jrec.hpp 2007-12-11 21:04:27 UTC (rev 1456)
@@ -42,9 +42,10 @@
}
#include <fstream>
+#include <jrnl/rec_hdr.hpp>
+#include <jrnl/rec_tail.hpp>
#include <string>
#include <sys/types.h>
-#include <jrnl/file_hdr.hpp>
namespace rhm
{
@@ -147,10 +148,10 @@
* \param max_size_dblks Maximum number of data-blocks to read from pointer rptr.
* \returns Number of data-blocks read (consumed).
*/
- virtual const u_int32_t decode(hdr& h, void* rptr, u_int32_t rec_offs_dblks,
+ virtual const u_int32_t decode(rec_hdr& h, void* rptr, u_int32_t rec_offs_dblks,
u_int32_t max_size_dblks) = 0;
- virtual const bool rcv_decode(hdr h, std::ifstream* ifsp, size_t& rec_offs) = 0;
+ virtual const bool rcv_decode(rec_hdr h, std::ifstream* ifsp, size_t& rec_offs) = 0;
virtual std::string& str(std::string& str) const = 0;
virtual const size_t data_size() const = 0;
@@ -168,9 +169,9 @@
virtual void chk_hdr() const = 0;
virtual void chk_hdr(u_int64_t rid) const = 0;
virtual void chk_tail() const = 0;
- static void chk_hdr(const hdr& hdr);
- static void chk_rid(const hdr& hdr, u_int64_t rid);
- static void chk_tail(const rec_tail& tail, const hdr& hdr);
+ static void chk_hdr(const rec_hdr& hdr);
+ static void chk_rid(const rec_hdr& hdr, u_int64_t rid);
+ static void chk_tail(const rec_tail& tail, const rec_hdr& hdr);
virtual void clean() = 0;
}; // class jrec
Modified: store/trunk/cpp/lib/jrnl/nlfh.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/nlfh.cpp 2007-12-11 21:04:00 UTC (rev 1455)
+++ store/trunk/cpp/lib/jrnl/nlfh.cpp 2007-12-11 21:04:27 UTC (rev 1456)
@@ -39,6 +39,7 @@
#include <iomanip>
#include <sstream>
#include <jrnl/jerrno.hpp>
+#include <jrnl/jexception.hpp>
namespace rhm
{
Modified: store/trunk/cpp/lib/jrnl/nlfh.hpp
===================================================================
--- store/trunk/cpp/lib/jrnl/nlfh.hpp 2007-12-11 21:04:00 UTC (rev 1455)
+++ store/trunk/cpp/lib/jrnl/nlfh.hpp 2007-12-11 21:04:27 UTC (rev 1456)
@@ -43,7 +43,7 @@
}
#include <string>
-#include <jrnl/file_hdr.hpp>
+//#include <jrnl/file_hdr.hpp>
#include <jrnl/rcvdat.hpp>
namespace rhm
Modified: store/trunk/cpp/lib/jrnl/rcvdat.hpp
===================================================================
--- store/trunk/cpp/lib/jrnl/rcvdat.hpp 2007-12-11 21:04:00 UTC (rev 1455)
+++ store/trunk/cpp/lib/jrnl/rcvdat.hpp 2007-12-11 21:04:27 UTC (rev 1456)
@@ -36,6 +36,7 @@
#include <map>
#include <sstream>
#include <vector>
+#include <jrnl/jcfg.hpp>
namespace rhm
{
Added: store/trunk/cpp/lib/jrnl/rec_hdr.hpp
===================================================================
--- store/trunk/cpp/lib/jrnl/rec_hdr.hpp (rev 0)
+++ store/trunk/cpp/lib/jrnl/rec_hdr.hpp 2007-12-11 21:04:27 UTC (rev 1456)
@@ -0,0 +1,142 @@
+/**
+* \file rec_hdr.hpp
+*
+* Red Hat Messaging - Message Journal
+*
+* File containing code for class rhm::journal::rec_hdr (record header),
+* which is a common initial header used for all journal record structures
+* except the record tail (rec_tail).
+*
+* \author Kim van der Riet
+*
+* Copyright 2007 Red Hat, Inc.
+*
+* This file is part of Red Hat Messaging.
+*
+* Red Hat Messaging is free software; you can redistribute it and/or
+* modify it under the terms of the GNU Lesser General Public
+* License as published by the Free Software Foundation; either
+* version 2.1 of the License, or (at your option) any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this library; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+* USA
+*
+* The GNU Lesser General Public License is available in the file COPYING.
+*/
+
+#ifndef rhm_journal_rec_hdr_hpp
+#define rhm_journal_rec_hdr_hpp
+
+#include <jrnl/jcfg.hpp>
+#include <sys/types.h>
+
+namespace rhm
+{
+namespace journal
+{
+
+#pragma pack(1)
+
+ /**
+ * \brief Struct for data common to the head of all journal files and records.
+ * This includes identification for the file type, the encoding version, endian
+ * indicator and a record ID.
+ *
+ * File header info in binary format (16 bytes):
+ * <pre>
+ * 0 7
+ * +---+---+---+---+---+---+---+---+
+ * | magic | v | e | flags |
+ * +---+---+---+---+---+---+---+---+
+ * | rid |
+ * +---+---+---+---+---+---+---+---+
+ * v = file version (If the format or encoding of this file changes, then this
+ * number should be incremented)
+ * e = endian flag, false (0x00) for little endian, true (0x01) for big endian
+ * </pre>
+ *
+ * Note that journal files should be transferable between 32- and 64-bit
+ * hardware of the same endianness, but not between hardware of opposite
+ * entianness without some sort of binary conversion utility. Thus buffering
+ * will be needed for types that change size between 32- and 64-bit compiles.
+ */
+ struct rec_hdr
+ {
+ u_int32_t _magic; ///< File type identifier (magic number)
+ u_int8_t _version; ///< File encoding version
+ u_int8_t _eflag; ///< Flag for determining endianness
+ u_int16_t _uflag; ///< User-defined flags
+ u_int64_t _rid; ///< Record ID (rotating 64-bit counter)
+
+ // Global flags
+ static const u_int16_t HDR_OVERWRITE_INDICATOR_MASK = 0x1;
+
+ // Convenience constructors and methods
+ /**
+ * \brief Default constructor, which sets all values to 0.
+ */
+ inline rec_hdr(): _magic(0), _version(0), _eflag(0), _uflag(0), _rid(0) {}
+
+ /**
+ * \brief Convenience constructor which initializes values during construction.
+ */
+ inline rec_hdr(const u_int32_t magic, const u_int8_t version, const u_int64_t rid,
+ const bool owi): _magic(magic), _version(version),
+#if defined(JRNL_BIG_ENDIAN)
+ _eflag(RHM_BENDIAN_FLAG),
+#else
+ _eflag(RHM_LENDIAN_FLAG),
+#endif
+ _uflag(owi ? HDR_OVERWRITE_INDICATOR_MASK : 0), _rid(rid) {}
+
+ /**
+ * \brief Convenience copy method.
+ */
+ inline void hdr_copy(const rec_hdr& h)
+ {
+ _magic = h._magic;
+ _version = h._version;
+ _eflag = h._eflag;
+ _uflag = h._uflag;
+ _rid =h._rid;
+ }
+
+ /**
+ * \brief Resets all fields to 0
+ */
+ inline void reset()
+ {
+ _magic = 0;
+ _version = 0;
+ _eflag = 0;
+ _uflag = 0;
+ _rid = 0;
+ }
+
+ inline const bool get_owi() const { return _uflag & HDR_OVERWRITE_INDICATOR_MASK; }
+
+ inline void set_owi(const bool owi)
+ {
+ _uflag = owi ? _uflag | HDR_OVERWRITE_INDICATOR_MASK :
+ _uflag & (~HDR_OVERWRITE_INDICATOR_MASK);
+ }
+
+ /**
+ * \brief Returns the size of the header in bytes.
+ */
+ inline static const size_t size() { return sizeof(rec_hdr); }
+ }; // struct rec_hdr
+
+#pragma pack()
+
+} // namespace journal
+} // namespace rhm
+
+#endif // ifndef rhm_journal_rec_hdr_hpp
Added: store/trunk/cpp/lib/jrnl/rec_tail.hpp
===================================================================
--- store/trunk/cpp/lib/jrnl/rec_tail.hpp (rev 0)
+++ store/trunk/cpp/lib/jrnl/rec_tail.hpp 2007-12-11 21:04:27 UTC (rev 1456)
@@ -0,0 +1,98 @@
+/**
+* \file rec_tail.hpp
+*
+* Red Hat Messaging - Message Journal
+*
+* File containing code for class rhm::journal::rec_tail (record tail), used to
+* finalize a persistent record. The presence of a valid tail at the expected
+* position in the journal file indicates that the record write was completed.
+*
+* \author Kim van der Riet
+*
+* Copyright 2007 Red Hat, Inc.
+*
+* This file is part of Red Hat Messaging.
+*
+* Red Hat Messaging is free software; you can redistribute it and/or
+* modify it under the terms of the GNU Lesser General Public
+* License as published by the Free Software Foundation; either
+* version 2.1 of the License, or (at your option) any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this library; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+* USA
+*
+* The GNU Lesser General Public License is available in the file COPYING.
+*/
+
+#ifndef rhm_journal_rec_tail_hpp
+#define rhm_journal_rec_tail_hpp
+
+
+#include <jrnl/jcfg.hpp>
+
+namespace rhm
+{
+namespace journal
+{
+
+#pragma pack(1)
+
+ /**
+ * \brief Struct for data common to the tail of all records. The magic number
+ * used here is the binary inverse (1's complement) of the magic used in the
+ * record header; this minimizes possible confusion with other headers that may
+ * be present during recovery.
+ *
+ * This header precedes all records in journal files.
+ *
+ * Record header info in binary format (12 bytes):
+ * <pre>
+ * 0 7
+ * +---+---+---+---+---+---+---+---+
+ * | ~(magic) | rid |
+ * +---+---+---+---+---+---+---+---+
+ * | rid (con't) |
+ * +---+---+---+---+
+ * </pre>
+ */
+ struct rec_tail
+ {
+ u_int32_t _xmagic; ///< Binary inverse (1's complement) of hdr magic number
+ u_int64_t _rid; ///< ID (rotating 64-bit counter)
+
+
+ /**
+ * \brief Default constructor, which sets all values to 0.
+ */
+ inline rec_tail(): _xmagic(0xffffffff), _rid(0) {}
+
+ /**
+ * \brief Convenience constructor which initializes values during construction from
+ * existing enq_hdr instance.
+ */
+ inline rec_tail(const rec_hdr& h): _xmagic(~h._magic), _rid(h._rid) {}
+
+ /**
+ * \brief Convenience constructor which initializes values during construction.
+ */
+ inline rec_tail(const u_int32_t xmagic, const u_int64_t rid): _xmagic(xmagic), _rid(rid) {}
+
+ /**
+ * \brief Returns the size of the header in bytes.
+ */
+ inline static const size_t size() { return sizeof(rec_tail); }
+ };
+
+#pragma pack()
+
+} // namespace journal
+} // namespace rhm
+
+#endif // ifndef rhm_journal_rec_tail_hpp
Modified: store/trunk/cpp/lib/jrnl/rmgr.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/rmgr.cpp 2007-12-11 21:04:00 UTC (rev 1455)
+++ store/trunk/cpp/lib/jrnl/rmgr.cpp 2007-12-11 21:04:27 UTC (rev 1456)
@@ -261,7 +261,7 @@
}
void* rptr = (void*)((char*)_page_ptr_arr[_pg_index] +
(_pg_offset_dblks * JRNL_DBLK_SIZE));
- ::memcpy(&_hdr, rptr, sizeof(hdr));
+ ::memcpy(&_hdr, rptr, sizeof(rec_hdr));
switch (_hdr._magic)
{
case RHM_JDAT_ENQ_MAGIC:
@@ -487,7 +487,7 @@
}
const iores
-rmgr::read_enq(hdr& h, void* rptr, data_tok* dtokp)
+rmgr::read_enq(rec_hdr& h, void* rptr, data_tok* dtokp)
{
if (_page_cb_arr[_pg_index]._state != AIO_COMPLETE)
{
@@ -529,7 +529,7 @@
}
void
-rmgr::consume_xid_rec(hdr& h, void* rptr, data_tok* dtokp)
+rmgr::consume_xid_rec(rec_hdr& h, void* rptr, data_tok* dtokp)
{
if (h._magic == RHM_JDAT_ENQ_MAGIC)
{
Modified: store/trunk/cpp/lib/jrnl/rmgr.hpp
===================================================================
--- store/trunk/cpp/lib/jrnl/rmgr.hpp 2007-12-11 21:04:00 UTC (rev 1455)
+++ store/trunk/cpp/lib/jrnl/rmgr.hpp 2007-12-11 21:04:27 UTC (rev 1456)
@@ -42,6 +42,7 @@
}
#include <jrnl/pmgr.hpp>
+#include <jrnl/rec_hdr.hpp>
#include <jrnl/rrfc.hpp>
namespace rhm
@@ -59,7 +60,7 @@
{
private:
rrfc& _rrfc; ///< Ref to read rotating file controller
- hdr _hdr; ///< Header used to determind record type
+ rec_hdr _hdr; ///< Header used to determind record type
public:
rmgr(jcntl* jc, enq_map& emap, txn_map& tmap, rrfc& rrfc);
@@ -79,8 +80,8 @@
private:
void initialize();
const iores pre_read_check(data_tok* dtokp);
- const iores read_enq(hdr& h, void* rptr, data_tok* dtokp);
- void consume_xid_rec(hdr& h, void* rptr, data_tok* dtokp);
+ const iores read_enq(rec_hdr& h, void* rptr, data_tok* dtokp);
+ void consume_xid_rec(rec_hdr& h, void* rptr, data_tok* dtokp);
void consume_filler();
const iores skip(data_tok* dtokp);
void aio_cycle();
Modified: store/trunk/cpp/lib/jrnl/rrfc.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/rrfc.cpp 2007-12-11 21:04:00 UTC (rev 1455)
+++ store/trunk/cpp/lib/jrnl/rrfc.cpp 2007-12-11 21:04:27 UTC (rev 1456)
@@ -34,6 +34,7 @@
#include <assert.h>
#include <jrnl/rrfc.hpp>
#include <jrnl/jerrno.hpp>
+#include <jrnl/jexception.hpp>
namespace rhm
{
Added: store/trunk/cpp/lib/jrnl/txn_hdr.hpp
===================================================================
--- store/trunk/cpp/lib/jrnl/txn_hdr.hpp (rev 0)
+++ store/trunk/cpp/lib/jrnl/txn_hdr.hpp 2007-12-11 21:04:27 UTC (rev 1456)
@@ -0,0 +1,126 @@
+/**
+* \file txn_hdr.hpp
+*
+* Red Hat Messaging - Message Journal
+*
+* File containing code for class rhm::journal::txn_hdr (transaction
+* record header), used to start a transaction (commit or abort) record.
+*
+* \author Kim van der Riet
+*
+* Copyright 2007 Red Hat, Inc.
+*
+* This file is part of Red Hat Messaging.
+*
+* Red Hat Messaging is free software; you can redistribute it and/or
+* modify it under the terms of the GNU Lesser General Public
+* License as published by the Free Software Foundation; either
+* version 2.1 of the License, or (at your option) any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this library; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+* USA
+*
+* The GNU Lesser General Public License is available in the file COPYING.
+*/
+
+#ifndef rhm_journal_txn_hdr_hpp
+#define rhm_journal_txn_hdr_hpp
+
+#include <jrnl/rec_hdr.hpp>
+//#include <jrnl/jcfg.hpp>
+//#include <sys/types.h>
+
+namespace rhm
+{
+namespace journal
+{
+
+#pragma pack(1)
+
+ /**
+ * \brief Struct for transaction commit and abort records.
+ *
+ * Struct for DTX commit and abort records. Only the magic distinguishes between them. Since
+ * this record must be used in the context of a valid XID, the xidsize field must not be zero.
+ * Immediately following this record is the XID itself which is xidsize bytes long, followed by
+ * a rec_tail.
+ *
+ * Note that this record had its own rid distinct from the rids of the record(s) making up the
+ * transaction it is committing or aborting.
+ *
+ * Record header info in binary format (24 bytes):
+ * <pre>
+ * 0 7
+ * +---+---+---+---+---+---+---+---+ -+
+ * | magic | v | e | flags | |
+ * +---+---+---+---+---+---+---+---+ | struct hdr
+ * | rid | |
+ * +---+---+---+---+---+---+---+---+ -+
+ * | xidsize |
+ * +---+---+---+---+---+---+---+---+
+ * v = file version (If the format or encoding of this file changes, then this
+ * number should be incremented)
+ * e = endian flag, false (0x00) for little endian, true (0x01) for big endian
+ * </pre>
+ *
+ * Note that journal files should be transferable between 32- and 64-bit
+ * hardware of the same endianness, but not between hardware of opposite
+ * entianness without some sort of binary conversion utility. Thus buffering
+ * will be needed for types that change size between 32- and 64-bit compiles.
+ */
+ struct txn_hdr : rec_hdr
+ {
+#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
+ u_int32_t _filler0; ///< Big-endian filler for 32-bit size_t
+#endif
+ size_t _xidsize; ///< XID size
+#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
+ u_int32_t _filler0; ///< Little-endian filler for 32-bit size_t
+#endif
+
+ /**
+ * \brief Default constructor, which sets all values to 0.
+ */
+ txn_hdr(): rec_hdr(),
+#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
+ _filler0(0),
+#endif
+ _xidsize(0)
+#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
+ , _filler0(0)
+#endif
+ {}
+
+ /**
+ * \brief Convenience constructor which initializes values during construction.
+ */
+ txn_hdr(const u_int32_t magic, const u_int8_t version, const u_int64_t rid,
+ const size_t xidsize, const bool owi): rec_hdr(magic, version, rid, owi),
+#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
+ _filler0(0),
+#endif
+ _xidsize(xidsize)
+#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
+ , _filler0(0)
+#endif
+ {}
+
+ /**
+ * \brief Returns the size of the header in bytes.
+ */
+ inline static const size_t size() { return sizeof(txn_hdr); }
+ };
+
+#pragma pack()
+
+} // namespace journal
+} // namespace rhm
+
+#endif // ifndef rhm_journal_txn_hdr_hpp
Modified: store/trunk/cpp/lib/jrnl/txn_rec.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/txn_rec.cpp 2007-12-11 21:04:00 UTC (rev 1455)
+++ store/trunk/cpp/lib/jrnl/txn_rec.cpp 2007-12-11 21:04:27 UTC (rev 1456)
@@ -37,6 +37,7 @@
#include <iomanip>
#include <sstream>
#include <jrnl/jerrno.hpp>
+#include <jrnl/jexception.hpp>
namespace rhm
{
@@ -49,7 +50,7 @@
_buff(NULL),
_txn_tail()
{
- _txn_hdr._hdr._version = RHM_JDAT_VERSION;
+ _txn_hdr._version = RHM_JDAT_VERSION;
}
txn_rec::txn_rec(const u_int32_t magic, const u_int64_t rid, const void* const xidp,
@@ -57,7 +58,7 @@
_txn_hdr(magic, RHM_JDAT_VERSION, rid, xidlen, owi),
_xidp(xidp),
_buff(NULL),
- _txn_tail(_txn_hdr._hdr)
+ _txn_tail(_txn_hdr)
{}
txn_rec::~txn_rec()
@@ -68,8 +69,8 @@
void
txn_rec::reset(const u_int32_t magic)
{
- _txn_hdr._hdr._magic = magic;
- _txn_hdr._hdr._rid = 0;
+ _txn_hdr._magic = magic;
+ _txn_hdr._rid = 0;
_txn_hdr._xidsize = 0;
_xidp = NULL;
_buff = NULL;
@@ -81,8 +82,8 @@
txn_rec::reset(const u_int32_t magic, const u_int64_t rid, const void* const xidp,
const size_t xidlen, const bool owi)
{
- _txn_hdr._hdr._magic = magic;
- _txn_hdr._hdr._rid = rid;
+ _txn_hdr._magic = magic;
+ _txn_hdr._rid = rid;
_txn_hdr.set_owi(owi);
_txn_hdr._xidsize = xidlen;
_xidp = xidp;
@@ -200,7 +201,7 @@
}
const u_int32_t
-txn_rec::decode(hdr& h, void* rptr, u_int32_t rec_offs_dblks, u_int32_t max_size_dblks)
+txn_rec::decode(rec_hdr& h, void* rptr, u_int32_t rec_offs_dblks, u_int32_t max_size_dblks)
{
assert(rptr != NULL);
assert(max_size_dblks > 0);
@@ -216,10 +217,10 @@
if (hdr_xid_tail_dblks - rec_offs_dblks <= max_size_dblks)
{
// Remainder of xid fits within this page
- if (rec_offs - deq_hdr::size() < _txn_hdr._xidsize)
+ if (rec_offs - txn_hdr::size() < _txn_hdr._xidsize)
{
// Part of xid still outstanding, copy remainder of xid and tail
- const size_t xid_offs = rec_offs - deq_hdr::size();
+ const size_t xid_offs = rec_offs - txn_hdr::size();
const size_t xid_rem = _txn_hdr._xidsize - xid_offs;
::memcpy((char*)_buff + xid_offs, rptr, xid_rem);
rd_cnt = xid_rem;
@@ -230,7 +231,7 @@
else
{
// Tail or part of tail only outstanding, complete tail
- const size_t tail_offs = rec_offs - deq_hdr::size() - _txn_hdr._xidsize;
+ const size_t tail_offs = rec_offs - txn_hdr::size() - _txn_hdr._xidsize;
const size_t tail_rem = rec_tail::size() - tail_offs;
::memcpy((char*)&_txn_tail + tail_offs, rptr, tail_rem);
chk_tail();
@@ -240,7 +241,7 @@
else if (hdr_xid_dblks - rec_offs_dblks <= max_size_dblks)
{
// Remainder of xid fits within this page, tail split
- const size_t xid_offs = rec_offs - deq_hdr::size();
+ const size_t xid_offs = rec_offs - txn_hdr::size();
const size_t xid_rem = _txn_hdr._xidsize - xid_offs;
::memcpy((char*)_buff + xid_offs, rptr, xid_rem);
rd_cnt += xid_rem;
@@ -255,15 +256,15 @@
{
// Remainder of xid split
const size_t xid_cp_size = (max_size_dblks * JRNL_DBLK_SIZE);
- ::memcpy((char*)_buff + rec_offs - deq_hdr::size(), rptr, xid_cp_size);
+ ::memcpy((char*)_buff + rec_offs - txn_hdr::size(), rptr, xid_cp_size);
rd_cnt += xid_cp_size;
}
}
else // Start of record
{
// Get and check header
- _txn_hdr._hdr.copy(h);
- rd_cnt = sizeof(hdr);
+ _txn_hdr.hdr_copy(h);
+ rd_cnt = sizeof(rec_hdr);
#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
rd_cnt += sizeof(u_int32_t); // Filler 0
#endif
@@ -311,12 +312,12 @@
}
const bool
-txn_rec::rcv_decode(hdr h, std::ifstream* ifsp, size_t& rec_offs)
+txn_rec::rcv_decode(rec_hdr h, std::ifstream* ifsp, size_t& rec_offs)
{
if (rec_offs == 0)
{
// Read header, allocate for xid
- _txn_hdr._hdr.copy(h);
+ _txn_hdr.hdr_copy(h);
#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
ifsp->ignore(sizeof(u_int32_t)); // _filler0
#endif
@@ -375,12 +376,12 @@
txn_rec::str(std::string& str) const
{
std::stringstream ss;
- if (_txn_hdr._hdr._magic == RHM_JDAT_TXA_MAGIC)
- ss << "dtxa_rec: m=" << _txn_hdr._hdr._magic;
+ if (_txn_hdr._magic == RHM_JDAT_TXA_MAGIC)
+ ss << "dtxa_rec: m=" << _txn_hdr._magic;
else
- ss << "dtxc_rec: m=" << _txn_hdr._hdr._magic;
- ss << " v=" << (int)_txn_hdr._hdr._version;
- ss << " rid=" << _txn_hdr._hdr._rid;
+ ss << "dtxc_rec: m=" << _txn_hdr._magic;
+ ss << " v=" << (int)_txn_hdr._version;
+ ss << " rid=" << _txn_hdr._rid;
ss << " xid=\"" << _xidp << "\"";
str.append(ss.str());
return str;
@@ -401,15 +402,15 @@
void
txn_rec::chk_hdr() const
{
- jrec::chk_hdr(_txn_hdr._hdr);
- if (_txn_hdr._hdr._magic != RHM_JDAT_TXA_MAGIC && _txn_hdr._hdr._magic != RHM_JDAT_TXC_MAGIC)
+ jrec::chk_hdr(_txn_hdr);
+ if (_txn_hdr._magic != RHM_JDAT_TXA_MAGIC && _txn_hdr._magic != RHM_JDAT_TXC_MAGIC)
{
std::stringstream ss;
ss << std::hex << std::setfill('0');
- ss << "dtx magic: rid=0x" << std::setw(16) << _txn_hdr._hdr._rid;
+ ss << "dtx magic: rid=0x" << std::setw(16) << _txn_hdr._rid;
ss << ": expected=(0x" << std::setw(8) << RHM_JDAT_TXA_MAGIC;
ss << " or 0x" << RHM_JDAT_TXC_MAGIC;
- ss << ") read=0x" << std::setw(2) << (int)_txn_hdr._hdr._magic;
+ ss << ") read=0x" << std::setw(2) << (int)_txn_hdr._magic;
throw jexception(jerrno::JERR_JREC_BADRECHDR, ss.str().c_str(), "txn_rec", "chk_hdr");
}
}
@@ -418,13 +419,13 @@
txn_rec::chk_hdr(u_int64_t rid) const
{
chk_hdr();
- jrec::chk_rid(_txn_hdr._hdr, rid);
+ jrec::chk_rid(_txn_hdr, rid);
}
void
txn_rec::chk_tail() const
{
- jrec::chk_tail(_txn_tail, _txn_hdr._hdr);
+ jrec::chk_tail(_txn_tail, _txn_hdr);
}
void
Modified: store/trunk/cpp/lib/jrnl/txn_rec.hpp
===================================================================
--- store/trunk/cpp/lib/jrnl/txn_rec.hpp 2007-12-11 21:04:00 UTC (rev 1455)
+++ store/trunk/cpp/lib/jrnl/txn_rec.hpp 2007-12-11 21:04:27 UTC (rev 1456)
@@ -42,6 +42,7 @@
}
#include <jrnl/jrec.hpp>
+#include <jrnl/txn_hdr.hpp>
namespace rhm
{
@@ -74,10 +75,10 @@
void reset(const u_int32_t magic, const u_int64_t rid, const void* const xidp,
const size_t xidlen, const bool owi);
const u_int32_t encode(void* wptr, u_int32_t rec_offs_dblks, u_int32_t max_size_dblks);
- const u_int32_t decode(hdr& h, void* rptr, u_int32_t rec_offs_dblks,
+ const u_int32_t decode(rec_hdr& h, void* rptr, u_int32_t rec_offs_dblks,
u_int32_t max_size_dblks);
// Decode used for recover
- const bool rcv_decode(hdr h, std::ifstream* ifsp, size_t& rec_offs);
+ const bool rcv_decode(rec_hdr h, std::ifstream* ifsp, size_t& rec_offs);
const size_t get_xid(void** const xidpp);
std::string& str(std::string& str) const;
Modified: store/trunk/cpp/lib/jrnl/wmgr.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/wmgr.cpp 2007-12-11 21:04:00 UTC (rev 1455)
+++ store/trunk/cpp/lib/jrnl/wmgr.cpp 2007-12-11 21:04:27 UTC (rev 1456)
@@ -35,6 +35,7 @@
#include <assert.h>
#include <cerrno>
#include <sstream>
+#include <jrnl/file_hdr.hpp>
#include <jrnl/jcntl.hpp>
#include <jrnl/jerrno.hpp>
Modified: store/trunk/cpp/lib/jrnl/wrfc.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/wrfc.cpp 2007-12-11 21:04:00 UTC (rev 1455)
+++ store/trunk/cpp/lib/jrnl/wrfc.cpp 2007-12-11 21:04:27 UTC (rev 1456)
@@ -33,6 +33,7 @@
#include <jrnl/wrfc.hpp>
#include <jrnl/jerrno.hpp>
+#include <jrnl/jexception.hpp>
namespace rhm
{
Property changes on: store/trunk/cpp/tests/jrnl
___________________________________________________________________
Name: svn:ignore
- .deps
.libs
Makefile
Makefile.in
jtest
unit_test_enq_map
unit_test_jerrno
unit_test_jexception
unit_test_jdir
unit_test_file_hdr
unit_test_jinf
unit_test_txn_map
+ .deps
.libs
Makefile
Makefile.in
jtest
unit_test_enq_map
unit_test_jerrno
unit_test_jexception
unit_test_jdir
unit_test_rec_hdr
unit_test_jinf
unit_test_txn_map
Modified: store/trunk/cpp/tests/jrnl/Makefile.am
===================================================================
--- store/trunk/cpp/tests/jrnl/Makefile.am 2007-12-11 21:04:00 UTC (rev 1455)
+++ store/trunk/cpp/tests/jrnl/Makefile.am 2007-12-11 21:04:27 UTC (rev 1456)
@@ -28,9 +28,9 @@
TESTS = \
unit_test_jexception \
unit_test_jerrno \
+ unit_test_rec_hdr \
unit_test_jinf \
unit_test_jdir \
- unit_test_file_hdr \
unit_test_enq_map \
unit_test_txn_map \
run-journal-tests
@@ -42,11 +42,11 @@
check_PROGRAMS = \
unit_test_jexception \
unit_test_jerrno \
+ unit_test_rec_hdr \
unit_test_jinf \
unit_test_jdir \
unit_test_enq_map \
- unit_test_txn_map \
- unit_test_file_hdr
+ unit_test_txn_map
unit_test_jexception_SOURCES = unit_test_jexception.cpp
unit_test_jexception_LDFLAGS = -lboost_unit_test_framework -lbdbstore -L../../lib/.libs
@@ -54,15 +54,15 @@
unit_test_jerrno_SOURCES = unit_test_jerrno.cpp
unit_test_jerrno_LDFLAGS = -lboost_unit_test_framework -lbdbstore -L../../lib/.libs
+unit_test_rec_hdr_SOURCES = unit_test_rec_hdr.cpp
+unit_test_rec_hdr_LDFLAGS = -lboost_unit_test_framework -lbdbstore -lrt -L../../lib/.libs
+
unit_test_jinf_SOURCES = unit_test_jinf.cpp
unit_test_jinf_LDFLAGS = -lboost_unit_test_framework -lbdbstore -lrt -L../../lib/.libs
unit_test_jdir_SOURCES = unit_test_jdir.cpp
unit_test_jdir_LDFLAGS = -lboost_unit_test_framework -lbdbstore -lrt -L../../lib/.libs
-unit_test_file_hdr_SOURCES = unit_test_file_hdr.cpp
-unit_test_file_hdr_LDFLAGS = -lboost_unit_test_framework -lbdbstore -lrt -L../../lib/.libs
-
unit_test_enq_map_SOURCES = unit_test_enq_map.cpp
unit_test_enq_map_LDFLAGS = -lboost_unit_test_framework -lbdbstore -lrt -L../../lib/.libs
Modified: store/trunk/cpp/tests/jrnl/Makefile.rtest
===================================================================
--- store/trunk/cpp/tests/jrnl/Makefile.rtest 2007-12-11 21:04:00 UTC (rev 1455)
+++ store/trunk/cpp/tests/jrnl/Makefile.rtest 2007-12-11 21:04:27 UTC (rev 1456)
@@ -55,11 +55,10 @@
txn_map.o \
jdir.o \
data_tok.o \
- file_hdr.o \
jrec.o \
- enq_rec.o \
- deq_rec.o \
- txn_rec.o \
+ enq_rec.o \
+ deq_rec.o \
+ txn_rec.o \
nlfh.o \
lfh.o \
rrfc.o \
Deleted: store/trunk/cpp/tests/jrnl/unit_test_file_hdr.cpp
===================================================================
--- store/trunk/cpp/tests/jrnl/unit_test_file_hdr.cpp 2007-12-11 21:04:00 UTC (rev 1455)
+++ store/trunk/cpp/tests/jrnl/unit_test_file_hdr.cpp 2007-12-11 21:04:27 UTC (rev 1456)
@@ -1,440 +0,0 @@
-/**
-* \file unit_test_file_hdr.cpp
-*
-* Red Hat Messaging - Message Journal
-*
-* This file contains the unit tests for the journal.
-*
-* \author Kim van der Riet
-*
-* Copyright 2007 Red Hat, Inc.
-*
-* This file is part of Red Hat Messaging.
-*
-* Red Hat Messaging is free software; you can redistribute it and/or
-* modify it under the terms of the GNU Lesser General Public
-* License as published by the Free Software Foundation; either
-* version 2.1 of the License, or (at your option) any later version.
-*
-* This library is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this library; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
-* USA
-*
-* The GNU Lesser General Public License is available in the file COPYING.
-*/
-
-#include <boost/test/results_reporter.hpp>
-#include <boost/test/unit_test.hpp>
-#include <boost/test/unit_test_log.hpp>
-#include <iostream>
-#include <jrnl/file_hdr.hpp>
-#include <jrnl/jcfg.hpp>
-
-using namespace boost::unit_test;
-using namespace rhm::journal;
-
-// Test functions of the form
-// void fn() {...}
-
-void test_hdr()
-{
- hdr h1;
- BOOST_CHECK_EQUAL(h1._magic, 0UL);
- BOOST_CHECK_EQUAL(h1._version, 0);
- BOOST_CHECK_EQUAL(h1._eflag, 0);
- BOOST_CHECK_EQUAL(h1._uflag, 0);
- BOOST_CHECK_EQUAL(h1._rid, 0ULL);
- BOOST_CHECK(!h1.get_owi());
-
- const u_int32_t magic = 0x89abcdefUL;
- const u_int16_t uflag = 0x5537;
- const u_int8_t version = 0xef;
- const u_int64_t rid = 0x123456789abcdef0ULL;
- const bool owi = true;
-
- hdr h2(magic, version, rid, owi);
- BOOST_CHECK_EQUAL(h2._magic, magic);
- BOOST_CHECK_EQUAL(h2._version, version);
-#ifdef JRNL_LITTLE_ENDIAN
- BOOST_CHECK_EQUAL(h2._eflag, RHM_LENDIAN_FLAG);
-#else
- BOOST_CHECK_EQUAL(h2._eflag, RHM_BENDIAN_FLAG);
-#endif
- BOOST_CHECK_EQUAL(h2._uflag, hdr::HDR_OVERWRITE_INDICATOR_MASK);
- BOOST_CHECK_EQUAL(h2._rid, rid);
- BOOST_CHECK_EQUAL(h2.get_owi(), owi);
- h2._uflag = uflag;
- BOOST_CHECK(h2.get_owi());
- h2.set_owi(true);
- BOOST_CHECK(h2.get_owi());
- BOOST_CHECK_EQUAL(h2._uflag, uflag);
- h2.set_owi(false);
- BOOST_CHECK(!h2.get_owi());
- BOOST_CHECK_EQUAL(h2._uflag, (uflag & ~hdr::HDR_OVERWRITE_INDICATOR_MASK));
- h2.set_owi(true);
- BOOST_CHECK(h2.get_owi());
- BOOST_CHECK_EQUAL(h2._uflag, uflag);
-
- h1.copy(h2);
- BOOST_CHECK_EQUAL(h1._magic, magic);
- BOOST_CHECK_EQUAL(h1._version, version);
-#ifdef JRNL_LITTLE_ENDIAN
- BOOST_CHECK_EQUAL(h1._eflag, RHM_LENDIAN_FLAG);
-#else
- BOOST_CHECK_EQUAL(h1._eflag, RHM_BENDIAN_FLAG);
-#endif
- BOOST_CHECK_EQUAL(h1._uflag, uflag);
- BOOST_CHECK_EQUAL(h1._rid, rid);
- BOOST_CHECK(h1.get_owi());
- BOOST_CHECK_EQUAL(h1._uflag, uflag);
-
- h1.reset();
- BOOST_CHECK_EQUAL(h1._magic, 0UL);
- BOOST_CHECK_EQUAL(h1._version, 0);
- BOOST_CHECK_EQUAL(h1._eflag, 0);
- BOOST_CHECK_EQUAL(h1._uflag, 0);
- BOOST_CHECK_EQUAL(h1._rid, 0ULL);
- BOOST_CHECK(!h1.get_owi());
-}
-
-void test_rec_tail()
-{
- const u_int32_t magic = 0xfedcba98;
- const u_int64_t rid = 0xfedcba9876543210ULL;
- const u_int32_t xmagic = ~magic;
-
- {
- rec_tail rt1;
- BOOST_CHECK_EQUAL(rt1._xmagic, 0xffffffffUL);
- BOOST_CHECK_EQUAL(rt1._rid, 0ULL);
- }
-
- {
- rec_tail rt2(magic, rid);
- BOOST_CHECK_EQUAL(rt2._xmagic, magic);
- BOOST_CHECK_EQUAL(rt2._rid, rid);
- }
-
- {
- hdr h(magic, RHM_JDAT_VERSION, rid, true);
- rec_tail rt3(h);
- BOOST_CHECK_EQUAL(rt3._xmagic, xmagic);
- BOOST_CHECK_EQUAL(rt3._rid, rid);
- }
-}
-
-void test_file_hdr()
-{
- const u_int32_t magic = 0xfedcba98UL;
- const u_int8_t version = 0xa5;
- const u_int16_t uflag = 0x5537;
- const u_int64_t rid = 0xfedcba9876543210ULL;
- const u_int32_t fid = 0xfedcba98UL;
-#ifdef JRNL_32_BIT
- const size_t fro = 0xfedcba98UL;
-#else
- const size_t fro = 0xfedcba9876543210ULL;
-#endif
- timespec ts;
- const bool owi = true;
-
- {
- file_hdr fh1;
- BOOST_CHECK_EQUAL(fh1._hdr._magic, 0UL);
- BOOST_CHECK_EQUAL(fh1._hdr._version, 0);
- BOOST_CHECK_EQUAL(fh1._hdr._eflag, 0);
- BOOST_CHECK_EQUAL(fh1._hdr._uflag, 0);
- BOOST_CHECK_EQUAL(fh1._hdr._rid, 0ULL);
- BOOST_CHECK_EQUAL(fh1._fid, 0UL);
- BOOST_CHECK_EQUAL(fh1._fro, size_t(0));
- BOOST_CHECK_EQUAL(fh1._ts_sec, time_t(0));
- BOOST_CHECK_EQUAL(fh1._ts_nsec, uint32_t(0));
- BOOST_CHECK(!fh1.get_owi());
- }
-
- {
- file_hdr fh2(magic, version, rid, fid, fro, owi, false);
- BOOST_CHECK_EQUAL(fh2._hdr._magic, magic);
- BOOST_CHECK_EQUAL(fh2._hdr._version, version);
-#ifdef JRNL_LITTLE_ENDIAN
- BOOST_CHECK_EQUAL(fh2._hdr._eflag, RHM_LENDIAN_FLAG);
-#else
- BOOST_CHECK_EQUAL(fh2._hdr._eflag, RHM_BENDIAN_FLAG);
-#endif
- BOOST_CHECK_EQUAL(fh2._hdr._uflag, hdr::HDR_OVERWRITE_INDICATOR_MASK);
- BOOST_CHECK_EQUAL(fh2._hdr._rid, rid);
- BOOST_CHECK_EQUAL(fh2._fid,fid );
- BOOST_CHECK_EQUAL(fh2._fro, fro);
- BOOST_CHECK_EQUAL(fh2._ts_sec, time_t(0));
- BOOST_CHECK_EQUAL(fh2._ts_nsec, uint32_t(0));
- ::clock_gettime(CLOCK_REALTIME, &ts);
- fh2.set_time(ts);
- BOOST_CHECK_EQUAL(fh2._ts_sec, ts.tv_sec);
- BOOST_CHECK_EQUAL(fh2._ts_nsec, u_int32_t(ts.tv_nsec));
- BOOST_CHECK(fh2.get_owi());
-
- fh2._hdr._uflag = uflag;
- BOOST_CHECK(fh2.get_owi());
-
- fh2.set_owi(false);
- BOOST_CHECK(!fh2.get_owi());
- BOOST_CHECK_EQUAL(fh2._hdr._uflag, (uflag & ~hdr::HDR_OVERWRITE_INDICATOR_MASK));
-
- fh2.set_owi(true);
- BOOST_CHECK(fh2.get_owi());
- BOOST_CHECK_EQUAL(fh2._hdr._uflag, uflag);
- }
-
- {
- file_hdr fh3(magic, version, rid, fid, fro, owi, true);
- BOOST_CHECK_EQUAL(fh3._hdr._magic, magic);
- BOOST_CHECK_EQUAL(fh3._hdr._version, version);
-#ifdef JRNL_LITTLE_ENDIAN
- BOOST_CHECK_EQUAL(fh3._hdr._eflag, RHM_LENDIAN_FLAG);
-#else
- BOOST_CHECK_EQUAL(fh3._hdr._eflag, RHM_BENDIAN_FLAG);
-#endif
- BOOST_CHECK_EQUAL(fh3._hdr._uflag, hdr::HDR_OVERWRITE_INDICATOR_MASK);
- BOOST_CHECK_EQUAL(fh3._hdr._rid, rid);
- BOOST_CHECK_EQUAL(fh3._fid, fid);
- BOOST_CHECK_EQUAL(fh3._fro, fro);
- BOOST_CHECK(fh3._ts_sec - ts.tv_sec <= 1); // No more than 1 sec difference
- }
-}
-
-void test_enq_hdr()
-{
- const u_int32_t magic = 0xfedcba98UL;
- const u_int8_t version = 0xa5;
- const u_int64_t rid = 0xfedcba9876543210ULL;
- const u_int16_t uflag = 0x5537;
-#ifdef JRNL_32_BIT
- const size_t xidsize = 0xfedcba98UL;
- const size_t dsize = 0x76543210UL;
-#else
- const size_t xidsize = 0xfedcba9876543210ULL;
- const size_t dsize = 0x76543210fedcba98ULL;
-#endif
- const bool owi = true;
-
- {
- enq_hdr eh1;
- BOOST_CHECK_EQUAL(eh1._hdr._magic, 0UL);
- BOOST_CHECK_EQUAL(eh1._hdr._version, 0);
- BOOST_CHECK_EQUAL(eh1._hdr._eflag, 0);
- BOOST_CHECK_EQUAL(eh1._hdr._uflag, 0);
- BOOST_CHECK_EQUAL(eh1._hdr._rid, 0ULL);
- BOOST_CHECK_EQUAL(eh1._xidsize, size_t(0));
- BOOST_CHECK_EQUAL(eh1._dsize, size_t(0));
- BOOST_CHECK(!eh1.get_owi());
- }
-
- {
- enq_hdr eh2(magic, version, rid, xidsize, dsize, owi, false);
- BOOST_CHECK_EQUAL(eh2._hdr._magic, magic);
- BOOST_CHECK_EQUAL(eh2._hdr._version, version);
-#ifdef JRNL_LITTLE_ENDIAN
- BOOST_CHECK_EQUAL(eh2._hdr._eflag, RHM_LENDIAN_FLAG);
-#else
- BOOST_CHECK_EQUAL(eh2._hdr._eflag, RHM_BENDIAN_FLAG);
-#endif
- BOOST_CHECK_EQUAL(eh2._hdr._uflag, hdr::HDR_OVERWRITE_INDICATOR_MASK);
- BOOST_CHECK_EQUAL(eh2._hdr._rid, rid);
- BOOST_CHECK_EQUAL(eh2._xidsize, xidsize);
- BOOST_CHECK_EQUAL(eh2._dsize, dsize);
- BOOST_CHECK(eh2.get_owi());
- BOOST_CHECK(!eh2.is_transient());
- BOOST_CHECK(!eh2.is_external());
-
- eh2._hdr._uflag = uflag;
- BOOST_CHECK(eh2.get_owi());
- BOOST_CHECK(eh2.is_transient());
- BOOST_CHECK(eh2.is_external());
-
- eh2.set_owi(false);
- BOOST_CHECK(!eh2.get_owi());
- BOOST_CHECK(eh2.is_transient());
- BOOST_CHECK(eh2.is_external());
- BOOST_CHECK_EQUAL(eh2._hdr._uflag, (uflag & ~hdr::HDR_OVERWRITE_INDICATOR_MASK));
-
- eh2.set_owi(true);
- BOOST_CHECK(eh2.get_owi());
- BOOST_CHECK(eh2.is_transient());
- BOOST_CHECK(eh2.is_external());
- BOOST_CHECK_EQUAL(eh2._hdr._uflag, uflag);
-
- eh2.set_transient(false);
- BOOST_CHECK(eh2.get_owi());
- BOOST_CHECK(!eh2.is_transient());
- BOOST_CHECK(eh2.is_external());
- BOOST_CHECK_EQUAL(eh2._hdr._uflag, uflag & ~enq_hdr::ENQ_HDR_TRANSIENT_MASK);
-
- eh2.set_transient(true);
- BOOST_CHECK(eh2.get_owi());
- BOOST_CHECK(eh2.is_transient());
- BOOST_CHECK(eh2.is_external());
- BOOST_CHECK_EQUAL(eh2._hdr._uflag, uflag);
-
- eh2.set_external(false);
- BOOST_CHECK(eh2.get_owi());
- BOOST_CHECK(eh2.is_transient());
- BOOST_CHECK(!eh2.is_external());
- BOOST_CHECK_EQUAL(eh2._hdr._uflag, uflag & ~enq_hdr::ENQ_HDR_EXTERNAL_MASK);
-
- eh2.set_external(true);
- BOOST_CHECK(eh2.get_owi());
- BOOST_CHECK(eh2.is_transient());
- BOOST_CHECK(eh2.is_external());
- BOOST_CHECK_EQUAL(eh2._hdr._uflag, uflag);
- }
-
- {
- enq_hdr eh3(magic, version, rid, xidsize, dsize, owi, true);
- BOOST_CHECK_EQUAL(eh3._hdr._magic, magic);
- BOOST_CHECK_EQUAL(eh3._hdr._version, version);
-#ifdef JRNL_LITTLE_ENDIAN
- BOOST_CHECK_EQUAL(eh3._hdr._eflag, RHM_LENDIAN_FLAG);
-#else
- BOOST_CHECK_EQUAL(eh3._hdr._eflag, RHM_BENDIAN_FLAG);
-#endif
- BOOST_CHECK_EQUAL(eh3._hdr._uflag,
- enq_hdr::ENQ_HDR_TRANSIENT_MASK | hdr::HDR_OVERWRITE_INDICATOR_MASK);
- BOOST_CHECK_EQUAL(eh3._hdr._rid, rid);
- BOOST_CHECK_EQUAL(eh3._xidsize, xidsize);
- BOOST_CHECK_EQUAL(eh3._dsize, dsize);
- BOOST_CHECK(eh3.get_owi());
- BOOST_CHECK(eh3.is_transient());
- BOOST_CHECK(!eh3.is_external());
- }
-}
-
-void test_deq_hdr()
-{
- const u_int32_t magic = 0xfedcba98UL;
- const u_int8_t version = 0xa5;
- const u_int16_t uflag = 0x5537;
- const u_int64_t rid = 0xfedcba9876543210ULL;
- const u_int64_t drid = 0x76543210fedcba98ULL;
-#ifdef JRNL_32_BIT
- const size_t xidsize = 0xfedcba98UL;
-#else
- const size_t xidsize = 0xfedcba9876543210ULL;
-#endif
- const bool owi = true;
-
- {
- deq_hdr dh1;
- BOOST_CHECK_EQUAL(dh1._hdr._magic, 0UL);
- BOOST_CHECK_EQUAL(dh1._hdr._version, 0);
- BOOST_CHECK_EQUAL(dh1._hdr._eflag, 0);
- BOOST_CHECK_EQUAL(dh1._hdr._uflag, 0);
- BOOST_CHECK_EQUAL(dh1._hdr._rid, 0ULL);
- BOOST_CHECK_EQUAL(dh1._deq_rid, 0ULL);
- BOOST_CHECK_EQUAL(dh1._xidsize, size_t(0));
- BOOST_CHECK(!dh1.get_owi());
- }
-
- {
- deq_hdr dh2(magic, version, rid, drid, xidsize, owi);
- BOOST_CHECK_EQUAL(dh2._hdr._magic, magic);
- BOOST_CHECK_EQUAL(dh2._hdr._version, version);
-#ifdef JRNL_LITTLE_ENDIAN
- BOOST_CHECK_EQUAL(dh2._hdr._eflag, RHM_LENDIAN_FLAG);
-#else
- BOOST_CHECK_EQUAL(dh2._hdr._eflag, RHM_BENDIAN_FLAG);
-#endif
- BOOST_CHECK_EQUAL(dh2._hdr._uflag, hdr::HDR_OVERWRITE_INDICATOR_MASK);
- BOOST_CHECK_EQUAL(dh2._hdr._rid, rid);
- BOOST_CHECK_EQUAL(dh2._deq_rid, drid);
- BOOST_CHECK_EQUAL(dh2._xidsize, xidsize);
- BOOST_CHECK(dh2.get_owi());
-
- dh2._hdr._uflag = uflag;
- BOOST_CHECK(dh2.get_owi());
-
- dh2.set_owi(false);
- BOOST_CHECK(!dh2.get_owi());
- BOOST_CHECK_EQUAL(dh2._hdr._uflag, (uflag & ~hdr::HDR_OVERWRITE_INDICATOR_MASK));
-
- dh2.set_owi(true);
- BOOST_CHECK(dh2.get_owi());
- BOOST_CHECK_EQUAL(dh2._hdr._uflag, uflag);
- }
-}
-
-void test_txn_hdr()
-{
- const u_int32_t magic = 0xfedcba98UL;
- const u_int8_t version = 0xa5;
- const u_int16_t uflag = 0x5537;
- const u_int64_t rid = 0xfedcba9876543210ULL;
-#ifdef JRNL_32_BIT
- const size_t xidsize = 0xfedcba98UL;
-#else
- const size_t xidsize = 0xfedcba9876543210ULL;
-#endif
- const bool owi = true;
-
- {
- txn_hdr th1;
- BOOST_CHECK_EQUAL(th1._hdr._magic, 0UL);
- BOOST_CHECK_EQUAL(th1._hdr._version, 0);
- BOOST_CHECK_EQUAL(th1._hdr._eflag, 0);
- BOOST_CHECK_EQUAL(th1._hdr._uflag, 0);
- BOOST_CHECK_EQUAL(th1._hdr._rid, 0ULL);
- BOOST_CHECK_EQUAL(th1._xidsize, size_t(0));
- BOOST_CHECK(!th1.get_owi());
- }
-
- {
- txn_hdr th2(magic, version, rid, xidsize, owi);
- BOOST_CHECK_EQUAL(th2._hdr._magic, magic);
- BOOST_CHECK_EQUAL(th2._hdr._version, version);
-#ifdef JRNL_LITTLE_ENDIAN
- BOOST_CHECK_EQUAL(th2._hdr._eflag, RHM_LENDIAN_FLAG);
-#else
- BOOST_CHECK_EQUAL(th2._hdr._eflag, RHM_BENDIAN_FLAG);
-#endif
- BOOST_CHECK_EQUAL(th2._hdr._uflag, hdr::HDR_OVERWRITE_INDICATOR_MASK);
- BOOST_CHECK_EQUAL(th2._hdr._rid, rid);
- BOOST_CHECK_EQUAL(th2._xidsize, xidsize);
- BOOST_CHECK(th2.get_owi());
-
- th2._hdr._uflag = uflag;
- BOOST_CHECK(th2.get_owi());
-
- th2.set_owi(false);
- BOOST_CHECK(!th2.get_owi());
- BOOST_CHECK_EQUAL(th2._hdr._uflag, (uflag & ~hdr::HDR_OVERWRITE_INDICATOR_MASK));
-
- th2.set_owi(true);
- BOOST_CHECK(th2.get_owi());
- BOOST_CHECK_EQUAL(th2._hdr._uflag, uflag);
- }
-}
-
-// Initialize test suite and include test functions
-
-test_suite* init_unit_test_suite(int, char**)
-{
- std::cout << "--------" << std::endl << "unit_test_file_hdr: ";
- test_suite* ts = BOOST_TEST_SUITE("unit_test_file_hdr");
-
- results_reporter::set_level(SHORT_REPORT);
- unit_test_log_t::instance().set_threshold_level(log_messages);
-
- ts->add(BOOST_TEST_CASE(&test_hdr));
- ts->add(BOOST_TEST_CASE(&test_rec_tail));
- ts->add(BOOST_TEST_CASE(&test_file_hdr));
- ts->add(BOOST_TEST_CASE(&test_enq_hdr));
- ts->add(BOOST_TEST_CASE(&test_deq_hdr));
- ts->add(BOOST_TEST_CASE(&test_txn_hdr));
-
- return ts;
-}
Modified: store/trunk/cpp/tests/jrnl/unit_test_jinf.cpp
===================================================================
--- store/trunk/cpp/tests/jrnl/unit_test_jinf.cpp 2007-12-11 21:04:00 UTC (rev 1455)
+++ store/trunk/cpp/tests/jrnl/unit_test_jinf.cpp 2007-12-11 21:04:27 UTC (rev 1456)
@@ -227,15 +227,15 @@
void init_fhdr(file_hdr& fh, const u_int32_t fid, const u_int64_t rid, const bool owi,
const bool no_enq)
{
- fh._hdr._magic = RHM_JDAT_FILE_MAGIC;
- fh._hdr._version = RHM_JDAT_VERSION;
+ fh._magic = RHM_JDAT_FILE_MAGIC;
+ fh._version = RHM_JDAT_VERSION;
#if defined(JRNL_BIG_ENDIAN)
- fh._hdr._eflag = RHM_BENDIAN_FLAG;
+ fh._eflag = RHM_BENDIAN_FLAG;
#else
- fh._hdr._eflag = RHM_LENDIAN_FLAG;
+ fh._eflag = RHM_LENDIAN_FLAG;
#endif
- fh._hdr._uflag = owi ? hdr::HDR_OVERWRITE_INDICATOR_MASK : 0;
- fh._hdr._rid = rid;
+ fh._uflag = owi ? rec_hdr::HDR_OVERWRITE_INDICATOR_MASK : 0;
+ fh._rid = rid;
fh._fid = fid;
fh._fro = no_enq ? 0 : 0x200;
timespec ts;
Copied: store/trunk/cpp/tests/jrnl/unit_test_rec_hdr.cpp (from rev 1450, store/trunk/cpp/tests/jrnl/unit_test_file_hdr.cpp)
===================================================================
--- store/trunk/cpp/tests/jrnl/unit_test_rec_hdr.cpp (rev 0)
+++ store/trunk/cpp/tests/jrnl/unit_test_rec_hdr.cpp 2007-12-11 21:04:27 UTC (rev 1456)
@@ -0,0 +1,448 @@
+/**
+* \file unit_test_file_hdr.cpp
+*
+* Red Hat Messaging - Message Journal
+*
+* This file contains the unit tests for the journal.
+*
+* \author Kim van der Riet
+*
+* Copyright 2007 Red Hat, Inc.
+*
+* This file is part of Red Hat Messaging.
+*
+* Red Hat Messaging is free software; you can redistribute it and/or
+* modify it under the terms of the GNU Lesser General Public
+* License as published by the Free Software Foundation; either
+* version 2.1 of the License, or (at your option) any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this library; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+* USA
+*
+* The GNU Lesser General Public License is available in the file COPYING.
+*/
+
+#include <boost/test/results_reporter.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/test/unit_test_log.hpp>
+#include <iostream>
+#include <jrnl/deq_hdr.hpp>
+#include <jrnl/enq_hdr.hpp>
+#include <jrnl/file_hdr.hpp>
+#include <jrnl/jcfg.hpp>
+#include <jrnl/rec_tail.hpp>
+#include <jrnl/txn_hdr.hpp>
+
+using namespace boost::unit_test;
+using namespace rhm::journal;
+
+// Test functions of the form
+// void fn() {...}
+
+void test_hdr()
+{
+ rec_hdr h1;
+ BOOST_CHECK_EQUAL(h1._magic, 0UL);
+ BOOST_CHECK_EQUAL(h1._version, 0);
+ BOOST_CHECK_EQUAL(h1._eflag, 0);
+ BOOST_CHECK_EQUAL(h1._uflag, 0);
+ BOOST_CHECK_EQUAL(h1._rid, 0ULL);
+ BOOST_CHECK(!h1.get_owi());
+
+ const u_int32_t magic = 0x89abcdefUL;
+ const u_int16_t uflag = 0x5537;
+ const u_int8_t version = 0xef;
+ const u_int64_t rid = 0x123456789abcdef0ULL;
+ const bool owi = true;
+
+ rec_hdr h2(magic, version, rid, owi);
+ BOOST_CHECK_EQUAL(h2._magic, magic);
+ BOOST_CHECK_EQUAL(h2._version, version);
+#ifdef JRNL_LITTLE_ENDIAN
+ BOOST_CHECK_EQUAL(h2._eflag, RHM_LENDIAN_FLAG);
+#else
+ BOOST_CHECK_EQUAL(h2._eflag, RHM_BENDIAN_FLAG);
+#endif
+ BOOST_CHECK_EQUAL(h2._uflag, (const u_int16_t)rec_hdr::HDR_OVERWRITE_INDICATOR_MASK);
+ BOOST_CHECK_EQUAL(h2._rid, rid);
+ BOOST_CHECK_EQUAL(h2.get_owi(), owi);
+ h2._uflag = uflag;
+ BOOST_CHECK(h2.get_owi());
+ h2.set_owi(true);
+ BOOST_CHECK(h2.get_owi());
+ BOOST_CHECK_EQUAL(h2._uflag, uflag);
+ h2.set_owi(false);
+ BOOST_CHECK(!h2.get_owi());
+ BOOST_CHECK_EQUAL(h2._uflag, (uflag & ~(const u_int16_t)rec_hdr::HDR_OVERWRITE_INDICATOR_MASK));
+ h2.set_owi(true);
+ BOOST_CHECK(h2.get_owi());
+ BOOST_CHECK_EQUAL(h2._uflag, uflag);
+
+ h1.hdr_copy(h2);
+ BOOST_CHECK_EQUAL(h1._magic, magic);
+ BOOST_CHECK_EQUAL(h1._version, version);
+#ifdef JRNL_LITTLE_ENDIAN
+ BOOST_CHECK_EQUAL(h1._eflag, RHM_LENDIAN_FLAG);
+#else
+ BOOST_CHECK_EQUAL(h1._eflag, RHM_BENDIAN_FLAG);
+#endif
+ BOOST_CHECK_EQUAL(h1._uflag, uflag);
+ BOOST_CHECK_EQUAL(h1._rid, rid);
+ BOOST_CHECK(h1.get_owi());
+ BOOST_CHECK_EQUAL(h1._uflag, uflag);
+
+ h1.reset();
+ BOOST_CHECK_EQUAL(h1._magic, 0UL);
+ BOOST_CHECK_EQUAL(h1._version, 0);
+ BOOST_CHECK_EQUAL(h1._eflag, 0);
+ BOOST_CHECK_EQUAL(h1._uflag, 0);
+ BOOST_CHECK_EQUAL(h1._rid, 0ULL);
+ BOOST_CHECK(!h1.get_owi());
+}
+
+void test_rec_tail()
+{
+ const u_int32_t magic = 0xfedcba98;
+ const u_int64_t rid = 0xfedcba9876543210ULL;
+ const u_int32_t xmagic = ~magic;
+
+ {
+ rec_tail rt1;
+ BOOST_CHECK_EQUAL(rt1._xmagic, 0xffffffffUL);
+ BOOST_CHECK_EQUAL(rt1._rid, 0ULL);
+ }
+
+ {
+ rec_tail rt2(magic, rid);
+ BOOST_CHECK_EQUAL(rt2._xmagic, magic);
+ BOOST_CHECK_EQUAL(rt2._rid, rid);
+ }
+
+ {
+ rec_hdr h(magic, RHM_JDAT_VERSION, rid, true);
+ rec_tail rt3(h);
+ BOOST_CHECK_EQUAL(rt3._xmagic, xmagic);
+ BOOST_CHECK_EQUAL(rt3._rid, rid);
+ }
+}
+
+void test_file_hdr()
+{
+ const u_int32_t magic = 0xfedcba98UL;
+ const u_int8_t version = 0xa5;
+ const u_int16_t uflag = 0x5537;
+ const u_int64_t rid = 0xfedcba9876543210ULL;
+ const u_int32_t fid = 0xfedcba98UL;
+#ifdef JRNL_32_BIT
+ const size_t fro = 0xfedcba98UL;
+#else
+ const size_t fro = 0xfedcba9876543210ULL;
+#endif
+ timespec ts;
+ const bool owi = true;
+
+ {
+ file_hdr fh1;
+ BOOST_CHECK_EQUAL(fh1._magic, 0UL);
+ BOOST_CHECK_EQUAL(fh1._version, 0);
+ BOOST_CHECK_EQUAL(fh1._eflag, 0);
+ BOOST_CHECK_EQUAL(fh1._uflag, 0);
+ BOOST_CHECK_EQUAL(fh1._rid, 0ULL);
+ BOOST_CHECK_EQUAL(fh1._fid, 0UL);
+ BOOST_CHECK_EQUAL(fh1._fro, size_t(0));
+ BOOST_CHECK_EQUAL(fh1._ts_sec, time_t(0));
+ BOOST_CHECK_EQUAL(fh1._ts_nsec, uint32_t(0));
+ BOOST_CHECK(!fh1.get_owi());
+ }
+
+ {
+ file_hdr fh2(magic, version, rid, fid, fro, owi, false);
+ BOOST_CHECK_EQUAL(fh2._magic, magic);
+ BOOST_CHECK_EQUAL(fh2._version, version);
+#ifdef JRNL_LITTLE_ENDIAN
+ BOOST_CHECK_EQUAL(fh2._eflag, RHM_LENDIAN_FLAG);
+#else
+ BOOST_CHECK_EQUAL(fh2._eflag, RHM_BENDIAN_FLAG);
+#endif
+ BOOST_CHECK_EQUAL(fh2._uflag, (const u_int16_t)rec_hdr::HDR_OVERWRITE_INDICATOR_MASK);
+ BOOST_CHECK_EQUAL(fh2._rid, rid);
+ BOOST_CHECK_EQUAL(fh2._fid,fid );
+ BOOST_CHECK_EQUAL(fh2._fro, fro);
+ BOOST_CHECK_EQUAL(fh2._ts_sec, time_t(0));
+ BOOST_CHECK_EQUAL(fh2._ts_nsec, uint32_t(0));
+ ::clock_gettime(CLOCK_REALTIME, &ts);
+ fh2.set_time(ts);
+ BOOST_CHECK_EQUAL(fh2._ts_sec, ts.tv_sec);
+ BOOST_CHECK_EQUAL(fh2._ts_nsec, u_int32_t(ts.tv_nsec));
+ BOOST_CHECK(fh2.get_owi());
+
+ fh2._uflag = uflag;
+ BOOST_CHECK(fh2.get_owi());
+
+ fh2.set_owi(false);
+ BOOST_CHECK(!fh2.get_owi());
+ BOOST_CHECK_EQUAL(fh2._uflag,
+ (uflag & ~(const u_int16_t)rec_hdr::HDR_OVERWRITE_INDICATOR_MASK));
+
+ fh2.set_owi(true);
+ BOOST_CHECK(fh2.get_owi());
+ BOOST_CHECK_EQUAL(fh2._uflag, uflag);
+ }
+
+ {
+ file_hdr fh3(magic, version, rid, fid, fro, owi, true);
+ BOOST_CHECK_EQUAL(fh3._magic, magic);
+ BOOST_CHECK_EQUAL(fh3._version, version);
+#ifdef JRNL_LITTLE_ENDIAN
+ BOOST_CHECK_EQUAL(fh3._eflag, RHM_LENDIAN_FLAG);
+#else
+ BOOST_CHECK_EQUAL(fh3._eflag, RHM_BENDIAN_FLAG);
+#endif
+ BOOST_CHECK_EQUAL(fh3._uflag, (const u_int16_t)rec_hdr::HDR_OVERWRITE_INDICATOR_MASK);
+ BOOST_CHECK_EQUAL(fh3._rid, rid);
+ BOOST_CHECK_EQUAL(fh3._fid, fid);
+ BOOST_CHECK_EQUAL(fh3._fro, fro);
+ BOOST_CHECK(fh3._ts_sec - ts.tv_sec <= 1); // No more than 1 sec difference
+ }
+}
+
+void test_enq_hdr()
+{
+ const u_int32_t magic = 0xfedcba98UL;
+ const u_int8_t version = 0xa5;
+ const u_int64_t rid = 0xfedcba9876543210ULL;
+ const u_int16_t uflag = 0x5537;
+#ifdef JRNL_32_BIT
+ const size_t xidsize = 0xfedcba98UL;
+ const size_t dsize = 0x76543210UL;
+#else
+ const size_t xidsize = 0xfedcba9876543210ULL;
+ const size_t dsize = 0x76543210fedcba98ULL;
+#endif
+ const bool owi = true;
+
+ {
+ enq_hdr eh1;
+ BOOST_CHECK_EQUAL(eh1._magic, 0UL);
+ BOOST_CHECK_EQUAL(eh1._version, 0);
+ BOOST_CHECK_EQUAL(eh1._eflag, 0);
+ BOOST_CHECK_EQUAL(eh1._uflag, 0);
+ BOOST_CHECK_EQUAL(eh1._rid, 0ULL);
+ BOOST_CHECK_EQUAL(eh1._xidsize, size_t(0));
+ BOOST_CHECK_EQUAL(eh1._dsize, size_t(0));
+ BOOST_CHECK(!eh1.get_owi());
+ }
+
+ {
+ enq_hdr eh2(magic, version, rid, xidsize, dsize, owi, false);
+ BOOST_CHECK_EQUAL(eh2._magic, magic);
+ BOOST_CHECK_EQUAL(eh2._version, version);
+#ifdef JRNL_LITTLE_ENDIAN
+ BOOST_CHECK_EQUAL(eh2._eflag, RHM_LENDIAN_FLAG);
+#else
+ BOOST_CHECK_EQUAL(eh2._eflag, RHM_BENDIAN_FLAG);
+#endif
+ BOOST_CHECK_EQUAL(eh2._uflag, (const u_int16_t)rec_hdr::HDR_OVERWRITE_INDICATOR_MASK);
+ BOOST_CHECK_EQUAL(eh2._rid, rid);
+ BOOST_CHECK_EQUAL(eh2._xidsize, xidsize);
+ BOOST_CHECK_EQUAL(eh2._dsize, dsize);
+ BOOST_CHECK(eh2.get_owi());
+ BOOST_CHECK(!eh2.is_transient());
+ BOOST_CHECK(!eh2.is_external());
+
+ eh2._uflag = uflag;
+ BOOST_CHECK(eh2.get_owi());
+ BOOST_CHECK(eh2.is_transient());
+ BOOST_CHECK(eh2.is_external());
+
+ eh2.set_owi(false);
+ BOOST_CHECK(!eh2.get_owi());
+ BOOST_CHECK(eh2.is_transient());
+ BOOST_CHECK(eh2.is_external());
+ BOOST_CHECK_EQUAL(eh2._uflag,
+ (uflag & ~(const u_int16_t)rec_hdr::HDR_OVERWRITE_INDICATOR_MASK));
+
+ eh2.set_owi(true);
+ BOOST_CHECK(eh2.get_owi());
+ BOOST_CHECK(eh2.is_transient());
+ BOOST_CHECK(eh2.is_external());
+ BOOST_CHECK_EQUAL(eh2._uflag, uflag);
+
+ eh2.set_transient(false);
+ BOOST_CHECK(eh2.get_owi());
+ BOOST_CHECK(!eh2.is_transient());
+ BOOST_CHECK(eh2.is_external());
+ BOOST_CHECK_EQUAL(eh2._uflag, uflag & ~(const u_int16_t)enq_hdr::ENQ_HDR_TRANSIENT_MASK);
+
+ eh2.set_transient(true);
+ BOOST_CHECK(eh2.get_owi());
+ BOOST_CHECK(eh2.is_transient());
+ BOOST_CHECK(eh2.is_external());
+ BOOST_CHECK_EQUAL(eh2._uflag, uflag);
+
+ eh2.set_external(false);
+ BOOST_CHECK(eh2.get_owi());
+ BOOST_CHECK(eh2.is_transient());
+ BOOST_CHECK(!eh2.is_external());
+ BOOST_CHECK_EQUAL(eh2._uflag, uflag & ~(const u_int16_t)enq_hdr::ENQ_HDR_EXTERNAL_MASK);
+
+ eh2.set_external(true);
+ BOOST_CHECK(eh2.get_owi());
+ BOOST_CHECK(eh2.is_transient());
+ BOOST_CHECK(eh2.is_external());
+ BOOST_CHECK_EQUAL(eh2._uflag, uflag);
+ }
+
+ {
+ enq_hdr eh3(magic, version, rid, xidsize, dsize, owi, true);
+ BOOST_CHECK_EQUAL(eh3._magic, magic);
+ BOOST_CHECK_EQUAL(eh3._version, version);
+#ifdef JRNL_LITTLE_ENDIAN
+ BOOST_CHECK_EQUAL(eh3._eflag, RHM_LENDIAN_FLAG);
+#else
+ BOOST_CHECK_EQUAL(eh3._eflag, RHM_BENDIAN_FLAG);
+#endif
+ BOOST_CHECK_EQUAL(eh3._uflag, (const u_int16_t)enq_hdr::ENQ_HDR_TRANSIENT_MASK |
+ (const u_int16_t)rec_hdr::HDR_OVERWRITE_INDICATOR_MASK);
+ BOOST_CHECK_EQUAL(eh3._rid, rid);
+ BOOST_CHECK_EQUAL(eh3._xidsize, xidsize);
+ BOOST_CHECK_EQUAL(eh3._dsize, dsize);
+ BOOST_CHECK(eh3.get_owi());
+ BOOST_CHECK(eh3.is_transient());
+ BOOST_CHECK(!eh3.is_external());
+ }
+}
+
+void test_deq_hdr()
+{
+ const u_int32_t magic = 0xfedcba98UL;
+ const u_int8_t version = 0xa5;
+ const u_int16_t uflag = 0x5537;
+ const u_int64_t rid = 0xfedcba9876543210ULL;
+ const u_int64_t drid = 0x76543210fedcba98ULL;
+#ifdef JRNL_32_BIT
+ const size_t xidsize = 0xfedcba98UL;
+#else
+ const size_t xidsize = 0xfedcba9876543210ULL;
+#endif
+ const bool owi = true;
+
+ {
+ deq_hdr dh1;
+ BOOST_CHECK_EQUAL(dh1._magic, 0UL);
+ BOOST_CHECK_EQUAL(dh1._version, 0);
+ BOOST_CHECK_EQUAL(dh1._eflag, 0);
+ BOOST_CHECK_EQUAL(dh1._uflag, 0);
+ BOOST_CHECK_EQUAL(dh1._rid, 0ULL);
+ BOOST_CHECK_EQUAL(dh1._deq_rid, 0ULL);
+ BOOST_CHECK_EQUAL(dh1._xidsize, size_t(0));
+ BOOST_CHECK(!dh1.get_owi());
+ }
+
+ {
+ deq_hdr dh2(magic, version, rid, drid, xidsize, owi);
+ BOOST_CHECK_EQUAL(dh2._magic, magic);
+ BOOST_CHECK_EQUAL(dh2._version, version);
+#ifdef JRNL_LITTLE_ENDIAN
+ BOOST_CHECK_EQUAL(dh2._eflag, RHM_LENDIAN_FLAG);
+#else
+ BOOST_CHECK_EQUAL(dh2._eflag, RHM_BENDIAN_FLAG);
+#endif
+ BOOST_CHECK_EQUAL(dh2._uflag, (const u_int16_t)rec_hdr::HDR_OVERWRITE_INDICATOR_MASK);
+ BOOST_CHECK_EQUAL(dh2._rid, rid);
+ BOOST_CHECK_EQUAL(dh2._deq_rid, drid);
+ BOOST_CHECK_EQUAL(dh2._xidsize, xidsize);
+ BOOST_CHECK(dh2.get_owi());
+
+ dh2._uflag = uflag;
+ BOOST_CHECK(dh2.get_owi());
+
+ dh2.set_owi(false);
+ BOOST_CHECK(!dh2.get_owi());
+ BOOST_CHECK_EQUAL(dh2._uflag,
+ (uflag & ~(const u_int16_t)rec_hdr::HDR_OVERWRITE_INDICATOR_MASK));
+
+ dh2.set_owi(true);
+ BOOST_CHECK(dh2.get_owi());
+ BOOST_CHECK_EQUAL(dh2._uflag, uflag);
+ }
+}
+
+void test_txn_hdr()
+{
+ const u_int32_t magic = 0xfedcba98UL;
+ const u_int8_t version = 0xa5;
+ const u_int16_t uflag = 0x5537;
+ const u_int64_t rid = 0xfedcba9876543210ULL;
+#ifdef JRNL_32_BIT
+ const size_t xidsize = 0xfedcba98UL;
+#else
+ const size_t xidsize = 0xfedcba9876543210ULL;
+#endif
+ const bool owi = true;
+
+ {
+ txn_hdr th1;
+ BOOST_CHECK_EQUAL(th1._magic, 0UL);
+ BOOST_CHECK_EQUAL(th1._version, 0);
+ BOOST_CHECK_EQUAL(th1._eflag, 0);
+ BOOST_CHECK_EQUAL(th1._uflag, 0);
+ BOOST_CHECK_EQUAL(th1._rid, 0ULL);
+ BOOST_CHECK_EQUAL(th1._xidsize, size_t(0));
+ BOOST_CHECK(!th1.get_owi());
+ }
+
+ {
+ txn_hdr th2(magic, version, rid, xidsize, owi);
+ BOOST_CHECK_EQUAL(th2._magic, magic);
+ BOOST_CHECK_EQUAL(th2._version, version);
+#ifdef JRNL_LITTLE_ENDIAN
+ BOOST_CHECK_EQUAL(th2._eflag, RHM_LENDIAN_FLAG);
+#else
+ BOOST_CHECK_EQUAL(th2._eflag, RHM_BENDIAN_FLAG);
+#endif
+ BOOST_CHECK_EQUAL(th2._uflag, (const u_int16_t)rec_hdr::HDR_OVERWRITE_INDICATOR_MASK);
+ BOOST_CHECK_EQUAL(th2._rid, rid);
+ BOOST_CHECK_EQUAL(th2._xidsize, xidsize);
+ BOOST_CHECK(th2.get_owi());
+
+ th2._uflag = uflag;
+ BOOST_CHECK(th2.get_owi());
+
+ th2.set_owi(false);
+ BOOST_CHECK(!th2.get_owi());
+ BOOST_CHECK_EQUAL(th2._uflag,
+ (uflag & ~(const u_int16_t)rec_hdr::HDR_OVERWRITE_INDICATOR_MASK));
+
+ th2.set_owi(true);
+ BOOST_CHECK(th2.get_owi());
+ BOOST_CHECK_EQUAL(th2._uflag, uflag);
+ }
+}
+
+// Initialize test suite and include test functions
+
+test_suite* init_unit_test_suite(int, char**)
+{
+ std::cout << "--------" << std::endl << "unit_test_rec_hdr: ";
+ test_suite* ts = BOOST_TEST_SUITE("unit_test_rec_hdr");
+
+ results_reporter::set_level(SHORT_REPORT);
+ unit_test_log_t::instance().set_threshold_level(log_messages);
+
+ ts->add(BOOST_TEST_CASE(&test_hdr));
+ ts->add(BOOST_TEST_CASE(&test_rec_tail));
+ ts->add(BOOST_TEST_CASE(&test_file_hdr));
+ ts->add(BOOST_TEST_CASE(&test_enq_hdr));
+ ts->add(BOOST_TEST_CASE(&test_deq_hdr));
+ ts->add(BOOST_TEST_CASE(&test_txn_hdr));
+
+ return ts;
+}
More information about the rhmessaging-commits
mailing list