SWC-DB  v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
RgrGet.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_RgrGet_h
8 #define swcdb_manager_Protocol_handlers_RgrGet_h
9 
11 
12 
13 namespace SWC { namespace Comm { namespace Protocol {
14 namespace Mngr { namespace Handler {
15 
16 
17 void rgr_get(const ConnHandlerPtr& conn, const Event::Ptr& ev) {
18  Params::RgrGetReq params;
19  Params::RgrGetRsp rsp_params;
20  try {
21  const uint8_t *ptr = ev->data.base;
22  size_t remain = ev->data.size;
23  params.decode(&ptr, &remain);
24 
25  auto col = Env::Mngr::mngd_columns()->get_column(
26  rsp_params.err, params.cid);
27  if(rsp_params.err)
28  goto send_response;
29 
30  //if(params.had_err == Error::RGR_NOT_LOADED_RANGE) / tick-check
31  // Env::Mngr::rangers()->need_health_check(col);
32 
33  Manager::Range::Ptr range;
34  if(!params.rid) { // MASTER-COLUMN
35  range = col->get_range(
36  rsp_params.err,
37  params.range_begin,
38  params.range_end,
39  params.next_range
40  );
41  if(range) {
42  range->get_interval(
43  rsp_params.range_begin, rsp_params.range_end,
44  rsp_params.revision
45  );
46  }
47  } else {
48  range = col->get_range(params.rid);
49  }
50 
51  if(!range) {
52  rsp_params.err = Error::RANGE_NOT_FOUND;
53  goto send_response;
54  }
55 
57  range->get_rgr_id(), rsp_params.endpoints);
58  if(rsp_params.endpoints.empty()) {
59  rsp_params.err = Error::RGR_NOT_READY;
60  goto send_response;
61  }
62 
63  rsp_params.cid = range->cfg->cid;
64  rsp_params.rid = range->rid;
65 
66  } catch(...) {
69  rsp_params.err = e.code();
70  }
71 
72  send_response:
73 
75  params.print(SWC_LOG_OSTREAM);
76  rsp_params.print(SWC_LOG_OSTREAM <<' ');
77  );
78 
79  conn->send_response(Buffers::make(ev, rsp_params));
80 
81 }
82 
83 
84 // flag(if cid==1)
85 // in(cid+interval) out(cid + rid + rgr-endpoints + ?next)
86 // else
87 // in(cid+rid) out(cid + rid + rgr-endpoints)
88 
89 }}}}}
90 
91 #endif // swcdb_manager_Protocol_handlers_RgrGet_h
SWC::Comm::Protocol::Mngr::Params::RgrGetReq
Definition: RgrGet.h:20
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::Protocol::Mngr::Params::RgrGetRsp
Definition: RgrGet.h:53
SWC_LOG_OUT
#define SWC_LOG_OUT(pr, _code_)
Definition: Logger.h:178
SWC::Error::RGR_NOT_READY
@ RGR_NOT_READY
Definition: Error.h:90
SWC::Comm::Protocol::Mngr::Params::RgrGetReq::next_range
bool next_range
Definition: RgrGet.h:38
RgrGet.h
SWC::Comm::Protocol::Mngr::Params::RgrGetRsp::print
void print(std::ostream &out) const
Definition: RgrGet.cc:72
SWC::Comm::Protocol::Mngr::Params::RgrGetRsp::rid
rid_t rid
Definition: RgrGet.h:80
SWC::Comm::Protocol::Mngr::Params::RgrGetRsp::range_begin
DB::Cell::Key range_begin
Definition: RgrGet.h:82
SWC::Manager::Range::Ptr
std::shared_ptr< Range > Ptr
Definition: Range.h:24
SWC::Comm::Protocol::Mngr::Params::RgrGetReq::range_end
DB::Cell::Key range_end
Definition: RgrGet.h:37
SWC::Comm::Protocol::Mngr::Handler::rgr_get
void rgr_get(const ConnHandlerPtr &conn, const Event::Ptr &ev)
Definition: RgrGet.h:17
SWC::Core::Vector::empty
constexpr SWC_CAN_INLINE bool empty() const noexcept
Definition: Vector.h:168
SWC::LOG_DEBUG
@ LOG_DEBUG
Definition: Logger.h:36
SWC::Comm::Protocol::Mngr::Params::RgrGetRsp::range_end
DB::Cell::Key range_end
Definition: RgrGet.h:81
SWC_CURRENT_EXCEPTION
#define SWC_CURRENT_EXCEPTION(_msg_)
Definition: Exception.h:119
SWC
The SWC-DB C++ namespace 'SWC'.
Definition: main.cc:12
SWC::Env::Mngr::mngd_columns
static SWC_CAN_INLINE Manager::MngdColumns * mngd_columns() noexcept
Definition: MngrEnv.h:74
SWC::Comm::Protocol::Mngr::Params::RgrGetReq::range_begin
DB::Cell::Key range_begin
Definition: RgrGet.h:37
SWC::Comm::Protocol::Mngr::Params::RgrGetRsp::cid
cid_t cid
Definition: RgrGet.h:79
SWC::Manager::Rangers::rgr_get
Ranger::Ptr rgr_get(const rgrid_t rgrid)
Definition: Rangers.cc:164
SWC::LOG_ERROR
@ LOG_ERROR
Definition: Logger.h:32
SWC::Comm::Protocol::Mngr::Params::RgrGetReq::cid
cid_t cid
Definition: RgrGet.h:35
SWC::Comm::Protocol::Mngr::Params::RgrGetRsp::revision
int64_t revision
Definition: RgrGet.h:83
SWC::Comm::ConnHandlerPtr
std::shared_ptr< ConnHandler > ConnHandlerPtr
Definition: AppContext.h:17
SWC::Comm::Buffers::make
static SWC_CAN_INLINE Ptr make(uint32_t reserve=0)
Definition: Buffers.h:27
SWC::Comm::Protocol::Mngr::Params::RgrGetRsp::err
int err
Definition: RgrGet.h:78
SWC::Error::RANGE_NOT_FOUND
@ RANGE_NOT_FOUND
Definition: Error.h:116
SWC::Comm::Serializable::decode
void decode(const uint8_t **bufp, size_t *remainp)
Definition: Serializable.h:59
SWC::Comm::Protocol::Mngr::Params::RgrGetReq::print
void print(std::ostream &out) const
Definition: RgrGet.cc:17
SWC::Comm::Event::Ptr
std::shared_ptr< Event > Ptr
Definition: Event.h:33
SWC::Comm::Protocol::Mngr::Params::RgrGetRsp::endpoints
EndPoints endpoints
Definition: RgrGet.h:77
SWC::Comm::Protocol::Mngr::Params::RgrGetReq::rid
rid_t rid
Definition: RgrGet.h:36
SWC::Error::Exception
Definition: Exception.h:21
SWC::Env::Mngr::rangers
static SWC_CAN_INLINE Manager::Rangers * rangers() noexcept
Definition: MngrEnv.h:69