SWC-DB  v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
Managers.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_db_client_mngr_Managers_h
7 #define swcdb_db_client_mngr_Managers_h
8 
9 
13 #include "swcdb/db/Cells/CellKey.h"
14 #include "swcdb/db/Types/KeySeq.h"
16 
17 
18 namespace SWC { namespace client {
19 
20 
21 
22 class Managers {
23  private:
24 
25  class MasterRangesCache final {
26 
27 
28  struct Range final {
29  int64_t ts;
34  int64_t revision;
36  Range(const int64_t a_ts,
37  const rid_t a_rid,
38  const DB::Cell::Key& range_begin,
39  const DB::Cell::Key& range_end,
40  const Comm::EndPoints& a_endpoints,
41  const int64_t a_revision)
42  : ts(a_ts), rid(a_rid),
43  key_begin(range_begin), key_end(range_end),
44  endpoints(a_endpoints), revision(a_revision) {
45  }
47  Range(Range&& other) noexcept
48  : ts(other.ts),
49  rid(other.rid),
50  key_begin(std::move(other.key_begin)),
51  key_end(std::move(other.key_end)),
52  endpoints(std::move(other.endpoints)),
53  revision(other.revision) {
54  }
56  ~Range() noexcept { }
58  Range& operator=(Range&& other) noexcept {
59  ts = other.ts;
60  rid = other.rid;
61  key_begin = std::move(other.key_begin);
62  key_end = std::move(other.key_end);
63  endpoints = std::move(other.endpoints);
64  revision = other.revision;
65  return *this;
66  }
68  void change(const int64_t _ts,
69  const rid_t _rid,
70  const DB::Cell::Key& _range_begin,
71  const DB::Cell::Key& _range_end,
72  const Comm::EndPoints& _endpoints,
73  const int64_t _revision) {
74  ts = _ts;
75  rid = _rid;
76  key_begin.copy(_range_begin);
77  key_end.copy(_range_end);
78  endpoints = _endpoints;
79  revision = _revision;
80  }
81  };
82 
83 
84  class Column final : private Core::Vector<Range> {
85 
89 
90  public:
91 
93  Column() noexcept: expiry_ms(nullptr), key_seq(), m_mutex() { }
94 
95  Column(const Column&) = delete;
96 
97  Column& operator=(const Column&) = delete;
98 
100  ~Column() noexcept { }
101 
102  void init(DB::Types::KeySeq _key_seq,
103  Config::Property::Value_int32_g::Ptr _expiry_ms) noexcept {
104  key_seq = _key_seq;
105  expiry_ms = _expiry_ms;
106  }
107 
108  void clear_expired() noexcept;
109 
110  void remove(const rid_t rid) noexcept;
111 
112  void set(const rid_t rid,
113  const DB::Cell::Key& range_begin,
114  const DB::Cell::Key& range_end,
115  const Comm::EndPoints& endpoints,
116  const int64_t revision);
117 
118  bool get_read(const DB::Cell::Key& range_begin,
119  const DB::Cell::Key& range_end,
120  rid_t& rid,
121  DB::Cell::Key& offset,
122  bool& is_end,
123  Comm::EndPoints& endpoints,
124  int64_t& revision);
125 
126  bool get_write(const DB::Cell::Key& key,
127  rid_t& rid,
128  DB::Cell::Key& key_end,
129  Comm::EndPoints& endpoints,
130  int64_t& revision);
131  };
132 
133 
134  public:
135 
137  MasterRangesCache() noexcept { }
138 
140  MasterRangesCache(const Config::Settings& settings) noexcept {
142  settings.get<Config::Property::Value_int32_g>(
143  "swc.client.Mngr.range.master.expiry"));
144  for(cid_t cid=1; cid<=DB::Types::SystemColumn::CID_MASTER_END; ++cid) {
145  columns[cid - 1].init(
147  expiry_ms
148  );
149  }
150  }
151 
153  ~MasterRangesCache() noexcept { }
154 
155  void clear_expired() noexcept {
156  for(auto& c : columns)
157  c.clear_expired();
158  }
159 
161  void remove(const cid_t cid, const rid_t rid) noexcept {
162  columns[cid - 1].remove(rid);
163  }
164 
166  void set(const cid_t cid, const rid_t rid,
167  const DB::Cell::Key& range_begin,
168  const DB::Cell::Key& range_end,
169  const Comm::EndPoints& endpoints,
170  const int64_t revision) {
171  columns[cid - 1].set(
172  rid, range_begin, range_end, endpoints, revision);
173  }
174 
176  bool get_read(const cid_t cid,
177  const DB::Cell::Key& range_begin,
178  const DB::Cell::Key& range_end,
179  rid_t& rid,
180  DB::Cell::Key& offset,
181  bool& is_end,
182  Comm::EndPoints& endpoints,
183  int64_t& revision) {
184  return columns[cid - 1].get_read(
185  range_begin, range_end, rid, offset, is_end, endpoints, revision);
186  }
187 
189  bool get_write(const cid_t cid,
190  const DB::Cell::Key& key,
191  rid_t& rid,
192  DB::Cell::Key& key_end,
193  Comm::EndPoints& endpoints,
194  int64_t& revision) {
195  return columns[cid - 1].get_write(
196  key, rid, key_end, endpoints, revision);
197  }
198 
199  private:
201 
202  };
203 
204 
205  public:
206 
208  Managers() noexcept
209  : queues(nullptr), groups(nullptr), master_ranges_cache() {
210  }
211 
212  Managers(const Config::Settings& settings,
213  Comm::IoContextPtr ioctx,
214  const ContextManager::Ptr& mngr_ctx);
215 
217  ~Managers() noexcept { }
218 
219  bool put(const ClientsPtr& clients,
220  const cid_t& cid, Comm::EndPoints& endpoints,
222 
223  bool put_role_schemas(const ClientsPtr& clients,
224  Comm::EndPoints& endpoints,
226 
230 
231 };
232 
233 
234 
235 }} // namespace SWC::client
236 
237 
238 
239 #endif // swcdb_db_client_mngr_Managers_h
SWC::client::Managers::MasterRangesCache::Range::key_end
DB::Cell::Key key_end
Definition: Managers.h:32
Groups.h
SWC::client::Managers::queues
const Comm::client::ConnQueuesPtr queues
Definition: Managers.h:227
SWC::client::ContextManager::Ptr
std::shared_ptr< ContextManager > Ptr
Definition: ContextManager.h:18
ContextManager.h
SWC::client::Managers::MasterRangesCache
Definition: Managers.h:25
SWC::client::Managers::MasterRangesCache::Column::Column
SWC_CAN_INLINE Column() noexcept
Definition: Managers.h:93
KeySeq.h
SWC::Comm::IoContextPtr
std::shared_ptr< IoContext > IoContextPtr
Definition: IoContext.h:16
SWC::client::Managers::MasterRangesCache::Column::m_mutex
Core::MutexSptd m_mutex
Definition: Managers.h:88
SWC::client::Managers::MasterRangesCache::MasterRangesCache
SWC_CAN_INLINE MasterRangesCache(const Config::Settings &settings) noexcept
Definition: Managers.h:140
SWC::client::Mngr::Groups::Ptr
std::shared_ptr< Groups > Ptr
Definition: Groups.h:78
SWC::client::Managers::MasterRangesCache::Column::~Column
SWC_CAN_INLINE ~Column() noexcept
Definition: Managers.h:100
SWC::DB::Cell::Key
Definition: CellKey.h:24
SWC::client::Managers::MasterRangesCache::Range::Range
SWC_CAN_INLINE Range(const int64_t a_ts, const rid_t a_rid, const DB::Cell::Key &range_begin, const DB::Cell::Key &range_end, const Comm::EndPoints &a_endpoints, const int64_t a_revision)
Definition: Managers.h:36
SWC::client::Managers::MasterRangesCache::Range::Range
SWC_CAN_INLINE Range(Range &&other) noexcept
Definition: Managers.h:47
SWC::client::Managers::~Managers
SWC_CAN_INLINE ~Managers() noexcept
Definition: Managers.h:217
SWC::client::Managers::MasterRangesCache::Range::operator=
SWC_CAN_INLINE Range & operator=(Range &&other) noexcept
Definition: Managers.h:58
SWC::Comm::client::ConnQueuesPtr
std::shared_ptr< ConnQueues > ConnQueuesPtr
Definition: ClientConnQueues.h:14
SWC::client::Managers::MasterRangesCache::Column::set
void set(const rid_t rid, const DB::Cell::Key &range_begin, const DB::Cell::Key &range_end, const Comm::EndPoints &endpoints, const int64_t revision)
Definition: Managers.cc:102
SWC::client::ClientsPtr
std::shared_ptr< Clients > ClientsPtr
Definition: Clients.h:23
SWC::DB::Types::KeySeq
KeySeq
Definition: KeySeq.h:13
SWC::client::Managers::MasterRangesCache::Column::key_seq
DB::Types::KeySeq key_seq
Definition: Managers.h:87
SWC::client::Managers::MasterRangesCache::Column
Definition: Managers.h:84
SWC_CAN_INLINE
#define SWC_CAN_INLINE
Definition: Compat.h:102
SWC::client::Managers::MasterRangesCache::Range::key_begin
DB::Cell::Key key_begin
Definition: Managers.h:31
SWC::client::Managers::MasterRangesCache::Column::operator=
Column & operator=(const Column &)=delete
SWC
The SWC-DB C++ namespace 'SWC'.
Definition: main.cc:12
SWC::client::Managers::MasterRangesCache::Range::revision
int64_t revision
Definition: Managers.h:34
SWC::client::Managers::MasterRangesCache::Column::Column
Column(const Column &)=delete
SWC::client::Managers::MasterRangesCache::Column::get_write
bool get_write(const DB::Cell::Key &key, rid_t &rid, DB::Cell::Key &key_end, Comm::EndPoints &endpoints, int64_t &revision)
Definition: Managers.cc:161
SWC::DB::Cell::Key::copy
void copy(const Key &other)
Definition: CellKey.h:314
SWC::client::Managers::master_ranges_cache
MasterRangesCache master_ranges_cache
Definition: Managers.h:229
SWC::client::Managers::MasterRangesCache::clear_expired
void clear_expired() noexcept
Definition: Managers.h:155
SWC::client::Managers::Managers
SWC_CAN_INLINE Managers() noexcept
Definition: Managers.h:208
SWC::client::Managers::MasterRangesCache::~MasterRangesCache
SWC_CAN_INLINE ~MasterRangesCache() noexcept
Definition: Managers.h:153
SWC::Comm::EndPoints
Core::Vector< EndPoint > EndPoints
Definition: Resolver.h:20
SWC::Config::Settings
Definition: Settings.h:25
SWC::client::Managers::MasterRangesCache::set
SWC_CAN_INLINE void set(const cid_t cid, const rid_t rid, const DB::Cell::Key &range_begin, const DB::Cell::Key &range_end, const Comm::EndPoints &endpoints, const int64_t revision)
Definition: Managers.h:166
ClientConnQueues.h
SWC::DB::Types::SystemColumn::CID_MASTER_END
const cid_t CID_MASTER_END
Definition: SystemColumn.h:18
SWC::client::Managers::MasterRangesCache::Column::expiry_ms
Config::Property::Value_int32_g::Ptr expiry_ms
Definition: Managers.h:86
SWC::DB::Types::SystemColumn::get_seq_type
KeySeq SWC_CONST_FUNC get_seq_type(cid_t cid) noexcept
Definition: SystemColumn.cc:15
SWC::client::Managers::MasterRangesCache::Column::init
void init(DB::Types::KeySeq _key_seq, Config::Property::Value_int32_g::Ptr _expiry_ms) noexcept
Definition: Managers.h:102
SWC::cid_t
uint64_t cid_t
Definition: Identifiers.h:16
SWC::client::Managers::put
bool put(const ClientsPtr &clients, const cid_t &cid, Comm::EndPoints &endpoints, const Comm::client::ConnQueue::ReqBase::Ptr &req)
Definition: Managers.cc:40
SWC::Core::Vector< EndPoint >
SWC::client::Managers::MasterRangesCache::get_read
SWC_CAN_INLINE bool get_read(const cid_t cid, const DB::Cell::Key &range_begin, const DB::Cell::Key &range_end, rid_t &rid, DB::Cell::Key &offset, bool &is_end, Comm::EndPoints &endpoints, int64_t &revision)
Definition: Managers.h:176
SWC::client::Managers::MasterRangesCache::Column::clear_expired
void clear_expired() noexcept
Definition: Managers.cc:80
SWC::client::Managers::MasterRangesCache::remove
SWC_CAN_INLINE void remove(const cid_t cid, const rid_t rid) noexcept
Definition: Managers.h:161
SWC::client::Managers::MasterRangesCache::Range::~Range
SWC_CAN_INLINE ~Range() noexcept
Definition: Managers.h:56
SWC::client::Managers::MasterRangesCache::Range::endpoints
Comm::EndPoints endpoints
Definition: Managers.h:33
SWC::rid_t
uint64_t rid_t
Definition: Identifiers.h:17
SWC::client::Managers::MasterRangesCache::Column::get_read
bool get_read(const DB::Cell::Key &range_begin, const DB::Cell::Key &range_end, rid_t &rid, DB::Cell::Key &offset, bool &is_end, Comm::EndPoints &endpoints, int64_t &revision)
Definition: Managers.cc:131
SWC::Core::MutexSptd
Definition: MutexSptd.h:16
SWC::client::Managers::MasterRangesCache::Range::rid
rid_t rid
Definition: Managers.h:30
SWC::client::Managers::groups
const Mngr::Groups::Ptr groups
Definition: Managers.h:228
SWC::client::Managers::MasterRangesCache::columns
Column columns[DB::Types::SystemColumn::CID_MASTER_END]
Definition: Managers.h:200
SWC::client::Managers::MasterRangesCache::Range::change
SWC_CAN_INLINE void change(const int64_t _ts, const rid_t _rid, const DB::Cell::Key &_range_begin, const DB::Cell::Key &_range_end, const Comm::EndPoints &_endpoints, const int64_t _revision)
Definition: Managers.h:68
SWC::client::Managers::MasterRangesCache::get_write
SWC_CAN_INLINE bool get_write(const cid_t cid, const DB::Cell::Key &key, rid_t &rid, DB::Cell::Key &key_end, Comm::EndPoints &endpoints, int64_t &revision)
Definition: Managers.h:189
SWC::client::Managers::put_role_schemas
bool put_role_schemas(const ClientsPtr &clients, Comm::EndPoints &endpoints, const Comm::client::ConnQueue::ReqBase::Ptr &req)
Definition: Managers.cc:59
SWC::client::Managers::MasterRangesCache::Range
Definition: Managers.h:28
SWC::Comm::client::ConnQueueReqBase::Ptr
std::shared_ptr< ConnQueueReqBase > Ptr
Definition: ClientConnQueue.h:25
SWC::client::Managers
Definition: Managers.h:22
SWC::client::Managers::MasterRangesCache::Column::remove
void remove(const rid_t rid) noexcept
Definition: Managers.cc:92
SWC::client::Managers::MasterRangesCache::Range::ts
int64_t ts
Definition: Managers.h:29
SWC::Config::Property::Value_int32_g
Definition: Property.h:586
SystemColumn.h
CellKey.h