Simplified distributed block storage with strong consistency, like in Ceph
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

85 lines
2.4 KiB

  1. // Copyright (c) Vitaliy Filippov, 2019+
  2. // License: VNPL-1.0 or GNU GPL-2.0+ (see README.md for details)
  3. #pragma once
  4. #include "osd_id.h"
  5. #include "http_client.h"
  6. #include "timerfd_manager.h"
  7. #define ETCD_CONFIG_WATCH_ID 1
  8. #define ETCD_PG_STATE_WATCH_ID 2
  9. #define ETCD_PG_HISTORY_WATCH_ID 3
  10. #define ETCD_OSD_STATE_WATCH_ID 4
  11. #define MAX_ETCD_ATTEMPTS 5
  12. #define ETCD_SLOW_TIMEOUT 5000
  13. #define ETCD_QUICK_TIMEOUT 1000
  14. #define DEFAULT_BLOCK_SIZE 128*1024
  15. struct json_kv_t
  16. {
  17. std::string key;
  18. json11::Json value;
  19. };
  20. struct pg_config_t
  21. {
  22. bool exists;
  23. osd_num_t primary;
  24. std::vector<osd_num_t> target_set;
  25. std::vector<std::vector<osd_num_t>> target_history;
  26. std::vector<osd_num_t> all_peers;
  27. bool pause;
  28. osd_num_t cur_primary;
  29. int cur_state;
  30. uint64_t epoch;
  31. };
  32. struct pool_config_t
  33. {
  34. bool exists;
  35. pool_id_t id;
  36. std::string name;
  37. uint64_t scheme;
  38. uint64_t pg_size, pg_minsize, parity_chunks;
  39. uint64_t pg_count;
  40. uint64_t real_pg_count;
  41. std::string failure_domain;
  42. uint64_t max_osd_combinations;
  43. uint64_t pg_stripe_size;
  44. std::map<pg_num_t, pg_config_t> pg_config;
  45. };
  46. struct etcd_state_client_t
  47. {
  48. std::vector<std::string> etcd_addresses;
  49. std::string etcd_prefix;
  50. int log_level = 0;
  51. timerfd_manager_t *tfd = NULL;
  52. int etcd_watches_initialised = 0;
  53. uint64_t etcd_watch_revision = 0;
  54. websocket_t *etcd_watch_ws = NULL;
  55. uint64_t bs_block_size = 0;
  56. std::map<pool_id_t, pool_config_t> pool_config;
  57. std::map<osd_num_t, json11::Json> peer_states;
  58. std::function<void(json11::Json::object &)> on_change_hook;
  59. std::function<void(json11::Json::object &)> on_load_config_hook;
  60. std::function<json11::Json()> load_pgs_checks_hook;
  61. std::function<void(bool)> on_load_pgs_hook;
  62. std::function<void(pool_id_t, pg_num_t)> on_change_pg_history_hook;
  63. std::function<void(osd_num_t)> on_change_osd_state_hook;
  64. json_kv_t parse_etcd_kv(const json11::Json & kv_json);
  65. void etcd_call(std::string api, json11::Json payload, int timeout, std::function<void(std::string, json11::Json)> callback);
  66. void etcd_txn(json11::Json txn, int timeout, std::function<void(std::string, json11::Json)> callback);
  67. void start_etcd_watcher();
  68. void load_global_config();
  69. void load_pgs();
  70. void parse_state(const std::string & key, const json11::Json & value);
  71. void parse_config(json11::Json & config);
  72. };