rhmessaging commits: r1456 - in store/trunk/cpp: lib/jrnl and 1 other directories.
by rhmessaging-commits@lists.jboss.org
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;
+}
18 years, 4 months
rhmessaging commits: r1455 - in mgmt: notes and 1 other directory.
by rhmessaging-commits@lists.jboss.org
Author: justi9
Date: 2007-12-11 16:04:00 -0500 (Tue, 11 Dec 2007)
New Revision: 1455
Modified:
mgmt/cumin/python/cumin/__init__.py
mgmt/cumin/python/cumin/charts.py
mgmt/cumin/python/cumin/exchange.strings
mgmt/cumin/python/cumin/model.py
mgmt/cumin/python/cumin/page.strings
mgmt/cumin/python/cumin/queue.py
mgmt/cumin/python/cumin/queue.strings
mgmt/cumin/python/cumin/widgets.py
mgmt/cumin/python/cumin/widgets.strings
mgmt/notes/justin-todo.txt
Log:
Adds pending command counts to the status boxes. Also cleans up the
ajax for status updates.
Modified: mgmt/cumin/python/cumin/__init__.py
===================================================================
--- mgmt/cumin/python/cumin/__init__.py 2007-12-11 16:36:19 UTC (rev 1454)
+++ mgmt/cumin/python/cumin/__init__.py 2007-12-11 21:04:00 UTC (rev 1455)
@@ -1,4 +1,4 @@
-import sys, os
+import sys, os, socket
from random import randint
from wooly import Application, Session, Page
@@ -32,7 +32,7 @@
for reg in BrokerRegistration.select():
try:
self.model.data.connectToBroker(reg.host, reg.port or 5672)
- except:
+ except socket.error:
print "Failed connecting to broker '%s' at %s:%i" % \
(reg.name, reg.host, reg.port or 5672)
Modified: mgmt/cumin/python/cumin/charts.py
===================================================================
--- mgmt/cumin/python/cumin/charts.py 2007-12-11 16:36:19 UTC (rev 1454)
+++ mgmt/cumin/python/cumin/charts.py 2007-12-11 21:04:00 UTC (rev 1455)
@@ -26,6 +26,10 @@
xs = range(self.width, 0 - self.value_interval, -self.value_interval)
for x, value in zip(xs, values):
+ if value is None:
+ print "Warning: unexpected null value" #XXX
+ value = 0
+
y = self.height - (value / float(self.max_value)) * self.height
cr.line_to(x, y)
Modified: mgmt/cumin/python/cumin/exchange.strings
===================================================================
--- mgmt/cumin/python/cumin/exchange.strings 2007-12-11 16:36:19 UTC (rev 1454)
+++ mgmt/cumin/python/cumin/exchange.strings 2007-12-11 21:04:00 UTC (rev 1455)
@@ -107,6 +107,8 @@
<div>{status_info}</div>
+ <div>{actions_pending}</div>
+
<table>
<tr>
<th></th>
Modified: mgmt/cumin/python/cumin/model.py
===================================================================
--- mgmt/cumin/python/cumin/model.py 2007-12-11 16:36:19 UTC (rev 1454)
+++ mgmt/cumin/python/cumin/model.py 2007-12-11 21:04:00 UTC (rev 1455)
@@ -40,10 +40,13 @@
if stat.name == name:
return stat
- def write_error_xml(self, object, writer):
- writer.write("<error-count>%i</error-count>" % 0)
- writer.write("<warning-count>%i</warning-count>" % 0)
+ def write_event_xml(self, object, writer):
+ writer.write("<events errors=\"%i\" warnings=\"%i\"/>" % (0, 0))
+ def write_action_xml(self, object, writer):
+ count = len(self.model.data.outstandingMethodCalls)
+ writer.write("<actions pending=\"%i\"/>" % count)
+
def write_stat_xml(self, object, writer):
for stat in self.stats:
stat.write_xml(object, writer)
@@ -265,7 +268,8 @@
writer.write("<queue id=\"%i\">" % queue.id)
writer.write("<name>%s</name>" % queue.name)
- self.write_error_xml(queue, writer)
+ self.write_event_xml(queue, writer)
+ self.write_action_xml(queue, writer)
self.write_stat_xml(queue, writer)
writer.write("</queue>")
@@ -322,7 +326,8 @@
writer.write("<exchange id=\"%i\">" % exchange.id)
writer.write("<name>%s</name>" % exchange.name)
- self.write_error_xml(exchange, writer)
+ self.write_event_xml(exchange, writer)
+ self.write_action_xml(exchange, writer)
self.write_stat_xml(exchange, writer)
writer.write("</exchange>")
Modified: mgmt/cumin/python/cumin/page.strings
===================================================================
--- mgmt/cumin/python/cumin/page.strings 2007-12-11 16:36:19 UTC (rev 1454)
+++ mgmt/cumin/python/cumin/page.strings 2007-12-11 21:04:00 UTC (rev 1455)
@@ -588,26 +588,6 @@
}
}())
-function updateStatus(id, object) {
- var ecount = object["error-count"];
- var errors = ecount + " " + (ecount == "1" && "error" || "errors");
-
- var wcount = object["warning-count"];
- var warnings = wcount + " " + (wcount == "1" && "warning" || "warnings");
-
- var status = wooly.doc().elembyid(id);
-
- if (ecount != "0") {
- status.setattr("class", "mstatus red");
- } else if (wcount != "0") {
- status.setattr("class", "mstatus yellow");
- } else {
- status.setattr("class", "mstatus green");
- }
-
- status.elem("div").set(errors + ", " + warnings);
-}
-
function updateImage(id, object) {
var img = wooly.doc().elembyid(id);
Modified: mgmt/cumin/python/cumin/queue.py
===================================================================
--- mgmt/cumin/python/cumin/queue.py 2007-12-11 16:36:19 UTC (rev 1454)
+++ mgmt/cumin/python/cumin/queue.py 2007-12-11 21:04:00 UTC (rev 1455)
@@ -354,6 +354,7 @@
def doit(error, args):
print error, args
+ print "did it!"
class QueuePurge(CuminConfirmForm):
def get_title(self, session, queue):
@@ -366,8 +367,10 @@
def process_submit(self, session, queue):
print "open purge"
+
+ print "queue.managedBroker", queue.managedBroker
- queue.vhost.broker.echo(self.app.model.data, doit, 1, "dude!")
+ queue.purge(self.app.model.data, queue.managedBroker, doit)
print "close purge"
Modified: mgmt/cumin/python/cumin/queue.strings
===================================================================
--- mgmt/cumin/python/cumin/queue.strings 2007-12-11 16:36:19 UTC (rev 1454)
+++ mgmt/cumin/python/cumin/queue.strings 2007-12-11 21:04:00 UTC (rev 1455)
@@ -113,6 +113,8 @@
<div>{status_info}</div>
+ <div>{actions_pending}</div>
+
<table>
<tr>
<th></th>
Modified: mgmt/cumin/python/cumin/widgets.py
===================================================================
--- mgmt/cumin/python/cumin/widgets.py 2007-12-11 16:36:19 UTC (rev 1454)
+++ mgmt/cumin/python/cumin/widgets.py 2007-12-11 21:04:00 UTC (rev 1455)
@@ -143,6 +143,10 @@
else:
return "mstatus green"
+ def render_actions_pending(self, session, object):
+ count = len(self.app.model.data.outstandingMethodCalls)
+ return "%i action%s pending" % (count, ess(count))
+
def render_status_info(self, session, object):
error_count = 0 #XXX len(object.errors)
warning_count = 0 #XXX len(object.warnings)
Modified: mgmt/cumin/python/cumin/widgets.strings
===================================================================
--- mgmt/cumin/python/cumin/widgets.strings 2007-12-11 16:36:19 UTC (rev 1454)
+++ mgmt/cumin/python/cumin/widgets.strings 2007-12-11 21:04:00 UTC (rev 1455)
@@ -13,11 +13,41 @@
wooly.doc().elembyid("{id}").node.elements[1].focus();
</script>
+[CuminStatus.javascript]
+function updateStatus(id, object) {
+ var ecount = object.events.errors
+ var errors = ecount + " " + (ecount == "1" && "error" || "errors");
+
+ var wcount = object.events.warnings
+ var warnings = wcount + " " + (wcount == "1" && "warning" || "warnings");
+
+ var status = wooly.doc().elembyid(id);
+
+ if (ecount != "0") {
+ status.setattr("class", "mstatus red");
+ } else if (wcount != "0") {
+ status.setattr("class", "mstatus yellow");
+ } else {
+ status.setattr("class", "mstatus green");
+ }
+
+ var divs = status.elems("div", null, null, 0, 2)
+
+ divs.next().set(errors + ", " + warnings);
+
+ var acount = object.actions.pending;
+ var actions = acount + " " + (acount == "1" && "action" || "actions") + " pending";
+
+ divs.next().set(actions);
+}
+
[CuminStatus.html]
<div id="{id}" class="{class}">
<h2>Status</h2>
<div>{status_info}</div>
+
+ <div>{actions_pending}</div>
</div>
[UnitSwitch.html]
Modified: mgmt/notes/justin-todo.txt
===================================================================
--- mgmt/notes/justin-todo.txt 2007-12-11 16:36:19 UTC (rev 1454)
+++ mgmt/notes/justin-todo.txt 2007-12-11 21:04:00 UTC (rev 1455)
@@ -30,12 +30,16 @@
* Render stats without values as something other than 0, say a --
- * Connect purge messages up
-
* Render the "" exchange as "Default"
* Add javascript for the check-all behavior
+ * Find some way to reattach brokers that come back after being down
+
+ * Email amqp-list, Jonathan, and Lana with doc requirements for mgmt
+
+ * Paginate queue bindings in exchange view
+
Deferred
* Add queue journal stats
18 years, 4 months
rhmessaging commits: r1454 - in mgmt: notes and 1 other directory.
by rhmessaging-commits@lists.jboss.org
Author: justi9
Date: 2007-12-11 11:36:19 -0500 (Tue, 11 Dec 2007)
New Revision: 1454
Modified:
mgmt/cumin/python/cumin/broker.py
mgmt/cumin/python/cumin/broker.strings
mgmt/notes/justin-todo.txt
Log:
Removes non-milestone-1 tabs from the broker view.
Adds more todo items.
Modified: mgmt/cumin/python/cumin/broker.py
===================================================================
--- mgmt/cumin/python/cumin/broker.py 2007-12-11 15:52:40 UTC (rev 1453)
+++ mgmt/cumin/python/cumin/broker.py 2007-12-11 16:36:19 UTC (rev 1454)
@@ -282,8 +282,8 @@
self.tabs.add_tab(self.BrokerClientTab(app, "clients"))
#self.config = self.BrokerConfigTab(app, "config")
#self.tabs.add_tab(self.config)
- self.tabs.add_tab(self.BrokerStatsTab(app, "stats"))
- self.tabs.add_tab(self.BrokerLogTab(app, "log"))
+ #self.tabs.add_tab(self.BrokerStatsTab(app, "stats"))
+ #self.tabs.add_tab(self.BrokerLogTab(app, "log"))
def show_config(self, session):
return self.tabs.show_mode(session, self.config)
Modified: mgmt/cumin/python/cumin/broker.strings
===================================================================
--- mgmt/cumin/python/cumin/broker.strings 2007-12-11 15:52:40 UTC (rev 1453)
+++ mgmt/cumin/python/cumin/broker.strings 2007-12-11 16:36:19 UTC (rev 1454)
@@ -9,8 +9,7 @@
<select name="{action_param_name}" onchange="submit()">
<option value="">Choose Action...</option>
- <option value="shutdown">Shutdown</option>
- <option value="loadbalance">Load Balance</option>
+ <option value="unregister">Unregister</option>
</select>
<h2>Add to Group:</h2>
@@ -136,13 +135,14 @@
<table class="props">
<tr><th>Name</th><td>{name}</td></tr>
+<!--
<tr><th>Cluster</th><td>{cluster_link}</td></tr>
<tr><th>Profile</th><td>{profile_link}</td></tr>
+-->
<tr><th>Version</th><td>{version}</td></tr>
<tr>
<th class="actions" colspan="2">
<h2>Act on This Broker:</h2>
- <a href="{href}">Shutdown</a>
<a href="{remove_href}">Unregister</a>
</th>
</tr>
Modified: mgmt/notes/justin-todo.txt
===================================================================
--- mgmt/notes/justin-todo.txt 2007-12-11 15:52:40 UTC (rev 1453)
+++ mgmt/notes/justin-todo.txt 2007-12-11 16:36:19 UTC (rev 1454)
@@ -1,7 +1,5 @@
Current
- * Add queue journal stats
-
* "purge messages from queues"
* "purge messages from queue"
@@ -10,8 +8,6 @@
* Add legends to charts
- * Prepare for journal stats on queue
-
* Make sure queue accel. a proper rate value
* Better demo data
@@ -22,8 +18,28 @@
* Sort in tables
+ * Add a ~3 second (or use broker update interval, if we can get that)
+ cache to *XmlPage
+
+ * Add said cache to ChartPages as well, perhaps
+
+ * Put broker connects on their own, separate thread so they do not
+ delay startup
+
+ * Connect queue, exchange, and broker dates to the data
+
+ * Render stats without values as something other than 0, say a --
+
+ * Connect purge messages up
+
+ * Render the "" exchange as "Default"
+
+ * Add javascript for the check-all behavior
+
Deferred
+ * Add queue journal stats
+
* Queue: Add a msg enq rate msg deq rate chart
* Restore the consumer, producer, and bindings stat links
18 years, 4 months
rhmessaging commits: r1453 - in mgmt: notes and 1 other directory.
by rhmessaging-commits@lists.jboss.org
Author: justi9
Date: 2007-12-11 10:52:40 -0500 (Tue, 11 Dec 2007)
New Revision: 1453
Modified:
mgmt/cumin/python/cumin/broker.strings
mgmt/cumin/python/cumin/page.py
mgmt/notes/justin-todo.txt
Log:
Removes broker clusters and profiles from the top-level ui.
Updates the todo list.
Modified: mgmt/cumin/python/cumin/broker.strings
===================================================================
--- mgmt/cumin/python/cumin/broker.strings 2007-12-11 15:23:33 UTC (rev 1452)
+++ mgmt/cumin/python/cumin/broker.strings 2007-12-11 15:52:40 UTC (rev 1453)
@@ -22,8 +22,10 @@
<tr>
<th><input type="checkbox"/></th>
<th>Name</th>
+<!--
<th>Profile</th>
<th>Cluster</th>
+-->
<th>Load</th>
<th>Status</th>
</tr>
@@ -38,8 +40,10 @@
<tr>
<td><input type="checkbox" name="{item_checkbox_name}" value="{item_checkbox_value}" {item_checkbox_checked_attr}/></td>
<td>{item_link}</td>
+<!--
<td>{item_profile_link}</td>
<td>{item_cluster_link}</td>
+-->
<td>{item_load}</td>
<td>{item_status}</td>
</tr>
@@ -157,12 +161,14 @@
<h2>Filter by Group</h2>
<ul class="slist">{group_filters}</ul>
+<!--
<h2>Filter by Profile</h2>
<ul class="slist">{profile_filters}</ul>
<h2>Filter by Cluster</h2>
<ul class="slist">{cluster_filters}</ul>
</td>
+-->
<td class="view">
<ul class="actions">
<li><a class="nav" href="{add_broker_href}">Register New Brokers</a></li>
Modified: mgmt/cumin/python/cumin/page.py
===================================================================
--- mgmt/cumin/python/cumin/page.py 2007-12-11 15:23:33 UTC (rev 1452)
+++ mgmt/cumin/python/cumin/page.py 2007-12-11 15:52:40 UTC (rev 1453)
@@ -166,9 +166,9 @@
self.add_tab(BrokerBrowser(app, "brokers"))
self.add_tab(BrokerGroupSet(app, "groups"))
- self.add_tab(BrokerProfileSet(app, "profiles"))
- self.add_tab(BrokerClusterSet(app, "clusters"))
- self.add_tab(self.TagTab(app, "tags"))
+ #self.add_tab(BrokerProfileSet(app, "profiles"))
+ #self.add_tab(BrokerClusterSet(app, "clusters"))
+ #self.add_tab(self.TagTab(app, "tags"))
def show_broker_group(self, session, group):
mode = self.show_mode(session, self.brokers)
Modified: mgmt/notes/justin-todo.txt
===================================================================
--- mgmt/notes/justin-todo.txt 2007-12-11 15:23:33 UTC (rev 1452)
+++ mgmt/notes/justin-todo.txt 2007-12-11 15:52:40 UTC (rev 1453)
@@ -14,20 +14,18 @@
* Make sure queue accel. a proper rate value
- * Paginate brokers
-
- * Paginate queues
-
* Better demo data
* Make group slider in broker browser work
+ * Add a groups column to the browser broker list
+
+ * Sort in tables
+
Deferred
* Queue: Add a msg enq rate msg deq rate chart
- * Sort in tables
-
* Restore the consumer, producer, and bindings stat links
* Add ability to send a test message to a queue
18 years, 4 months
rhmessaging commits: r1452 - mgmt/cumin/python/cumin.
by rhmessaging-commits@lists.jboss.org
Author: justi9
Date: 2007-12-11 10:23:33 -0500 (Tue, 11 Dec 2007)
New Revision: 1452
Modified:
mgmt/cumin/python/cumin/broker.py
mgmt/cumin/python/cumin/queue.py
Log:
Try to avoid generating so many queries.
The change to ExchangeInputSet should avoid half of the per-row stats
queries, but it dowsn't. Still working on that.
Modified: mgmt/cumin/python/cumin/broker.py
===================================================================
--- mgmt/cumin/python/cumin/broker.py 2007-12-10 21:50:07 UTC (rev 1451)
+++ mgmt/cumin/python/cumin/broker.py 2007-12-11 15:23:33 UTC (rev 1452)
@@ -42,11 +42,14 @@
self.add_child(self.paginator)
def get_title(self, session, model):
- return "Brokers %s" % fmt_count(BrokerRegistration.select().count())
+ return "Brokers %s" % fmt_count(self.get_item_count(session, model))
+ def get_item_count(self, session, model):
+ return BrokerRegistration.select().count()
+
def do_get_items(self, session, model):
start, end = self.paginator.get_bounds(session)
- return BrokerRegistration.select()[start:end]
+ return BrokerRegistration.select(orderBy="name")[start:end]
def do_process(self, session, model):
if self.submit.get(session):
@@ -70,7 +73,8 @@
self.page().set_redirect_url(session, session.marshal())
else:
- self.paginator.set_count(session, BrokerRegistration.select().count())
+ count = self.get_item_count(session, model)
+ self.paginator.set_count(session, count)
def render_action_param_name(self, session, broker):
return self.action.path()
Modified: mgmt/cumin/python/cumin/queue.py
===================================================================
--- mgmt/cumin/python/cumin/queue.py 2007-12-10 21:50:07 UTC (rev 1451)
+++ mgmt/cumin/python/cumin/queue.py 2007-12-11 15:23:33 UTC (rev 1452)
@@ -4,6 +4,7 @@
from wooly.forms import *
from wooly.resources import *
from datetime import datetime
+from sqlobject.sqlbuilder import LEFTJOINOn
from exchange import ExchangeInputSet
from stat import *
@@ -43,6 +44,7 @@
if vhost:
start, end = self.paginator.get_bounds(session)
return Queue.select(Queue.q.vhostID == vhost.id,
+ join=LEFTJOINOn(None, QueueStats, Queue.q.statsCurrID == QueueStats.q.id),
orderBy="name")[start:end]
def render_item_link(self, session, queue):
18 years, 4 months
rhmessaging commits: r1451 - in store/trunk/cpp/lib: jrnl and 1 other directory.
by rhmessaging-commits@lists.jboss.org
Author: kpvdr
Date: 2007-12-10 16:50:07 -0500 (Mon, 10 Dec 2007)
New Revision: 1451
Modified:
store/trunk/cpp/lib/BdbMessageStore.cpp
store/trunk/cpp/lib/JournalImpl.cpp
store/trunk/cpp/lib/JournalImpl.h
store/trunk/cpp/lib/jrnl/jcfg.hpp
store/trunk/cpp/lib/jrnl/jcntl.cpp
store/trunk/cpp/lib/jrnl/jcntl.hpp
store/trunk/cpp/lib/jrnl/rcvdat.hpp
store/trunk/cpp/lib/jrnl/txn_map.cpp
Log:
Minor fixes and cleanup
Modified: store/trunk/cpp/lib/BdbMessageStore.cpp
===================================================================
--- store/trunk/cpp/lib/BdbMessageStore.cpp 2007-12-10 19:34:57 UTC (rev 1450)
+++ store/trunk/cpp/lib/BdbMessageStore.cpp 2007-12-10 21:50:07 UTC (rev 1451)
@@ -898,7 +898,8 @@
try {
JournalImpl* jc = static_cast<JournalImpl*>(queue.getExternalQueueStore());
if (jc){
- jc->flush();
+ // TODO: check if this result should be used...
+ /*rhm::journal::iores res =*/ jc->flush();
}
}catch (const journal::jexception& e) {
THROW_STORE_EXCEPTION(std::string("Queue ") + queue.getName() + ": flush() failed: " + e.what() );
Modified: store/trunk/cpp/lib/JournalImpl.cpp
===================================================================
--- store/trunk/cpp/lib/JournalImpl.cpp 2007-12-10 19:34:57 UTC (rev 1450)
+++ store/trunk/cpp/lib/JournalImpl.cpp 2007-12-10 21:50:07 UTC (rev 1451)
@@ -240,15 +240,16 @@
jcntl::stop(block_till_aio_cmpl);
}
-void
+const iores
JournalImpl::flush()
{
- jcntl::flush();
+ const iores res = jcntl::flush();
if (_wmgr.get_aio_evt_rem() && !getEventsTimerSetFlag) {
getEventsFireEventsPtr->addRef();
journalTimer.add(getEventsFireEventsPtr);
getEventsTimerSetFlag = true;
}
+ return res;
}
void
Modified: store/trunk/cpp/lib/JournalImpl.h
===================================================================
--- store/trunk/cpp/lib/JournalImpl.h 2007-12-10 19:34:57 UTC (rev 1450)
+++ store/trunk/cpp/lib/JournalImpl.h 2007-12-10 21:50:07 UTC (rev 1451)
@@ -136,7 +136,7 @@
void stop(bool block_till_aio_cmpl = false);
// Overrides for get_events timer
- void flush();
+ const journal::iores flush();
// TimerTask callback
void getEventsFire();
Modified: store/trunk/cpp/lib/jrnl/jcfg.hpp
===================================================================
--- store/trunk/cpp/lib/jrnl/jcfg.hpp 2007-12-10 19:34:57 UTC (rev 1450)
+++ store/trunk/cpp/lib/jrnl/jcfg.hpp 2007-12-10 21:50:07 UTC (rev 1451)
@@ -33,9 +33,6 @@
#ifndef rhm_journal_jcfg_hpp
#define rhm_journal_jcfg_hpp
-// #include <iomanip> // for debug only
-// #include <iostream> // for debug only
-
#if defined(__i386__) /* little endian, 32 bits */
#define JRNL_LITTLE_ENDIAN
#define JRNL_32_BIT
Modified: store/trunk/cpp/lib/jrnl/jcntl.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/jcntl.cpp 2007-12-10 19:34:57 UTC (rev 1450)
+++ store/trunk/cpp/lib/jrnl/jcntl.cpp 2007-12-10 21:50:07 UTC (rev 1451)
@@ -146,7 +146,7 @@
throw jexception(jerrno::JERR_JCNTL_RECOVERJFULL, "jcntl", "recover_complete");
// Debug info; may be useful to print with a flag
- // _rcvdat.print(_jid);
+ // std::cout << _rcvdat.to_string(_jid) << std::endl;
if (_datafh)
{
@@ -329,15 +329,15 @@
}
}
-void
+const iores
jcntl::flush()
{
if (!_init_flag)
- return;
+ return RHM_IORES_SUCCESS;
if (_readonly_flag)
throw jexception(jerrno::JERR_JCNTL_READONLY, "jcntl", "flush");
slock s(&_mutex);
- _wmgr.flush();
+ return _wmgr.flush();
}
// Private functions
Modified: store/trunk/cpp/lib/jrnl/jcntl.hpp
===================================================================
--- store/trunk/cpp/lib/jrnl/jcntl.hpp 2007-12-10 19:34:57 UTC (rev 1450)
+++ store/trunk/cpp/lib/jrnl/jcntl.hpp 2007-12-10 21:50:07 UTC (rev 1451)
@@ -545,7 +545,7 @@
/**
* \brief Force a flush of the write page cache, creating a single AIO write operation.
*/
- void flush();
+ const iores flush();
inline const u_int32_t get_enq_cnt() const { return _emap.size(); }
Modified: store/trunk/cpp/lib/jrnl/rcvdat.hpp
===================================================================
--- store/trunk/cpp/lib/jrnl/rcvdat.hpp 2007-12-10 19:34:57 UTC (rev 1450)
+++ store/trunk/cpp/lib/jrnl/rcvdat.hpp 2007-12-10 21:50:07 UTC (rev 1451)
@@ -32,9 +32,9 @@
#ifndef rhm_journal_rcvdat_hpp
#define rhm_journal_rcvdat_hpp
-#include <iostream>
#include <iomanip>
#include <map>
+#include <sstream>
#include <vector>
namespace rhm
@@ -80,26 +80,25 @@
_enq_cnt_list[f] = 0;
}
- void print(std::string& jid)
+ std::string to_string(std::string& jid)
{
- std::cout << "Jorunal file analysis (jid=\"" << jid << "\"):" << std::endl;
- std::cout << " Overwrite indicator (_owi) = " << (_owi ? "TRUE" : "FALSE") <<
- std::endl;
- std::cout << " Journal empty (_empty) = " << (_empty ? "TRUE" : "FALSE") <<
- std::endl;
- std::cout << " First fid (_ffid) = " << _ffid << std::endl;
- std::cout << " First record offset in first fid (_fro) = 0x" << std::hex << _fro <<
+ std::ostringstream oss;
+ oss << "Jorunal file analysis (jid=\"" << jid << "\"):" << std::endl;
+ oss << " Overwrite indicator (_owi) = " << (_owi ? "TRUE" : "FALSE") << std::endl;
+ oss << " Journal empty (_empty) = " << (_empty ? "TRUE" : "FALSE") << std::endl;
+ oss << " First fid (_ffid) = " << _ffid << std::endl;
+ oss << " First record offset in first fid (_fro) = 0x" << std::hex << _fro <<
std::dec << " (" << (_fro/JRNL_DBLK_SIZE) << " dblks)" << std::endl;
- std::cout << " Last fid (_lfid) = " << _lfid << std::endl;
- std::cout << " End offset (_eo) = 0x" << std::hex << _eo << std::dec << " (" <<
+ oss << " Last fid (_lfid) = " << _lfid << std::endl;
+ oss << " End offset (_eo) = 0x" << std::hex << _eo << std::dec << " (" <<
(_eo/JRNL_DBLK_SIZE) << " dblks)" << std::endl;
- std::cout << " Highest rid (_h_rid) = 0x" << std::hex << _h_rid << std::dec <<
- std::endl;
- std::cout << " Journal full (_full) = " << (_full ? "TRUE" : "FALSE") << std::endl;
- std::cout << " Enqueued records (txn & non-txn):" << std::endl;
+ oss << " Highest rid (_h_rid) = 0x" << std::hex << _h_rid << std::dec << std::endl;
+ oss << " Journal full (_full) = " << (_full ? "TRUE" : "FALSE") << std::endl;
+ oss << " Enqueued records (txn & non-txn):" << std::endl;
for (unsigned i=0; i<_enq_cnt_list.size(); i++)
- std::cout << " File " << std::setw(2) << i << ": " << _enq_cnt_list[i] <<
+ oss << " File " << std::setw(2) << i << ": " << _enq_cnt_list[i] <<
std::endl;
+ return oss.str();
}
};
}
Modified: store/trunk/cpp/lib/jrnl/txn_map.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/txn_map.cpp 2007-12-10 19:34:57 UTC (rev 1450)
+++ store/trunk/cpp/lib/jrnl/txn_map.cpp 2007-12-10 21:50:07 UTC (rev 1451)
@@ -154,11 +154,9 @@
ss << std::hex << "xid=\"" << xid << "\"";
throw jexception(jerrno::JERR_MAP_NOTFOUND, ss.str().c_str(), "txn_map", "is_txn_synced");
}
-//std::cout << " its: found XID" << std::flush;
bool is_synced = true;
for (tdl_itr litr = itr->second.begin(); litr < itr->second.end(); litr++)
{
-//std::cout << " rid=" << litr->_rid << " aioc=" << litr->_aio_compl << std::flush;
if (!litr->_aio_compl)
{
is_synced = false;
@@ -180,19 +178,12 @@
ok = false;
else
{
-//std::cout << " sac: found XID" << std::flush;
-// txn_data_list list = itr->second;
for (tdl_itr litr = itr->second.begin(); litr < itr->second.end(); litr++)
{
if (litr->_rid == rid)
{
-// txn_data_struct t(litr->_rid, litr->_drid, litr->_fid, litr->_enq_flag);
-// t._aio_compl = true;
-// itr->second.erase(litr);
-// itr->second.push_back(t);
found = true;
litr->_aio_compl = true;
-//std::cout << " rid=" << rid << " aioc=" << litr->_aio_compl << " ptr=" << std::flush;
break;
}
}
18 years, 4 months
rhmessaging commits: r1450 - in store/trunk/cpp/lib: jrnl and 1 other directory.
by rhmessaging-commits@lists.jboss.org
Author: kpvdr
Date: 2007-12-10 14:34:57 -0500 (Mon, 10 Dec 2007)
New Revision: 1450
Added:
store/trunk/cpp/lib/jrnl/slock.hpp
Modified:
store/trunk/cpp/lib/BdbMessageStore.cpp
store/trunk/cpp/lib/Makefile.am
store/trunk/cpp/lib/jrnl/jcntl.cpp
store/trunk/cpp/lib/jrnl/jcntl.hpp
store/trunk/cpp/lib/jrnl/jexception.hpp
store/trunk/cpp/lib/jrnl/rcvdat.hpp
store/trunk/cpp/lib/jrnl/wmgr.cpp
store/trunk/cpp/lib/jrnl/wrfc.cpp
Log:
Fixed error in owi initialization on recover (which gave a 50% chance of a recover exception). Also replaced mutexes with s simple scoped lock class for write mutex. Added catch for condition RHM_IORES_FULL in dequeue.
Modified: store/trunk/cpp/lib/BdbMessageStore.cpp
===================================================================
--- store/trunk/cpp/lib/BdbMessageStore.cpp 2007-12-10 17:05:06 UTC (rev 1449)
+++ store/trunk/cpp/lib/BdbMessageStore.cpp 2007-12-10 19:34:57 UTC (rev 1450)
@@ -1026,8 +1026,8 @@
usleep(AIO_SLEEP_TIME); // TODO add sleep time to get events call as option
break;
case rhm::journal::RHM_IORES_FULL:
- std::cerr << "Error storing message -- Journal full on queue \"" << queue->getName() << "\"." << std::endl << std::flush;
- THROW_STORE_FULL_EXCEPTION("Error storing message -- Journal full :" + queue->getName());
+ std::cerr << "Enqueue: Error storing record -- Journal full on queue \"" << queue->getName() << "\"." << std::endl << std::flush;
+ THROW_STORE_FULL_EXCEPTION("Enqueue: Error storing record -- Journal full on queue \"" + queue->getName() + "\".");
break;
default:
assert( "Store Error: Unexpected msg state");
@@ -1167,6 +1167,10 @@
THROW_STORE_EXCEPTION("Timeout waiting for mutex: RHM_IORES_BUSY");
usleep(AIO_SLEEP_TIME); // TODO add sleep time to get events call as option
break;
+ case rhm::journal::RHM_IORES_FULL:
+ std::cerr << "Dequeue: Error storing record -- Journal full on queue \"" << queue.getName() << "\"." << std::endl << std::flush;
+ THROW_STORE_FULL_EXCEPTION("Dequeue: Error storing record -- Journal full on queue \"" + queue.getName() + "\".");
+ break;
default:
assert( "Store Error: Unexpected msg state");
}
Modified: store/trunk/cpp/lib/Makefile.am
===================================================================
--- store/trunk/cpp/lib/Makefile.am 2007-12-10 17:05:06 UTC (rev 1449)
+++ store/trunk/cpp/lib/Makefile.am 2007-12-10 19:34:57 UTC (rev 1450)
@@ -76,6 +76,7 @@
jrnl/rcvdat.hpp \
jrnl/rmgr.hpp \
jrnl/rrfc.hpp \
+ jrnl/slock.hpp \
jrnl/txn_map.hpp \
jrnl/txn_rec.hpp \
jrnl/wmgr.hpp \
Modified: store/trunk/cpp/lib/jrnl/jcntl.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/jcntl.cpp 2007-12-10 17:05:06 UTC (rev 1449)
+++ store/trunk/cpp/lib/jrnl/jcntl.cpp 2007-12-10 19:34:57 UTC (rev 1450)
@@ -139,14 +139,14 @@
_rcvdat.reset();
_emap.clear();
_tmap.clear();
-//std::cout << "Starting journal analysis..." << std::endl;
+
rcvr_janalyze(_rcvdat, prep_txn_list);
highest_rid = _rcvdat._h_rid;
if (_rcvdat._full)
throw jexception(jerrno::JERR_JCNTL_RECOVERJFULL, "jcntl", "recover_complete");
-// Debug info, but may be useful to print with a flag
-//_rcvdat.print(_jid);
+ // Debug info; may be useful to print with a flag
+ // _rcvdat.print(_jid);
if (_datafh)
{
@@ -177,7 +177,6 @@
_readonly_flag = true;
_init_flag = true;
-//std::cout << "Journal analysis complete." << std::endl;
}
void
@@ -191,7 +190,6 @@
_rrfc.initialize(_num_jfiles, (nlfh**)_datafh, _rcvdat._ffid);
_rmgr.recover_complete(_rcvdat._fro);
_readonly_flag = false;
-//std::cout << "Journal revovery complete." << std::endl;
}
void
@@ -206,32 +204,17 @@
jcntl::enqueue_data_record(const void* const data_buff, const size_t tot_data_len,
const size_t this_data_len, data_tok* dtokp, const bool transient)
{
- iores res;
check_wstatus("enqueue_data_record");
- pthread_mutex_lock(&_mutex);
- try
- {
- res = _wmgr.enqueue(data_buff, tot_data_len, this_data_len, dtokp, NULL, 0, transient,
- false);
- }
- catch(const std::exception& e) { pthread_mutex_unlock(&_mutex); throw; }
- pthread_mutex_unlock(&_mutex);
- return res;
+ slock s(&_mutex);
+ return _wmgr.enqueue(data_buff, tot_data_len, this_data_len, dtokp, NULL, 0, transient, false);
}
const iores
jcntl::enqueue_extern_data_record(const size_t tot_data_len, data_tok* dtokp, const bool transient)
{
- iores res;
check_wstatus("enqueue_extern_data_record");
- pthread_mutex_lock(&_mutex);
- try
- {
- res = _wmgr.enqueue(NULL, tot_data_len, 0, dtokp, NULL, 0, transient, true);
- }
- catch(const std::exception& e) { pthread_mutex_unlock(&_mutex); throw; }
- pthread_mutex_unlock(&_mutex);
- return res;
+ slock s(&_mutex);
+ return _wmgr.enqueue(NULL, tot_data_len, 0, dtokp, NULL, 0, transient, true);
}
const iores
@@ -239,33 +222,19 @@
const size_t this_data_len, data_tok* dtokp, const std::string& xid,
const bool transient)
{
- iores res;
check_wstatus("enqueue_tx_data_record");
- pthread_mutex_lock(&_mutex);
- try
- {
- res = _wmgr.enqueue(data_buff, tot_data_len, this_data_len, dtokp, xid.data(), xid.size(),
- transient, false);
- }
- catch(const std::exception& e) { pthread_mutex_unlock(&_mutex); throw; }
- pthread_mutex_unlock(&_mutex);
- return res;
+ slock s(&_mutex);
+ return _wmgr.enqueue(data_buff, tot_data_len, this_data_len, dtokp, xid.data(), xid.size(),
+ transient, false);
}
const iores
jcntl::enqueue_extern_txn_data_record(const size_t tot_data_len, data_tok* dtokp,
const std::string& xid, const bool transient)
{
- iores res;
check_wstatus("enqueue_extern_txn_data_record");
- pthread_mutex_lock(&_mutex);
- try
- {
- res = _wmgr.enqueue(NULL, tot_data_len, 0, dtokp, xid.data(), xid.size(), transient, true);
- }
- catch(const std::exception& e) { pthread_mutex_unlock(&_mutex); throw; }
- pthread_mutex_unlock(&_mutex);
- return res;
+ slock s(&_mutex);
+ return _wmgr.enqueue(NULL, tot_data_len, 0, dtokp, xid.data(), xid.size(), transient, true);
}
const iores
@@ -294,49 +263,33 @@
const iores
jcntl::dequeue_data_record(data_tok* const dtokp)
{
- iores res;
check_wstatus("dequeue_data");
- pthread_mutex_lock(&_mutex);
- try { res = _wmgr.dequeue(dtokp, NULL, 0); }
- catch(const std::exception& e) { pthread_mutex_unlock(&_mutex); throw; }
- pthread_mutex_unlock(&_mutex);
- return res;
+ slock s(&_mutex);
+ return _wmgr.dequeue(dtokp, NULL, 0);
}
const iores
jcntl::dequeue_txn_data_record(data_tok* const dtokp, const std::string& xid)
{
- iores res;
check_wstatus("dequeue_data");
- pthread_mutex_lock(&_mutex);
- try { res = _wmgr.dequeue(dtokp, xid.data(), xid.size()); }
- catch(const std::exception& e) { pthread_mutex_unlock(&_mutex); throw; }
- pthread_mutex_unlock(&_mutex);
- return res;
+ slock s(&_mutex);
+ return _wmgr.dequeue(dtokp, xid.data(), xid.size());
}
const iores
jcntl::txn_abort(data_tok* const dtokp, const std::string& xid)
{
- iores res;
check_wstatus("txn_abort");
- pthread_mutex_lock(&_mutex);
- try { res = _wmgr.abort(dtokp, xid.data(), xid.size()); }
- catch(const std::exception& e) { pthread_mutex_unlock(&_mutex); throw; }
- pthread_mutex_unlock(&_mutex);
- return res;
+ slock s(&_mutex);
+ return _wmgr.abort(dtokp, xid.data(), xid.size());
}
const iores
jcntl::txn_commit(data_tok* const dtokp, const std::string& xid)
{
- iores res;
check_wstatus("txn_commit");
- pthread_mutex_lock(&_mutex);
- try { res = _wmgr.commit(dtokp, xid.data(), xid.size()); }
- catch(const std::exception& e) { pthread_mutex_unlock(&_mutex); throw; }
- pthread_mutex_unlock(&_mutex);
- return res;
+ slock s(&_mutex);
+ return _wmgr.commit(dtokp, xid.data(), xid.size());
}
const bool
@@ -348,22 +301,10 @@
const u_int32_t
jcntl::get_wr_events()
{
- u_int32_t res;
- int ret = pthread_mutex_trylock(&_mutex);
- if (ret)
- {
- if (ret != EBUSY)
- {
- std::stringstream ss;
- ss << "pthread_mutex_trylock() returned " << errno << " (" << strerror(errno) << ")";
- throw jexception(jerrno::JERR__PTHREAD, ss.str().c_str(), "jcntl", "get_wr_events");
- }
- return 0; // already locked, return immediately
- }
- try { res = _wmgr.get_events(pmgr::UNUSED); }
- catch(const std::exception& e) { pthread_mutex_unlock(&_mutex); throw; }
- pthread_mutex_unlock(&_mutex);
- return res;
+ stlock t(&_mutex);
+ if (t.locked())
+ return _wmgr.get_events(pmgr::UNUSED);
+ return 0;
}
const u_int32_t
@@ -395,10 +336,8 @@
return;
if (_readonly_flag)
throw jexception(jerrno::JERR_JCNTL_READONLY, "jcntl", "flush");
- pthread_mutex_lock(&_mutex);
- try { _wmgr.flush(); }
- catch(const std::exception& e) { pthread_mutex_unlock(&_mutex); throw; }
- pthread_mutex_unlock(&_mutex);
+ slock s(&_mutex);
+ _wmgr.flush();
}
// Private functions
@@ -491,7 +430,8 @@
{
u_int16_t fid = rd._ffid;
std::ifstream ifs;
- while (rcvr_get_next_record(fid, &ifs, rd));
+ bool lowi = rd._owi; // local copy of owi to be used during analysis
+ while (rcvr_get_next_record(fid, &ifs, lowi, rd));
// Check for journal full condition
u_int16_t next_wr_fid = (rd._lfid + 1) % _num_jfiles;
@@ -512,12 +452,12 @@
}
const bool
-jcntl::rcvr_get_next_record(u_int16_t& fid, std::ifstream* ifsp, rcvdat& rd)
+jcntl::rcvr_get_next_record(u_int16_t& fid, std::ifstream* ifsp, bool& lowi, rcvdat& rd)
{
size_t cum_size_read = 0;
void* xidp = NULL;
hdr h;
- if (!jfile_cycle(fid, ifsp, rd, true))
+ if (!jfile_cycle(fid, ifsp, lowi, rd, true))
return false;
std::streampos read_pos = ifsp->tellg();
ifsp->read((char*)&h, sizeof(hdr));
@@ -526,7 +466,7 @@
case RHM_JDAT_ENQ_MAGIC:
{
enq_rec er;
- if (!decode(er, fid, ifsp, cum_size_read, h, rd, read_pos))
+ if (!decode(er, fid, ifsp, cum_size_read, h, lowi, rd, read_pos))
return false;
if (!er.is_transient()) // Ignore transient msgs
{
@@ -547,7 +487,7 @@
case RHM_JDAT_DEQ_MAGIC:
{
deq_rec dr;
- if (!decode(dr, fid, ifsp, cum_size_read, h, rd, read_pos))
+ if (!decode(dr, fid, ifsp, cum_size_read, h, lowi, rd, read_pos))
return false;
if (dr.xid_size())
{
@@ -580,7 +520,7 @@
case RHM_JDAT_TXA_MAGIC:
{
txn_rec ar;
- if (!decode(ar, fid, ifsp, cum_size_read, h, rd, read_pos))
+ if (!decode(ar, fid, ifsp, cum_size_read, h, lowi, rd, read_pos))
return false;
// Delete this txn from tmap, unlock any locked records in emap
ar.get_xid(&xidp);
@@ -607,7 +547,7 @@
case RHM_JDAT_TXC_MAGIC:
{
txn_rec cr;
- if (!decode(cr, fid, ifsp, cum_size_read, h, rd, read_pos))
+ if (!decode(cr, fid, ifsp, cum_size_read, h, lowi, rd, read_pos))
return false;
// Delete this txn from tmap, process records into emap
cr.get_xid(&xidp);
@@ -656,9 +596,9 @@
const bool
jcntl::decode(jrec& rec, u_int16_t& fid, std::ifstream* ifsp, size_t& cum_size_read, hdr& h,
- rcvdat& rd, std::streampos& rec_offset)
+ bool& lowi, rcvdat& rd, std::streampos& rec_offset)
{
- if (!check_owi(fid, h, rd, rec_offset))
+ if (!check_owi(fid, h, lowi, rd, rec_offset))
return false;
bool done = false;
while (!done)
@@ -673,14 +613,14 @@
rd._eo = rec_offset;
return false;
}
- if (!jfile_cycle(fid, ifsp, rd, false))
+ if (!jfile_cycle(fid, ifsp, lowi, rd, false))
return false;
}
return true;
}
const bool
-jcntl::jfile_cycle(u_int16_t& fid, std::ifstream* ifsp, rcvdat& rd, const bool jump_fro)
+jcntl::jfile_cycle(u_int16_t& fid, std::ifstream* ifsp, bool& lowi, rcvdat& rd, const bool jump_fro)
{
if (ifsp->is_open())
{
@@ -692,7 +632,7 @@
if (fid >= _num_jfiles)
{
fid = 0;
- rd._owi = !rd._owi; // Flip owi
+ lowi = !lowi; // Flip local owi
}
if (fid == rd._ffid) // used up all journal files
return false;
@@ -728,9 +668,9 @@
}
const bool
-jcntl::check_owi(const u_int16_t fid, hdr& h, rcvdat& rd, std::streampos& read_pos)
+jcntl::check_owi(const u_int16_t fid, hdr& h, bool& lowi, rcvdat& rd, std::streampos& read_pos)
{
- if (rd._ffid ? h.get_owi() == rd._owi : h.get_owi() != rd._owi) // Overwrite indicator changed
+ if (rd._ffid ? h.get_owi() == lowi : h.get_owi() != lowi) // Overwrite indicator changed
{
u_int16_t expected_fid = rd._ffid ? rd._ffid - 1 : _num_jfiles - 1;
if (fid == expected_fid)
Modified: store/trunk/cpp/lib/jrnl/jcntl.hpp
===================================================================
--- store/trunk/cpp/lib/jrnl/jcntl.hpp 2007-12-10 17:05:06 UTC (rev 1449)
+++ store/trunk/cpp/lib/jrnl/jcntl.hpp 2007-12-10 19:34:57 UTC (rev 1450)
@@ -46,9 +46,9 @@
#include <jrnl/lfh.hpp>
#include <jrnl/rcvdat.hpp>
#include <jrnl/rmgr.hpp>
+#include <jrnl/slock.hpp>
#include <jrnl/wmgr.hpp>
#include <jrnl/wrfc.hpp>
-#include <pthread.h>
#include <qpid/broker/PersistableQueue.h>
namespace rhm
@@ -548,12 +548,16 @@
void flush();
inline const u_int32_t get_enq_cnt() const { return _emap.size(); }
+
inline const u_int32_t get_wr_outstanding_aio_dblks() const
{ return _wrfc.aio_outstanding_dblks(); }
+
inline const u_int32_t get_wr_outstanding_aio_dblks(u_int16_t pi) const
{ return _wrfc.file_handle(pi)->wr_aio_outstanding_dblks(); }
+
inline const u_int32_t get_rd_outstanding_aio_dblks() const
{ return _rrfc.aio_outstanding_dblks(); }
+
inline const u_int32_t get_rd_outstanding_aio_dblks(u_int16_t pi) const
{ return _rrfc.file_handle(pi)->rd_aio_outstanding_dblks(); }
@@ -639,15 +643,17 @@
*/
void rcvr_janalyze(rcvdat& rd, const std::vector<std::string>& prep_txn_list);
- const bool rcvr_get_next_record(u_int16_t& fid, std::ifstream* ifsp, rcvdat& rd);
+ const bool rcvr_get_next_record(u_int16_t& fid, std::ifstream* ifsp, bool& lowi,
+ rcvdat& rd);
const bool decode(jrec& rec, u_int16_t& fid, std::ifstream* ifsp, size_t& cum_size_read,
- hdr& h, rcvdat& rd, std::streampos& rec_offset);
+ hdr& h, bool& lowi, rcvdat& rd, std::streampos& rec_offset);
- const bool jfile_cycle(u_int16_t& fid, std::ifstream* ifsp, rcvdat& rd,
+ 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, rcvdat& rd, std::streampos& read_pos);
+ const bool check_owi(const u_int16_t fid, 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/jexception.hpp
===================================================================
--- store/trunk/cpp/lib/jrnl/jexception.hpp 2007-12-10 17:05:06 UTC (rev 1449)
+++ store/trunk/cpp/lib/jrnl/jexception.hpp 2007-12-10 19:34:57 UTC (rev 1450)
@@ -49,13 +49,20 @@
// Macro for formatting commom system errors
#define FORMAT_SYSERR(errno) " errno=" << errno << " (" << strerror(errno) << ")"
-#define MALLOC_CHK(ptr, var, cls, fn) if (ptr == NULL) { \
+
+#define MALLOC_CHK(ptr, var, cls, fn) if(ptr == NULL) { \
clean(); \
std::stringstream ss; \
ss << var << ": malloc() failed: " << FORMAT_SYSERR(errno); \
throw jexception(jerrno::JERR__MALLOC, ss.str().c_str(), cls, fn); \
}
+#define PTHREAD_CHK(err, pfn, cls, fn) if(err != 0) { \
+ std::stringstream ss; \
+ ss << pfn << " failed: " << FORMAT_SYSERR(err); \
+ throw jexception(jerrno::JERR__PTHREAD, ss.str().c_str(), cls, fn); \
+ }
+
#define MAX_MSG_SIZE 1024
#define MAX_THROWING_SIZE 128
Modified: store/trunk/cpp/lib/jrnl/rcvdat.hpp
===================================================================
--- store/trunk/cpp/lib/jrnl/rcvdat.hpp 2007-12-10 17:05:06 UTC (rev 1449)
+++ store/trunk/cpp/lib/jrnl/rcvdat.hpp 2007-12-10 19:34:57 UTC (rev 1450)
@@ -83,6 +83,8 @@
void print(std::string& jid)
{
std::cout << "Jorunal file analysis (jid=\"" << jid << "\"):" << std::endl;
+ std::cout << " Overwrite indicator (_owi) = " << (_owi ? "TRUE" : "FALSE") <<
+ std::endl;
std::cout << " Journal empty (_empty) = " << (_empty ? "TRUE" : "FALSE") <<
std::endl;
std::cout << " First fid (_ffid) = " << _ffid << std::endl;
Added: store/trunk/cpp/lib/jrnl/slock.hpp
===================================================================
--- store/trunk/cpp/lib/jrnl/slock.hpp (rev 0)
+++ store/trunk/cpp/lib/jrnl/slock.hpp 2007-12-10 19:34:57 UTC (rev 1450)
@@ -0,0 +1,86 @@
+/**
+* \file slock.hpp
+*
+* Red Hat Messaging - Message Journal
+*
+* Messaging journal top-level control and interface class
+* rhm::journal::slock. See class documentation 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.
+*/
+
+#ifndef rhm_journal_slock_hpp
+#define rhm_journal_slock_hpp
+
+#include <pthread.h>
+#include <jrnl/jerrno.hpp>
+#include <jrnl/jexception.hpp>
+
+namespace rhm
+{
+namespace journal
+{
+
+ // Ultra-simple scoped lock class, auto-releases mutex when it goes out-of-scope
+ class slock
+ {
+ protected:
+ pthread_mutex_t* _m;
+ public:
+ inline slock(pthread_mutex_t* m) : _m(m)
+ {
+ PTHREAD_CHK(pthread_mutex_lock(_m), "pthread_mutex_lock", "slock", "slock");
+ }
+ inline ~slock()
+ {
+ PTHREAD_CHK(pthread_mutex_unlock(_m), "pthread_mutex_unlock", "slock", "~slock");
+ }
+ };
+
+ // Ultra-simple scoped try-lock class, auto-releases mutex when it goes out-of-scope
+ class stlock
+ {
+ protected:
+ pthread_mutex_t* _m;
+ bool _locked;
+ public:
+ inline stlock(pthread_mutex_t* m) : _m(m), _locked(false)
+ {
+ int ret = pthread_mutex_trylock(_m);
+ _locked = (ret == 0); // check if lock obtained
+ if (!_locked && ret != EBUSY) PTHREAD_CHK(ret, "pthread_mutex_trylock", "stlock",
+ "stlock");
+ }
+ inline ~stlock()
+ {
+ if (_locked)
+ PTHREAD_CHK(pthread_mutex_unlock(_m), "pthread_mutex_unlock", "stlock", "~stlock");
+ }
+ inline const bool locked() const { return _locked; }
+ };
+
+} // namespace journal
+} // namespace rhm
+
+#endif // ifndef rhm_journal_slock_hpp
Modified: store/trunk/cpp/lib/jrnl/wmgr.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/wmgr.cpp 2007-12-10 17:05:06 UTC (rev 1449)
+++ store/trunk/cpp/lib/jrnl/wmgr.cpp 2007-12-10 19:34:57 UTC (rev 1450)
@@ -118,13 +118,13 @@
if (this_data_len != tot_data_len && !external)
return RHM_IORES_NOTIMPL;
- if (_deq_busy || _abort_busy || _commit_busy)
- return RHM_IORES_BUSY;
-
iores res = pre_write_check(WMGR_ENQUEUE, dtokp);
if (res != RHM_IORES_SUCCESS)
return res;
+ if (_deq_busy || _abort_busy || _commit_busy)
+ return RHM_IORES_BUSY;
+
bool cont = false;
if (_enq_busy) // If enqueue() exited last time with RHM_IORES_FULL or RHM_IORES_AIO_WAIT
{
@@ -254,13 +254,13 @@
if (xid_len)
assert(xid_ptr != NULL);
- if (_enq_busy || _abort_busy || _commit_busy)
- return RHM_IORES_BUSY;
-
iores res = pre_write_check(WMGR_DEQUEUE, dtokp);
if (res != RHM_IORES_SUCCESS)
return res;
+ if (_enq_busy || _abort_busy || _commit_busy)
+ return RHM_IORES_BUSY;
+
bool cont = false;
if (_deq_busy) // If dequeue() exited last time with RHM_IORES_FULL or RHM_IORES_AIO_WAIT
{
Modified: store/trunk/cpp/lib/jrnl/wrfc.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/wrfc.cpp 2007-12-10 17:05:06 UTC (rev 1449)
+++ store/trunk/cpp/lib/jrnl/wrfc.cpp 2007-12-10 19:34:57 UTC (rev 1450)
@@ -61,6 +61,7 @@
rrfc::initialize(nfiles, fh_arr, rdp->_lfid);
_rid = rdp->_h_rid + 1;
_reset_ok = true;
+ _owi = rdp->_owi;
}
else
{
18 years, 4 months
rhmessaging commits: r1449 - mgmt/cumin/python/cumin.
by rhmessaging-commits@lists.jboss.org
Author: justi9
Date: 2007-12-10 12:05:06 -0500 (Mon, 10 Dec 2007)
New Revision: 1449
Modified:
mgmt/cumin/python/cumin/formats.py
Log:
For demo purposes, add some random status changes.
Modified: mgmt/cumin/python/cumin/formats.py
===================================================================
--- mgmt/cumin/python/cumin/formats.py 2007-12-10 16:57:09 UTC (rev 1448)
+++ mgmt/cumin/python/cumin/formats.py 2007-12-10 17:05:06 UTC (rev 1449)
@@ -1,4 +1,5 @@
from datetime import datetime
+from random import random
from util import *
@@ -81,8 +82,16 @@
return "<div class=\"statuslight %s\">%s</div>" % (class_, number)
def fmt_ostatus(object):
- return fmt_status(0, 0)
+ errs, warns = 0, 0
+ if random() < 0.075:
+ errs = 1
+
+ if random() < 0.10:
+ warns = 1
+
+ return fmt_status(errs, warns)
+
def fmt_none():
return "<span class=\"none\">None</span>"
18 years, 4 months
rhmessaging commits: r1448 - mgmt/cumin/python/cumin.
by rhmessaging-commits@lists.jboss.org
Author: justi9
Date: 2007-12-10 11:57:09 -0500 (Mon, 10 Dec 2007)
New Revision: 1448
Modified:
mgmt/cumin/python/cumin/model.py
Log:
Change a constructor to be compatible with older versions of python.
Modified: mgmt/cumin/python/cumin/model.py
===================================================================
--- mgmt/cumin/python/cumin/model.py 2007-12-10 16:56:28 UTC (rev 1447)
+++ mgmt/cumin/python/cumin/model.py 2007-12-10 16:57:09 UTC (rev 1448)
@@ -3,7 +3,7 @@
from util import *
-class CuminModel():
+class CuminModel(object):
def __init__(self):
self.data = MintModel()
18 years, 4 months
rhmessaging commits: r1447 - in mgmt: cumin/python/cumin and 1 other directories.
by rhmessaging-commits@lists.jboss.org
Author: justi9
Date: 2007-12-10 11:56:28 -0500 (Mon, 10 Dec 2007)
New Revision: 1447
Modified:
mgmt/bin/quirk
mgmt/cumin/python/cumin/broker.py
mgmt/cumin/python/cumin/client.py
mgmt/cumin/python/cumin/exchange.py
mgmt/cumin/python/cumin/queue.py
mgmt/cumin/python/wooly/widgets.py
Log:
Bunch of grotty changes to work better with sqlobject.
Modified: mgmt/bin/quirk
===================================================================
--- mgmt/bin/quirk 2007-12-10 14:57:57 UTC (rev 1446)
+++ mgmt/bin/quirk 2007-12-10 16:56:28 UTC (rev 1447)
@@ -1,6 +1,8 @@
#!/usr/bin/env python
-import sys, qpid, time
+import sys, qpid
+from time import sleep
+from random import random, sample, randint
class Exchange(object):
def __init__(self, session, name):
@@ -195,6 +197,17 @@
e.declare()
es.append(e)
+
+ while True:
+ sqs = sample(qs, 5)
+
+ for q in sqs:
+ m = session.message()
+ m.set("test")
+ m.send(q)
+
+ sleep(1)
+
finally:
session.close()
Modified: mgmt/cumin/python/cumin/broker.py
===================================================================
--- mgmt/cumin/python/cumin/broker.py 2007-12-10 14:57:57 UTC (rev 1446)
+++ mgmt/cumin/python/cumin/broker.py 2007-12-10 16:56:28 UTC (rev 1447)
@@ -314,35 +314,77 @@
return "1.0"
class BrokerQueueTab(QueueSet):
- def get_title(self, session, broker):
- vhost = self.get_object(session, broker)
- return "Queues %s" % fmt_count(vhost and len(vhost.queues) or 0)
def get_object(self, session, broker):
broker = broker.broker # Navigate from registration to real broker
if broker:
return Vhost.selectBy(broker=broker, name="/")[0]
- class BrokerExchangeTab(ExchangeSet):
def get_title(self, session, broker):
vhost = self.get_object(session, broker)
- return "Exchanges %s" \
- % fmt_count(vhost and len(vhost.exchanges) or 0)
+ if vhost:
+ return super(BrokerView.BrokerQueueTab, self).get_title \
+ (session, vhost)
+ else:
+ return "Queues"
+ def do_process(self, session, vhost):
+ if vhost:
+ super(BrokerView.BrokerQueueTab, self).do_process \
+ (session, vhost)
+
+ def do_render(self, session, vhost):
+ if vhost:
+ return super(BrokerView.BrokerQueueTab, self).do_render \
+ (session, vhost)
+
+ class BrokerExchangeTab(ExchangeSet):
def get_object(self, session, broker):
broker = broker.broker # Navigate from registration to real broker
if broker:
return Vhost.selectBy(broker=broker, name="/")[0]
- class BrokerClientTab(ClientSet):
def get_title(self, session, broker):
vhost = self.get_object(session, broker)
- return "Clients %s" % fmt_count(vhost and len(vhost.clients) or 0)
+ if vhost:
+ return super(BrokerView.BrokerExchangeTab, self).get_title \
+ (session, vhost)
+ else:
+ return "Exchanges"
+ def do_process(self, session, vhost):
+ if vhost:
+ super(BrokerView.BrokerExchangeTab, self).do_process \
+ (session, vhost)
+
+ def do_render(self, session, vhost):
+ if vhost:
+ return super(BrokerView.BrokerExchangeTab, self).do_render \
+ (session, vhost)
+
+ class BrokerClientTab(ClientSet):
def get_object(self, session, broker):
broker = broker.broker # Navigate from registration to real broker
if broker:
return Vhost.selectBy(broker=broker, name="/")[0]
+ def get_title(self, session, broker):
+ vhost = self.get_object(session, broker)
+ if vhost:
+ return super(BrokerView.BrokerClientTab, self).get_title \
+ (session, vhost)
+ else:
+ return "Clients"
+
+ def do_process(self, session, vhost):
+ if vhost:
+ super(BrokerView.BrokerClientTab, self).do_process \
+ (session, vhost)
+
+ def do_render(self, session, vhost):
+ if vhost:
+ return super(BrokerView.BrokerClientTab, self).do_render \
+ (session, vhost)
+
class BrokerVirtualHostTab(VirtualHostSet):
def get_title(self, session, broker):
broker = broker.broker # Navigate from registration to real broker
Modified: mgmt/cumin/python/cumin/client.py
===================================================================
--- mgmt/cumin/python/cumin/client.py 2007-12-10 14:57:57 UTC (rev 1446)
+++ mgmt/cumin/python/cumin/client.py 2007-12-10 16:56:28 UTC (rev 1447)
@@ -16,15 +16,26 @@
self.unit = UnitSwitch(app, "unit")
self.add_child(self.unit)
+ self.paginator = Paginator(app, "page")
+ self.add_child(self.paginator)
+
def get_title(self, session, vhost):
- return "Clients %s" % fmt_count(len(vhost.clients))
+ return "Clients %s" % fmt_count(self.get_item_count(session, vhost))
+ def do_process(self, session, vhost):
+ self.paginator.set_count(session, self.get_item_count(session, vhost))
+
def render_unit_plural(self, session, vhost):
return self.unit.get(session) == "b" and "Bytes" or "Msgs."
+ def get_item_count(self, session, vhost):
+ return Client.select(Client.q.vhostID == vhost.id).count()
+
def do_get_items(self, session, vhost):
if vhost:
- return sorted_by(vhost.clients, "ipAddr")
+ start, end = self.paginator.get_bounds(session)
+ return Client.select(Client.q.vhostID == vhost.id,
+ orderBy="ipAddr")[start:end]
def render_item_link(self, session, client):
branch = session.branch()
Modified: mgmt/cumin/python/cumin/exchange.py
===================================================================
--- mgmt/cumin/python/cumin/exchange.py 2007-12-10 14:57:57 UTC (rev 1446)
+++ mgmt/cumin/python/cumin/exchange.py 2007-12-10 16:56:28 UTC (rev 1447)
@@ -43,18 +43,22 @@
self.add_child(self.paginator)
def get_title(self, session, vhost):
- return "Exchanges %s" % fmt_count(len(vhost.exchanges))
+ return "Exchanges %s" % fmt_count(self.get_item_count(session, vhost))
def do_process(self, session, vhost):
- self.paginator.set_count(session, len(vhost.exchanges))
+ self.paginator.set_count(session, self.get_item_count(session, vhost))
def render_unit_plural(self, session, vhost):
return self.unit.get(session) == "b" and "Bytes" or "Msgs."
+ def get_item_count(self, session, vhost):
+ return Exchange.select(Exchange.q.vhostID == vhost.id).count()
+
def do_get_items(self, session, vhost):
if vhost:
start, end = self.paginator.get_bounds(session)
- return vhost.exchanges[start:end]
+ return Exchange.select(Exchange.q.vhostID == vhost.id,
+ orderBy="name")[start:end]
def render_item_link(self, session, exchange):
branch = session.branch()
Modified: mgmt/cumin/python/cumin/queue.py
===================================================================
--- mgmt/cumin/python/cumin/queue.py 2007-12-10 14:57:57 UTC (rev 1446)
+++ mgmt/cumin/python/cumin/queue.py 2007-12-10 16:56:28 UTC (rev 1447)
@@ -25,10 +25,10 @@
self.add_child(self.paginator)
def get_title(self, session, vhost):
- return "Queues (%s)" % len(vhost.queues)
+ return "Queues %s" % fmt_count(self.get_item_count(session, vhost))
def do_process(self, session, vhost):
- self.paginator.set_count(session, len(vhost.queues))
+ self.paginator.set_count(session, self.get_item_count(session, vhost))
def render_unit_singular(self, session, vhost):
return self.unit.get(session) == "b" and "Byte" or "Msg."
@@ -36,10 +36,14 @@
def render_unit_plural(self, session, vhost):
return self.unit.get(session) == "b" and "Bytes" or "Msgs."
+ def get_item_count(self, session, vhost):
+ return Queue.select(Queue.q.vhostID == vhost.id).count()
+
def do_get_items(self, session, vhost):
if vhost:
start, end = self.paginator.get_bounds(session)
- return vhost.queues[start:end]
+ return Queue.select(Queue.q.vhostID == vhost.id,
+ orderBy="name")[start:end]
def render_item_link(self, session, queue):
branch = session.branch()
Modified: mgmt/cumin/python/wooly/widgets.py
===================================================================
--- mgmt/cumin/python/wooly/widgets.py 2007-12-10 14:57:57 UTC (rev 1446)
+++ mgmt/cumin/python/wooly/widgets.py 2007-12-10 16:56:28 UTC (rev 1447)
@@ -126,7 +126,6 @@
self.item_tmpl = Template(self, "item_html")
def get_item_count(self, session, object):
-
return len(self.get_items(session, object))
def get_items(self, session, object):
18 years, 4 months