SWC-DB  v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
RangeCreate.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_RangeCreate_h
8 #define swcdb_manager_Protocol_handlers_RangeCreate_h
9 
11 
12 
13 namespace SWC { namespace Comm { namespace Protocol {
14 namespace Mngr { namespace Handler {
15 
16 
17 struct RangeCreate {
20 
23  const Comm::Event::Ptr& a_ev) noexcept
24  : conn(a_conn), ev(a_ev) {
25  }
26 
28  RangeCreate(RangeCreate&& other) noexcept
29  : conn(std::move(other.conn)), ev(std::move(other.ev)) {
30  }
31 
32  RangeCreate(const RangeCreate&) = delete;
34  RangeCreate& operator=(const RangeCreate&) = delete;
35 
36  ~RangeCreate() noexcept { }
37 
38  void operator()() {
39  if(ev->expired())
40  return;
41 
42  Params::RangeCreateRsp rsp_params;
43  try {
44  const uint8_t *ptr = ev->data.base;
45  size_t remain = ev->data.size;
46 
48  params.decode(&ptr, &remain);
49  SWC_PRINT << "RangeCreate: " << params.to_string() << SWC_PRINT_CLOSE;
50 
51  auto col = Env::Mngr::mngd_columns()->get_column(
52  rsp_params.err, params.cid);
53  if(rsp_params.err) {
54  if(rsp_params.err == Error::COLUMN_MARKED_REMOVED ||
55  rsp_params.err == Error::MNGR_NOT_ACTIVE ||
56  rsp_params.err == Error::COLUMN_NOT_EXISTS)
57  goto send_response;
58  }
59 
60  auto range = col->create_new_range(params.rgrid);
61  if(range && range->rid) {
62  rsp_params.rid = range->rid;
63  rsp_params.err = Error::OK;
64  } else {
65  rsp_params.err = Error::RANGE_NOT_FOUND;
66  }
67 
68  } catch(...) {
71  rsp_params.err = e.code();
72  }
73 
74  send_response:
75  SWC_PRINT << "RangeCreate(RSP): " << rsp_params.to_string()
76  << SWC_PRINT_CLOSE;
77  conn->send_response(Buffers::make(ev, rsp_params));
78 
79  }
80 
81 };
82 
83 
84 }}}}}
85 
86 #endif // swcdb_manager_Protocol_handlers_RangeCreate_h
SWC::Comm::Protocol::Mngr::Params::RangeCreateReq::rgrid
rgrid_t rgrid
Definition: RangeCreate.h:27
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::Handler::RangeCreate::ev
Comm::Event::Ptr ev
Definition: RangeCreate.h:19
SWC_LOG_OUT
#define SWC_LOG_OUT(pr, _code_)
Definition: Logger.h:178
SWC::Comm::Protocol::Mngr::Handler::RangeCreate::operator=
RangeCreate & operator=(const RangeCreate &)=delete
SWC::Comm::Protocol::Mngr::Params::RangeCreateReq
Definition: RangeCreate.h:16
SWC::Comm::Protocol::Mngr::Handler::RangeCreate::~RangeCreate
~RangeCreate() noexcept
Definition: RangeCreate.h:36
SWC::Comm::Protocol::Mngr::Params::RangeCreateRsp
Definition: RangeCreate.h:59
SWC_PRINT
#define SWC_PRINT
Definition: Logger.h:167
SWC_PRINT_CLOSE
#define SWC_PRINT_CLOSE
Definition: Logger.h:171
SWC::Error::OK
@ OK
Definition: Error.h:45
SWC_CAN_INLINE
#define SWC_CAN_INLINE
Definition: Compat.h:102
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::Handler::RangeCreate::operator()
void operator()()
Definition: RangeCreate.h:38
SWC::LOG_ERROR
@ LOG_ERROR
Definition: Logger.h:32
RangeCreate.h
SWC::Comm::ConnHandlerPtr
std::shared_ptr< ConnHandler > ConnHandlerPtr
Definition: AppContext.h:17
SWC::Error::COLUMN_NOT_EXISTS
@ COLUMN_NOT_EXISTS
Definition: Error.h:100
SWC::Comm::Buffers::make
static SWC_CAN_INLINE Ptr make(uint32_t reserve=0)
Definition: Buffers.h:27
SWC::Error::RANGE_NOT_FOUND
@ RANGE_NOT_FOUND
Definition: Error.h:116
SWC::Comm::Protocol::Mngr::Params::RangeCreateReq::to_string
std::string to_string() const
Definition: RangeCreate.h:29
SWC::Error::COLUMN_MARKED_REMOVED
@ COLUMN_MARKED_REMOVED
Definition: Error.h:102
SWC::Comm::Protocol::Mngr::Params::RangeCreateRsp::err
int err
Definition: RangeCreate.h:78
SWC::Comm::Protocol::Mngr::Handler::RangeCreate
Definition: RangeCreate.h:17
SWC::Comm::Serializable::decode
void decode(const uint8_t **bufp, size_t *remainp)
Definition: Serializable.h:59
SWC::Comm::Protocol::Mngr::Params::RangeCreateRsp::to_string
std::string to_string() const
Definition: RangeCreate.h:81
SWC::Comm::Event::Ptr
std::shared_ptr< Event > Ptr
Definition: Event.h:33
SWC::Comm::Protocol::Mngr::Params::RangeCreateReq::cid
cid_t cid
Definition: RangeCreate.h:26
SWC::Comm::Protocol::Mngr::Handler::RangeCreate::RangeCreate
SWC_CAN_INLINE RangeCreate(const Comm::ConnHandlerPtr &a_conn, const Comm::Event::Ptr &a_ev) noexcept
Definition: RangeCreate.h:22
SWC::Error::MNGR_NOT_ACTIVE
@ MNGR_NOT_ACTIVE
Definition: Error.h:87
SWC::Comm::Protocol::Mngr::Handler::RangeCreate::operator=
RangeCreate & operator=(RangeCreate &&)=delete
SWC::Comm::Protocol::Mngr::Handler::RangeCreate::RangeCreate
RangeCreate(const RangeCreate &)=delete
SWC::Comm::Protocol::Mngr::Handler::RangeCreate::conn
Comm::ConnHandlerPtr conn
Definition: RangeCreate.h:18
SWC::Error::Exception
Definition: Exception.h:21
SWC::Comm::Protocol::Mngr::Handler::RangeCreate::RangeCreate
SWC_CAN_INLINE RangeCreate(RangeCreate &&other) noexcept
Definition: RangeCreate.h:28
SWC::Comm::Protocol::Mngr::Params::RangeCreateRsp::rid
rid_t rid
Definition: RangeCreate.h:79