Use json11 instead of blockstore_config_t

allow-etcd-address-option
Vitaliy Filippov 2021-04-30 00:46:03 +03:00
parent 483c5ab380
commit 5010b0dd75
6 changed files with 69 additions and 66 deletions

View File

@ -85,7 +85,7 @@ void etcd_state_client_t::add_etcd_url(std::string addr)
} }
} }
void etcd_state_client_t::parse_config(json11::Json & config) void etcd_state_client_t::parse_config(const json11::Json & config)
{ {
this->etcd_addresses.clear(); this->etcd_addresses.clear();
if (config["etcd_address"].is_string()) if (config["etcd_address"].is_string())
@ -342,7 +342,7 @@ void etcd_state_client_t::load_pgs()
}); });
} }
#else #else
void etcd_state_client_t::parse_config(json11::Json & config) void etcd_state_client_t::parse_config(const json11::Json & config)
{ {
} }

View File

@ -106,7 +106,7 @@ public:
void load_global_config(); void load_global_config();
void load_pgs(); void load_pgs();
void parse_state(const etcd_kv_t & kv); void parse_state(const etcd_kv_t & kv);
void parse_config(json11::Json & config); void parse_config(const json11::Json & config);
inode_watch_t* watch_inode(std::string name); inode_watch_t* watch_inode(std::string name);
void close_watch(inode_watch_t* watch); void close_watch(inode_watch_t* watch);
~etcd_state_client_t(); ~etcd_state_client_t();

View File

