SWC-DB  v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
MngrRole.h
Go to the documentation of this file.
1 /*
2  * SWC-DB© Copyright since 2019 Alex Kashirin <kashirin.alex@gmail.com>
3  * License details at <https://github.com/kashirin-alex/swc-db/#license>
4  */
5 
6 #ifndef swcdb_manager_MngrRole_h
7 #define swcdb_manager_MngrRole_h
8 
11 
12 
13 namespace SWC { namespace Manager {
14 
15 
16 class MngrRole final {
17 
18  public:
19 
20  MngrRole(const Comm::IoContextPtr& app_io,
21  const Comm::EndPoints& endpoints);
22 
23  MngrRole(const MngrRole&) = delete;
24  MngrRole(MngrRole&&) = delete;
25  MngrRole& operator=(const MngrRole&) = delete;
26  MngrRole& operator=(MngrRole&&) = delete;
27 
28  ~MngrRole() noexcept { }
29 
31  bool running() const noexcept {
32  return m_run;
33  }
34 
35  void schedule_checkin(uint32_t t_ms = 10000);
36 
37  bool is_active(cid_t cid);
38 
39  bool is_active_role(uint8_t role);
40 
42 
43  MngrStatus::Ptr active_mngr_role(uint8_t role);
44 
45  bool are_all_active(const client::Mngr::Groups::Vec& groups);
46 
47  void get_states(MngrsStatus& states);
48 
50 
52 
53  void fill_states(const MngrsStatus& states, uint64_t token,
54  const Comm::ResponseCallback::Ptr& cb);
55 
56  void update_manager_addr(uint64_t hash, const Comm::EndPoint& mngr_host);
57 
58  void disconnection(const Comm::EndPoint& endpoint_server,
59  const Comm::EndPoint& endpoint_client,
60  bool srv=false);
61 
62  void stop();
63 
64  void print(std::ostream& out);
65 
66 
67  private:
68 
69  void _apply_cfg();
70 
71  void managers_checkin();
72 
73  void fill_states();
74 
75  void managers_checker(uint32_t next, uint32_t total, bool flw);
76 
78  uint32_t next, uint32_t total, bool flw,
79  const Comm::ConnHandlerPtr& conn);
80 
81  void update_state(const Comm::EndPoint& endpoint,
82  DB::Types::MngrState state);
83 
84  void update_state(const Comm::EndPoints& endpoints,
85  DB::Types::MngrState state);
86 
87  MngrStatus::Ptr get_host(const Comm::EndPoints& endpoints);
88 
90 
91  bool is_group_off(const MngrStatus::Ptr& other);
92 
93  void apply_role_changes();
94 
95  void set_mngr_inchain(const Comm::ConnHandlerPtr& mngr);
96 
97 
99  const uint64_t m_local_token;
100 
101  std::shared_mutex m_mutex;
107  std::unordered_map<uint64_t, Comm::EndPoint> m_mngrs_client_srv;
108 
110  asio::high_resolution_timer m_check_timer;
112 
114 
115 
119 
124 };
125 
126 
127 
128 }}
129 
130 
131 #endif // swcdb_manager_MngrRole_h
SWC::Manager::MngrRole::~MngrRole
~MngrRole() noexcept
Definition: MngrRole.h:28
SWC::Manager::MngrRole::fill_states
void fill_states()
Definition: MngrRole.cc:441
SWC::Manager::MngrRole::managers_checker
void managers_checker(uint32_t next, uint32_t total, bool flw)
Definition: MngrRole.cc:450
SWC::Manager::MngrRole::m_local_endpoints
const Comm::EndPoints m_local_endpoints
Definition: MngrRole.h:98
SWC::Manager::MngrRole::update_manager_addr
void update_manager_addr(uint64_t hash, const Comm::EndPoint &mngr_host)
Definition: MngrRole.cc:267
SWC::Core::AtomicBase< bool >
SWC::Manager::MngrRole::m_check_timer
asio::high_resolution_timer m_check_timer
Definition: MngrRole.h:110
SWC::Manager::MngrRole::get_inchain_endpoint
Comm::EndPoint get_inchain_endpoint() const
Definition: MngrRole.cc:132
SWC::Manager::MngrRole::update_state
void update_state(const Comm::EndPoint &endpoint, DB::Types::MngrState state)
Definition: MngrRole.cc:534
SWC::Core::Atomic< uint8_t >
MngrState.h
SWC::Manager::MngrRole::apply_role_changes
void apply_role_changes()
Definition: MngrRole.cc:590
SWC::Manager::MngrRole::cfg_conn_fb_failures
const Config::Property::Value_int32_g::Ptr cfg_conn_fb_failures
Definition: MngrRole.h:118
SWC::Comm::EndPoint
asio::ip::tcp::endpoint EndPoint
Definition: Resolver.h:19
SWC::Manager::MngrStatus::Ptr
std::shared_ptr< MngrStatus > Ptr
Definition: MngrStatus.h:21
SWC::Manager::MngrRole::get_states
void get_states(MngrsStatus &states)
Definition: MngrRole.cc:126
SWC::Comm::IoContextPtr
std::shared_ptr< IoContext > IoContextPtr
Definition: IoContext.h:16
SWC::Manager::MngrRole::operator=
MngrRole & operator=(const MngrRole &)=delete
SWC::Manager::MngrRole::m_run
Core::AtomicBool m_run
Definition: MngrRole.h:111
SWC::Manager::MngrRole::m_mutex_timer
Core::MutexAtomic m_mutex_timer
Definition: MngrRole.h:109
SWC::Manager::MngrRole::cfg_delay_fallback
const Config::Property::Value_int32_g::Ptr cfg_delay_fallback
Definition: MngrRole.h:123
SWC::Manager::MngrRole::stop
void stop()
Definition: MngrRole.cc:319
MngrStatus.h
SWC::Manager::MngrRole::active_mngr
MngrStatus::Ptr active_mngr(cid_t cid)
Definition: MngrRole.cc:85
SWC_CAN_INLINE
#define SWC_CAN_INLINE
Definition: Compat.h:102
SWC::Manager::MngrRole::get_host
MngrStatus::Ptr get_host(const Comm::EndPoints &endpoints)
Definition: MngrRole.cc:556
SWC::Manager::MngrRole::schedule_checkin
void schedule_checkin(uint32_t t_ms=10000)
Definition: MngrRole.cc:47
SWC::Manager::MngrRole::m_local_token
const uint64_t m_local_token
Definition: MngrRole.h:99
SWC::Manager::MngrRole::manager_checker
void manager_checker(MngrStatus::Ptr host, uint32_t next, uint32_t total, bool flw, const Comm::ConnHandlerPtr &conn)
Definition: MngrRole.cc:514
SWC
The SWC-DB C++ namespace 'SWC'.
Definition: main.cc:12
SWC::Core::MutexAtomic
Definition: MutexAtomic.h:17
SWC::Manager::MngrRole::cfg_conn_probes
const Config::Property::Value_uint16_g::Ptr cfg_conn_probes
Definition: MngrRole.h:116
SWC::Manager::MngrRole::m_mngr_inchain
Comm::client::ConnQueuePtr m_mngr_inchain
Definition: MngrRole.h:113
SWC::Manager::MngrRole::cfg_conn_timeout
const Config::Property::Value_int32_g::Ptr cfg_conn_timeout
Definition: MngrRole.h:117
SWC::Comm::ResponseCallback::Ptr
std::shared_ptr< ResponseCallback > Ptr
Definition: ResponseCallback.h:18
SWC::Manager::MngrRole::running
SWC_CAN_INLINE bool running() const noexcept
Definition: MngrRole.h:31
SWC::Manager::MngrRole::is_active_role
bool is_active_role(uint8_t role)
Definition: MngrRole.cc:80
SWC::Manager::MngrRole::MngrRole
MngrRole(MngrRole &&)=delete
SWC::Manager::MngrRole::are_all_active
bool are_all_active(const client::Mngr::Groups::Vec &groups)
Definition: MngrRole.cc:108
SWC::cid_t
uint64_t cid_t
Definition: Identifiers.h:16
SWC::Comm::ConnHandlerPtr
std::shared_ptr< ConnHandler > ConnHandlerPtr
Definition: AppContext.h:17
SWC::Manager::MngrRole::m_mngrs_client_srv
std::unordered_map< uint64_t, Comm::EndPoint > m_mngrs_client_srv
Definition: MngrRole.h:107
SWC::Manager::MngrRole::MngrRole
MngrRole(const Comm::IoContextPtr &app_io, const Comm::EndPoints &endpoints)
Definition: MngrRole.cc:12
SWC::Manager::MngrRole::MngrRole
MngrRole(const MngrRole &)=delete
SWC::Manager::MngrRole::disconnection
void disconnection(const Comm::EndPoint &endpoint_server, const Comm::EndPoint &endpoint_client, bool srv=false)
Definition: MngrRole.cc:285
SWC::Core::Vector< EndPoint >
SWC::Manager::MngrRole::cfg_delay_updated
const Config::Property::Value_int32_g::Ptr cfg_delay_updated
Definition: MngrRole.h:121
SWC::Manager::MngrRole::m_major_updates
bool m_major_updates
Definition: MngrRole.h:106
SWC::Manager::MngrRole::active_mngr_role
MngrStatus::Ptr active_mngr_role(uint8_t role)
Definition: MngrRole.cc:98
SWC::Manager::MngrRole::print
void print(std::ostream &out)
Definition: MngrRole.cc:346
SWC::Config::Property::Value_uint16_g
Definition: Property.h:548
SWC::DB::Types::MngrState
MngrState
Definition: MngrState.h:14
SWC::Manager::MngrRole::is_active
bool is_active(cid_t cid)
Definition: MngrRole.cc:74
SWC::Core::StateRunning
Definition: StateRunning.h:16
SWC::Manager::MngrRole::m_local_active_role
Core::Atomic< uint8_t > m_local_active_role
Definition: MngrRole.h:105
SWC::Manager::MngrRole
Definition: MngrRole.h:16
SWC::Manager::MngrRole::req_mngr_inchain
void req_mngr_inchain(const Comm::client::ConnQueue::ReqBase::Ptr &req)
Definition: MngrRole.cc:137
SWC::Manager::MngrRole::is_group_off
bool is_group_off(const MngrStatus::Ptr &other)
Definition: MngrRole.cc:578
SWC::Manager::MngrRole::m_states
MngrsStatus m_states
Definition: MngrRole.h:102
SWC::Manager::MngrRole::cfg_req_timeout
const Config::Property::Value_int32_g::Ptr cfg_req_timeout
Definition: MngrRole.h:120
SWC::Manager::MngrRole::m_local_groups
client::Mngr::Groups::Vec m_local_groups
Definition: MngrRole.h:104
SWC::Manager::MngrRole::m_mutex
std::shared_mutex m_mutex
Definition: MngrRole.h:101
SWC::Manager::MngrRole::managers_checkin
void managers_checkin()
Definition: MngrRole.cc:403
SWC::Manager::MngrRole::get_highest_state_host
MngrStatus::Ptr get_highest_state_host(const MngrStatus::Ptr &other)
Definition: MngrRole.cc:566
SWC::Comm::client::ConnQueueReqBase::Ptr
std::shared_ptr< ConnQueueReqBase > Ptr
Definition: ClientConnQueue.h:25
SWC::Manager::MngrRole::m_checkin
Core::StateRunning m_checkin
Definition: MngrRole.h:103
SWC::Manager::MngrRole::set_mngr_inchain
void set_mngr_inchain(const Comm::ConnHandlerPtr &mngr)
Definition: MngrRole.cc:653
SWC::Manager::MngrRole::cfg_check_interval
const Config::Property::Value_int32_g::Ptr cfg_check_interval
Definition: MngrRole.h:122
SWC::Manager::MngrRole::operator=
MngrRole & operator=(MngrRole &&)=delete
SWC::Manager::MngrRole::_apply_cfg
void _apply_cfg()
Definition: MngrRole.cc:359
SWC::Config::Property::Value_int32_g
Definition: Property.h:586
SWC::Comm::client::ConnQueuePtr
std::shared_ptr< ConnQueue > ConnQueuePtr
Definition: ClientConnQueue.h:19