SWC-DB  v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
RangeBlock.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_RangeBlock_h
8 #define swcdb_ranger_db_RangeBlock_h
9 
10 
11 #include "swcdb/fs/Interface.h"
12 #include "swcdb/db/Cells/Mutable.h"
14 
15 
16 namespace SWC { namespace Ranger {
17 
18  //Forawrd Declaration
19 class Blocks;
20 class BlockLoader;
21 
22 
23 class Block final {
24  public:
25 
26  typedef Block* Ptr;
27 
28  enum State : uint8_t {
29  NONE = 0x00,
30  LOADING = 0x01,
31  LOADED = 0x02
32  };
33 
34  enum ScanState : uint8_t {
35  UKNOWN = 0x00,
36  QUEUED = 0x01,
37  RESPONDED = 0x02,
38  SYNCED = 0x03
39  };
40 
44 
45 
46  static Ptr make(const DB::Cells::Interval& interval,
47  Blocks* blocks,
48  State state=State::NONE);
49 
50  explicit Block(const DB::Cells::Interval& interval,
51  Blocks* blocks, State state=State::NONE);
52 
53  Block(const Block&) = delete;
54 
55  Block(const Block&&) = delete;
56 
57  Block& operator=(const Block&) = delete;
58 
59  ~Block() noexcept;
60 
61  size_t _releasing_size() const noexcept;
62 
63  Ptr ptr();
64 
65  void schema_update() noexcept;
66 
67  void _set_prev_key_end(const DB::Cell::Key& key);
68 
69  void _set_prev_key_end(const Ptr blk);
70 
71  Condition::Comp _cond_key_end(const DB::Cell::Key& key) const;
72 
73  void _set_key_end(const DB::Cell::Key& key);
74 
75  void _free_key_end();
76 
77  bool is_consist(const DB::Cells::Interval& intval) const;
78 
79  bool is_in_end(const DB::Cell::Key& key) const;
80 
81  bool _is_in_end(const DB::Cell::Key& key) const;
82 
83  bool is_next(const DB::Specs::Interval& spec) const;
84 
85  bool includes(const DB::Specs::Interval& spec) const;
86 
87  bool _includes_begin(const DB::Specs::Interval& spec) const;
88 
89  bool includes_end(const DB::Specs::Interval& spec) const;
90 
91  void preload();
92 
93  bool add_logged(const DB::Cells::Cell& cell);
94 
95  void load_final(const DB::Cells::MutableVec& cells);
96 
97  size_t load_cells(const uint8_t* buf, size_t remain,
98  uint32_t revs, size_t avail,
99  bool& was_splitted, bool synced=false);
100 
101  bool splitter(bool loaded);
102 
103  ScanState scan(const ReqScan::Ptr& req);
104 
105  void loader_loaded();
106 
107  Ptr split(bool loaded);
108 
109  Ptr _split(bool loaded);
110 
111  void _add(Ptr blk);
112 
113  size_t release();
114 
115  void processing_increment() noexcept;
116 
117  void processing_decrement() noexcept;
118 
119  bool loaded() const noexcept;
120 
121  bool need_load() const noexcept;
122 
123  bool processing() noexcept;
124 
125  size_t size();
126 
127  size_t _size() const noexcept;
128 
129  size_t size_bytes();
130 
131  size_t size_of_internal();
132 
133  bool _need_split() const noexcept;
134 
135  void print(std::ostream& out);
136 
137  private:
138 
139  ScanState _scan(const ReqScan::Ptr& req, bool synced=false);
140 
141 
142  std::shared_mutex m_mutex;
143  DB::Cells::Mutable m_cells;
144  Core::Atomic<size_t> m_releasable_bytes;
145 
146  mutable Core::MutexAtomic m_mutex_intval;
147  uint32_t m_split_rev;
148  DB::Cell::Key m_prev_key_end;
149  DB::Cell::Key m_key_end;
150 
151  Core::MutexSptd m_mutex_state;
152  Core::Atomic<size_t> m_processing;
153  Core::Atomic<State> m_state;
155 
156 };
157 
158 
159 
160 
161 
162 
163 }}
164 
165 #endif // swcdb_ranger_db_RangeBlock_h
SWC::Ranger::Block::m_mutex
std::shared_mutex m_mutex
Definition: RangeBlock.h:142
SWC::Ranger::Block::UKNOWN
@ UKNOWN
Definition: RangeBlock.h:35
SWC::Ranger::Block::blocks
Blocks * blocks
Definition: RangeBlock.h:41
SWC::Ranger::Block::includes_end
bool includes_end(const DB::Specs::Interval &spec) const
Definition: RangeBlock.cc:144
SWC::Ranger::ReqScan
Definition: ReqScan.h:21
SWC::Ranger::Block::is_next
bool is_next(const DB::Specs::Interval &spec) const
Definition: RangeBlock.cc:119
SWC::Ranger::Block::m_split_rev
uint32_t m_split_rev
Definition: RangeBlock.h:147
SWC::Ranger::Block::make
static Ptr make(const DB::Cells::Interval &interval, Blocks *blocks, State state=State::NONE)
Definition: RangeBlock.cc:16
SWC::Ranger::Block::load_cells
size_t load_cells(const uint8_t *buf, size_t remain, uint32_t revs, size_t avail, bool &was_splitted, bool synced=false)
Definition: RangeBlock.cc:209
SWC::Ranger::Block
Definition: RangeBlock.h:23
SWC::Ranger::Block::RESPONDED
@ RESPONDED
Definition: RangeBlock.h:37
SWC::Ranger::Block::processing
bool processing() noexcept
Definition: RangeBlock.cc:442
SWC::Ranger::Block::next
Block::Ptr next
Definition: RangeBlock.h:42
SWC::Ranger::Block::m_key_end
DB::Cell::Key m_key_end
Definition: RangeBlock.h:149
SWC::Ranger::Block::State
State
Definition: RangeBlock.h:28
SWC::Ranger::Block::schema_update
void schema_update() noexcept
Definition: RangeBlock.cc:60
SWC::Ranger::Block::processing_increment
void processing_increment() noexcept
Definition: RangeBlock.cc:422
SWC::Ranger::Block::add_logged
bool add_logged(const DB::Cells::Cell &cell)
Definition: RangeBlock.cc:168
SWC::Ranger::Block::SYNCED
@ SYNCED
Definition: RangeBlock.h:38
SWC::Ranger::Block::size
size_t size()
Definition: RangeBlock.cc:463
SWC::Ranger::Block::m_releasable_bytes
Core::Atomic< size_t > m_releasable_bytes
Definition: RangeBlock.h:144
SWC::Ranger::Block::includes
bool includes(const DB::Specs::Interval &spec) const
Definition: RangeBlock.cc:129
SWC::Ranger::Block::_scan
ScanState _scan(const ReqScan::Ptr &req, bool synced=false)
Definition: RangeBlock.cc:513
SWC::Ranger::Block::ptr
Ptr ptr()
Definition: RangeBlock.cc:56
SWC::Ranger::Block::_is_in_end
bool _is_in_end(const DB::Cell::Key &key) const
Definition: RangeBlock.cc:112
SWC::Ranger::Block::QUEUED
@ QUEUED
Definition: RangeBlock.h:36
SWC::Ranger::Block::is_in_end
bool is_in_end(const DB::Cell::Key &key) const
Definition: RangeBlock.cc:106
SWC::Ranger::Block::size_bytes
size_t size_bytes()
Definition: RangeBlock.cc:474
SWC::Ranger::Block::prev
Block::Ptr prev
Definition: RangeBlock.h:43
SWC::Ranger::Block::m_loader
BlockLoader * m_loader
Definition: RangeBlock.h:154
SWC::Ranger::Block::_split
Ptr _split(bool loaded)
Definition: RangeBlock.cc:357
SWC::Ranger::Block::_free_key_end
void _free_key_end()
Definition: RangeBlock.cc:91
SWC::Ranger::Block::scan
ScanState scan(const ReqScan::Ptr &req)
Definition: RangeBlock.cc:271
SWC::Ranger::Block::~Block
~Block() noexcept
Definition: RangeBlock.cc:44
SWC::Ranger::Block::Block
Block(const Block &)=delete
SWC::Ranger::Block::Block
Block(const Block &&)=delete
SWC::Ranger::Block::LOADING
@ LOADING
Definition: RangeBlock.h:30
SWC::Ranger::Block::m_prev_key_end
DB::Cell::Key m_prev_key_end
Definition: RangeBlock.h:148
SWC::Condition::Comp
Comp
Definition: Comparators.h:27
SWC::Ranger::Block::Block
Block(const DB::Cells::Interval &interval, Blocks *blocks, State state=State::NONE)
Definition: RangeBlock.cc:22
SWC::Ranger::Block::m_state
Core::Atomic< State > m_state
Definition: RangeBlock.h:153
SWC::Ranger::Block::release
size_t release()
Definition: RangeBlock.cc:401
SWC::Ranger::Block::_cond_key_end
Condition::Comp _cond_key_end(const DB::Cell::Key &key) const
Definition: RangeBlock.cc:81
SWC::Ranger::Block::preload
void preload()
Definition: RangeBlock.cc:150
SWC::Ranger::Block::splitter
bool splitter(bool loaded)
Definition: RangeBlock.cc:267
SWC::Ranger::Block::ScanState
ScanState
Definition: RangeBlock.h:34
SWC
The SWC-DB C++ namespace 'SWC'.
Definition: main.cc:12
SWC::Ranger::Block::m_mutex_intval
Core::MutexAtomic m_mutex_intval
Definition: RangeBlock.h:146
SWC::Ranger::BlockLoader
Definition: RangeBlockLoader.h:19
SWC::Ranger::Block::size_of_internal
size_t size_of_internal()
Definition: RangeBlock.cc:480
SWC::Ranger::Block::m_cells
DB::Cells::Mutable m_cells
Definition: RangeBlock.h:143
SWC::Ranger::Block::_includes_begin
bool _includes_begin(const DB::Specs::Interval &spec) const
Definition: RangeBlock.cc:138
SWC::Condition::NONE
@ NONE
Definition: Comparators.h:28
SWC::Ranger::Block::loaded
bool loaded() const noexcept
Definition: RangeBlock.cc:432
SWC::Ranger::Block::_size
size_t _size() const noexcept
Definition: RangeBlock.cc:469
SWC::Ranger::Block::print
void print(std::ostream &out)
Definition: RangeBlock.cc:494
SWC::Ranger::Block::loader_loaded
void loader_loaded()
Definition: RangeBlock.cc:304
SWC::Ranger::Block::NONE
@ NONE
Definition: RangeBlock.h:29
SWC::Ranger::Block::m_mutex_state
Core::MutexSptd m_mutex_state
Definition: RangeBlock.h:151
SWC::Ranger::Block::is_consist
bool is_consist(const DB::Cells::Interval &intval) const
Definition: RangeBlock.cc:96
SWC::Ranger::Block::_add
void _add(Ptr blk)
Definition: RangeBlock.cc:392
SWC::Ranger::Block::_set_key_end
void _set_key_end(const DB::Cell::Key &key)
Definition: RangeBlock.cc:86
SWC::Ranger::Block::processing_decrement
void processing_decrement() noexcept
Definition: RangeBlock.cc:427
SWC::Ranger::Block::m_processing
Core::Atomic< size_t > m_processing
Definition: RangeBlock.h:152
SWC::Ranger::Blocks
Definition: RangeBlocks.h:23
SWC::Ranger::Block::Ptr
Block * Ptr
Definition: RangeBlock.h:26
SWC::Ranger::Block::need_load
bool need_load() const noexcept
Definition: RangeBlock.cc:437
SWC::Ranger::Block::operator=
Block & operator=(const Block &)=delete
SWC::Ranger::Block::LOADED
@ LOADED
Definition: RangeBlock.h:31
SWC::DB::Cells::Interval
Definition: Interval.h:17
Interface.h
SWC::Ranger::Block::load_final
void load_final(const DB::Cells::MutableVec &cells)
Definition: RangeBlock.cc:190
SWC::Ranger::Block::_need_split
bool _need_split() const noexcept
Definition: RangeBlock.cc:486
SWC::Ranger::Block::_releasing_size
size_t _releasing_size() const noexcept
Definition: RangeBlock.cc:51
SWC::Ranger::Block::split
Ptr split(bool loaded)
Definition: RangeBlock.cc:348
SWC::Ranger::Block::_set_prev_key_end
void _set_prev_key_end(const DB::Cell::Key &key)
Definition: RangeBlock.cc:71
Mutable.h
MutableVec.h