Derecho  0.9
Distributed systems toolkit for RDMA
conf.hpp
Go to the documentation of this file.
1 #ifndef CONF_HPP
2 #define CONF_HPP
3 
4 #include <atomic>
5 #include "getpot/GetPot"
6 #include <getopt.h>
7 #include <inttypes.h>
8 #include <map>
9 #include <memory>
10 #include <stdio.h>
11 #include <unistd.h>
12 
13 namespace derecho {
14 
15 #define CONF_ENTRY_INTEGER(name, section, string)
16 
18 class Conf {
19 private:
20  // Configuration Table:
21  // config name --> default value
22 #define CONF_DERECHO_LEADER_IP "DERECHO/leader_ip"
23 #define CONF_DERECHO_LEADER_GMS_PORT "DERECHO/leader_gms_port"
24 #define CONF_DERECHO_LOCAL_ID "DERECHO/local_id"
25 #define CONF_DERECHO_LOCAL_IP "DERECHO/local_ip"
26 #define CONF_DERECHO_GMS_PORT "DERECHO/gms_port"
27 #define CONF_DERECHO_RPC_PORT "DERECHO/rpc_port"
28 #define CONF_DERECHO_SST_PORT "DERECHO/sst_port"
29 #define CONF_DERECHO_RDMC_PORT "DERECHO/rdmc_port"
30 #define CONF_DERECHO_HEARTBEAT_MS "DERECHO/heartbeat_ms"
31 #define CONF_DERECHO_SST_POLL_CQ_TIMEOUT_MS "DERECHO/sst_poll_cq_timeout_ms"
32 #define CONF_DERECHO_DISABLE_PARTITIONING_SAFETY "DERECHO/disable_partitioning_safety"
33 
34 #define CONF_DERECHO_MAX_P2P_REQUEST_PAYLOAD_SIZE "DERECHO/max_p2p_request_payload_size"
35 #define CONF_DERECHO_MAX_P2P_REPLY_PAYLOAD_SIZE "DERECHO/max_p2p_reply_payload_size"
36 #define CONF_DERECHO_P2P_WINDOW_SIZE "DERECHO/p2p_window_size"
37 
38 #define CONF_SUBGROUP_DEFAULT_MAX_PAYLOAD_SIZE "SUBGROUP/DEFAULT/max_payload_size"
39 #define CONF_SUBGROUP_DEFAULT_MAX_REPLY_PAYLOAD_SIZE "SUBGROUP/DEFAULT/max_reply_payload_size"
40 #define CONF_SUBGROUP_DEFAULT_MAX_SMC_PAYLOAD_SIZE "SUBGROUP/DEFAULT/max_smc_payload_size"
41 #define CONF_SUBGROUP_DEFAULT_BLOCK_SIZE "SUBGROUP/DEFAULT/block_size"
42 #define CONF_SUBGROUP_DEFAULT_WINDOW_SIZE "SUBGROUP/DEFAULT/window_size"
43 #define CONF_SUBGROUP_DEFAULT_RDMC_SEND_ALGORITHM "SUBGROUP/DEFAULT/rdmc_send_algorithm"
44 
45 #define CONF_RDMA_PROVIDER "RDMA/provider"
46 #define CONF_RDMA_DOMAIN "RDMA/domain"
47 #define CONF_RDMA_TX_DEPTH "RDMA/tx_depth"
48 #define CONF_RDMA_RX_DEPTH "RDMA/rx_depth"
49 #define CONF_PERS_FILE_PATH "PERS/file_path"
50 #define CONF_PERS_RAMDISK_PATH "PERS/ramdisk_path"
51 #define CONF_PERS_RESET "PERS/reset"
52 #define CONF_PERS_MAX_LOG_ENTRY "PERS/max_log_entry"
53 #define CONF_PERS_MAX_DATA_SIZE "PERS/max_data_size"
54 #define CONF_LOGGER_DEFAULT_LOG_NAME "LOGGER/default_log_name"
55 #define CONF_LOGGER_DEFAULT_LOG_LEVEL "LOGGER/default_log_level"
56 
57  std::map<const std::string, std::string> config = {
58  // [DERECHO]
59  {CONF_DERECHO_LEADER_IP, "127.0.0.1"},
61  {CONF_DERECHO_LOCAL_ID, "0"},
62  {CONF_DERECHO_LOCAL_IP, "127.0.0.1"},
63  {CONF_DERECHO_GMS_PORT, "23580"},
64  {CONF_DERECHO_RPC_PORT, "28366"},
65  {CONF_DERECHO_SST_PORT, "37683"},
66  {CONF_DERECHO_RDMC_PORT, "31675"},
73  // [SUBGROUP/<subgroupname>]
80  // [RDMA]
81  {CONF_RDMA_PROVIDER, "sockets"},
82  {CONF_RDMA_DOMAIN, "eth0"},
83  {CONF_RDMA_TX_DEPTH, "256"},
84  {CONF_RDMA_RX_DEPTH, "256"},
85  // [PERS]
86  {CONF_PERS_FILE_PATH, ".plog"},
87  {CONF_PERS_RAMDISK_PATH, "/dev/shm/volatile_t"},
88  {CONF_PERS_RESET, "false"},
89  {CONF_PERS_MAX_LOG_ENTRY, "1048576"}, // 1M log entries.
90  {CONF_PERS_MAX_DATA_SIZE, "549755813888"}, // 512G total data size.
91  // [LOGGER]
92  {CONF_LOGGER_DEFAULT_LOG_NAME, "derecho_debug"},
94 
95 public:
96  // the option for parsing command line with getopt(not GetPot!!!)
97  static struct option long_options[];
98 
99 public:
106  Conf(int argc, char* argv[], GetPot* getpotcfg = nullptr) noexcept {
107  // 1 - load configuration from configuration file
108  if(getpotcfg != nullptr) {
109  for(const std::string& key : getpotcfg->get_variable_names()) {
110  this->config[key] = (*getpotcfg)(key, "");
111  }
112  }
113  // 2 - load configuration from the command line
114  int c;
115  while(1) {
116  int option_index = 0;
117 
118  c = getopt_long(argc, argv, "", long_options, &option_index);
119  if(c == -1) {
120  break;
121  }
122 
123  switch(c) {
124  case 0:
125  this->config[long_options[option_index].name] = optarg;
126  break;
127 
128  case '?':
129  break;
130 
131  default:
132  std::cerr << "ignore unknown commandline code:" << c << std::endl;
133  }
134  }
135  }
137  const std::string& getString(const std::string& key) const {
138  return this->config.at(key);
139  }
140  const int16_t getInt16(const std::string& key) const {
141  return (const int16_t)std::stoi(this->config.at(key));
142  }
143  const uint16_t getUInt16(const std::string& key) const {
144  return (const uint16_t)std::stoi(this->config.at(key));
145  }
146  const int32_t getInt32(const std::string& key) const {
147  return (const int32_t)std::stoi(this->config.at(key));
148  }
149  const uint32_t getUInt32(const std::string& key) const {
150  return (const uint32_t)std::stoi(this->config.at(key));
151  }
152  const int64_t getInt64(const std::string& key) const {
153  return (const int64_t)std::stoll(this->config.at(key));
154  }
155  const uint64_t getUInt64(const std::string& key) const {
156  return (const uint64_t)std::stoll(this->config.at(key));
157  }
158  const float getFloat(const std::string& key) const {
159  return (const float)std::stof(this->config.at(key));
160  }
161  const double getDouble(const std::string& key) const {
162  return (const float)std::stod(this->config.at(key));
163  }
164  const bool getBoolean(const std::string& key) const {
165  return (this->config.at(key) == "true") || (this->config.at(key) == "yes") || (this->config.at(key) == "1");
166  }
167  // Please check if a customized key exists, otherwise the getXXX() function
168  // will throw an exception on unknown keys.
169  const bool hasCustomizedKey(const std::string& key) const {
170  return (this->config.find(key) != this->config.end());
171  }
172  // Initialize the singleton from the command line and the configuration file.
173  // The command line has higher priority than the configuration file
174  // The process we find the configuration file:
175  // 1) if conf_file is not null, use it, otherwise,
176  // 2) try DERECHO_CONF_FILE environment, otherwise,
177  // 3) use "derecho.cfg" at local, otherwise,
178  // 4) use all default settings.
179  // Note: initialize will be called on the first 'get()' if it is not called
180  // before.
181  static void initialize(int argc, char* argv[],
182  const char* conf_file = nullptr);
183  static const Conf* get() noexcept;
184 
185  // Defines fields used for loading subgroup profiles in multicast_group.h
186  static const std::vector<std::string> subgroupProfileFields;
187 
188 private:
189  // singleton
190  static std::unique_ptr<Conf> singleton;
191  static std::atomic<uint32_t> singleton_initialized_flag;
192 };
193 
194 // helpers
195 const std::string& getConfString(const std::string& key);
196 const int16_t getConfInt16(const std::string& key);
197 const uint16_t getConfUInt16(const std::string& key);
198 const int32_t getConfInt32(const std::string& key);
199 const uint32_t getConfUInt32(const std::string& key);
200 const int64_t getConfInt64(const std::string& key);
201 const uint64_t getConfUInt64(const std::string& key);
202 const float getConfFloat(const std::string& key);
203 const double getConfDouble(const std::string& key);
204 const bool getConfBoolean(const std::string& key);
205 const bool hasCustomizedConfKey(const std::string& key);
206 } // namespace derecho
207 #endif // CONF_HPP
#define CONF_SUBGROUP_DEFAULT_MAX_SMC_PAYLOAD_SIZE
Definition: conf.hpp:40
#define CONF_SUBGROUP_DEFAULT_MAX_PAYLOAD_SIZE
Definition: conf.hpp:38
const uint16_t getUInt16(const std::string &key) const
Definition: conf.hpp:143
const uint16_t getConfUInt16(const std::string &key)
Definition: conf.cpp:126
#define CONF_SUBGROUP_DEFAULT_RDMC_SEND_ALGORITHM
Definition: conf.hpp:43
const int32_t getInt32(const std::string &key) const
Definition: conf.hpp:146
static const std::vector< std::string > subgroupProfileFields
Definition: conf.hpp:186
const std::string & getConfString(const std::string &key)
Definition: conf.cpp:110
#define CONF_PERS_RESET
Definition: conf.hpp:51
const bool hasCustomizedKey(const std::string &key) const
Definition: conf.hpp:169
int argc
#define CONF_PERS_MAX_DATA_SIZE
Definition: conf.hpp:53
const int32_t getConfInt32(const std::string &key)
Definition: conf.cpp:114
static struct option long_options[]
Definition: conf.hpp:97
#define CONF_DERECHO_MAX_P2P_REPLY_PAYLOAD_SIZE
Definition: conf.hpp:35
const int16_t getConfInt16(const std::string &key)
Definition: conf.cpp:122
const float getFloat(const std::string &key) const
Definition: conf.hpp:158
const uint32_t getConfUInt32(const std::string &key)
Definition: conf.cpp:118
#define CONF_SUBGROUP_DEFAULT_MAX_REPLY_PAYLOAD_SIZE
Definition: conf.hpp:39
#define CONF_SUBGROUP_DEFAULT_WINDOW_SIZE
Definition: conf.hpp:42
#define CONF_DERECHO_SST_POLL_CQ_TIMEOUT_MS
Definition: conf.hpp:31
#define CONF_DERECHO_SST_PORT
Definition: conf.hpp:28
#define CONF_RDMA_PROVIDER
Definition: conf.hpp:45
static void initialize(int argc, char *argv[], const char *conf_file=nullptr)
Definition: conf.cpp:67
const uint32_t getUInt32(const std::string &key) const
Definition: conf.hpp:149
#define CONF_DERECHO_DISABLE_PARTITIONING_SAFETY
Definition: conf.hpp:32
char ** argv
#define CONF_DERECHO_LEADER_GMS_PORT
Definition: conf.hpp:23
const bool getBoolean(const std::string &key) const
Definition: conf.hpp:164
const int64_t getInt64(const std::string &key) const
Definition: conf.hpp:152
const uint64_t getUInt64(const std::string &key) const
Definition: conf.hpp:155
#define CONF_RDMA_RX_DEPTH
Definition: conf.hpp:48
#define CONF_DERECHO_LOCAL_IP
Definition: conf.hpp:25
#define CONF_DERECHO_HEARTBEAT_MS
Definition: conf.hpp:30
const int16_t getInt16(const std::string &key) const
Definition: conf.hpp:140
#define CONF_DERECHO_RPC_PORT
Definition: conf.hpp:27
#define CONF_DERECHO_P2P_WINDOW_SIZE
Definition: conf.hpp:36
const int64_t getConfInt64(const std::string &key)
Definition: conf.cpp:130
static std::atomic< uint32_t > singleton_initialized_flag
Definition: conf.hpp:191
#define CONF_DERECHO_GMS_PORT
Definition: conf.hpp:26
The single configuration file for derecho.
Definition: conf.hpp:18
#define CONF_DERECHO_MAX_P2P_REQUEST_PAYLOAD_SIZE
Definition: conf.hpp:34
#define CONF_RDMA_TX_DEPTH
Definition: conf.hpp:47
const bool getConfBoolean(const std::string &key)
Definition: conf.cpp:146
#define CONF_RDMA_DOMAIN
Definition: conf.hpp:46
#define CONF_SUBGROUP_DEFAULT_BLOCK_SIZE
Definition: conf.hpp:41
#define CONF_DERECHO_RDMC_PORT
Definition: conf.hpp:29
#define CONF_LOGGER_DEFAULT_LOG_LEVEL
Definition: conf.hpp:55
std::map< const std::string, std::string > config
Definition: conf.hpp:57
#define CONF_PERS_MAX_LOG_ENTRY
Definition: conf.hpp:52
#define CONF_DERECHO_LOCAL_ID
Definition: conf.hpp:24
#define CONF_LOGGER_DEFAULT_LOG_NAME
Definition: conf.hpp:54
#define CONF_PERS_RAMDISK_PATH
Definition: conf.hpp:50
Conf(int argc, char *argv[], GetPot *getpotcfg=nullptr) noexcept
Constructor: Conf can read configure from multiple sources.
Definition: conf.hpp:106
static std::unique_ptr< Conf > singleton
Definition: conf.hpp:190
const double getDouble(const std::string &key) const
Definition: conf.hpp:161
const float getConfFloat(const std::string &key)
Definition: conf.cpp:138
const double getConfDouble(const std::string &key)
Definition: conf.cpp:142
#define CONF_PERS_FILE_PATH
Definition: conf.hpp:49
#define CONF_DERECHO_LEADER_IP
Definition: conf.hpp:22
const uint64_t getConfUInt64(const std::string &key)
Definition: conf.cpp:134
const bool hasCustomizedConfKey(const std::string &key)
Definition: conf.cpp:150
const std::string & getString(const std::string &key) const
get configuration
Definition: conf.hpp:137