2020-05-21 21:00:54 +03:00
|
|
|
#pragma once
|
|
|
|
|
2020-06-06 01:39:58 +03:00
|
|
|
#include "osd_id.h"
|
2020-05-21 21:00:54 +03:00
|
|
|
#include "http_client.h"
|
|
|
|
#include "timerfd_manager.h"
|
|
|
|
|
|
|
|
#define ETCD_CONFIG_WATCH_ID 1
|
|
|
|
#define ETCD_PG_STATE_WATCH_ID 2
|
|
|
|
#define ETCD_PG_HISTORY_WATCH_ID 3
|
|
|
|
#define ETCD_OSD_STATE_WATCH_ID 4
|
|
|
|
|
|
|
|
#define MAX_ETCD_ATTEMPTS 5
|
|
|
|
#define ETCD_SLOW_TIMEOUT 5000
|
|
|
|
#define ETCD_QUICK_TIMEOUT 1000
|
|
|
|
|
2020-09-02 21:54:32 +03:00
|
|
|
struct json_kv_t
|
|
|
|
{
|
|
|
|
std::string key;
|
|
|
|
json11::Json value;
|
|
|
|
};
|
|
|
|
|
2020-05-21 21:00:54 +03:00
|
|
|
struct pg_config_t
|
|
|
|
{
|
|
|
|
bool exists;
|
|
|
|
osd_num_t primary;
|
|
|
|
std::vector<osd_num_t> target_set;
|
|
|
|
std::vector<std::vector<osd_num_t>> target_history;
|
|
|
|
std::vector<osd_num_t> all_peers;
|
|
|
|
bool pause;
|
|
|
|
osd_num_t cur_primary;
|
|
|
|
int cur_state;
|
2020-07-02 00:41:28 +03:00
|
|
|
uint64_t epoch;
|
2020-05-21 21:00:54 +03:00
|
|
|
};
|
|
|
|
|
2020-09-02 21:54:32 +03:00
|
|
|
struct pool_config_t
|
2020-05-21 21:00:54 +03:00
|
|
|
{
|
2020-09-02 21:54:32 +03:00
|
|
|
bool exists;
|
|
|
|
pool_id_t id;
|
|
|
|
std::string name;
|
|
|
|
uint64_t scheme;
|
|
|
|
uint64_t pg_size, pg_minsize;
|
|
|
|
uint64_t pg_count;
|
2020-09-03 00:52:41 +03:00
|
|
|
uint64_t real_pg_count;
|
2020-09-02 21:54:32 +03:00
|
|
|
std::string failure_domain;
|
|
|
|
uint64_t max_osd_combinations;
|
|
|
|
std::map<pg_num_t, pg_config_t> pg_config;
|
2020-05-21 21:00:54 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct etcd_state_client_t
|
|
|
|
{
|
2020-05-25 15:53:48 +03:00
|
|
|
std::vector<std::string> etcd_addresses;
|
|
|
|
std::string etcd_prefix;
|
2020-05-21 21:00:54 +03:00
|
|
|
int log_level = 0;
|
|
|
|
timerfd_manager_t *tfd = NULL;
|
|
|
|
|
|
|
|
int etcd_watches_initialised = 0;
|
|
|
|
uint64_t etcd_watch_revision = 0;
|
|
|
|
websocket_t *etcd_watch_ws = NULL;
|
2020-09-02 21:54:32 +03:00
|
|
|
std::map<pool_id_t, pool_config_t> pool_config;
|
2020-05-21 21:00:54 +03:00
|
|
|
std::map<osd_num_t, json11::Json> peer_states;
|
|
|
|
|
|
|
|
std::function<void(json11::Json::object &)> on_change_hook;
|
|
|
|
std::function<void(json11::Json::object &)> on_load_config_hook;
|
|
|
|
std::function<json11::Json()> load_pgs_checks_hook;
|
|
|
|
std::function<void(bool)> on_load_pgs_hook;
|
2020-09-02 21:54:32 +03:00
|
|
|
std::function<void(pool_id_t, pg_num_t)> on_change_pg_history_hook;
|
2020-07-02 00:41:28 +03:00
|
|
|
std::function<void(osd_num_t)> on_change_osd_state_hook;
|
2020-05-21 21:00:54 +03:00
|
|
|
|
|
|
|
json_kv_t parse_etcd_kv(const json11::Json & kv_json);
|
|
|
|
void etcd_call(std::string api, json11::Json payload, int timeout, std::function<void(std::string, json11::Json)> callback);
|
|
|
|
void etcd_txn(json11::Json txn, int timeout, std::function<void(std::string, json11::Json)> callback);
|
|
|
|
void start_etcd_watcher();
|
|
|
|
void load_global_config();
|
|
|
|
void load_pgs();
|
|
|
|
void parse_state(const std::string & key, const json11::Json & value);
|
2020-06-06 16:32:35 +03:00
|
|
|
void parse_config(json11::Json & config);
|
2020-05-21 21:00:54 +03:00
|
|
|
};
|