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_ranger_db_ReqScan_h
8 #define swcdb_ranger_db_ReqScan_h
9 
10 
11 #include "swcdb/db/Cells/ReqScan.h"
12 
13 
14 namespace SWC { namespace Ranger {
15 
16 
17 #define SWC_SCAN_RSVD_BUFFS 3
18 // 4 == (blk + cs-blk + fragments) + intermediate-buffers
19 
20 
21 class ReqScan : public DB::Cells::ReqScan {
22  public:
23 
24  enum Type : uint8_t {
28  };
29 
30  typedef std::shared_ptr<ReqScan> Ptr;
31 
33  ReqScan(Type a_type=Type::QUERY, bool a_release_block=false,
34  uint8_t a_readahead=1, uint32_t a_blk_size=0)
35  noexcept
36  : type(a_type),
37  release_block(a_release_block),
38  readahead(a_readahead),
39  blk_size(a_blk_size),
40  block(nullptr) {
42  }
43 
46  const DB::Cell::Key& range_begin, const DB::Cell::Key& range_end,
47  uint32_t a_blk_size)
48  : DB::Cells::ReqScan(conn, ev, range_begin, range_end),
49  type(Type::QUERY),
50  release_block(false), readahead(0),
51  blk_size(a_blk_size),
52  block(nullptr) {
54  }
55 
58  DB::Specs::Interval&& a_spec, uint32_t a_blk_size)
59  : DB::Cells::ReqScan(conn, ev, std::move(a_spec)),
60  type(Type::QUERY),
61  release_block(false),
62  readahead((!spec.flags.limit || spec.flags.offset)//?>block_cells
63  ? 2 : spec.flags.limit > 1),
64  blk_size(a_blk_size),
65  block(nullptr) {
67  }
68 
70  ReqScan(ReqScan&&) = delete;
71  ReqScan(const ReqScan&) = delete;
72  ReqScan& operator=(const ReqScan&) = delete;
73  ReqScan& operator=(ReqScan&&) = delete;
74 
75  virtual ~ReqScan() noexcept {
77  }
78 
80  Ptr get_req_scan() noexcept {
81  return std::dynamic_pointer_cast<ReqScan>(shared_from_this());
82  }
83 
84  virtual bool with_block() const noexcept {
85  return false;
86  }
87 
90  uint8_t readahead;
91  const uint32_t blk_size;
92  void* block;
93 };
94 
95 
96 
97 class ReqScanBlockLoader : public ReqScan {
98  public:
99  typedef std::shared_ptr<ReqScanBlockLoader> Ptr;
100 
102  ReqScanBlockLoader(uint32_t a_blk_size) noexcept
103  : ReqScan(ReqScan::Type::BLK_PRELOAD, false, 1, a_blk_size) {
104  }
105 
106  virtual ~ReqScanBlockLoader() noexcept { }
107 
108  bool reached_limits() override {
109  return true;
110  }
111 
112  bool add_cell_and_more(const DB::Cells::Cell&) override {
113  return !reached_limits();
114  }
115 };
116 
117 
118 
119 class ReqScanTest : public ReqScan {
120  public:
121 
122  typedef std::shared_ptr<ReqScanTest> Ptr;
123 
124  static Ptr make() { return Ptr(new ReqScanTest()); }
125 
126  ReqScanTest() noexcept : cells(), cb() { }
127 
128  bool reached_limits() override {
129  return (spec.flags.limit && spec.flags.limit <= cells.size()) ||
131  }
132 
133  bool add_cell_and_more(const DB::Cells::Cell& cell) override {
134  cells.add(cell, only_keys);
135  return !reached_limits();
136  }
137 
138  virtual ~ReqScanTest() noexcept { }
139 
140  void response(int &err) override {
141  cb(err);
142  }
143 
145  std::function<void(int)> cb;
146 };
147 
148 }}
149 
150 #endif // swcdb_ranger_db_ReqScan_h
SWC::Ranger::ReqScanTest
Definition: ReqScan.h:119
SWC::Ranger::ReqScanTest::response
void response(int &err) override
Definition: ReqScan.h:140
SWC::Ranger::ReqScanBlockLoader::ReqScanBlockLoader
SWC_CAN_INLINE ReqScanBlockLoader(uint32_t a_blk_size) noexcept
Definition: ReqScan.h:102
SWC::Ranger::ReqScan
Definition: ReqScan.h:21
SWC::Ranger::ReqScanTest::add_cell_and_more
bool add_cell_and_more(const DB::Cells::Cell &cell) override
Definition: ReqScan.h:133
SWC::Ranger::ReqScan::ReqScan
SWC_CAN_INLINE ReqScan(Type a_type=Type::QUERY, bool a_release_block=false, uint8_t a_readahead=1, uint32_t a_blk_size=0) noexcept
Definition: ReqScan.h:33
SWC::Ranger::ReqScanTest::cb
std::function< void(int)> cb
Definition: ReqScan.h:145
SWC::Ranger::ReqScan::type
Type type
Definition: ReqScan.h:88
SWC::Ranger::ReqScanBlockLoader::~ReqScanBlockLoader
virtual ~ReqScanBlockLoader() noexcept
Definition: ReqScan.h:106
SWC::Env::Rgr::scan_reserved_bytes_add
static SWC_CAN_INLINE void scan_reserved_bytes_add(uint32_t bytes) noexcept
Definition: RangerEnv.h:88
SWC::Ranger::ReqScan::release_block
bool release_block
Definition: ReqScan.h:89
SWC::Ranger::ReqScan::operator=
ReqScan & operator=(ReqScan &&)=delete
SWC::Ranger::ReqScan::ReqScan
ReqScan(const ReqScan &)=delete
SWC::Ranger::ReqScan::~ReqScan
virtual ~ReqScan() noexcept
Definition: ReqScan.h:75
SWC::DB::Cells::Cell
Definition: Cell.h:92
SWC::DB::Cell::Key
Definition: CellKey.h:24
SWC::Ranger::ReqScanBlockLoader::Ptr
std::shared_ptr< ReqScanBlockLoader > Ptr
Definition: ReqScan.h:99
SWC::Ranger::ReqScan::operator=
ReqScan & operator=(const ReqScan &)=delete
SWC::DB::Cells::Result
Definition: Result.h:16
SWC::Ranger::ReqScanTest::Ptr
std::shared_ptr< ReqScanTest > Ptr
Definition: ReqScan.h:122
SWC::Ranger::ReqScan::Type
Type
Definition: ReqScan.h:24
SWC_CAN_INLINE
#define SWC_CAN_INLINE
Definition: Compat.h:102
SWC::Ranger::ReqScan::COMPACTION
@ COMPACTION
Definition: ReqScan.h:27
SWC::Ranger::ReqScan::BLK_PRELOAD
@ BLK_PRELOAD
Definition: ReqScan.h:26
SWC::DB::Cells::ReqScan
Definition: ReqScan.h:19
SWC::Ranger::ReqScanTest::cells
DB::Cells::Result cells
Definition: ReqScan.h:144
SWC::Ranger::ReqScan::ReqScan
SWC_CAN_INLINE ReqScan(ReqScan &&)=delete
SWC::Ranger::ReqScanTest::~ReqScanTest
virtual ~ReqScanTest() noexcept
Definition: ReqScan.h:138
SWC::DB::Cells::ReqScan::offset
uint64_t offset
Definition: ReqScan.h:109
SWC::Ranger::ReqScan::ReqScan
SWC_CAN_INLINE ReqScan(const Comm::ConnHandlerPtr &conn, const Comm::Event::Ptr &ev, DB::Specs::Interval &&a_spec, uint32_t a_blk_size)
Definition: ReqScan.h:57
SWC
The SWC-DB C++ namespace 'SWC'.
Definition: main.cc:12
SWC::Ranger::ReqScan::readahead
uint8_t readahead
Definition: ReqScan.h:90
SWC::Comm::ResponseCallback::Ptr
std::shared_ptr< ResponseCallback > Ptr
Definition: ResponseCallback.h:18
SWC::Ranger::ReqScanBlockLoader::reached_limits
bool reached_limits() override
Definition: ReqScan.h:108
SWC::Ranger::ReqScan::get_req_scan
SWC_CAN_INLINE Ptr get_req_scan() noexcept
Definition: ReqScan.h:80
SWC::DB::Cells::ReqScan::only_keys
bool only_keys
Definition: ReqScan.h:107
SWC::DB::Specs::Interval::flags
Flags flags
Definition: SpecsInterval.h:242
SWC::Comm::ConnHandlerPtr
std::shared_ptr< ConnHandler > ConnHandlerPtr
Definition: AppContext.h:17
SWC::Ranger::ReqScanBlockLoader
Definition: ReqScan.h:97
SWC::DB::Cells::ReqScan::spec
DB::Specs::Interval spec
Definition: ReqScan.h:106
SWC::DB::Specs::Interval
Definition: SpecsInterval.h:25
SWC::Ranger::ReqScan::with_block
virtual bool with_block() const noexcept
Definition: ReqScan.h:84
SWC::Ranger::ReqScanTest::make
static Ptr make()
Definition: ReqScan.h:124
ReqScan.h
SWC_SCAN_RSVD_BUFFS
#define SWC_SCAN_RSVD_BUFFS
Definition: ReqScan.h:17
SWC::Ranger::ReqScan::QUERY
@ QUERY
Definition: ReqScan.h:25
SWC::DB::Cells::ReqScan::ReqScan
SWC_CAN_INLINE ReqScan() noexcept
Definition: ReqScan.h:25
SWC::Ranger::ReqScanTest::reached_limits
bool reached_limits() override
Definition: ReqScan.h:128
SWC::Ranger::ReqScan::blk_size
const uint32_t blk_size
Definition: ReqScan.h:91
SWC::Comm::Event::Ptr
std::shared_ptr< Event > Ptr
Definition: Event.h:33
SWC::Env::Rgr::scan_reserved_bytes_sub
static SWC_CAN_INLINE void scan_reserved_bytes_sub(uint32_t bytes) noexcept
Definition: RangerEnv.h:93
SWC::DB::Specs::Flags::max_buffer
uint32_t max_buffer
Definition: SpecsFlags.h:144
SWC::Ranger::ReqScan::block
void * block
Definition: ReqScan.h:92
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::Specs::Flags::limit
uint64_t limit
Definition: SpecsFlags.h:142
SWC::Ranger::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, uint32_t a_blk_size)
Definition: ReqScan.h:45
SWC::Ranger::ReqScan::Ptr
std::shared_ptr< ReqScan > Ptr
Definition: ReqScan.h:30
SWC::Ranger::ReqScanBlockLoader::add_cell_and_more
bool add_cell_and_more(const DB::Cells::Cell &) override
Definition: ReqScan.h:112
SWC::Ranger::ReqScanTest::ReqScanTest
ReqScanTest() noexcept
Definition: ReqScan.h:126
SWC::DB::Cells::Result::add
void add(const Cell &cell, bool no_value=false)
Definition: Result.h:109