Derecho  0.9
Distributed systems toolkit for RDMA
conf.cpp
Go to the documentation of this file.
1 #include <derecho/conf/conf.hpp>
2 #include <cstdlib>
3 #include <sys/stat.h>
4 #include <unistd.h>
5 #ifndef NDEBUG
6 #include <spdlog/sinks/stdout_color_sinks.h>
7 #endif //NDEBUG
8 
9 namespace derecho {
10 
11 static const char* default_conf_file = "derecho.cfg";
12 
13 const std::vector<std::string> Conf::subgroupProfileFields = {
14  "max_payload_size",
15  "max_reply_payload_size",
16  "max_smc_payload_size",
17  "block_size",
18  "window_size",
19  "rdmc_send_algorithm"
20 };
21 
22 std::unique_ptr<Conf> Conf::singleton = nullptr;
23 
24 std::atomic<uint32_t> Conf::singleton_initialized_flag = 0;
25 #define CONF_UNINITIALIZED (0)
26 #define CONF_INITIALIZING (1)
27 #define CONF_INITIALIZED (2)
28 
29 #define MAKE_LONG_OPT_ENTRY(x) \
30  { x, required_argument, 0, 0 }
31 struct option Conf::long_options[] = {
32  // [DERECHO]
47  // [SUBGROUP/<subgroup name>]
54  // [RDMA]
59  // [PERS]
65  {0, 0, 0, 0}};
66 
67 void Conf::initialize(int argc, char* argv[], const char* conf_file) {
68  uint32_t expected = CONF_UNINITIALIZED;
69  // if not initialized(0), set the flag to under initialization ...
70  if(Conf::singleton_initialized_flag.compare_exchange_strong(
71  expected, CONF_INITIALIZING, std::memory_order_acq_rel)) {
72  // 1 - get configuration file path
73  std::string real_conf_file;
74  struct stat buffer;
75  if(conf_file)
76  real_conf_file = conf_file;
77  else if(std::getenv("DERECHO_CONF_FILE"))
78  // try environment variable: DERECHO_CONF_FILE
79  real_conf_file = std::getenv("DERECHO_CONF_FILE");
80  else if(stat(default_conf_file, &buffer) == 0) {
81  if(S_ISREG(buffer.st_mode) && (S_IRUSR | buffer.st_mode)) {
82  real_conf_file = default_conf_file;
83  }
84  } else
85  real_conf_file.clear();
86 
87  // 2 - load configuration
88  GetPot* cfg = nullptr;
89  if(!real_conf_file.empty()) {
90  cfg = new GetPot(real_conf_file);
91  }
92  Conf::singleton = std::make_unique<Conf>(argc, argv, cfg);
93  delete cfg;
94 
95  // 3 - set the flag to initialized
96  Conf::singleton_initialized_flag.store(CONF_INITIALIZED, std::memory_order_acq_rel);
97  }
98 }
99 
100 // should we force the user to call Conf::initialize() by throw an expcetion
101 // for uninitialized configuration?
102 const Conf* Conf::get() noexcept {
103  while(Conf::singleton_initialized_flag.load(std::memory_order_acquire) != CONF_INITIALIZED) {
104  char *empty_arg[1] = {nullptr};
105  Conf::initialize(0, empty_arg, nullptr);
106  }
107  return Conf::singleton.get();
108 }
109 
110 const std::string& getConfString(const std::string& key) {
111  return Conf::get()->getString(key);
112 }
113 
114 const int32_t getConfInt32(const std::string& key) {
115  return Conf::get()->getInt32(key);
116 }
117 
118 const uint32_t getConfUInt32(const std::string& key) {
119  return Conf::get()->getUInt32(key);
120 }
121 
122 const int16_t getConfInt16(const std::string& key) {
123  return Conf::get()->getInt16(key);
124 }
125 
126 const uint16_t getConfUInt16(const std::string& key) {
127  return Conf::get()->getUInt16(key);
128 }
129 
130 const int64_t getConfInt64(const std::string& key) {
131  return Conf::get()->getInt64(key);
132 }
133 
134 const uint64_t getConfUInt64(const std::string& key) {
135  return Conf::get()->getUInt64(key);
136 }
137 
138 const float getConfFloat(const std::string& key) {
139  return Conf::get()->getFloat(key);
140 }
141 
142 const double getConfDouble(const std::string& key) {
143  return Conf::get()->getDouble(key);
144 }
145 
146 const bool getConfBoolean(const std::string& key) {
147  return Conf::get()->getBoolean(key);
148 }
149 
150 const bool hasCustomizedConfKey(const std::string& key) {
151  return Conf::get()->hasCustomizedKey(key);
152 }
153 }
#define CONF_SUBGROUP_DEFAULT_MAX_SMC_PAYLOAD_SIZE
Definition: conf.hpp:40
#define CONF_INITIALIZED
Definition: conf.cpp:27
#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
#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 const Conf * get() noexcept
Definition: conf.cpp:102
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_INITIALIZING
Definition: conf.cpp:26
#define CONF_SUBGROUP_DEFAULT_BLOCK_SIZE
Definition: conf.hpp:41
#define CONF_DERECHO_RDMC_PORT
Definition: conf.hpp:29
#define CONF_PERS_MAX_LOG_ENTRY
Definition: conf.hpp:52
#define CONF_DERECHO_LOCAL_ID
Definition: conf.hpp:24
#define CONF_PERS_RAMDISK_PATH
Definition: conf.hpp:50
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
#define CONF_UNINITIALIZED
Definition: conf.cpp:25
const uint64_t getConfUInt64(const std::string &key)
Definition: conf.cpp:134
const bool hasCustomizedConfKey(const std::string &key)
Definition: conf.cpp:150
#define MAKE_LONG_OPT_ENTRY(x)
Definition: conf.cpp:29
const std::string & getString(const std::string &key) const
get configuration
Definition: conf.hpp:137