CUBRID Engine  latest
log_lsa.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Search Solution Corporation
3  * Copyright 2016 CUBRID Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 //
20 // log_lsa.hpp - log sequence address header
21 //
22 
23 #ifndef _LOG_LSA_HPP_
24 #define _LOG_LSA_HPP_
25 
26 #if !defined (SERVER_MODE) && !defined (SA_MODE) && !defined (CS_MODE)
27 #define Wrong module
28 #endif
29 
30 #include <cassert>
31 #include <cinttypes>
32 #include <cstddef>
33 
34 struct log_lsa
35 {
36  std::int64_t pageid:48; /* Log page identifier : 6 bytes length */
37  std::int64_t offset:16; /* Offset in page : 2 bytes length */
38  /* The offset field is defined as 16bit-INT64 type (not short), because of alignment */
39 
40  inline log_lsa () = default;
41  inline log_lsa (std::int64_t log_pageid, std::int16_t log_offset);
42  inline log_lsa (const log_lsa &olsa) = default;
43  inline log_lsa &operator= (const log_lsa &olsa) = default;
44 
45  inline bool is_null () const;
46  inline void set_null ();
47 
48  inline bool operator== (const log_lsa &olsa) const;
49  inline bool operator< (const log_lsa &olsa) const;
50  inline bool operator<= (const log_lsa &olsa) const;
51  inline bool operator> (const log_lsa &olsa) const;
52  inline bool operator>= (const log_lsa &olsa) const;
53 };
54 
55 using LOG_LSA = log_lsa; /* Log address identifier */
56 
57 static const std::int64_t NULL_LOG_PAGEID = -1;
58 static const std::int16_t NULL_LOG_OFFSET = -1;
60 
61 // functions
62 void lsa_to_string (char *buf, int buf_size, const log_lsa *lsa);
63 
64 //
65 // macro replacements
66 //
67 inline void LSA_COPY (log_lsa *plsa1, const log_lsa *plsa2);
68 inline void LSA_SET_NULL (log_lsa *lsa_ptr);
69 inline bool LSA_ISNULL (const log_lsa *lsa_ptr);
70 inline bool LSA_EQ (const log_lsa *plsa1, const log_lsa *plsa2);
71 inline bool LSA_LE (const log_lsa *plsa1, const log_lsa *plsa2);
72 inline bool LSA_LT (const log_lsa *plsa1, const log_lsa *plsa2);
73 inline bool LSA_GE (const log_lsa *plsa1, const log_lsa *plsa2);
74 inline bool LSA_GT (const log_lsa *plsa1, const log_lsa *plsa2);
75 
76 #define LSA_INITIALIZER {NULL_LOG_PAGEID, NULL_LOG_OFFSET}
77 
78 #define LSA_AS_ARGS(lsa_ptr) (long long int) (lsa_ptr)->pageid, (int) (lsa_ptr)->offset
79 
81 // inline/template implementation
83 
84 log_lsa::log_lsa (std::int64_t log_pageid, std::int16_t log_offset)
85  : pageid (log_pageid)
86  , offset (log_offset)
87 {
88  //
89 }
90 
91 bool
93 {
94  return pageid == NULL_LOG_PAGEID;
95 }
96 
97 void
99 {
101  offset = NULL_LOG_OFFSET; // this is how LOG_LSA is initialized many times; we need to initialize both fields or
102  // we'll have "conditional jump or move on uninitialized value"
103 }
104 
105 bool
106 log_lsa::operator== (const log_lsa &olsa) const
107 {
108  return pageid == olsa.pageid && offset == olsa.offset;
109 }
110 
111 bool
112 log_lsa::operator< (const log_lsa &olsa) const
113 {
114  return (pageid < olsa.pageid) || (pageid == olsa.pageid && offset < olsa.offset);
115 }
116 
117 bool
118 log_lsa::operator> (const log_lsa &olsa) const
119 {
120  return olsa.operator< (*this);
121 }
122 
123 bool
124 log_lsa::operator<= (const log_lsa &olsa) const
125 {
126  return !operator> (olsa);
127 }
128 
129 bool
130 log_lsa::operator>= (const log_lsa &olsa) const
131 {
132  return !operator< (olsa);
133 }
134 
135 //
136 // macro replacements
137 //
138 void
139 LSA_COPY (log_lsa *plsa1, const log_lsa *plsa2)
140 {
141  assert (plsa1 != NULL && plsa2 != NULL);
142  *plsa1 = *plsa2;
143 }
144 
145 void
147 {
148  assert (lsa_ptr != NULL);
149  lsa_ptr->set_null ();
150 }
151 
152 bool
153 LSA_ISNULL (const log_lsa *lsa_ptr)
154 {
155  assert (lsa_ptr != NULL);
156  return lsa_ptr->is_null ();
157 }
158 
159 bool
160 LSA_EQ (const log_lsa *plsa1, const log_lsa *plsa2)
161 {
162  assert (plsa1 != NULL && plsa2 != NULL);
163  return *plsa1 == *plsa2;
164 }
165 
166 bool
167 LSA_LE (const log_lsa *plsa1, const log_lsa *plsa2)
168 {
169  assert (plsa1 != NULL && plsa2 != NULL);
170  return *plsa1 <= *plsa2;
171 }
172 
173 bool
174 LSA_LT (const log_lsa *plsa1, const log_lsa *plsa2)
175 {
176  assert (plsa1 != NULL && plsa2 != NULL);
177  return *plsa1 < *plsa2;
178 }
179 
180 bool
181 LSA_GE (const log_lsa *plsa1, const log_lsa *plsa2)
182 {
183  assert (plsa1 != NULL && plsa2 != NULL);
184  return *plsa1 >= *plsa2;
185 }
186 
187 bool
188 LSA_GT (const log_lsa *plsa1, const log_lsa *plsa2)
189 {
190  assert (plsa1 != NULL && plsa2 != NULL);
191  return *plsa1 > *plsa2;
192 }
193 
194 #endif // _LOG_LSA_HPP_
bool is_null() const
Definition: log_lsa.hpp:92
static const std::int64_t NULL_LOG_PAGEID
Definition: log_lsa.hpp:57
void set_null()
Definition: log_lsa.hpp:98
bool LSA_EQ(const log_lsa *plsa1, const log_lsa *plsa2)
Definition: log_lsa.hpp:160
bool operator>(const log_lsa &olsa) const
Definition: log_lsa.hpp:118
void LSA_COPY(log_lsa *plsa1, const log_lsa *plsa2)
Definition: log_lsa.hpp:139
log_lsa()=default
bool LSA_LT(const log_lsa *plsa1, const log_lsa *plsa2)
Definition: log_lsa.hpp:174
#define assert(x)
static const std::int16_t NULL_LOG_OFFSET
Definition: log_lsa.hpp:58
void lsa_to_string(char *buf, int buf_size, const log_lsa *lsa)
Definition: log_lsa.cpp:28
bool LSA_LE(const log_lsa *plsa1, const log_lsa *plsa2)
Definition: log_lsa.hpp:167
bool operator<=(const log_lsa &olsa) const
Definition: log_lsa.hpp:124
bool operator==(const log_lsa &olsa) const
Definition: log_lsa.hpp:106
std::int64_t pageid
Definition: log_lsa.hpp:36
#define NULL
Definition: freelistheap.h:34
bool LSA_ISNULL(const log_lsa *lsa_ptr)
Definition: log_lsa.hpp:153
bool LSA_GE(const log_lsa *plsa1, const log_lsa *plsa2)
Definition: log_lsa.hpp:181
bool operator>=(const log_lsa &olsa) const
Definition: log_lsa.hpp:130
void LSA_SET_NULL(log_lsa *lsa_ptr)
Definition: log_lsa.hpp:146
bool LSA_GT(const log_lsa *plsa1, const log_lsa *plsa2)
Definition: log_lsa.hpp:188
bool operator<(const log_lsa &olsa) const
Definition: log_lsa.hpp:112
std::int64_t offset
Definition: log_lsa.hpp:37
log_lsa & operator=(const log_lsa &olsa)=default
const log_lsa NULL_LSA
Definition: log_lsa.hpp:59