// Copyright (c) Vitaliy Filippov, 2019+ // License: VNPL-1.0 or GNU GPL-2.0+ (see README.md for details) #pragma once #include "osd_id.h" #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 #define DEFAULT_BLOCK_SIZE 128*1024 struct json_kv_t { std::string key; json11::Json value; }; struct pg_config_t { bool exists; osd_num_t primary; std::vector target_set; std::vector> target_history; std::vector all_peers; bool pause; osd_num_t cur_primary; int cur_state; uint64_t epoch; }; struct pool_config_t { bool exists; pool_id_t id; std::string name; uint64_t scheme; uint64_t pg_size, pg_minsize, parity_chunks; uint64_t pg_count; uint64_t real_pg_count; std::string failure_domain; uint64_t max_osd_combinations; uint64_t pg_stripe_size; std::map pg_config; }; struct etcd_state_client_t { std::vector etcd_addresses; std::string etcd_prefix; 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; uint64_t bs_block_size = 0; std::map pool_config; std::map peer_states; std::function on_change_hook; std::function on_load_config_hook; std::function load_pgs_checks_hook; std::function on_load_pgs_hook; std::function on_change_pg_history_hook; std::function on_change_osd_state_hook; json_kv_t parse_etcd_kv(const json11::Json & kv_json); void etcd_call(std::string api, json11::Json payload, int timeout, std::function callback); void etcd_txn(json11::Json txn, int timeout, std::function callback); void start_etcd_watcher(); void load_global_config(); void load_pgs(); void parse_state(const std::string & key, const json11::Json & value); void parse_config(json11::Json & config); };