SWC-DB  v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
CellsSelect.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_broker_Protocol_handlers_CellsSelect_h
8 #define swcdb_broker_Protocol_handlers_CellsSelect_h
9 
10 
14 
15 
16 namespace SWC { namespace Comm { namespace Protocol {
17 namespace Bkr { namespace Handler {
18 
19 
20 
22  public:
23 
24  typedef std::shared_ptr<Selector> Ptr;
25 
28  bool sent;
29 
31  Selector(const ConnHandlerPtr& a_conn, const Event::Ptr& a_ev) noexcept
33  conn(a_conn), ev(a_ev), sent(false) {
34  }
35 
36  virtual ~Selector() noexcept { }
37 
38  bool valid() noexcept override {
39  return !state_error && !ev->expired() && conn->is_open() &&
41  }
42 
43  void error(const cid_t, int err) override {
45  }
46 
47  size_t get_size_bytes() noexcept override {
48  return 0;
49  }
50 
51  bool add_cells(const cid_t, StaticBuffer& buffer,
52  bool, DB::Specs::Interval& interval) override {
53  if(!ev->expired() && conn->is_open()) {
54  conn->send_response(Buffers::make(
55  ev,
59  : state_error,
60  true,
61  interval.flags.offset
62  ),
63  buffer
64  ));
65  }
66  sent = true;
67  return false;
68  }
69 
70  void response(int err) override {
72 
73  if(!sent && !ev->expired() && conn->is_open()) {
76  conn->send_response(
78  }
79  profile.finished();
80 
82  profile.print(SWC_LOG_OSTREAM << "Select-");
84  );
85 
87  }
88 };
89 
90 
91 
92 
93 void cells_select(const ConnHandlerPtr& conn, const Event::Ptr& ev) {
94  int err = Error::OK;
95 
96  try {
97  const uint8_t *ptr = ev->data.base;
98  size_t remain = ev->data.size;
99 
100  Params::CellsSelectReq params;
101  params.decode(&ptr, &remain);
102 
103  auto schema = Env::Clients::get()->get_schema(err, params.cid);
104  if(!err) {
105  Selector::Ptr(new Selector(conn, ev))
106  ->scan(schema, std::move(params.interval));
107  return;
108  }
109  } catch(...) {
112  err = e.code();
113  }
114  conn->send_response(Buffers::make(ev, Params::CellsSelectRsp(err)));
116 }
117 
118 
119 }}}}}
120 
121 #endif // swcdb_broker_Protocol_handlers_CellsSelect_h
Base.h
SWC::Comm::Protocol::Bkr::Handler::Selector::Selector
SWC_CAN_INLINE Selector(const ConnHandlerPtr &a_conn, const Event::Ptr &a_ev) noexcept
Definition: CellsSelect.h:31
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::client::Query::Select::Handlers::Base
Definition: Base.h:26
SWC::Comm::Protocol::Bkr::Handler::Selector::add_cells
bool add_cells(const cid_t, StaticBuffer &buffer, bool, DB::Specs::Interval &interval) override
Definition: CellsSelect.h:51
SWC::Comm::Protocol::Bkr::Handler::cells_select
void cells_select(const ConnHandlerPtr &conn, const Event::Ptr &ev)
Definition: CellsSelect.h:93
SWC::Error::SERVER_SHUTTING_DOWN
@ SERVER_SHUTTING_DOWN
Definition: Error.h:84
SWC::Env::Clients::get
static SWC_CAN_INLINE client::Clients::Ptr & get() noexcept
Definition: Clients.h:299
SWC_LOG_OUT
#define SWC_LOG_OUT(pr, _code_)
Definition: Logger.h:178
SWC::client::Query::Select::Handlers::Base::error
virtual int error() noexcept
Definition: Base.h:69
SWC::DB::Specs::Flags::offset
uint64_t offset
Definition: SpecsFlags.h:142
SWC::Comm::Protocol::Bkr::Params::CellsSelectReq::interval
DB::Specs::Interval interval
Definition: CellsSelect.h:34
SWC::Comm::Protocol::Bkr::Handler::Selector::~Selector
virtual ~Selector() noexcept
Definition: CellsSelect.h:36
SWC::Env::Bkr::is_accepting
static SWC_CAN_INLINE bool is_accepting() noexcept
Definition: BrokerEnv.h:37
SWC::Core::AtomicBase::store
constexpr SWC_CAN_INLINE void store(T v) noexcept
Definition: Atomic.h:37
SWC::Error::OK
@ OK
Definition: Error.h:45
Scanner.h
SWC_CAN_INLINE
#define SWC_CAN_INLINE
Definition: Compat.h:102
SWC::LOG_DEBUG
@ LOG_DEBUG
Definition: Logger.h:36
SWC_CURRENT_EXCEPTION
#define SWC_CURRENT_EXCEPTION(_msg_)
Definition: Exception.h:119
SWC
The SWC-DB C++ namespace 'SWC'.
Definition: main.cc:12
SWC::Comm::Protocol::Bkr::Handler::Selector::error
void error(const cid_t, int err) override
Definition: CellsSelect.h:43
SWC::Comm::Protocol::Bkr::Handler::Selector::response
void response(int err) override
Definition: CellsSelect.h:70
SWC::Core::Buffer
Definition: Buffer.h:18
SWC::Comm::Protocol::Bkr::Handler::Selector::valid
bool valid() noexcept override
Definition: CellsSelect.h:38
SWC::Comm::Protocol::Bkr::Handler::Selector::ev
Event::Ptr ev
Definition: CellsSelect.h:27
SWC::Comm::Protocol::Bkr::Handler::Selector::conn
ConnHandlerPtr conn
Definition: CellsSelect.h:26
SWC::client::Query::Profiling::finished
SWC_CAN_INLINE void finished() noexcept
Definition: Profiling.h:127
CellsSelect.h
SWC::Error::CLIENT_STOPPING
@ CLIENT_STOPPING
Definition: Error.h:127
SWC::LOG_ERROR
@ LOG_ERROR
Definition: Logger.h:32
SWC::DB::Specs::Interval::flags
Flags flags
Definition: SpecsInterval.h:242
SWC::Comm::Protocol::Bkr::Handler::Selector::get_size_bytes
size_t get_size_bytes() noexcept override
Definition: CellsSelect.h:47
SWC::cid_t
uint64_t cid_t
Definition: Identifiers.h:16
SWC::Comm::ConnHandlerPtr
std::shared_ptr< ConnHandler > ConnHandlerPtr
Definition: AppContext.h:17
SWC::Comm::Protocol::Bkr::Params::CellsSelectReq
Definition: CellsSelect.h:18
SWC::DB::Specs::Interval
Definition: SpecsInterval.h:25
SWC::Comm::Buffers::make
static SWC_CAN_INLINE Ptr make(uint32_t reserve=0)
Definition: Buffers.h:27
SWC::Comm::Protocol::Bkr::Handler::Selector::sent
bool sent
Definition: CellsSelect.h:28
SWC::client::Query::Select::Handlers::Base::state_error
Core::Atomic< int > state_error
Definition: Base.h:32
SWC::Comm::Serializable::decode
void decode(const uint8_t **bufp, size_t *remainp)
Definition: Serializable.h:59
SWC::Comm::Protocol::Bkr::Params::CellsSelectRsp
Definition: CellsSelect.h:77
SWC::Comm::Protocol::Bkr::Params::CellsSelectReq::cid
cid_t cid
Definition: CellsSelect.h:33
SWC::Comm::Protocol::Bkr::Handler::Selector::Ptr
std::shared_ptr< Selector > Ptr
Definition: CellsSelect.h:24
SWC::Comm::Event::Ptr
std::shared_ptr< Event > Ptr
Definition: Event.h:33
SWC::Comm::Protocol::Bkr::Handler::Selector
Definition: CellsSelect.h:21
SWC::Error::print
void print(std::ostream &out, int err)
Definition: Error.cc:191
SWC::Env::Bkr::processed
static SWC_CAN_INLINE void processed() noexcept
Definition: BrokerEnv.h:55
SWC::client::Query::Profiling::print
void print(std::ostream &out) const
Definition: Profiling.h:204
SWC::client::Query::Select::Handlers::Base::profile
Profiling profile
Definition: Base.h:31
SWC::Error::Exception
Definition: Exception.h:21