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.
 
 
 
 
 
 

114 lines
3.0 KiB

  1. // Copyright (c) Vitaliy Filippov, 2019+
  2. // License: VNPL-1.1 or GNU GPL-2.0+ (see README.md for details)
  3. #pragma once
  4. #include "json11/json11.hpp"
  5. #include "osd_id.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 etcd_kv_t
  16. {
  17. std::string key;
  18. json11::Json value;
  19. uint64_t mod_revision;
  20. };
  21. struct pg_config_t
  22. {
  23. bool exists;
  24. osd_num_t primary;
  25. std::vector<osd_num_t> target_set;
  26. std::vector<std::vector<osd_num_t>> target_history;
  27. std::vector<osd_num_t> all_peers;
  28. bool pause;
  29. osd_num_t cur_primary;
  30. int cur_state;
  31. uint64_t epoch;
  32. };
  33. struct pool_config_t
  34. {
  35. bool exists;
  36. pool_id_t id;
  37. std::string name;
  38. uint64_t scheme;
  39. uint64_t pg_size, pg_minsize, parity_chunks;
  40. uint64_t pg_count;
  41. uint64_t real_pg_count;
  42. std::string failure_domain;
  43. uint64_t max_osd_combinations;
  44. uint64_t pg_stripe_size;
  45. std::map<pg_num_t, pg_config_t> pg_config;
  46. };
  47. struct inode_config_t
  48. {
  49. uint64_t num;
  50. std::string name;
  51. uint64_t size;
  52. inode_t parent_id;
  53. bool readonly;
  54. // Change revision of the metadata in etcd
  55. uint64_t mod_revision;
  56. };
  57. struct inode_watch_t
  58. {
  59. std::string name;
  60. inode_config_t cfg;
  61. };
  62. struct websocket_t;
  63. struct etcd_state_client_t
  64. {
  65. protected:
  66. std::vector<inode_watch_t*> watches;
  67. websocket_t *etcd_watch_ws = NULL;
  68. uint64_t bs_block_size = DEFAULT_BLOCK_SIZE;
  69. void add_etcd_url(std::string);
  70. public:
  71. std::vector<std::string> etcd_addresses;
  72. std::string etcd_prefix;
  73. int log_level = 0;
  74. timerfd_manager_t *tfd = NULL;
  75. int etcd_watches_initialised = 0;
  76. uint64_t etcd_watch_revision = 0;
  77. std::map<pool_id_t, pool_config_t> pool_config;
  78. std::map<osd_num_t, json11::Json> peer_states;
  79. std::map<inode_t, inode_config_t> inode_config;
  80. std::map<std::string, inode_t> inode_by_name;
  81. std::function<void(std::map<std::string, etcd_kv_t> &)> on_change_hook;
  82. std::function<void(json11::Json::object &)> on_load_config_hook;
  83. std::function<json11::Json()> load_pgs_checks_hook;
  84. std::function<void(bool)> on_load_pgs_hook;
  85. std::function<void(pool_id_t, pg_num_t)> on_change_pg_history_hook;
  86. std::function<void(osd_num_t)> on_change_osd_state_hook;
  87. etcd_kv_t parse_etcd_kv(const json11::Json & kv_json);
  88. void etcd_call(std::string api, json11::Json payload, int timeout, std::function<void(std::string, json11::Json)> callback);
  89. void etcd_txn(json11::Json txn, int timeout, std::function<void(std::string, json11::Json)> callback);
  90. void start_etcd_watcher();
  91. void load_global_config();
  92. void load_pgs();
  93. void parse_state(const etcd_kv_t & kv);
  94. void parse_config(const json11::Json & config);
  95. inode_watch_t* watch_inode(std::string name);
  96. void close_watch(inode_watch_t* watch);
  97. ~etcd_state_client_t();
  98. };