summaryrefslogtreecommitdiff
path: root/cpp/src/qpid/legacystore/jrnl/enq_rec.h
blob: 805a96a1aa587e71b448520d0847962cd4a8c639 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
 */

/**
 * \file enq_rec.h
 *
 * Qpid asynchronous store plugin library
 *
 * This file contains the code for the mrg::journal::enq_rec (journal enqueue
 * record) class. See class documentation for details.
 */

#ifndef QPID_LEGACYSTORE_JRNL_ENQ_REC_H
#define QPID_LEGACYSTORE_JRNL_ENQ_REC_H

namespace mrg
{
namespace journal
{
class enq_rec;
}
}

#include <cstddef>
#include "qpid/legacystore/jrnl/enq_hdr.h"
#include "qpid/legacystore/jrnl/jrec.h"

namespace mrg
{
namespace journal
{

    /**
    * \class enq_rec
    * \brief Class to handle a single journal enqueue record.
    */
    class enq_rec : public jrec
    {
    private:
        enq_hdr _enq_hdr;
        const void* _xidp;          ///< xid pointer for encoding (for writing to disk)
        const void* _data;          ///< Pointer to data to be written to disk
        void* _buff;                ///< Pointer to buffer to receive data read from disk
        rec_tail _enq_tail;

    public:
        /**
        * \brief Constructor used for read operations.
        */
        enq_rec();

        /**
        * \brief Constructor used for write operations, where mbuf contains data to be written.
        */
        enq_rec(const u_int64_t rid, const void* const dbuf, const std::size_t dlen,
                const void* const xidp, const std::size_t xidlen, const bool owi, const bool transient);

        /**
        * \brief Destructor
        */
        virtual ~enq_rec();

        // Prepare instance for use in reading data from journal, xid and data will be allocated
        void reset();
        // Prepare instance for use in writing data to journal
        void reset(const u_int64_t rid, const void* const dbuf, const std::size_t dlen,
                const void* const xidp, const std::size_t xidlen, const bool owi, const bool transient,
                const bool external);

        u_int32_t encode(void* wptr, u_int32_t rec_offs_dblks, u_int32_t max_size_dblks);
        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
        bool rcv_decode(rec_hdr h, std::ifstream* ifsp, std::size_t& rec_offs);

        std::size_t get_xid(void** const xidpp);
        std::size_t get_data(void** const datapp);
        inline bool is_transient() const { return _enq_hdr.is_transient(); }
        inline bool is_external() const { return _enq_hdr.is_external(); }
        std::string& str(std::string& str) const;
        inline std::size_t data_size() const { return _enq_hdr._dsize; }
        inline std::size_t xid_size() const { return _enq_hdr._xidsize; }
        std::size_t rec_size() const;
        static std::size_t rec_size(const std::size_t xidsize, const std::size_t dsize, const bool external);
        inline u_int64_t rid() const { return _enq_hdr._rid; }
        void set_rid(const u_int64_t rid);

    private:
        void chk_hdr() const;
        void chk_hdr(u_int64_t rid) const;
        void chk_tail() const;
        virtual void clean();
    }; // class enq_rec

} // namespace journal
} // namespace mrg

#endif // ifndef QPID_LEGACYSTORE_JRNL_ENQ_REC_H