SWC-DB  v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
Report.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 
7 #ifndef swcdb_manager_Protocol_handlers_Report_h
8 #define swcdb_manager_Protocol_handlers_Report_h
9 
11 
12 
13 namespace SWC { namespace Comm { namespace Protocol {
14 namespace Mngr { namespace Handler {
15 
16 
17 struct Report {
20 
23  const Comm::Event::Ptr& a_ev) noexcept
24  : conn(a_conn), ev(a_ev) {
25  }
26 
28  Report(Report&& other) noexcept
29  : conn(std::move(other.conn)), ev(std::move(other.ev)) {
30  }
31 
32  Report(const Report&) = delete;
33  Report& operator=(Report&&) = delete;
34  Report& operator=(const Report&) = delete;
35 
36  ~Report() noexcept { }
37 
38  void operator()() {
39  if(ev->expired())
40  return;
41 
42 
43  int err = Error::OK;
44  Buffers::Ptr cbp;
45 
46  try {
47 
48  const uint8_t *ptr = ev->data.base;
49  size_t remain = ev->data.size;
50 
51  switch(
53 
55 
56  if(Env::Mngr::mngd_columns()->is_schemas_mngr(err) && err)
57  goto function_send_response;
58 
59  if(Env::Mngr::role()->is_active_role(DB::Types::MngrRole::RANGERS)
60  && Env::Mngr::rangers()->empty()) {
62  goto function_send_response;
63  }
64 
66 
67  function_send_response:
68  cbp = Buffers::make(ev, 4);
69  cbp->append_i32(err);
70  goto send_response;
71  }
72 
74  auto& role = *Env::Mngr::role();
75 
77  role.get_states(mngrs);
78 
80  rsp_params.managers.resize(mngrs.size());
81  size_t i = 0;
82  for(auto& mngr : mngrs) {
83  auto& m = rsp_params.managers[i];
84  m.priority = mngr->priority;
85  m.state = mngr->state;
86  m.role = mngr->role;
87  m.cid_begin = mngr->cid_begin;
88  m.cid_end = mngr->cid_end;
89  m.failures = mngr->failures;
90  m.endpoints = mngr->endpoints;
91  ++i;
92  }
93  rsp_params.inchain = role.get_inchain_endpoint();
94 
95  cbp = Buffers::make(ev, rsp_params, 4);
96  cbp->append_i32(err);
97  goto send_response;
98  }
99 
101  auto& mngr_rangers = *Env::Mngr::rangers();
102 
103  Manager::RangerList rangers;
104  mngr_rangers.rgr_list(0, rangers);
105 
107  rsp_params.rangers.resize(rangers.size());
108  size_t i = 0;
109  for(auto& rgr : rangers) {
110  auto& r = rsp_params.rangers[i];
111  r.state = rgr->state;
112  r.rgr_id = rgr->rgrid;
113  r.failures = rgr->failures;
114  r.interm_ranges = rgr->interm_ranges;
115  r.load_scale = rgr->load_scale;
116  r.rebalance = rgr->rebalance();
117  mngr_rangers.rgr_get(rgr, r.endpoints);
118  ++i;
119  }
120  cbp = Buffers::make(ev, rsp_params, 4);
121  cbp->append_i32(err);
122  goto send_response;
123  }
124 
127  params.decode(&ptr, &remain);
128 
130  auto col = Env::Mngr::mngd_columns()->get_column(err, params.cid);
131  if(err == Error::COLUMN_NOT_READY)
132  err = Error::OK;
133  else if(err)
134  goto send_error;
135 
137  col->get_ranges(ranges);
138  rsp_params.ranges.resize(ranges.size());
139  size_t i = 0;
140  for(auto& r : ranges) {
141  auto& set_r = rsp_params.ranges[i];
142  set_r.state = r->state();
143  set_r.rid = r->rid;
144  set_r.rgr_id = r->get_rgr_id();
145  ++i;
146  }
147  rsp_params.state = col->state();
148  cbp = Buffers::make(ev, rsp_params, 4);
149  cbp->append_i32(err);
150  goto send_response;
151  }
152 
153  default:
155  break;
156  }
157 
158  } catch(...) {
161  err = e.code();
162  }
163 
164 
165  send_error:
166  cbp = Buffers::make(ev, 4);
167  cbp->append_i32(err);
168 
169 
170  send_response:
171  conn->send_response(cbp);
172  }
173 
174 };
175 
176 
177 }}}}}
178 
179 #endif // swcdb_manager_Protocol_handlers_:Report_h
SWC::Manager::MngdColumns::get_column
Column::Ptr get_column(int &err, cid_t cid)
Definition: MngdColumns.cc:174
SWC::Error::Exception::code
constexpr SWC_CAN_INLINE int code() const noexcept
Definition: Exception.h:51
SWC_LOG_OSTREAM
#define SWC_LOG_OSTREAM
Definition: Logger.h:44
SWC::Comm::Buffers::Ptr
std::shared_ptr< Buffers > Ptr
Definition: Buffers.h:23
SWC_LOG_OUT
#define SWC_LOG_OUT(pr, _code_)
Definition: Logger.h:178
SWC::Comm::Protocol::Mngr::Params::Report::RspRangersStatus
Definition: Report.h:113
SWC::Comm::Protocol::Mngr::Params::Report::CLUSTER_STATUS
@ CLUSTER_STATUS
Definition: Report.h:27
SWC::Comm::Protocol::Mngr::Handler::Report::Report
Report(const Report &)=delete
SWC::Comm::Protocol::Mngr::Handler::Report::operator=
Report & operator=(Report &&)=delete
SWC::Manager::MngdColumns::columns_ready
void columns_ready(int &err)
Definition: MngdColumns.cc:161
SWC::Comm::Protocol::Mngr::Params::Report::RspColumnStatus::ranges
Core::Vector< RangeStatus > ranges
Definition: Report.h:99
SWC::Comm::Protocol::Mngr::Handler::Report::ev
Comm::Event::Ptr ev
Definition: Report.h:19
Report.h
SWC::Error::OK
@ OK
Definition: Error.h:45
SWC_CAN_INLINE
#define SWC_CAN_INLINE
Definition: Compat.h:102
SWC::Comm::Protocol::Mngr::Handler::Report::Report
SWC_CAN_INLINE Report(Report &&other) noexcept
Definition: Report.h:28
SWC::Comm::Protocol::Mngr::Params::Report::RspManagersStatus
Definition: Report.h:180
SWC_CURRENT_EXCEPTION
#define SWC_CURRENT_EXCEPTION(_msg_)
Definition: Exception.h:119
SWC::Comm::Protocol::Mngr::Params::Report::COLUMN_STATUS
@ COLUMN_STATUS
Definition: Report.h:28
SWC
The SWC-DB C++ namespace 'SWC'.
Definition: main.cc:12
SWC::Error::MNGR_NOT_INITIALIZED
@ MNGR_NOT_INITIALIZED
Definition: Error.h:88
SWC::Comm::Protocol::Mngr::Params::Report::RspManagersStatus::inchain
EndPoint inchain
Definition: Report.h:237
SWC::Env::Mngr::mngd_columns
static SWC_CAN_INLINE Manager::MngdColumns * mngd_columns() noexcept
Definition: MngrEnv.h:74
SWC::Comm::Protocol::Mngr::Handler::Report::~Report
~Report() noexcept
Definition: Report.h:36
SWC::Comm::Protocol::Mngr::Handler::Report::operator()
void operator()()
Definition: Report.h:38
SWC::Error::COLUMN_NOT_READY
@ COLUMN_NOT_READY
Definition: Error.h:99
SWC::Comm::Protocol::Mngr::Params::Report::RspManagersStatus::managers
Core::Vector< Manager > managers
Definition: Report.h:236
SWC::LOG_ERROR
@ LOG_ERROR
Definition: Logger.h:32
SWC::Comm::Protocol::Mngr::Params::Report::Function
Function
Definition: Report.h:26
SWC::Comm::Protocol::Mngr::Params::Report::RspRangersStatus::rangers
Core::Vector< Ranger > rangers
Definition: Report.h:166
SWC::Comm::Protocol::Mngr::Handler::Report::Report
SWC_CAN_INLINE Report(const Comm::ConnHandlerPtr &a_conn, const Comm::Event::Ptr &a_ev) noexcept
Definition: Report.h:22
SWC::Comm::ConnHandlerPtr
std::shared_ptr< ConnHandler > ConnHandlerPtr
Definition: AppContext.h:17
SWC::Core::Vector< MngrStatus::Ptr >
SWC::Comm::Buffers::make
static SWC_CAN_INLINE Ptr make(uint32_t reserve=0)
Definition: Buffers.h:27
SWC::Comm::Protocol::Mngr::Handler::Report
Definition: Report.h:17
SWC::Comm::Protocol::Mngr::Params::Report::ReqColumnStatus
Definition: Report.h:36
SWC::Comm::Protocol::Mngr::Params::Report::RspColumnStatus
Definition: Report.h:59
SWC::Error::NOT_IMPLEMENTED
@ NOT_IMPLEMENTED
Definition: Error.h:74
SWC::Comm::Serializable::decode
void decode(const uint8_t **bufp, size_t *remainp)
Definition: Serializable.h:59
SWC::Env::Mngr::role
static SWC_CAN_INLINE Manager::MngrRole * role() noexcept
Definition: MngrEnv.h:64
SWC::Comm::Protocol::Mngr::Params::Report::ReqColumnStatus::cid
cid_t cid
Definition: Report.h:46
SWC::Comm::Event::Ptr
std::shared_ptr< Event > Ptr
Definition: Event.h:33
SWC::Comm::Protocol::Mngr::Params::Report::RANGERS_STATUS
@ RANGERS_STATUS
Definition: Report.h:29
SWC::DB::Types::MngrRole::RANGERS
const uint8_t RANGERS
Definition: MngrRole.h:16
SWC::Comm::Protocol::Mngr::Handler::Report::operator=
Report & operator=(const Report &)=delete
SWC::Comm::Protocol::Mngr::Handler::Report::conn
Comm::ConnHandlerPtr conn
Definition: Report.h:18
SWC::Serialization::decode_i8
constexpr SWC_CAN_INLINE uint8_t decode_i8(const uint8_t **bufp, size_t *remainp)
Definition: Serialization.h:91
SWC::Comm::Protocol::Mngr::Params::Report::MANAGERS_STATUS
@ MANAGERS_STATUS
Definition: Report.h:30
SWC::Core::Vector::size
constexpr SWC_CAN_INLINE size_type size() const noexcept
Definition: Vector.h:189
SWC::Error::Exception
Definition: Exception.h:21
SWC::Env::Mngr::rangers
static SWC_CAN_INLINE Manager::Rangers * rangers() noexcept
Definition: MngrEnv.h:69
SWC::Comm::Protocol::Mngr::Params::Report::RspColumnStatus::state
DB::Types::MngrColumn::State state
Definition: Report.h:98