libfoedus-core
FOEDUS Core Library
common_log_types.cpp
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  */
19 
20 #include <ostream>
21 
22 #include "foedus/engine.hpp"
25 #include "foedus/log/log_type.hpp"
27 #include "foedus/thread/thread.hpp"
28 
29 namespace foedus {
30 namespace log {
31 std::ostream& operator<<(std::ostream& o, const LogHeader& v) {
32  o << "<Header type=\"" << assorted::Hex(v.log_type_code_) << "\" type_name=\""
33  << get_log_type_name(v.get_type()) << "\" length=\"" << assorted::Hex(v.log_length_)
34  << "\" storage_id=\"" << v.storage_id_ << "\" />";
35  return o;
36 }
37 std::ostream& operator<<(std::ostream& o, const FillerLogType &v) {
38  o << "<FillerLog>" << v.header_ << "</FillerLog>";
39  return o;
40 }
41 
42 std::ostream& operator<<(std::ostream& o, const EpochMarkerLogType& v) {
43  o << "<EpochMarker>" << v.header_
44  << "<old_epoch_>" << v.old_epoch_ << "</old_epoch_>"
45  << "<new_epoch_>" << v.new_epoch_ << "</new_epoch_>"
46  << "<logger_numa_node_>" << static_cast<int>(v.logger_numa_node_) << "</logger_numa_node_>"
47  << "<logger_in_node_ordinal_>"
48  << static_cast<int>(v.logger_in_node_ordinal_) << "</logger_in_node_ordinal_>"
49  << "<logger_id_>" << v.logger_id_ << "</logger_id_>"
50  << "<log_file_ordinal_>" << v.log_file_ordinal_ << "</log_file_ordinal_>"
51  << "<log_file_offset_>" << assorted::Hex(v.log_file_offset_) << "</log_file_offset_>"
52  << "</EpochMarker>";
53  return o;
54 }
55 
58  logger.add_epoch_history(*this);
59 }
60 
61 void EpochMarkerLogType::populate(Epoch old_epoch, Epoch new_epoch,
62  uint8_t logger_numa_node, uint8_t logger_in_node_ordinal,
63  uint16_t logger_id, uint32_t log_file_ordinal, uint64_t log_file_offset) {
64  header_.storage_id_ = 0;
66  header_.log_type_code_ = get_log_code<EpochMarkerLogType>();
67  new_epoch_ = new_epoch;
68  old_epoch_ = old_epoch;
69  logger_numa_node_ = logger_numa_node;
70  logger_in_node_ordinal_ = logger_in_node_ordinal;
71  logger_id_ = logger_id;
72  log_file_ordinal_ = log_file_ordinal;
73  log_file_offset_ = log_file_offset;
74  assert_valid();
75 }
76 
77 void FillerLogType::populate(uint64_t size) {
78  ASSERT_ND(size < (1 << 16));
79  header_.storage_id_ = 0;
80  header_.log_length_ = size;
81  header_.log_type_code_ = get_log_code<FillerLogType>();
82 }
83 
84 } // namespace log
85 } // namespace foedus
LoggerRef get_logger(LoggerId logger_id)
Returns a reference to the logger of the given ID.
Definition: log_manager.cpp:49
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
Definition: assert_nd.hpp:44
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.
void populate(Epoch old_epoch, Epoch new_epoch, uint8_t logger_numa_node, uint8_t logger_in_node_ordinal, uint16_t logger_id, uint32_t log_file_ordinal, uint64_t log_file_offset)
void assert_valid() const __attribute__((always_inline))
Represents a time epoch.
Definition: epoch.hpp:61
uint16_t logger_id_
Unique ID of the logger.
Epoch old_epoch_
Epoch before this switch.
Declares common log types used in all packages.
Engine * get_engine() const
Definition: thread.cpp:52
void populate(uint64_t size)
Populate this log to fill up the specified byte size.
void apply_engine(thread::Thread *context)
A view of Logger object for other SOCs and master engine.
Definition: logger_ref.hpp:35
log::LogManager * get_log_manager() const
See Log Manager.
Definition: engine.cpp:49
uint32_t log_file_ordinal_
Ordinal of log files (eg "log.0", "log.1").
A log type to declare a switch of epoch in a logger or the engine.
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...
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.
std::ostream & operator<<(std::ostream &o, const LogHeader &v)
Epoch new_epoch_
Epoch after this switch.
const char * get_log_type_name(LogCode code)
Returns the names of LogCode enum defined in log_type.xmacro.
Definition: log_type.cpp:28
Convenient way of writing hex integers to stream.
storage::StorageId storage_id_
The storage this loggable operation mainly affects.
LogCode get_type() const __attribute__((always_inline))
Convenience method to cast into LogCode.
void add_epoch_history(const EpochMarkerLogType &epoch_marker)
Append a new epoch history.
Definition: logger_ref.cpp:65
#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.