libfoedus-core
FOEDUS Core Library
common_log_types.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2015, Hewlett-Packard Development Company, LP.
3  * This program is free software; you can redistribute it and/or modify it
4  * under the terms of the GNU General Public License as published by the Free
5  * Software Foundation; either version 2 of the License, or (at your option)
6  * any later version.
7  *
8  * This program is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11  * more details. You should have received a copy of the GNU General Public
12  * License along with this program; if not, write to the Free Software
13  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14  *
15  * HP designates this particular file as subject to the "Classpath" exception
16  * as provided by HP in the LICENSE.txt file that accompanied this code.
17  */
18 #ifndef FOEDUS_LOG_COMMON_LOG_TYPES_HPP_
19 #define FOEDUS_LOG_COMMON_LOG_TYPES_HPP_
20 #include <iosfwd>
21 
22 #include "foedus/assert_nd.hpp"
23 #include "foedus/compiler.hpp"
24 #include "foedus/cxx11.hpp"
25 #include "foedus/epoch.hpp"
26 #include "foedus/fwd.hpp"
28 #include "foedus/log/log_type.hpp"
29 #include "foedus/storage/fwd.hpp"
31 #include "foedus/thread/fwd.hpp"
32 #include "foedus/xct/fwd.hpp"
33 #include "foedus/xct/xct_id.hpp"
34 
40 namespace foedus {
41 namespace log {
42 
50 struct LogHeader {
55  uint16_t log_type_code_; // +2 => 2
61  uint16_t log_length_; // +2 => 4
67 
75  xct::XctId xct_id_; // +8 => 16
76 
78  LogCode get_type() const ALWAYS_INLINE { return static_cast<LogCode>(log_type_code_); }
81 
83  bool is_valid_type() const { return is_valid_log_type(get_type()); }
84 
86  inline void set_xct_id(xct::XctId new_xct_id) {
87  if (log_length_ >= 16) {
88  xct_id_ = new_xct_id;
89  } else {
90  // So far only log type that omits xct_id is FillerLogType.
92  }
93  }
94 
95  friend std::ostream& operator<<(std::ostream& o, const LogHeader& v);
96 };
97 
103 #define LOG_TYPE_NO_CONSTRUCT(clazz) \
104  clazz() CXX11_FUNC_DELETE;\
105  clazz(const clazz &other) CXX11_FUNC_DELETE;\
106  ~clazz() CXX11_FUNC_DELETE;
107 
112 struct BaseLogType {
114 };
116 
117 
121 struct EngineLogType : public BaseLogType {
122  bool is_engine_log() const { return true; }
123  bool is_storage_log() const { return false; }
124  bool is_record_log() const { return false; }
125  void apply_storage(Engine* /*engine*/, storage::StorageId /*storage_id*/) {
126  ASSERT_ND(false);
127  }
129  thread::Thread* /*context*/,
130  storage::StorageId /*storage_id*/,
131  xct::RwLockableXctId* /*owner_id*/,
132  char* /*payload*/) {
133  ASSERT_ND(false);
134  }
139  ASSERT_ND(header_.is_valid_type());
140  ASSERT_ND(header_.log_length_ != 0);
141  ASSERT_ND(header_.log_length_ % 8 == 0); // must be 8 byte aligned
142  ASSERT_ND(header_.storage_id_ == 0);
143  }
144 };
145 STATIC_SIZE_CHECK(sizeof(EngineLogType), 16)
146 
147 
151 struct StorageLogType : public BaseLogType {
152  bool is_engine_log() const { return false; }
153  bool is_storage_log() const { return true; }
154  bool is_record_log() const { return false; }
155  void apply_engine(thread::Thread* /*context*/) {
156  ASSERT_ND(false);
157  }
159  thread::Thread* /*context*/,
160  storage::StorageId /*storage_id*/,
161  xct::RwLockableXctId* /*owner_id*/,
162  char* /*payload*/) {
163  ASSERT_ND(false);
164  }
169  ASSERT_ND(header_.is_valid_type());
170  ASSERT_ND(header_.log_length_ != 0);
171  ASSERT_ND(header_.log_length_ % 8 == 0); // must be 8 byte aligned
172  ASSERT_ND(header_.storage_id_ > 0);
173  }
174 };
175 STATIC_SIZE_CHECK(sizeof(StorageLogType), 16)
176 
177 
181 struct RecordLogType : public BaseLogType {
182  bool is_engine_log() const { return false; }
183  bool is_storage_log() const { return false; }
184  bool is_record_log() const { return true; }
185  void apply_engine(thread::Thread* /*context*/) {
186  ASSERT_ND(false);
187  }
188  void apply_storage(Engine* /*engine*/, storage::StorageId /*storage_id*/) {
189  ASSERT_ND(false);
190  }
195  ASSERT_ND(header_.is_valid_type());
196  ASSERT_ND(header_.log_length_ != 0);
197  ASSERT_ND(header_.log_length_ % 8 == 0); // must be 8 byte aligned
198  ASSERT_ND(header_.storage_id_ > 0);
199  }
200 };
201 STATIC_SIZE_CHECK(sizeof(RecordLogType), 16)
202 
203 
215 struct FillerLogType : public BaseLogType {
217  enum Constants {
222  kLogWriteUnitSize = 1 << 12,
223  };
224 
226 
227  // this is a special log type where it is valid and skipped in every context
228  bool is_engine_log() const { return true; }
229  bool is_storage_log() const { return true; }
230  bool is_record_log() const { return true; }
231  void apply_engine(thread::Thread* /*context*/) {}
232  void apply_storage(Engine* /*engine*/, storage::StorageId /*storage_id*/) {}
234  thread::Thread* /*context*/,
235  storage::StorageId /*storage_id*/,
236  xct::RwLockableXctId* /*owner_id*/,
237  char* /*payload*/) {}
238 
240  void populate(uint64_t size);
241 
243  ASSERT_ND(header_.get_type() == kLogCodeFiller);
244  ASSERT_ND(header_.log_length_ >= 8); // note: it CAN be only 8, not 16 (sizeof FillerLogType)
245  ASSERT_ND(header_.log_length_ % 8 == 0);
246  ASSERT_ND(header_.storage_id_ == 0);
247  }
248 
249  friend std::ostream& operator<<(std::ostream& o, const FillerLogType &v);
250 };
251 STATIC_SIZE_CHECK(sizeof(FillerLogType), 16)
252 // NOTE: As a class, it's 16 bytes. However, it might be only 8 bytes in actual log.
253 // In that case, xct_id is omitted.
254 
255 
273 
274  void apply_engine(thread::Thread* context);
275 
277  Epoch old_epoch_; // +4 => 20
279  Epoch new_epoch_; // +4 => 24
280 
282  uint8_t logger_numa_node_; // +1 => 25
284  uint8_t logger_in_node_ordinal_; // +1 => 26
286  uint16_t logger_id_; // +2 => 28
287 
289  uint32_t log_file_ordinal_; // +4 => 32
290 
295  uint64_t log_file_offset_; // +8 => 40
296 
297  void populate(Epoch old_epoch, Epoch new_epoch,
298  uint8_t logger_numa_node, uint8_t logger_in_node_ordinal,
299  uint16_t logger_id, uint32_t log_file_ordinal, uint64_t log_file_offset);
300  void assert_valid() const ALWAYS_INLINE { assert_valid_generic(); }
301 
302  friend std::ostream& operator<<(std::ostream& o, const EpochMarkerLogType &v);
303 };
304 STATIC_SIZE_CHECK(sizeof(EpochMarkerLogType), 40)
305 
306 } // namespace log
307 } // namespace foedus
308 #endif // FOEDUS_LOG_COMMON_LOG_TYPES_HPP_
void apply_engine(thread::Thread *)
LogCodeKind get_kind() const __attribute__((always_inline))
Convenience method to get LogCodeKind.
LogCode
A unique identifier of all log types.
Definition: log_type.hpp:87
Base class for log type of storage-wide operation.
void apply_engine(thread::Thread *)
friend std::ostream & operator<<(std::ostream &o, const LogHeader &v)
Base class for log type of engine-wide operation.
Definitions of IDs in this package and a few related constant values.
LogCodeKind
Represents the kind of log types.
Definition: log_type.hpp:101
void apply_record(thread::Thread *, storage::StorageId, xct::RwLockableXctId *, char *)
void apply_storage(Engine *, storage::StorageId)
uint32_t StorageId
Unique ID for storage.
Definition: storage_id.hpp:55
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
Definition: assert_nd.hpp:44
bool is_valid_type() const
Another convenience method to see if the type code is non-zero and exists.
Represents one thread running on one NUMA core.
Definition: thread.hpp:48
uint64_t log_file_offset_
Byte offset of the epoch mark log itself in the log.
Forward declarations of classes in transaction package.
Forward declarations of classes in root package.
Persistent status part of Transaction ID.
Definition: xct_id.hpp:955
void set_xct_id(xct::XctId new_xct_id)
Because of the special case of FillerLogType, we must use this method to set xct_id.
void assert_valid() const __attribute__((always_inline))
Represents a time epoch.
Definition: epoch.hpp:61
void apply_record(thread::Thread *, storage::StorageId, xct::RwLockableXctId *, char *)
uint16_t logger_id_
Unique ID of the logger.
Epoch old_epoch_
Epoch before this switch.
void apply_storage(Engine *, storage::StorageId)
void assert_valid() const __attribute__((always_inline))
Base class for log type.
bool is_valid_log_type(LogCode code)
Returns if the LogCode value exists.
Definition: log_type.hpp:128
The MCS reader-writer lock variant of LockableXctId.
Definition: xct_id.hpp:1132
Forward declarations of classes in storage package.
Definitions of IDs in this package and a few related constant values.
uint32_t log_file_ordinal_
Ordinal of log files (eg "log.0", "log.1").
void assert_valid_generic() const __attribute__((always_inline))
Verifies the log contains essential fields set.
Database engine object that holds all resources and provides APIs.
Definition: engine.hpp:109
A log type to declare a switch of epoch in a logger or the engine.
void apply_engine(thread::Thread *)
xct::XctId xct_id_
Epoch and in-epoch ordinal of this log.
A common header part for all log types.
uint16_t log_type_code_
Actually of LogCode defined in the X-Macro, but we want to make sure the type size is 2 bytes...
LogCodeKind get_log_code_kind(LogCode code)
Returns the kind of the given log code.
Definition: log_type.hpp:118
A dummy log type to fill up a sector in log files.
uint16_t log_length_
Byte size of this log entry including this header itself and everything.
uint8_t logger_in_node_ordinal_
Ordinal of the logger in the numa node.
void apply_record(thread::Thread *, storage::StorageId, xct::RwLockableXctId *, char *)
std::ostream & operator<<(std::ostream &o, const LogHeader &v)
Epoch new_epoch_
Epoch after this switch.
void apply_storage(Engine *, storage::StorageId)
#define LOG_TYPE_NO_CONSTRUCT(clazz)
Macro to delete all constructors/destructors to prevent misuse for log type classes.
storage::StorageId storage_id_
The storage this loggable operation mainly affects.
0x3001 : foedus::log::FillerLogType .
Definition: log_type.hpp:111
LogCode get_type() const __attribute__((always_inline))
Convenience method to cast into LogCode.
#define STATIC_SIZE_CHECK(desired, actual)
void assert_valid_generic() const __attribute__((always_inline))
Verifies the log contains essential fields set.
Base class for log type of record-wise operation.
#define ASSERT_ND(x)
A warning-free wrapper macro of assert() that has no performance effect in release mode even when 'x'...
Definition: assert_nd.hpp:72
uint8_t logger_numa_node_
Numa node of the logger that produced this log.
Forward declarations of classes in thread package.
#define ALWAYS_INLINE
A function suffix to hint that the function should always be inlined.
Definition: compiler.hpp:106
void assert_valid_generic() __attribute__((always_inline))
Verifies the log contains essential fields set.