libfoedus-core
FOEDUS Core Library
log_options.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 <sstream>
21 #include <string>
22 
25 
26 namespace foedus {
27 namespace log {
30  folder_path_pattern_ = "logs/node_$NODE$/logger_$LOGGER$";
33  flush_at_shutdown_ = true;
34 }
35 
36 std::string LogOptions::convert_folder_path_pattern(int node, int logger) const {
37  std::string tmp = assorted::replace_all(folder_path_pattern_.str(), "$NODE$", node);
38  return assorted::replace_all(tmp, "$LOGGER$", logger);
39 }
40 
42  int node,
43  int logger,
44  LogFileOrdinal ordinal) const {
45  std::string folder = convert_folder_path_pattern(node, logger);
46  std::stringstream path_str;
47  path_str << folder << "/" << logger << "_" << ordinal << ".log";
48  return path_str.str();
49 }
50 
52  return convert_folder_path_pattern(0, 0) + std::string("/meta.log");
53 }
54 
55 ErrorStack LogOptions::load(tinyxml2::XMLElement* element) {
61  CHECK_ERROR(get_child_element(element, "LogDeviceEmulationOptions", &emulation_))
62  return kRetOk;
63 }
64 
65 ErrorStack LogOptions::save(tinyxml2::XMLElement* element) const {
66  CHECK_ERROR(insert_comment(element, "Set of options for log manager"));
67 
69  "String pattern of path of log folders in each NUMA node.\n"
70  " This specifies the path of the folder to contain log file written out in each NUMA node."
71  " Two special placeholders can be used; $NODE$ and $LOGGER$."
72  " $NODE$ is replaced with the NUMA node number."
73  " $LOGGER$ is replaced with the logger index in the node (0 to loggers_per_node_ - 1)."
74  " For example,\n"
75  " /log/node_$NODE$/logger_$LOGGER$ becomes /log/node_1/logger_0 on node-1 and logger-0."
76  " /log/logger_$INDEX$ becomes /log/logger_1 on any node and logger-1."
77  " Both are optional. You can specify a fixed path without the patterns, which means you"
78  " will use the same folder for multiple loggers and nodes. Even in that case, log file"
79  " names include node/logger number, so it wouldn't cause any data corruption."
80  " It just makes things harder for poor sysadmins.");
81  EXTERNALIZE_SAVE_ELEMENT(element, loggers_per_node_, "Number of loggers per NUMA node."
82  "This value must be at least 1 (which is also default)."
83  " A larger value might be able to employ more CPU power if you have succient # of cores."
84  " For the best performance, the number of loggers in each NUMA node must be"
85  " a submultiple of the number of cores in the node (s.t. logger assignment is balanced).");
86  EXTERNALIZE_SAVE_ELEMENT(element, log_buffer_kb_, "Buffer size in KB of each worker thread");
87  EXTERNALIZE_SAVE_ELEMENT(element, log_file_size_mb_, "Size in MB of files loggers write out");
89  "Whether to flush transaction logs and take savepoint when uninitialize() is called");
90  CHECK_ERROR(add_child_element(element, "LogDeviceEmulationOptions",
91  "[Experiments-only] Settings to emulate slower logging device", emulation_));
92  return kRetOk;
93 }
94 
95 } // namespace log
96 } // namespace foedus
std::string convert_folder_path_pattern(int node, int logger) const
converts folder_path_pattern_ into a string with the given IDs.
Definition: log_options.cpp:36
#define EXTERNALIZE_LOAD_ELEMENT(element, attribute)
Reads a child xml element to load a member variable of this object.
static ErrorStack get_child_element(tinyxml2::XMLElement *parent, const std::string &tag, Externalizable *child, bool optional=false)
child Externalizable version
std::string construct_suffixed_log_path(int node, int logger, LogFileOrdinal ordinal) const
construct full path of individual log file (log_folder/LOGGERID_ORDINAL.log)
Definition: log_options.cpp:41
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
Definition: assert_nd.hpp:44
static ErrorStack add_child_element(tinyxml2::XMLElement *parent, const std::string &tag, const std::string &comment, const Externalizable &child)
child Externalizable version
bool flush_at_shutdown_
Whether to flush transaction logs and take savepoint when uninitialize() is called.
Brings error stacktrace information as return value of functions.
Definition: error_stack.hpp:81
static ErrorStack insert_comment(tinyxml2::XMLElement *element, const std::string &comment)
fs::FixedPath folder_path_pattern_
String pattern of path of log folders in each NUMA node.
Definition: log_options.hpp:70
ErrorStack save(tinyxml2::XMLElement *element) const override
Writes the content of this object to the given XML element.
Definition: log_options.cpp:65
LogOptions()
Constructs option values with default values.
Definition: log_options.cpp:28
uint32_t LogFileOrdinal
Ordinal of log files (eg "log.0", "log.1").
Definition: log_id.hpp:46
uint32_t log_buffer_kb_
Size in KB of log buffer for each worker thread.
Definition: log_options.hpp:83
std::string replace_all(const std::string &target, const std::string &search, const std::string &replacement)
target.replaceAll(search, replacement).
ErrorStack load(tinyxml2::XMLElement *element) override
Reads the content of this object from the given XML element.
Definition: log_options.cpp:55
Default value for log_file_size_mb_.
Definition: log_options.hpp:45
std::basic_string< CHAR > str() const
Convert to a std::string object.
Default value for log_buffer_kb_.
Definition: log_options.hpp:43
std::string construct_meta_log_path() const
metadata log file is placed in node-0/logger-0 folder
Definition: log_options.cpp:51
#define CHECK_ERROR(x)
This macro calls x and checks its returned value.
foedus::fs::DeviceEmulationOptions emulation_
Settings to emulate slower logging device.
const ErrorStack kRetOk
Normal return value for no-error case.
#define EXTERNALIZE_SAVE_ELEMENT(element, attribute, comment)
Adds an xml element to represent a member variable of this object.
uint32_t log_file_size_mb_
Size in MB of each file loggers write out.
Definition: log_options.hpp:92
uint16_t loggers_per_node_
Number of loggers per NUMA node.
Definition: log_options.hpp:80