SWC-DB  v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
ReqScan.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_db_Cells_ReqScan_h
8 #define swcdb_db_Cells_ReqScan_h
9 
10 
12 #include "swcdb/db/Cells/Result.h"
13 #include "swcdb/db/Cells/Mutable.h"
14 
15 
16 namespace SWC { namespace DB { namespace Cells {
17 
18 
20  public:
21 
22  typedef std::shared_ptr<ReqScan> Ptr;
23 
25  ReqScan() noexcept
26  : Comm::ResponseCallback(nullptr, nullptr),
27  spec(),
28  only_keys(false), offset(0),
29  profile() {
30  }
31 
34  : Comm::ResponseCallback(nullptr, nullptr),
35  spec(a_spec),
36  only_keys(spec.flags.is_only_keys()),
38  profile() {
39  }
40 
43  DB::Specs::Interval&& a_spec)
44  : Comm::ResponseCallback(conn, ev),
45  spec(std::move(a_spec)),
46  only_keys(spec.flags.is_only_keys()),
48  profile() {
49  }
50 
53  const DB::Specs::Interval& a_spec)
54  : Comm::ResponseCallback(conn, ev),
55  spec(a_spec),
56  only_keys(spec.flags.is_only_keys()),
58  profile() {
59  }
60 
63  const DB::Cell::Key& range_begin, const DB::Cell::Key& range_end)
64  : Comm::ResponseCallback(conn, ev),
65  spec(range_begin, range_end),
66  only_keys(false),
67  offset(0),
68  profile() {
69  }
70 
71  ReqScan(const ReqScan&) = delete;
72 
73  ReqScan(const ReqScan&&) = delete;
74 
75  ReqScan& operator=(const ReqScan&) = delete;
76 
78  Ptr get_req_scan() noexcept {
79  return std::dynamic_pointer_cast<ReqScan>(shared_from_this());
80  }
81 
83  bool offset_adjusted() noexcept {
84  if(offset) {
85  --offset;
86  return true;
87  }
88  return false;
89  }
90 
91  virtual bool selector(const Types::KeySeq key_seq, const Cell& cell,
92  bool& stop);
93 
94  virtual bool reached_limits() = 0;
95 
96  virtual bool add_cell_and_more(const Cell& cell) = 0;
97 
98  virtual bool has_update() const noexcept {
99  return false;
100  }
101 
102  virtual void update(DB::Cells::Mutable&) { }
103 
104  virtual void print(std::ostream& out) const;
105 
107  bool only_keys;
108 
109  uint64_t offset;
110 
111  struct Profile {
112  const int64_t ts_start = Time::now_ns();
113  int64_t ts_finish = 0;
114  uint64_t cells_count = 0;
115  uint64_t cells_bytes = 0;
116  uint64_t cells_skipped = 0;
117 
118  uint64_t blocks_located = 0;
119  uint64_t block_time_locate= 0;
120 
121  uint64_t blocks_loaded = 0;
122  uint64_t blocks_cs_blocks = 0;
123  uint64_t blocks_fragments = 0;
124  uint64_t block_time_load = 0;
125 
126  uint64_t blocks_scanned = 0;
127  uint64_t block_time_scan = 0;
128 
130  void finished() {
132  }
133 
135  void add_cell(uint32_t bytes) noexcept {
136  ++cells_count;
137  cells_bytes += bytes;
138  }
139 
141  void skip_cell() noexcept {
142  ++cells_skipped;
143  }
144 
146  void add_block_locate(int64_t ts) {
147  ++blocks_located;
149  }
150 
152  void add_block_load(int64_t ts, size_t count_cs_blocks,
153  size_t count_fragments) {
154  ++blocks_loaded;
155  block_time_load += Time::now_ns() - ts;
156  blocks_cs_blocks += count_cs_blocks;
157  blocks_fragments += count_fragments;
158  }
159 
161  void add_block_scan(int64_t ts) {
162  ++blocks_scanned;
163  block_time_scan += Time::now_ns() - ts;
164  }
165 
167  std::string to_string() const {
168  std::string s;
169  {
170  std::stringstream ss;
171  print(ss);
172  s = ss.str();
173  }
174  return s;
175  }
176 
177  void print(std::ostream& out) const {
178  out << "profile(took="
179  << (ts_finish - ts_start)
180  << "ns cells(count=" << cells_count
181  << " bytes=" << cells_bytes
182  << " skip=" << cells_skipped
183  << ") blocks(located=" << blocks_located
184  << " loaded=" << blocks_loaded
185  << "(cs=" << blocks_cs_blocks
186  << " frags=" << blocks_fragments
187  << ") scanned=" << blocks_scanned
188  << ") block(locate=" << block_time_locate
189  << "ns load=" << block_time_load
190  << "ns scan=" << block_time_scan
191  << "ns))";
192  }
193  };
195 
196  protected:
197 
198  virtual ~ReqScan() noexcept { }
199 
200 };
201 
202 
203 
204 class ReqScanTest : public ReqScan {
205  public:
206 
207  typedef std::shared_ptr<ReqScanTest> Ptr;
208 
210  static Ptr make() { return Ptr(new ReqScanTest()); }
211 
213  ReqScanTest() noexcept: cells(), cb() { }
214 
215  bool reached_limits() override {
216  return (spec.flags.limit && spec.flags.limit <= cells.size()) ||
218  }
219 
220  bool add_cell_and_more(const DB::Cells::Cell& cell) override {
221  cells.add(cell, only_keys);
222  return !reached_limits();
223  }
224 
225  virtual ~ReqScanTest() noexcept { }
226 
227  void response(int &err) override {
228  cb(err);
229  }
230 
232  std::function<void(int)> cb;
233 };
234 
235 }}}
236 
237 
238 #ifdef SWC_IMPL_SOURCE
239 #include "swcdb/db/Cells/ReqScan.cc"
240 #endif
241 
242 #endif // swcdb_db_Cells_ReqScan_h
SWC::DB::Cells::ReqScan::Profile::blocks_located
uint64_t blocks_located
Definition: ReqScan.h:118
SWC::DB::Cells::ReqScan::ReqScan
SWC_CAN_INLINE ReqScan(const Comm::ConnHandlerPtr &conn, const Comm::Event::Ptr &ev, const DB::Specs::Interval &a_spec)
Definition: ReqScan.h:52
SWC::DB::Cells::ReqScan::ReqScan
ReqScan(const ReqScan &&)=delete
SWC::DB::Cells::ReqScan::offset_adjusted
SWC_CAN_INLINE bool offset_adjusted() noexcept
Definition: ReqScan.h:83
SWC::DB::Cells::ReqScan::Profile::add_block_locate
SWC_CAN_INLINE void add_block_locate(int64_t ts)
Definition: ReqScan.h:146
SWC::Time::now_ns
SWC_CAN_INLINE int64_t now_ns() noexcept
Definition: Time.h:43
SWC::DB::Cells::ReqScan::Profile::print
void print(std::ostream &out) const
Definition: ReqScan.h:177
SWC::DB::Cells::ReqScan::Profile::cells_skipped
uint64_t cells_skipped
Definition: ReqScan.h:116
SWC::DB::Cells::ReqScan::operator=
ReqScan & operator=(const ReqScan &)=delete
SWC::DB::Cells::ReqScan::Profile::add_block_scan
SWC_CAN_INLINE void add_block_scan(int64_t ts)
Definition: ReqScan.h:161
SWC::DB::Cells::ReqScanTest::ReqScanTest
SWC_CAN_INLINE ReqScanTest() noexcept
Definition: ReqScan.h:213
SWC::Comm::ResponseCallback::ResponseCallback
ResponseCallback(const ConnHandlerPtr &conn, const Event::Ptr &ev)
Definition: ResponseCallback.h:20
SWC::DB::Cells::Cell
Definition: Cell.h:92
SWC::DB::Cells::ReqScan::Profile::blocks_loaded
uint64_t blocks_loaded
Definition: ReqScan.h:121
SWC::DB::Cells::ReqScan::add_cell_and_more
virtual bool add_cell_and_more(const Cell &cell)=0
SWC::DB::Cell::Key
Definition: CellKey.h:24
SWC::DB::Cells::ReqScan::Profile::blocks_cs_blocks
uint64_t blocks_cs_blocks
Definition: ReqScan.h:122
Result.h
SWC::DB::Cells::ReqScan::Profile::cells_bytes
uint64_t cells_bytes
Definition: ReqScan.h:115
SWC::DB::Cells::Result
Definition: Result.h:16
SWC::DB::Cells::ReqScan::profile
Profile profile
Definition: ReqScan.h:194
SWC::DB::Cells::ReqScan::Profile::to_string
SWC_CAN_INLINE std::string to_string() const
Definition: ReqScan.h:167
SWC::DB::Cells::ReqScan::Profile::add_block_load
SWC_CAN_INLINE void add_block_load(int64_t ts, size_t count_cs_blocks, size_t count_fragments)
Definition: ReqScan.h:152
SWC::DB::Types::KeySeq
KeySeq
Definition: KeySeq.h:13
SWC::DB::Cells::ReqScan::selector
virtual bool selector(const Types::KeySeq key_seq, const Cell &cell, bool &stop)
Definition: ReqScan.cc:13
SWC::DB::Cells::ReqScanTest
Definition: ReqScan.h:204
SWC_CAN_INLINE
#define SWC_CAN_INLINE
Definition: Compat.h:102
SWC::DB::Cells::ReqScan
Definition: ReqScan.h:19
SWC::DB::Cells::ReqScan::Ptr
std::shared_ptr< ReqScan > Ptr
Definition: ReqScan.h:22
SWC::DB::Cells::ReqScan::Profile::skip_cell
SWC_CAN_INLINE void skip_cell() noexcept
Definition: ReqScan.h:141
SWC::DB::Cells::ReqScan::offset
uint64_t offset
Definition: ReqScan.h:109
SWC::DB::Cells::ReqScan::Profile::finished
SWC_CAN_INLINE void finished()
Definition: ReqScan.h:130
SWC::DB::Cells::ReqScanTest::reached_limits
bool reached_limits() override
Definition: ReqScan.h:215
SWC
The SWC-DB C++ namespace 'SWC'.
Definition: main.cc:12
SWC::DB::Cells::ReqScan::Profile::cells_count
uint64_t cells_count
Definition: ReqScan.h:114
SWC::DB::Cells::ReqScanTest::cb
std::function< void(int)> cb
Definition: ReqScan.h:232
SWC::DB::Cells::ReqScan::Profile::blocks_scanned
uint64_t blocks_scanned
Definition: ReqScan.h:126
ReqScan.cc
SWC::DB::Cells::ReqScan::print
virtual void print(std::ostream &out) const
Definition: ReqScan.cc:18
SWC::DB::Cells::ReqScan::ReqScan
SWC_CAN_INLINE ReqScan(const Comm::ConnHandlerPtr &conn, const Comm::Event::Ptr &ev, const DB::Cell::Key &range_begin, const DB::Cell::Key &range_end)
Definition: ReqScan.h:62
SWC::DB::Cells::ReqScan::ReqScan
ReqScan(const ReqScan &)=delete
SWC::DB::Cells::ReqScan::Profile::ts_start
const int64_t ts_start
Definition: ReqScan.h:112
SWC::DB::Cells::ReqScan::Profile::block_time_locate
uint64_t block_time_locate
Definition: ReqScan.h:119
SWC::Comm::ResponseCallback::Ptr
std::shared_ptr< ResponseCallback > Ptr
Definition: ResponseCallback.h:18
SWC::DB::Cells::ReqScan::only_keys
bool only_keys
Definition: ReqScan.h:107
SWC::DB::Cells::ReqScan::reached_limits
virtual bool reached_limits()=0
SWC::DB::Cells::ReqScan::Profile::block_time_scan
uint64_t block_time_scan
Definition: ReqScan.h:127
SWC::Comm::ResponseCallback
Definition: ResponseCallback.h:14
SWC::DB::Specs::Interval::flags
Flags flags
Definition: SpecsInterval.h:242
SWC::DB::Cells::ReqScan::get_req_scan
SWC_CAN_INLINE Ptr get_req_scan() noexcept
Definition: ReqScan.h:78
SWC::Comm::ConnHandlerPtr
std::shared_ptr< ConnHandler > ConnHandlerPtr
Definition: AppContext.h:17
SWC::DB::Cells::ReqScanTest::make
static SWC_CAN_INLINE Ptr make()
Definition: ReqScan.h:210
SWC::DB::Cells::ReqScan::Profile::blocks_fragments
uint64_t blocks_fragments
Definition: ReqScan.h:123
SWC::DB::Cells::ReqScanTest::response
void response(int &err) override
Definition: ReqScan.h:227
SWC::DB::Cells::ReqScan::spec
DB::Specs::Interval spec
Definition: ReqScan.h:106
SWC::DB::Specs::Interval
Definition: SpecsInterval.h:25
SWC::DB::Cells::ReqScan::Profile::ts_finish
int64_t ts_finish
Definition: ReqScan.h:113
SWC::DB::Cells::ReqScan::has_update
virtual bool has_update() const noexcept
Definition: ReqScan.h:98
SWC::DB::Cells::ReqScan::Profile
Definition: ReqScan.h:111
SWC::DB::Cells::ReqScan::ReqScan
SWC_CAN_INLINE ReqScan() noexcept
Definition: ReqScan.h:25
SWC::Comm::Event::Ptr
std::shared_ptr< Event > Ptr
Definition: Event.h:33
SWC::DB::Specs::Flags::max_buffer
uint32_t max_buffer
Definition: SpecsFlags.h:144
SWC::DB::Cells::ReqScan::ReqScan
SWC_CAN_INLINE ReqScan(const Comm::ConnHandlerPtr &conn, const Comm::Event::Ptr &ev, DB::Specs::Interval &&a_spec)
Definition: ReqScan.h:42
SWC::DB::Cells::ReqScanTest::Ptr
std::shared_ptr< ReqScanTest > Ptr
Definition: ReqScan.h:207
ResponseCallback.h
flags
uint8_t flags
Flags.
Definition: Header.h:55
SWC::DB::Cells::Result::size_bytes
constexpr SWC_CAN_INLINE size_t size_bytes() const noexcept
Definition: Result.h:64
SWC::DB::Cells::ReqScanTest::cells
Result cells
Definition: ReqScan.h:231
SWC::DB::Cells::ReqScan::update
virtual void update(DB::Cells::Mutable &)
Definition: ReqScan.h:102
SWC::DB::Cells::ReqScan::Profile::add_cell
SWC_CAN_INLINE void add_cell(uint32_t bytes) noexcept
Definition: ReqScan.h:135
SWC::DB::Specs::Flags::limit
uint64_t limit
Definition: SpecsFlags.h:142
SWC::DB::Cells::ReqScan::~ReqScan
virtual ~ReqScan() noexcept
Definition: ReqScan.h:198
SWC::DB::Cells::ReqScan::ReqScan
SWC_CAN_INLINE ReqScan(const DB::Specs::Interval &a_spec)
Definition: ReqScan.h:33
SWC::DB::Cells::Mutable
Definition: Mutable.h:21
SWC::DB::Cells::ReqScanTest::~ReqScanTest
virtual ~ReqScanTest() noexcept
Definition: ReqScan.h:225
SWC::DB::Cells::ReqScanTest::add_cell_and_more
bool add_cell_and_more(const DB::Cells::Cell &cell) override
Definition: ReqScan.h:220
SWC::DB::Cells::ReqScan::Profile::block_time_load
uint64_t block_time_load
Definition: ReqScan.h:124
Mutable.h
SWC::DB::Cells::Result::add
void add(const Cell &cell, bool no_value=false)
Definition: Result.h:109