SWC-DB  v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
MutableVec.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_MutableVec_h
8 #define swcdb_db_cells_MutableVec_h
9 
10 
11 #include "swcdb/core/Compat.h"
12 #include "swcdb/core/Buffer.h"
13 #include "swcdb/db/Cells/Mutable.h"
14 
15 
16 namespace SWC { namespace DB { namespace Cells {
17 
18 
19 
20 class MutableVec final : private Core::Vector<Mutable*> {
21 
23 
24  public:
25 
26  using Vec::begin;
27  using Vec::end;
28 
30  uint32_t split_size;
31  uint32_t max_revs;
32  uint64_t ttl;
34 
36  explicit MutableVec(const Types::KeySeq a_key_seq, uint32_t a_split_size=100000,
37  const uint32_t a_max_revs=1, const uint64_t ttl_ns=0,
38  const Types::Column a_type=Types::Column::PLAIN) noexcept
39  : key_seq(a_key_seq), split_size(a_split_size),
40  max_revs(a_max_revs), ttl(ttl_ns), type(a_type) {
41  }
42 
43  MutableVec(const MutableVec&) = delete;
44 
45  MutableVec(const MutableVec&&) = delete;
46 
47  MutableVec& operator=(const MutableVec&) = delete;
48 
49  ~MutableVec() noexcept {
50  for(auto cells : *this)
51  delete cells;
52  }
53 
55  void free() noexcept {
56  for(auto cells : *this)
57  delete cells;
58  clear();
59  }
60 
61  void configure(uint32_t split,
62  const uint32_t revs, const uint64_t ttl_ns,
63  const Types::Column typ, bool finalized) noexcept;
64 
66  bool empty() const noexcept {
67  return Vec::empty();
68  }
69 
71  size_t size() const noexcept {
72  size_t sz = 0;
73  for(auto cells : *this)
74  sz += cells->size();
75  return sz;
76  }
77 
79  size_t size_bytes() const noexcept {
80  size_t sz = 0;
81  for(auto cells : *this)
82  sz += cells->size_bytes();
83  return sz;
84  }
85 
87  size_t size_of_internal() const noexcept {
88  size_t sz = 0;
89  for(auto cells : *this) {
90  sz += cells->size_of_internal();
91  sz += sizeof(cells);
92  }
93  return sz;
94  }
95 
96  void add_sorted(const Cell& cell);
97 
98  void add_raw(const Cell& cell, bool finalized);
99 
100  void add_raw(const Cell& cell,
101  size_t* offset_itp, size_t* offsetp, bool finalized);
102 
103  void write_and_free(DynamicBuffer& cells, uint32_t& cell_count,
104  Interval& intval, uint32_t threshold,
105  uint32_t max_cells);
106 
108  void check_sequence(const char* msg, bool w_assert=true) const {
109  for(auto it = cbegin(); it != cend();) {
110  Mutable* cells = *it;
111  if(++it != cend() && DB::KeySeq::compare(key_seq, (*it)->front().key, cells->back().key) == Condition::GT) {
112  SWC_LOG_OUT(
113  LOG_ERROR,
114  SWC_LOG_OSTREAM << "BAD cells-sequence at " << msg;
115  cells->back().key.print(SWC_LOG_OSTREAM << "\n current-");
116  (*it)->front().key.print(SWC_LOG_OSTREAM << "\n next-");
117  );
118  SWC_ASSERT(!w_assert);
119  }
120  cells->check_sequence(msg, w_assert);
121  }
122  }
123 
124  private:
125 
127  bool split(Mutable& cells, const const_iterator& it) {
128  if(cells.size() >= split_size && !cells.has_one_key()) {
129  Mutable next_cells(key_seq, max_revs, ttl, type);
130  if(cells.split(next_cells, split_size, 0, true)) {
131  insert(it, new Mutable(std::move(next_cells)));
132  return true;
133  }
134  }
135  return false;
136  }
137 
138 };
139 
140 
141 }}}
142 
143 
144 
145 #ifdef SWC_IMPL_SOURCE
147 #endif
148 
149 
150 #endif // swcdb_db_Cells_MutableVec_h
SWC::DB::Cells::Mutable::back
constexpr SWC_CAN_INLINE Cell & back() noexcept
Definition: Mutable.h:203
SWC_LOG_OSTREAM
#define SWC_LOG_OSTREAM
Definition: Logger.h:44
SWC::DB::Cells::MutableVec::key_seq
const Types::KeySeq key_seq
Definition: MutableVec.h:29
SWC::DB::Cells::Mutable::size
constexpr SWC_CAN_INLINE size_t size() const noexcept
Definition: Mutable.h:175
MutableVec.cc
SWC::Core::Vector< Mutable * >::clear
SWC_CAN_INLINE void clear() noexcept(_NoExceptDestructor)
Definition: Vector.h:120
SWC_LOG_OUT
#define SWC_LOG_OUT(pr, _code_)
Definition: Logger.h:178
SWC::DB::Cells::MutableVec::MutableVec
SWC_CAN_INLINE MutableVec(const Types::KeySeq a_key_seq, uint32_t a_split_size=100000, const uint32_t a_max_revs=1, const uint64_t ttl_ns=0, const Types::Column a_type=Types::Column::PLAIN) noexcept
Definition: MutableVec.h:36
SWC::DB::Cells::MutableVec::split_size
uint32_t split_size
Definition: MutableVec.h:30
SWC::DB::Cells::MutableVec::configure
void configure(uint32_t split, const uint32_t revs, const uint64_t ttl_ns, const Types::Column typ, bool finalized) noexcept
Definition: MutableVec.cc:17
SWC::DB::Cells::MutableVec::MutableVec
MutableVec(const MutableVec &&)=delete
SWC::DB::Cells::MutableVec::type
Types::Column type
Definition: MutableVec.h:33
SWC::Condition::GT
@ GT
Definition: Comparators.h:30
SWC::DB::Types::Column
Column
Definition: Column.h:18
SWC::DB::Cells::Cell
Definition: Cell.h:92
SWC::Core::Vector< Mutable * >::const_iterator
const value_type * const_iterator
Definition: Vector.h:51
SWC::DB::Cells::MutableVec::~MutableVec
~MutableVec() noexcept
Definition: MutableVec.h:49
SWC::DB::Cells::Cell::key
DB::Cell::Key key
Definition: Cell.h:357
SWC::DB::Cells::Mutable::check_sequence
SWC_CAN_INLINE void check_sequence(const char *msg, bool w_assert=true) const
Definition: Mutable.h:525
SWC::DB::Cells::MutableVec::size
SWC_CAN_INLINE size_t size() const noexcept
Definition: MutableVec.h:71
SWC::DB::Cells::MutableVec::write_and_free
void write_and_free(DynamicBuffer &cells, uint32_t &cell_count, Interval &intval, uint32_t threshold, uint32_t max_cells)
Definition: MutableVec.cc:71
SWC::DB::Cells::MutableVec::empty
SWC_CAN_INLINE bool empty() const noexcept
Definition: MutableVec.h:66
SWC::DB::Types::KeySeq
KeySeq
Definition: KeySeq.h:13
SWC::Core::Vector< Mutable * >::empty
constexpr SWC_CAN_INLINE bool empty() const noexcept
Definition: Vector.h:168
SWC_CAN_INLINE
#define SWC_CAN_INLINE
Definition: Compat.h:102
SWC::Core::Vector< Mutable * >::end
constexpr SWC_CAN_INLINE iterator end() noexcept
Definition: Vector.h:227
SWC
The SWC-DB C++ namespace 'SWC'.
Definition: main.cc:12
SWC::Core::BufferDyn< StaticBuffer >
Compat.h
SWC::DB::Cells::MutableVec::ttl
uint64_t ttl
Definition: MutableVec.h:32
SWC::DB::Cells::MutableVec::add_raw
void add_raw(const Cell &cell, bool finalized)
Definition: MutableVec.cc:35
Buffer.h
SWC::LOG_ERROR
@ LOG_ERROR
Definition: Logger.h:32
SWC::DB::Cells::MutableVec::Vec
Core::Vector< Mutable * > Vec
Definition: MutableVec.h:22
SWC::DB::Cells::Cell::print
void print(std::ostream &out, Types::Column typ) const
Definition: Cell.cc:187
SWC::DB::Cells::MutableVec::split
SWC_CAN_INLINE bool split(Mutable &cells, const const_iterator &it)
Definition: MutableVec.h:127
SWC::DB::Cells::MutableVec::size_bytes
SWC_CAN_INLINE size_t size_bytes() const noexcept
Definition: MutableVec.h:79
SWC::Core::Vector
Definition: Vector.h:14
SWC::DB::Cells::Mutable::has_one_key
constexpr SWC_CAN_INLINE bool has_one_key() const noexcept
Definition: Mutable.h:218
SWC::DB::Cells::MutableVec::free
SWC_CAN_INLINE void free() noexcept
Definition: MutableVec.h:55
SWC::Core::Vector< Mutable * >::cend
constexpr SWC_CAN_INLINE const_iterator cend() const noexcept
Definition: Vector.h:232
SWC::DB::Cells::MutableVec::operator=
MutableVec & operator=(const MutableVec &)=delete
SWC::DB::Cells::MutableVec::MutableVec
MutableVec(const MutableVec &)=delete
SWC::DB::Cells::MutableVec
Definition: MutableVec.h:20
SWC::DB::Cells::MutableVec::size_of_internal
SWC_CAN_INLINE size_t size_of_internal() const noexcept
Definition: MutableVec.h:87
SWC::DB::Cells::MutableVec::check_sequence
SWC_CAN_INLINE void check_sequence(const char *msg, bool w_assert=true) const
Definition: MutableVec.h:108
SWC::DB::Cells::MutableVec::add_sorted
void add_sorted(const Cell &cell)
Definition: MutableVec.cc:28
SWC::DB::Cells::MutableVec::max_revs
uint32_t max_revs
Definition: MutableVec.h:31
SWC::DB::Cells::Interval
Definition: Interval.h:17
SWC_ASSERT
#define SWC_ASSERT(_e_)
Definition: Exception.h:165
SWC::Core::Vector< Mutable * >::cbegin
constexpr SWC_CAN_INLINE const_iterator cbegin() const noexcept
Definition: Vector.h:216
SWC::DB::Cells::Mutable::split
SWC_CAN_INLINE bool split(Mutable &cells, size_t count, size_t bytes, bool loaded)
Definition: Mutable.h:583
SWC::Core::Vector< Mutable * >::insert
SWC_CAN_INLINE iterator insert(size_type offset, ArgsT &&... args)
Definition: Vector.h:367
SWC::DB::Cells::Mutable
Definition: Mutable.h:21
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
Mutable.h
SWC::Core::Vector< Mutable * >::begin
constexpr SWC_CAN_INLINE iterator begin() noexcept
Definition: Vector.h:211