@ -10,31 +10,39 @@
#include "osd.h" #include "osd.h"
#include "http_client.h" #include "http_client.h"
osd_t::osd_t(blockstore_config_t & config, ring_loop_t *ringloop) static blockstore_config_t json_to_bs(const json11::Json::object & config)
{ {
bs_block_size = strtoull(config["block_size"].c_str(), NULL, 10); blockstore_config_t bs;
bs_bitmap_granularity = strtoull(config["bitmap_granularity"].c_str(), NULL, 10); for (auto kv: config)
if (!bs_block_size) {
bs_block_size = DEFAULT_BLOCK_SIZE; if (kv.second.is_string())
if (!bs_bitmap_granularity) bs[kv.first] = kv.second.string_value();
bs_bitmap_granularity = DEFAULT_BITMAP_GRANULARITY; else
clean_entry_bitmap_size = bs_block_size / bs_bitmap_granularity / 8; bs[kv.first] = kv.second.dump();
}
return bs;
}
osd_t::osd_t(const json11::Json & config, ring_loop_t *ringloop)
{
zero_buffer_size = 1<<20; zero_buffer_size = 1<<20;
zero_buffer = malloc_or_die(zero_buffer_size); zero_buffer = malloc_or_die(zero_buffer_size);
memset(zero_buffer, 0, zero_buffer_size); memset(zero_buffer, 0, zero_buffer_size);
this->config = config; this->config = config.object_items();
this->ringloop = ringloop; this->ringloop = ringloop;
if (this->config.find("log_level") == this->config.end())
this->config["log_level"] = 1;
parse_config(this->config);
epmgr = new epoll_manager_t(ringloop); epmgr = new epoll_manager_t(ringloop);
// FIXME: Use timerfd_interval based directly on io_uring // FIXME: Use timerfd_interval based directly on io_uring
this->tfd = epmgr->tfd; this->tfd = epmgr->tfd;
// FIXME: Create Blockstore from on-disk superblock config and check it against the OSD cluster config // FIXME: Create Blockstore from on-disk superblock config and check it against the OSD cluster config
this->bs = new blockstore_t(config, ringloop, tfd); auto bs_cfg = json_to_bs(this->config);
this->bs = new blockstore_t(bs_cfg, ringloop, tfd);
parse_config(config);
this->tfd->set_timer(print_stats_interval*1000, true, [this](int timer_id) this->tfd->set_timer(print_stats_interval*1000, true, [this](int timer_id)
{ {
@ -66,63 +74,69 @@ osd_t::~osd_t()
free(zero_buffer); free(zero_buffer);
} }
void osd_t::parse_config(blockstore_config_t & config) void osd_t::parse_config(const json11::Json & config)
{ {
if (config.find("log_level") == config.end()) st_cli.parse_config(config);
config["log_level"] = "1"; msgr.parse_config(config);
log_level = strtoull(config["log_level"].c_str(), NULL, 10); // OSD number
// Initial startup configuration osd_num = config["osd_num"].uint64_value();
json11::Json json_config = json11::Json(config);
st_cli.parse_config(json_config);
etcd_report_interval = strtoull(config["etcd_report_interval"].c_str(), NULL, 10);
if (etcd_report_interval <= 0)
etcd_report_interval = 30;
osd_num = strtoull(config["osd_num"].c_str(), NULL, 10);
if (!osd_num) if (!osd_num)
throw std::runtime_error("osd_num is required in the configuration"); throw std::runtime_error("osd_num is required in the configuration");
msgr.osd_num = osd_num; msgr.osd_num = osd_num;
// Vital Blockstore parameters
bs_block_size = config["block_size"].uint64_value();
if (!bs_block_size)
bs_block_size = DEFAULT_BLOCK_SIZE;
bs_bitmap_granularity = config["bitmap_granularity"].uint64_value();
if (!bs_bitmap_granularity)
bs_bitmap_granularity = DEFAULT_BITMAP_GRANULARITY;
clean_entry_bitmap_size = bs_block_size / bs_bitmap_granularity / 8;
// Bind address
bind_address = config["bind_address"].string_value();
if (bind_address == "")
bind_address = "0.0.0.0";
bind_port = config["bind_port"].uint64_value();
if (bind_port <= 0 || bind_port > 65535)
bind_port = 0;
// OSD configuration
log_level = config["log_level"].uint64_value();
etcd_report_interval = config["etcd_report_interval"].uint64_value();
if (etcd_report_interval <= 0)
etcd_report_interval = 30;
readonly = config["readonly"] == "true" || config["readonly"] == "1" || config["readonly"] == "yes";
run_primary = config["run_primary"] != "false" && config["run_primary"] != "0" && config["run_primary"] != "no"; run_primary = config["run_primary"] != "false" && config["run_primary"] != "0" && config["run_primary"] != "no";
no_rebalance = config["no_rebalance"] == "true" || config["no_rebalance"] == "1" || config["no_rebalance"] == "yes"; no_rebalance = config["no_rebalance"] == "true" || config["no_rebalance"] == "1" || config["no_rebalance"] == "yes";
no_recovery = config["no_recovery"] == "true" || config["no_recovery"] == "1" || config["no_recovery"] == "yes"; no_recovery = config["no_recovery"] == "true" || config["no_recovery"] == "1" || config["no_recovery"] == "yes";
allow_test_ops = config["allow_test_ops"] == "true" || config["allow_test_ops"] == "1" || config["allow_test_ops"] == "yes"; allow_test_ops = config["allow_test_ops"] == "true" || config["allow_test_ops"] == "1" || config["allow_test_ops"] == "yes";
// Cluster configuration
bind_address = config["bind_address"];
if (bind_address == "")
bind_address = "0.0.0.0";
bind_port = stoull_full(config["bind_port"]);
if (bind_port <= 0 || bind_port > 65535)
bind_port = 0;
if (config["immediate_commit"] == "all") if (config["immediate_commit"] == "all")
immediate_commit = IMMEDIATE_ALL; immediate_commit = IMMEDIATE_ALL;
else if (config["immediate_commit"] == "small") else if (config["immediate_commit"] == "small")
immediate_commit = IMMEDIATE_SMALL; immediate_commit = IMMEDIATE_SMALL;
if (config.find("autosync_interval") != config.end()) if (!config["autosync_interval"].is_null())
{ {
autosync_interval = strtoull(config["autosync_interval"].c_str(), NULL, 10); // Allow to set it to 0
autosync_interval = config["autosync_interval"].uint64_value();
if (autosync_interval > MAX_AUTOSYNC_INTERVAL) if (autosync_interval > MAX_AUTOSYNC_INTERVAL)
autosync_interval = DEFAULT_AUTOSYNC_INTERVAL; autosync_interval = DEFAULT_AUTOSYNC_INTERVAL;
} }
if (config.find("client_queue_depth") != config.end()) if (!config["client_queue_depth"].is_null())
{ {
client_queue_depth = strtoull(config["client_queue_depth"].c_str(), NULL, 10); client_queue_depth = config["client_queue_depth"].uint64_value();
if (client_queue_depth < 128) if (client_queue_depth < 128)
client_queue_depth = 128; client_queue_depth = 128;
} }
recovery_queue_depth = strtoull(config["recovery_queue_depth"].c_str(), NULL, 10); recovery_queue_depth = config["recovery_queue_depth"].uint64_value();
if (recovery_queue_depth < 1 || recovery_queue_depth > MAX_RECOVERY_QUEUE) if (recovery_queue_depth < 1 || recovery_queue_depth > MAX_RECOVERY_QUEUE)
recovery_queue_depth = DEFAULT_RECOVERY_QUEUE; recovery_queue_depth = DEFAULT_RECOVERY_QUEUE;
recovery_sync_batch = strtoull(config["recovery_sync_batch"].c_str(), NULL, 10); recovery_sync_batch = config["recovery_sync_batch"].uint64_value();
if (recovery_sync_batch < 1 || recovery_sync_batch > MAX_RECOVERY_QUEUE) if (recovery_sync_batch < 1 || recovery_sync_batch > MAX_RECOVERY_QUEUE)
recovery_sync_batch = DEFAULT_RECOVERY_BATCH; recovery_sync_batch = DEFAULT_RECOVERY_BATCH;
if (config["readonly"] == "true" || config["readonly"] == "1" || config["readonly"] == "yes") print_stats_interval = config["print_stats_interval"].uint64_value();
readonly = true;
print_stats_interval = strtoull(config["print_stats_interval"].c_str(), NULL, 10);
if (!print_stats_interval) if (!print_stats_interval)
print_stats_interval = 3; print_stats_interval = 3;
slow_log_interval = strtoull(config["slow_log_interval"].c_str(), NULL, 10); slow_log_interval = config["slow_log_interval"].uint64_value();
if (!slow_log_interval) if (!slow_log_interval)
slow_log_interval = 10; slow_log_interval = 10;
msgr.parse_config(json_config);
} }
void osd_t::bind_socket() void osd_t::bind_socket()

View File

@ -92,7 +92,7 @@ class osd_t
{ {
// config // config
blockstore_config_t config; json11::Json::object config;
int etcd_report_interval = 30; int etcd_report_interval = 30;
bool readonly = false; bool readonly = false;
@ -167,7 +167,7 @@ class osd_t
uint64_t recovery_stat_bytes[2][2] = { 0 }; uint64_t recovery_stat_bytes[2][2] = { 0 };
// cluster connection // cluster connection
void parse_config(blockstore_config_t & config); void parse_config(const json11::Json & config);
void init_cluster(); void init_cluster();
void on_change_osd_state_hook(osd_num_t peer_osd); void on_change_osd_state_hook(osd_num_t peer_osd);
void on_change_pg_history_hook(pool_id_t pool_id, pg_num_t pg_num); void on_change_pg_history_hook(pool_id_t pool_id, pg_num_t pg_num);
@ -268,7 +268,7 @@ class osd_t
} }
public: public:
osd_t(blockstore_config_t & config, ring_loop_t *ringloop); osd_t(const json11::Json & config, ring_loop_t *ringloop);
~osd_t(); ~osd_t();
void force_stop(int exitcode); void force_stop(int exitcode);
bool shutdown(); bool shutdown();

View File

@ -21,7 +21,7 @@ void osd_t::init_cluster()
{ {
// Test version of clustering code with 1 pool, 1 PG and 2 peers // Test version of clustering code with 1 pool, 1 PG and 2 peers
// Example: peers = 2:127.0.0.1:11204,3:127.0.0.1:11205 // Example: peers = 2:127.0.0.1:11204,3:127.0.0.1:11205
std::string peerstr = config["peers"]; std::string peerstr = config["peers"].string_value();
while (peerstr.size()) while (peerstr.size())
{ {
int pos = peerstr.find(','); int pos = peerstr.find(',');
@ -340,21 +340,10 @@ void osd_t::on_change_pg_history_hook(pool_id_t pool_id, pg_num_t pg_num)
void osd_t::on_load_config_hook(json11::Json::object & global_config) void osd_t::on_load_config_hook(json11::Json::object & global_config)
{ {
blockstore_config_t osd_config = this->config; json11::Json::object osd_config = this->config;
for (auto & cfg_var: global_config) for (auto & kv: global_config)
{ if (osd_config.find(kv.first) == osd_config.end())
if (this->config.find(cfg_var.first) == this->config.end()) osd_config[kv.first] = kv.second;
{
if (cfg_var.second.is_string())
{
osd_config[cfg_var.first] = cfg_var.second.string_value();
}
else
{
osd_config[cfg_var.first] = cfg_var.second.dump();
}
}
}
parse_config(osd_config); parse_config(osd_config);
bind_socket(); bind_socket();
acquire_lease(); acquire_lease();
@ -380,7 +369,7 @@ void osd_t::acquire_lease()
etcd_lease_id = data["ID"].string_value(); etcd_lease_id = data["ID"].string_value();
create_osd_state(); create_osd_state();
}); });
printf("[OSD %lu] reporting to etcd at %s every %d seconds\n", this->osd_num, config["etcd_address"].c_str(), etcd_report_interval); printf("[OSD %lu] reporting to etcd at %s every %d seconds\n", this->osd_num, config["etcd_address"].string_value().c_str(), etcd_report_interval);
tfd->set_timer(etcd_report_interval*1000, true, [this](int timer_id) tfd->set_timer(etcd_report_interval*1000, true, [this](int timer_id)
{ {
renew_lease(); renew_lease();

View File

@ -29,13 +29,13 @@ int main(int narg, char *args[])
perror("BUG: too small packet size"); perror("BUG: too small packet size");
return 1; return 1;
} }
blockstore_config_t config; json11::Json::object config;
for (int i = 1; i < narg; i++) for (int i = 1; i < narg; i++)
{ {
if (args[i][0] == '-' && args[i][1] == '-' && i < narg-1) if (args[i][0] == '-' && args[i][1] == '-' && i < narg-1)
{ {
char *opt = args[i]+2; char *opt = args[i]+2;
config[opt] = args[++i]; config[std::string(opt)] = std::string(args[++i]);
} }
} }
signal(SIGINT, handle_sigint); signal(SIGINT, handle_sigint);