SWC-DB  v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
RangeLocateScan.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 #ifndef swcdb_ranger_callbacks_RangeLocateScan_h
7 #define swcdb_ranger_callbacks_RangeLocateScan_h
8 
11 
12 namespace SWC { namespace Ranger { namespace Callback {
13 
14 
15 class RangeLocateScan : public ReqScan {
16  public:
17 
18  typedef std::shared_ptr<RangeLocateScan> Ptr;
19 
22  const Comm::Event::Ptr& ev,
23  const DB::Cell::Key& a_range_begin,
24  const DB::Cell::Key& a_range_end,
25  const RangePtr& a_range,
26  uint8_t a_flags)
27  : ReqScan(
28  conn, ev,
29  a_range_begin, a_range_end,
30  a_range->cfg->block_size()
31  ),
32  range(a_range), flags(a_flags),
33  any_is(range->cfg->range_type != DB::Types::Range::DATA),
34  range_begin(a_range_begin, false),
35  params() {
36  auto c = range->known_interval_count();
37  spec.range_begin.remove(c ? c : uint24_t(1), true);
41  a_range_end.count == any_is)
43  /*
44  SWC_PRINT << "--------------------- "
45  << range->cfg->cid << '/' << range->rid
46  << "\n\t" << spec.to_string() << SWC_PRINT_CLOSE;
47  */
48  }
49 
50  virtual ~RangeLocateScan() noexcept { }
51 
52  bool selector(const DB::Types::KeySeq key_seq,
53  const DB::Cells::Cell& cell, bool& stop) override {
54  //SWC_PRINT << "---------------------"
55  // << " cell.key: " << cell.key.to_string() << SWC_PRINT_CLOSE;
56  if(any_is &&
58  != Condition::EQ)
59  return false;
60 
62  DB::KeySeq::compare(key_seq, spec.offset_key, cell.key)
63  != Condition::GT)
64  return false;
65 
67  DB::KeySeq::compare(key_seq, spec.offset_key, cell.key)
68  == Condition::LT)
69  return false;
70 
71  if(cell.key.count > any_is && spec.range_end.count > any_is &&
72  !spec.is_matching_end(key_seq, cell.key)) {
73  stop = true;
74  //SWC_PRINT << "-- KEY-BEGIN NO MATCH STOP --" << SWC_PRINT_CLOSE;
75  return false;
76  }
77 
78  StaticBuffer v;
79  cell.get_value(v, false);
80  const uint8_t* ptr = v.base;
81  size_t remain = v.size;
82 
84  DB::Cell::Key key_end;
85  key_end.decode(&ptr, &remain, false);
86  if(key_end.count > any_is && range_begin.count > any_is &&
87  !spec.is_matching_begin(key_seq, key_end)) {
88  //SWC_PRINT << "-- KEY-END NO MATCH --" << SWC_PRINT_CLOSE;
89  return false;
90  }
91  //return true; // without aligned min-max
92 
94  rid_t rid = Serialization::decode_vi64(&ptr, &remain);
95 
96  DB::Cell::Key dekey;
97  // aligned_min
99  dekey.decode(&ptr, &remain, false);
100  if(spec.range_end.count != any_is && !dekey.empty() &&
101  !DB::KeySeq::compare(key_seq,
102  spec.range_end, dekey,
103  Condition::GT, spec.range_end.count, true)) {
104  //SWC_PRINT << "-- ALIGNED MIN NO MATCH --" << SWC_PRINT_CLOSE;
105  return false;
106  }
107 
108  // aligned_max
110  dekey.decode(&ptr, &remain, false);
111  if(range_begin.count != any_is && !dekey.empty() &&
112  !DB::KeySeq::compare(key_seq,
113  range_begin, dekey,
114  Condition::LT, range_begin.count, true)) {
115  //SWC_PRINT << "-- ALIGNED MAX NO MATCH --" << SWC_PRINT_CLOSE;
116  return false;
117  }
118  //SWC_PRINT << "-- ALIGNED MATCH -------" << SWC_PRINT_CLOSE;
119  uint8_t after_idx = range->cfg->range_type == DB::Types::Range::MASTER;
120  params.range_begin.copy(after_idx, cell.key);
121  params.range_end.copy(after_idx, key_end);
122  params.rid = rid;
123  return true;
124  }
125 
126  bool reached_limits() override {
127  return params.cid && params.rid;
128  }
129 
130  bool add_cell_and_more(const DB::Cells::Cell& cell) override {
132 
133  std::string id_name(cell.key.get_string(0));
134  params.cid = strtoull(id_name.c_str(), nullptr, 0);
135  return false;
136  }
137 
138 
139  void response(int &err) override {
140 
141  if(err)
142  params.err = err;
143  else if(Env::Rgr::is_shuttingdown())
145  else if(range->deleted())
147  else if(!params.cid || !params.rid)
149 
150  m_conn->send_response(Comm::Buffers::make(m_ev, params));
151 
152  profile.finished();
155  << "Range(" << range->cfg->cid << '/' << range->rid << ") ";
157  profile.print(SWC_LOG_OSTREAM << " flags=" << int(flags) << " Locate-");
158  if(params.err) {
159  spec.print(SWC_LOG_OSTREAM << ' ');
160  range_begin.print(SWC_LOG_OSTREAM << " range_begin=");
161  }
162  );
163 
164  if(err == Error::RGR_NOT_LOADED_RANGE)
165  range->issue_unload();
166  }
167 
169  uint8_t flags;
170  uint32_t any_is;
172 
174 
175 };
176 
177 
178 }}}
179 #endif // swcdb_ranger_callbacks_RangeLocateScan_h
SWC::DB::Cell::Key::get_string
SWC_CAN_INLINE std::string get_string(uint32_t idx) const
Definition: CellKey.h:169
SWC::Error::RGR_NOT_LOADED_RANGE
@ RGR_NOT_LOADED_RANGE
Definition: Error.h:91
SWC::Ranger::Callback::RangeLocateScan::selector
bool selector(const DB::Types::KeySeq key_seq, const DB::Cells::Cell &cell, bool &stop) override
Definition: RangeLocateScan.h:52
SWC::Ranger::ReqScan
Definition: ReqScan.h:21
SWC::DB::Specs::Interval::is_matching_end
bool is_matching_end(const Types::KeySeq key_seq, const DB::Cell::Key &key) const
Definition: SpecsInterval.h:300
SWC::Ranger::Callback::RangeLocateScan::Ptr
std::shared_ptr< RangeLocateScan > Ptr
Definition: RangeLocateScan.h:18
SWC_LOG_OSTREAM
#define SWC_LOG_OSTREAM
Definition: Logger.h:44
SWC::Comm::Protocol::Rgr::Params::RangeLocateRsp::cid
cid_t cid
Definition: RangeLocate.h:76
SWC::Error::SERVER_SHUTTING_DOWN
@ SERVER_SHUTTING_DOWN
Definition: Error.h:84
SWC_LOG_OUT
#define SWC_LOG_OUT(pr, _code_)
Definition: Logger.h:178
SWC::DB::Cells::ReqScan::Profile::print
void print(std::ostream &out) const
Definition: ReqScan.h:177
SWC::Comm::Protocol::Rgr::Params::RangeLocateRsp
Definition: RangeLocate.h:59
SWC::Comm::ResponseCallback::m_ev
Event::Ptr m_ev
Definition: ResponseCallback.h:42
SWC::Comm::Protocol::Rgr::Params::RangeLocateReq::NEXT_RANGE
static const uint8_t NEXT_RANGE
Definition: RangeLocate.h:23
SWC::Condition::GT
@ GT
Definition: Comparators.h:30
SWC::DB::Specs::Interval::range_begin
Cell::Key range_begin
Definition: SpecsInterval.h:238
SWC::Comm::Protocol::Rgr::Params::RangeLocateRsp::range_end
DB::Cell::Key range_end
Definition: RangeLocate.h:78
SWC::Condition::LT
@ LT
Definition: Comparators.h:34
SWC::Comm::Protocol::Rgr::Params::RangeLocateRsp::rid
rid_t rid
Definition: RangeLocate.h:77
SWC::Comm::ResponseCallback::m_conn
ConnHandlerPtr m_conn
Definition: ResponseCallback.h:41
SWC::DB::Cells::Cell
Definition: Cell.h:92
SWC::DB::Cell::Key
Definition: CellKey.h:24
SWC::Ranger::Callback::RangeLocateScan::reached_limits
bool reached_limits() override
Definition: RangeLocateScan.h:126
SWC::DB::Cells::Cell::key
DB::Cell::Key key
Definition: Cell.h:357
SWC::DB::Cells::ReqScan::profile
Profile profile
Definition: ReqScan.h:194
SWC::DB::Cell::Key::decode
void decode(const uint8_t **bufp, size_t *remainp, bool owner)
Definition: CellKey.h:337
SWC::Comm::Protocol::Rgr::Params::RangeLocateRsp::print
void print(std::ostream &out) const
Definition: RangeLocate.cc:80
SWC::DB::Types::KeySeq
KeySeq
Definition: KeySeq.h:13
SWC::DB::Cell::Key::empty
constexpr SWC_CAN_INLINE bool empty() const noexcept
Definition: CellKey.h:186
SWC::Comm::Protocol::Rgr::Params::RangeLocateReq::RANGE_END_REST
static const uint8_t RANGE_END_REST
Definition: RangeLocate.h:25
SWC::Ranger::RangePtr
std::shared_ptr< Range > RangePtr
Definition: Columns.h:15
SWC_CAN_INLINE
#define SWC_CAN_INLINE
Definition: Compat.h:102
SWC::LOG_DEBUG
@ LOG_DEBUG
Definition: Logger.h:36
SWC::Comm::Protocol::Rgr::Params::RangeLocateRsp::range_begin
DB::Cell::Key range_begin
Definition: RangeLocate.h:79
SWC::DB::Cells::ReqScan::Profile::finished
SWC_CAN_INLINE void finished()
Definition: ReqScan.h:130
SWC::Ranger::Callback::RangeLocateScan::flags
uint8_t flags
Definition: RangeLocateScan.h:169
SWC::Core::Buffer::base
value_type * base
Definition: Buffer.h:131
SWC
The SWC-DB C++ namespace 'SWC'.
Definition: main.cc:12
SWC::DB::KeySeq::compare_upto
Condition::Comp compare_upto(const Types::KeySeq seq, const Cell::Key &key, const Cell::Key &other, uint24_t max) SWC_ATTRIBS((SWC_ATTRIB_O3))
Definition: KeyComparator.h:417
SWC::Ranger::Callback::RangeLocateScan::response
void response(int &err) override
Definition: RangeLocateScan.h:139
SWC::Ranger::Callback::RangeLocateScan::range
RangePtr range
Definition: RangeLocateScan.h:168
RangeLocate.h
SWC::Ranger::Callback::RangeLocateScan
Definition: RangeLocateScan.h:15
SWC::Core::Buffer
Definition: Buffer.h:18
SWC::Core::Buffer::size
size_t size
Definition: Buffer.h:130
SWC::Condition::EQ
@ EQ
Definition: Comparators.h:32
SWC::DB::Cells::Cell::get_value
Types::Encoder get_value(StaticBuffer &v, bool owner) const
Definition: Cell.cc:77
SWC::DB::Cell::Key::copy
void copy(const Key &other)
Definition: CellKey.h:314
SWC::Ranger::Callback::RangeLocateScan::range_begin
const DB::Cell::Key range_begin
Definition: RangeLocateScan.h:171
ReqScan.h
SWC::DB::Specs::Interval::is_matching_begin
bool is_matching_begin(const Types::KeySeq key_seq, const DB::Cell::Key &key) const
Definition: SpecsInterval.h:265
SWC::Ranger::Callback::RangeLocateScan::RangeLocateScan
SWC_CAN_INLINE RangeLocateScan(const Comm::ConnHandlerPtr &conn, const Comm::Event::Ptr &ev, const DB::Cell::Key &a_range_begin, const DB::Cell::Key &a_range_end, const RangePtr &a_range, uint8_t a_flags)
Definition: RangeLocateScan.h:21
SWC::DB::Specs::Interval::set_opt__range_end_rest
constexpr SWC_CAN_INLINE void set_opt__range_end_rest() noexcept
Definition: SpecsInterval.h:153
SWC::Comm::ConnHandlerPtr
std::shared_ptr< ConnHandler > ConnHandlerPtr
Definition: AppContext.h:17
SWC::DB::Specs::Interval::range_end
Cell::Key range_end
Definition: SpecsInterval.h:238
SWC::Ranger::Range
Definition: Range.h:27
SWC::DB::Cells::ReqScan::spec
DB::Specs::Interval spec
Definition: ReqScan.h:106
SWC::DB::Cells::Cell::encoded_length
constexpr SWC_CAN_INLINE size_t encoded_length(bool no_value=false) const noexcept
Definition: Cell.h:285
SWC::Ranger::Callback::RangeLocateScan::any_is
uint32_t any_is
Definition: RangeLocateScan.h:170
SWC::Comm::Buffers::make
static SWC_CAN_INLINE Ptr make(uint32_t reserve=0)
Definition: Buffers.h:27
SWC::DB::Cell::Key::count
uint24_t count
Definition: CellKey.h:255
SWC::uint24_t
Core::uint24_t uint24_t
Definition: BitFieldInt.h:401
SWC::DB::Cell::Serial::Value::skip_type_and_id
SWC_CAN_INLINE void skip_type_and_id(const uint8_t **bufp, size_t *remainp)
Definition: CellValueSerialField.h:61
SWC::Comm::Protocol::Rgr::Params::RangeLocateRsp::err
int err
Definition: RangeLocate.h:75
SWC::Error::RANGE_NOT_FOUND
@ RANGE_NOT_FOUND
Definition: Error.h:116
SWC::Error::COLUMN_MARKED_REMOVED
@ COLUMN_MARKED_REMOVED
Definition: Error.h:102
SWC::Env::Rgr::is_shuttingdown
static SWC_CAN_INLINE bool is_shuttingdown() noexcept
Definition: RangerEnv.h:58
SWC::Comm::Protocol::Rgr::Params::RangeLocateReq::KEY_EQUAL
static const uint8_t KEY_EQUAL
Definition: RangeLocate.h:26
SWC::Serialization::decode_vi64
constexpr SWC_CAN_INLINE uint64_t decode_vi64(const uint8_t **bufp, size_t *remainp)
Definition: Serialization.h:302
SWC::rid_t
uint64_t rid_t
Definition: Identifiers.h:17
SWC::DB::Specs::Interval::offset_key
Cell::Key offset_key
Definition: SpecsInterval.h:244
SWC::Ranger::Callback::RangeLocateScan::params
Comm::Protocol::Rgr::Params::RangeLocateRsp params
Definition: RangeLocateScan.h:173
SWC::Comm::Event::Ptr
std::shared_ptr< Event > Ptr
Definition: Event.h:33
SWC::DB::Cell::Key::remove
void remove(uint32_t idx, bool recursive=false)
Definition: CellKey.cc:94
SWC::Ranger::Callback::RangeLocateScan::~RangeLocateScan
virtual ~RangeLocateScan() noexcept
Definition: RangeLocateScan.h:50
SWC::DB::Specs::Interval::set_opt__key_equal
constexpr SWC_CAN_INLINE void set_opt__key_equal() noexcept
Definition: SpecsInterval.h:148
SWC::Ranger::Callback::RangeLocateScan::add_cell_and_more
bool add_cell_and_more(const DB::Cells::Cell &cell) override
Definition: RangeLocateScan.h:130
SWC::DB::Cells::ReqScan::Profile::add_cell
SWC_CAN_INLINE void add_cell(uint32_t bytes) noexcept
Definition: ReqScan.h:135
SWC::Comm::Protocol::Rgr::Params::RangeLocateReq::CURRENT_RANGE
static const uint8_t CURRENT_RANGE
Definition: RangeLocate.h:22
SWC::DB::KeySeq::compare
Condition::Comp compare(const Types::KeySeq seq, const Cell::Key &key, const Cell::Key &other) SWC_ATTRIBS((SWC_ATTRIB_O3))
Definition: KeyComparator.h:294