SWC-DB  v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
CellStore.cc
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 
8 
9 
10 namespace SWC { namespace Ranger { namespace CellStore {
11 
12 
13 Read::Ptr Read::make(int& err, const csid_t csid, const RangePtr& range,
14  bool chk_base) {
15  auto smartfd = FS::SmartFd::make_ptr(range->get_path_cs(csid), 0);
18  DB::Cells::Interval interval(range->cfg->key_seq);
19  Blocks blocks;
20  uint32_t cell_revs = 0;
21  try {
24  blocks, cell_revs, chk_base);
26  } catch(...) {
29  err = e.code();
30  }
31  if(err)
33  Error::print(SWC_LOG_OSTREAM << "CellStore load_blocks_index ", err);
34  SWC_LOG_OSTREAM << " csid=" << csid
35  << " range(" << range->cfg->cid << '/' << range->rid << ") ";
37  );
38 
39  return new Read(
40  csid,
41  std::move(prev_key_end),
42  std::move(key_end),
43  std::move(interval),
44  std::move(blocks),
45  cell_revs,
46  smartfd
47  );
48 }
49 
50 SWC_SHOULD_NOT_INLINE
51 bool Read::load_trailer(int& err, FS::SmartFd::Ptr& smartfd,
52  uint32_t& cell_revs,
53  uint32_t& blks_idx_count,
54  uint64_t& blks_idx_offset,
55  bool close_after, bool chk_base) {
56  const auto& fs_if = Env::FsInterface::interface();
57  const auto& fs = Env::FsInterface::fs();
58 
59  bool loaded = false;
60  err = Error::OK;
61  while(err != Error::FS_EOF) {
62  if(err) {
64  Error::print(SWC_LOG_OSTREAM << "Retrying to ", err);
65  smartfd->print(SWC_LOG_OSTREAM << ' ');
66  );
67  fs_if->close(err, smartfd);
68  err = Error::OK;
69  }
70 
71  if(!fs_if->exists(err, smartfd->filepath())) {
72  if(!err)
74  return loaded;
75  }
76 
77  size_t length = fs_if->length(err, smartfd->filepath());
78  if(err)
79  return loaded;
80 
81  if(!smartfd->valid() && !fs_if->open(err, smartfd) && err)
82  return loaded;
83  if(err)
84  continue;
85 
86  uint8_t buf[TRAILER_SIZE];
87  const uint8_t *ptr = buf;
88  if(fs->pread(err, smartfd, length - TRAILER_SIZE, buf,
90  if(chk_base)
91  break;
92  continue;
93  }
94 
95  size_t remain = TRAILER_SIZE;
96  Serialization::decode_i8(&ptr, &remain); // int8_t version =
97  cell_revs = Serialization::decode_i32(&ptr, &remain);
98  blks_idx_count = Serialization::decode_i32(&ptr, &remain);
99  blks_idx_offset = Serialization::decode_i64(&ptr, &remain);
100 
102  buf, TRAILER_SIZE-4)) {
104  if(chk_base)
105  break;
106  continue;
107  }
108  loaded = true;
109  break;
110  }
111 
112  if(close_after)
113  fs_if->close(err, smartfd);
114  return loaded;
115 }
116 
117 SWC_SHOULD_NOT_INLINE
119  DB::Cell::Key& prev_key_end,
120  DB::Cell::Key& key_end,
121  DB::Cells::Interval& interval,
122  Blocks& blocks,
123  uint32_t& cell_revs,
124  bool chk_base) {
125  uint32_t blks_idx_count = 0;
126  uint64_t offset_fixed = 0;
127  uint64_t offset;
128 
129  const auto& fs_if = Env::FsInterface::interface();
130  const auto& fs = Env::FsInterface::fs();
131 
132  StaticBuffer read_buf;
133  bool trailer = false;
134  err = Error::OK;
135 
136  const uint8_t* ptr;
137  size_t remain;
138 
139  DB::Types::Encoder idx_encoder;
140  size_t idx_size_plain;
141  size_t idx_size_enc;
142  uint32_t idx_checksum_data;
143 
144  uint32_t blks_count;
146 
147  while(err != Error::FS_EOF) {
148  if(err) {
150  Error::print(SWC_LOG_OSTREAM << "Retrying to ", err);
151  smartfd->print(SWC_LOG_OSTREAM << ' ');
152  );
153  fs_if->close(err, smartfd);
154  err = Error::OK;
155  }
156 
157  if(!trailer) {
158  if(!load_trailer(err, smartfd, cell_revs, blks_idx_count, offset_fixed,
159  false, chk_base))
160  break;
161  trailer = true;
162  }
163  offset = offset_fixed;
164 
165  if(!smartfd->valid() && !fs_if->open(err, smartfd) && err)
166  return;
167  if(err)
168  continue;
169 
170  for(auto blk : blocks)
171  delete blk;
172  blocks.clear();
173 
174  for(uint32_t i=0; i < blks_idx_count; ++i) {
175  read_buf.free();
176  if(fs->pread(err, smartfd, offset, &read_buf,
178  trailer = false;
179  break;
180  }
181  ptr = read_buf.base;
182  remain = IDX_BLKS_HEADER_SIZE;
183 
184  idx_encoder = DB::Types::Encoder(
185  Serialization::decode_i8(&ptr, &remain));
186  idx_size_enc = Serialization::decode_i32(&ptr, &remain);
187  idx_size_plain = Serialization::decode_i32(&ptr, &remain);
188  idx_checksum_data = Serialization::decode_i32(&ptr, &remain);
190  read_buf.base, IDX_BLKS_HEADER_SIZE - 4)) {
192  break;
193  }
194  offset += IDX_BLKS_HEADER_SIZE;
195 
196  read_buf.free();
197  if(fs->pread(err, smartfd, offset, &read_buf,
198  idx_size_enc) != idx_size_enc) {
199  trailer = false;
200  break;
201  }
202  if(!Core::checksum_i32_chk(idx_checksum_data,
203  read_buf.base, idx_size_enc)) {
205  trailer = false;
206  break;
207  }
208  offset += idx_size_enc;
209 
210  if(idx_encoder != DB::Types::Encoder::PLAIN) {
211  StaticBuffer decoded_buf(idx_size_plain);
212  Core::Encoder::decode(err, idx_encoder, read_buf.base, idx_size_enc,
213  decoded_buf.base, idx_size_plain);
214  if(err)
215  break;
216  read_buf.set(decoded_buf);
217  }
218 
219  ptr = read_buf.base;
220  remain = idx_size_plain;
221  if(!i)
222  prev_key_end.decode(&ptr, &remain, true);
223  blks_count = Serialization::decode_vi32(&ptr, &remain);
224  blocks.reserve(blocks.size() + blks_count);
225 
226  for(uint32_t blk_i = 0; blk_i < blks_count; ) {
227  header.decode_idx(&ptr, &remain);
228  interval.align(header.interval);
229  if(++blk_i == blks_count && i + 1 == blks_idx_count)
230  key_end.copy(header.interval.key_end);
231 
232  if(header.is_any & Block::Header::ANY_BEGIN)
233  header.interval.key_begin.free();
234  if(header.is_any & Block::Header::ANY_END)
235  header.interval.key_end.free();
236  interval.expand(header.interval);
237  blocks.push_back(new Block::Read(std::move(header)));
238  }
239 
240  }
241  if(!trailer || err) {
242  if(chk_base)
243  break;
244  continue;
245  }
246  break;
247  }
248 
249  fs_if->close(err, smartfd);
250 }
251 
252 //
253 
255 Read::Read(const csid_t a_csid,
256  DB::Cell::Key&& a_prev_key_end,
257  DB::Cell::Key&& a_key_end,
258  DB::Cells::Interval&& a_interval,
259  Blocks&& blks,
260  const uint32_t a_cell_revs,
261  const FS::SmartFd::Ptr& a_smartfd) noexcept
262  : csid(a_csid),
263  prev_key_end(std::move(a_prev_key_end)),
264  key_end(std::move(a_key_end)),
265  interval(std::move(a_interval)),
266  blocks(std::move(blks)),
267  cell_revs(a_cell_revs),
268  smartfd(a_smartfd),
269  m_queue() {
270  for(auto blk : blocks)
271  blk->init(this);
272 }
273 
274 Read::~Read() noexcept {
275  for(auto blk : blocks)
276  delete blk;
277 }
278 
279 /*
280 size_t Read::size_of() const noexcept {
281  return sizeof(*this) + sizeof(Ptr)
282  + prev_key_end.size
283  + key_end.size
284  + interval.size_of_internal()
285  + sizeof(*smartfd.get()) + smartfd->filepath().size()
286  ;
287 }
288 */
289 
291 const std::string& Read::filepath() const {
292  return smartfd->filepath();
293 }
294 
297  for(auto blk : blocks) {
298  if(loader->block->is_consist(blk->header.interval)) {
299  loader->add(blk);
300  if(blk->load(loader)) {
301  if(m_queue.activating(blk))
302  blk->load();
303  }
304  } else if(!blk->header.interval.key_end.empty() &&
305  !loader->block->is_in_end(blk->header.interval.key_end))
306  break;
307  }
308 }
309 
312  Block::Read::Ptr blk = nullptr;
313  m_queue.deactivating(blk) ? _release_fd() : blk->load();
314 }
315 
317 void Read::get_blocks(int&, Blocks& to) const {
318  to.insert(to.cend(), blocks.cbegin(), blocks.cend());
319 }
320 
322 size_t Read::release(size_t bytes) {
323  size_t released = 0;
324  for(auto blk : blocks) {
325  released += blk->release();
326  if(released >= bytes)
327  break;
328  }
329 
330  if(!m_queue.is_active())
331  _release_fd();
332  return released;
333 }
334 
336  if(smartfd->valid() &&
337  Env::FsInterface::interface()->need_fds() &&
338  !processing()) {
339  int err = Error::OK;
340  close(err);
341  }
342 }
343 
345 void Read::close(int &err) {
346  int32_t fd = smartfd->invalidate();
347  if(fd != -1) {
348  auto r = FS::SmartFd::make_ptr(smartfd->filepath(), smartfd->flags(), fd);
349  Env::FsInterface::interface()->close(err, r);
350  }
351 }
352 
354 void Read::remove(int &err) {
355  Env::FsInterface::interface()->remove(err, smartfd->filepath());
356 }
357 
359 bool Read::processing() const noexcept{
360  if(m_queue.is_active())
361  return true;
362 
363  for(auto blk : blocks)
364  if(blk->processing())
365  return true;
366  return false;
367 }
368 
370 size_t Read::size_bytes(bool only_loaded) const {
371  size_t size = 0;
372  for(auto blk : blocks)
373  size += blk->size_bytes(only_loaded);
374  return size;
375 }
376 
378 size_t Read::size_bytes_enc(bool only_loaded) const {
379  size_t size = 0;
380  for(auto blk : blocks)
381  size += blk->size_bytes_enc(only_loaded);
382  return size;
383 }
384 
386 size_t Read::blocks_count() const {
387  return blocks.size();
388 }
389 
390 void Read::print(std::ostream& out, bool minimal) const {
391  out << "Read(v=" << int(VERSION)
392  << " csid=" << csid
393  << " prev=" << prev_key_end
394  << " end=" << key_end
395  << ' ' << interval
396  << " file=" << smartfd->filepath()
397  << " blocks=" << blocks_count();
398  if(!minimal) {
399  out << " blocks=[";
400  for(auto blk : blocks) {
401  blk->print(out);
402  out << ", ";
403  }
404  out << ']';
405  }
406  out << " queue=" << m_queue.size()
407  << " processing=" << processing()
408  << " used/actual=" << size_bytes(true) << '/' << size_bytes()
409  << ')';
410 }
411 
412 
413 
414 
415 
416 
418 Write::Write(const csid_t a_csid, std::string&& filepath,
419  const RangePtr& range, uint32_t a_cell_revs,
420  const DB::Cell::Key& a_prev_key_end)
421  : csid(a_csid),
422  smartfd(
423  FS::SmartFd::make_ptr(
424  std::move(filepath), FS::OpenFlags::OPEN_FLAG_OVERWRITE)
425  ),
426  encoder(range->cfg->block_enc()),
427  block_size(range->cfg->block_size()),
428  cell_revs(a_cell_revs),
429  prev_key_end(a_prev_key_end),
430  size(0), blocks() {
431 }
432 
433 void Write::create(int& err, uint8_t blk_replicas) {
434  while(
435  Env::FsInterface::interface()->create(err, smartfd, blk_replicas));
436 }
437 
438 void Write::block_encode(int& err, DynamicBuffer& cells_buff,
439  Block::Header&& header) {
440  header.encoder = encoder;
441  DynamicBuffer output;
442  Block::Write::encode(err, cells_buff, output, header);
443  if(err)
444  return;
445 
446  block_write(err, output, std::move(header));
447 }
448 
449 void Write::block_write(int& err, DynamicBuffer& blk_buff,
450  Block::Header&& header) {
451  header.offset_data = size + Block::Header::SIZE;
452  blocks.emplace_back(new Block::Write(std::move(header)));
453  block(err, blk_buff);
454 }
455 
456 void Write::block(int& err, DynamicBuffer& blk_buff) {
457  StaticBuffer buff_write(blk_buff);
458  size += buff_write.size;
459 
460  Env::FsInterface::fs()->append(
461  err,
462  smartfd,
463  buff_write,
465  );
466 }
467 
469 void Write::write_blocks_index(int& err, uint32_t& blks_idx_count) {
470  if(blocks.empty())
471  return;
472 
473  blks_idx_count = 0;
474  uint32_t blks_count = 0;
475  uint32_t len_data = 0;
476  Block::Write::Ptr blk;
477 
478  auto it = blocks.cbegin();
479  auto it_last = it;
480  do {
481  blk = *it;
482 
483  if(!blks_idx_count && !blks_count)
484  len_data += prev_key_end.encoded_length();
485  ++blks_count;
486  len_data += blk->header.encoded_length_idx();
487 
488  if(++it == blocks.cend() || len_data >= block_size) {
489  len_data += Serialization::encoded_length_vi32(blks_count);
490 
491  StaticBuffer raw_buffer(static_cast<size_t>(len_data));
492  uint8_t* ptr = raw_buffer.base;
493 
494  if(!blks_idx_count)
495  prev_key_end.encode(&ptr);
496  ++blks_idx_count;
497  Serialization::encode_vi32(&ptr, blks_count);
498 
499  for(; it_last != it; ++it_last)
500  (*it_last)->header.encode_idx(&ptr);
501 
502  DynamicBuffer buffer_write;
503  size_t len_enc = 0;
504  Core::Encoder::encode(err, encoder, raw_buffer.base, len_data,
505  &len_enc, buffer_write, IDX_BLKS_HEADER_SIZE);
506  raw_buffer.free();
507  if(err)
508  return;
509  DB::Types::Encoder _encoder;
510  if(len_enc) {
511  _encoder = encoder;
512  } else {
513  _encoder = DB::Types::Encoder::PLAIN;
514  len_enc = len_data;
515  }
516 
517  uint8_t* header_ptr = buffer_write.base;
518  Serialization::encode_i8(&header_ptr, uint8_t(_encoder));
519  Serialization::encode_i32(&header_ptr, len_enc);
520  Serialization::encode_i32(&header_ptr, len_data);
522  buffer_write.base + IDX_BLKS_HEADER_SIZE, len_enc, &header_ptr);
523  Core::checksum_i32(buffer_write.base, header_ptr, &header_ptr);
524 
525  StaticBuffer buff_write(buffer_write);
526  Env::FsInterface::fs()->append(
527  err,
528  smartfd,
529  buff_write,
531  );
532  if(err)
533  return;
534 
535  size += buff_write.size;
536  blks_count = len_data = 0;
537  }
538  } while (it != blocks.cend());
539 }
540 
542 void Write::write_trailer(int& err) {
543  uint64_t blks_idx_offset = size;
544  uint32_t blks_idx_count = 0;
545  write_blocks_index(err, blks_idx_count);
546  if(err)
547  return;
548 
549  StaticBuffer buff_write(static_cast<size_t>(TRAILER_SIZE));
550  uint8_t* ptr = buff_write.base;
553  Serialization::encode_i32(&ptr, blks_idx_count);
554  Serialization::encode_i64(&ptr, blks_idx_offset);
555  Core::checksum_i32(buff_write.base, ptr, &ptr);
556 
557  Env::FsInterface::fs()->append(
558  err,
559  smartfd,
560  buff_write,
562  );
563 
564  size += buff_write.size;
565 }
566 
569  Env::FsInterface::interface()->close(err, smartfd);
570 
571  if(Env::FsInterface::interface()->length(err, smartfd->filepath())
572  != size || err)
573  err = Error::FS_EOF;
574  // + trailer-checksum
575 }
576 
577 void Write::finalize(int& err) {
578  write_trailer(err);
579  if(!err) {
580  close_and_validate(err);
581  if(!err)
582  return;
583  }
584  int tmperr = Error::OK;
585  remove(tmperr);
586 }
587 
588 void Write::remove(int &err) {
589  Env::FsInterface::interface()->close(err, smartfd);
590  Env::FsInterface::interface()->remove(err, smartfd->filepath());
591 }
592 
593 void Write::print(std::ostream& out) const {
594  out << "Write(v=" << int(CellStore::VERSION)
595  << " size=" << size
596  << " encoder=" << Core::Encoder::to_string(encoder)
597  << " cell_revs=" << cell_revs
598  << " prev=" << prev_key_end;
599  smartfd->print(out << ' ');
600  out << " blocks=" << blocks.size()
601  << " blocks=[";
602  for(auto blk : blocks) {
603  blk->print(out);
604  out << ", ";
605  }
606  out << "])";
607 }
608 
609 
610 Read::Ptr create_initial(int& err, const RangePtr& range) {
611  Write writer(
612  1, range->get_path_cs(1), range, range->cfg->cell_versions(),
613  DB::Cell::Key()
614  );
615  writer.create(err, range->cfg->file_replication());
616  if(err)
617  return nullptr;
618 
619  Block::Header header(range->cfg->key_seq);
620  range->_get_interval(header.interval);
621 
622  if(header.interval.key_begin.empty())
624  if(header.interval.key_end.empty())
625  header.is_any |= Block::Header::ANY_END;
626 
627  DynamicBuffer cells_buff;
628  writer.block_encode(err, cells_buff, std::move(header));
629  if(!err) {
630  writer.finalize(err);
631  if(!err) {
632  auto cs = Read::make(err, 1, range, true);
633  if(!err)
634  return cs;
635  delete cs;
636  }
637  }
638  int errtmp;
639  writer.remove(errtmp);
640  return nullptr;
641 
642 }
643 
644 
645 }}} // namespace SWC::Ranger::CellStore
SWC::Ranger::CellStore::Write::Write
Write(const csid_t csid, std::string &&filepath, const RangePtr &range, uint32_t cell_revs, const DB::Cell::Key &prev_key_end)
Definition: CellStore.cc:418
SWC::Ranger::CellStore::Block::Header
Definition: CellStoreBlockHeader.h:23
SWC::Ranger::CellStore::Block::Header::decode_idx
void decode_idx(const uint8_t **bufp, size_t *remainp)
Definition: CellStoreBlockHeader.cc:98
SWC::Ranger::CellStore::Write::blocks
Core::Vector< Block::Write::Ptr > blocks
Definition: CellStore.h:140
SWC::DB::Cells::Interval::key_end
DB::Cell::Key key_end
Definition: Interval.h:225
SWC::Error::Exception::code
constexpr SWC_CAN_INLINE int code() const noexcept
Definition: Exception.h:51
SWC_LOG_OSTREAM
#define SWC_LOG_OSTREAM
Definition: Logger.h:44
SWC::Ranger::CellStore::Write::block_size
const uint32_t block_size
Definition: CellStore.h:135
SWC::Ranger::CellStore::Block::Write::encode
static void encode(int &err, DynamicBuffer &cells, DynamicBuffer &output, Header &header)
Definition: CellStoreBlock.cc:370
SWC::Ranger::CellStore::Write::finalize
void finalize(int &err)
Definition: CellStore.cc:577
SWC::Ranger::CellStore::Read::size_bytes_enc
size_t size_bytes_enc(bool only_loaded=false) const
Definition: CellStore.cc:378
SWC::Ranger::CellStore::Read::Read
Read(const csid_t csid, DB::Cell::Key &&prev_key_end, DB::Cell::Key &&key_end, DB::Cells::Interval &&interval, Blocks &&blocks, const uint32_t cell_revs, const FS::SmartFd::Ptr &smartfd) noexcept
Definition: CellStore.cc:255
SWC::Ranger::CellStore::Block::Header::is_any
uint8_t is_any
Definition: CellStoreBlockHeader.h:31
SWC::Serialization::encode_i64
SWC_CAN_INLINE void encode_i64(uint8_t **bufp, uint64_t val) noexcept
Definition: Serialization.h:151
SWC::Ranger::CellStore::Read::get_blocks
void get_blocks(int &err, Blocks &to) const
Definition: CellStore.cc:317
SWC::Core::Vector::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::Ranger::CellStore::Read::remove
void remove(int &err)
Definition: CellStore.cc:354
SWC::DB::Cells::Interval::align
SWC_CAN_INLINE bool align(const Interval &other)
Definition: Interval.h:152
SWC::Core::Encoder::Type
Type
Definition: Encoder.h:28
SWC::Serialization::encoded_length_vi32
constexpr SWC_CAN_INLINE uint8_t encoded_length_vi32(uint32_t val) noexcept
Definition: Serialization.h:234
SWC::Serialization::encode_i32
SWC_CAN_INLINE void encode_i32(uint8_t **bufp, uint32_t val) noexcept
Definition: Serialization.h:138
SWC::Env::FsInterface::interface
static SWC_CAN_INLINE FS::Interface::Ptr & interface() noexcept
Definition: Interface.h:150
SWC::DB::Cells::Interval::print
void print(std::ostream &out) const
Definition: Interval.cc:146
SWC::FS::SmartFd::make_ptr
static SWC_CAN_INLINE Ptr make_ptr(const std::string &filepath, uint32_t flags, int32_t fd=-1, uint64_t pos=0)
Definition: SmartFd.h:40
SWC::DB::Cells::Interval::key_seq
const Types::KeySeq key_seq
Definition: Interval.h:25
SWC::csid_t
uint32_t csid_t
Definition: Identifiers.h:19
SWC::Core::checksum_i32_chk
SWC_CAN_INLINE bool checksum_i32_chk(uint32_t checksum, const uint8_t *base, uint32_t len)
Definition: Checksum.h:94
SWC::Error::FS_PATH_NOT_FOUND
@ FS_PATH_NOT_FOUND
Definition: Error.h:97
SWC::Ranger::CellStore::Read::interval
const DB::Cells::Interval interval
Definition: CellStore.h:71
SWC::Ranger::BlockLoader::add
void add(const ReqScan::Ptr &req)
Definition: RangeBlockLoader.cc:78
SWC::Ranger::CellStore::Block::Header::interval
DB::Cells::Interval interval
Definition: CellStoreBlockHeader.h:30
SWC::DB::Cells::Interval::expand
void expand(const Interval &other)
Definition: Interval.cc:38
SWC::Ranger::Block::is_in_end
bool is_in_end(const DB::Cell::Key &key) const
Definition: RangeBlock.cc:106
SWC::Ranger::CellStore::Read::key_end
const DB::Cell::Key key_end
Definition: CellStore.h:70
SWC::DB::Cell::Key
Definition: CellKey.h:24
SWC::Ranger::CellStore::Read::close
void close(int &err)
Definition: CellStore.cc:345
SWC::Serialization::encode_i8
constexpr SWC_CAN_INLINE void encode_i8(uint8_t **bufp, uint8_t val) noexcept
Definition: Serialization.h:85
SWC::Ranger::CellStore::IDX_BLKS_HEADER_SIZE
static const uint8_t IDX_BLKS_HEADER_SIZE
Definition: CellStore.h:38
SWC::Ranger::CellStore::Read::release
size_t release(size_t bytes)
Definition: CellStore.cc:322
SWC::DB::Cell::Key::decode
void decode(const uint8_t **bufp, size_t *remainp, bool owner)
Definition: CellKey.h:337
SWC::Ranger::CellStore::create_initial
static Read::Ptr create_initial(int &err, const RangePtr &range)
Definition: CellStore.cc:610
SWC::Ranger::CellStore::Block::Header::ANY_BEGIN
static const uint8_t ANY_BEGIN
Definition: CellStoreBlockHeader.h:26
SWC::Ranger::CellStore::Write::cell_revs
const uint32_t cell_revs
Definition: CellStore.h:136
SWC::FS::OpenFlags
OpenFlags
Definition: FileSystem.h:33
SWC::Ranger::CellStore::Block::Header::SIZE
static const uint8_t SIZE
Definition: CellStoreBlockHeader.h:24
SWC::Ranger::CellStore::Write::block_write
void block_write(int &err, DynamicBuffer &blk_buff, Block::Header &&header)
Definition: CellStore.cc:449
SWC::Ranger::CellStore::Read::prev_key_end
const DB::Cell::Key prev_key_end
Definition: CellStore.h:69
encoder
Core::Encoder::Type encoder
Buffer Encoder.
Definition: HeaderBufferInfo.h:50
SWC::Ranger::CellStore::VERSION
static const int8_t VERSION
Definition: CellStore.h:36
SWC::DB::Cell::Key::empty
constexpr SWC_CAN_INLINE bool empty() const noexcept
Definition: CellKey.h:186
SWC::Ranger::CellStore::Read::load_trailer
static bool load_trailer(int &err, FS::SmartFd::Ptr &smartfd, uint32_t &cell_revs, uint32_t &blks_idx_count, uint64_t &blks_idx_offset, bool close_after=false, bool chk_base=false)
Definition: CellStore.cc:51
SWC::Error::OK
@ OK
Definition: Error.h:45
SWC::Core::Vector::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::Ranger::RangePtr
std::shared_ptr< Range > RangePtr
Definition: Columns.h:15
SWC::Error::FS_EOF
@ FS_EOF
Definition: Error.h:96
SWC::Ranger::CellStore::Write::smartfd
FS::SmartFd::Ptr smartfd
Definition: CellStore.h:133
SWC::Ranger::CellStore::Write::block
void block(int &err, DynamicBuffer &blk_buff)
Definition: CellStore.cc:456
SWC::Core::Encoder::decode
void decode(int &err, Type encoder, const uint8_t *src, size_t sz_enc, uint8_t *dst, size_t sz)
Definition: Encoder.cc:99
SWC_CURRENT_EXCEPTION
#define SWC_CURRENT_EXCEPTION(_msg_)
Definition: Exception.h:119
SWC::Core::Buffer::base
value_type * base
Definition: Buffer.h:131
SWC
The SWC-DB C++ namespace 'SWC'.
Definition: main.cc:12
SWC::FS::OPEN_FLAG_OVERWRITE
@ OPEN_FLAG_OVERWRITE
Definition: FileSystem.h:35
SWC::Ranger::CellStore::Write::block_encode
void block_encode(int &err, DynamicBuffer &cells_buff, Block::Header &&header)
Definition: CellStore.cc:438
SWC::Ranger::CellStore::Read::load_blocks_index
static void load_blocks_index(int &err, FS::SmartFd::Ptr &smartfd, DB::Cell::Key &prev_key_end, DB::Cell::Key &key_end, DB::Cells::Interval &interval, Blocks &blocks, uint32_t &cell_revs, bool chk_base=false)
Definition: CellStore.cc:118
SWC::Ranger::CellStore::Read::make
static Ptr make(int &err, const csid_t csid, const RangePtr &range, bool chk_base=false)
Definition: CellStore.cc:13
SWC::Core::BufferDyn< StaticBuffer >
SWC::Ranger::CellStore::Read::cell_revs
const uint32_t cell_revs
Definition: CellStore.h:73
SWC::Core::Buffer
Definition: Buffer.h:18
size
uint32_t size
Buffer size.
Definition: HeaderBufferInfo.h:47
SWC::Core::Buffer::size
size_t size
Definition: Buffer.h:130
SWC::Env::FsInterface::fs
static SWC_CAN_INLINE FS::FileSystem::Ptr & fs() noexcept
Definition: Interface.h:155
SWC::Ranger::CellStore::Read::~Read
~Read() noexcept
Definition: CellStore.cc:274
SWC::Ranger::CellStore::Read
Definition: CellStore.h:41
SWC::Ranger::CellStore::Read::load_cells
void load_cells(BlockLoader *loader)
Definition: CellStore.cc:296
SWC::DB::Cell::Key::copy
void copy(const Key &other)
Definition: CellKey.h:314
SWC::Ranger::CellStore::Write::create
void create(int &err, uint8_t blk_replicas=0)
Definition: CellStore.cc:433
SWC::Ranger::CellStore::TRAILER_SIZE
static const uint8_t TRAILER_SIZE
Definition: CellStore.h:37
SWC::Ranger::CellStore::Read::blocks
const Blocks blocks
Definition: CellStore.h:72
SWC::Ranger::CellStore::Read::smartfd
FS::SmartFd::Ptr smartfd
Definition: CellStore.h:74
SWC::Ranger::CellStore::Read::processing
bool processing() const noexcept
Definition: CellStore.cc:359
SWC::Ranger::CellStore::Write::size
size_t size
Definition: CellStore.h:139
SWC::Ranger::BlockLoader
Definition: RangeBlockLoader.h:19
SWC::Comm::Protocol::FsBroker::Handler::length
void length(const ConnHandlerPtr &conn, const Event::Ptr &ev)
Definition: Length.h:17
SWC::Ranger::CellStore::Block::Read
Definition: CellStoreBlock.h:28
SWC::Ranger::BlockLoader::block
Block::Ptr block
Definition: RangeBlockLoader.h:22
SWC::Ranger::CellStore::Read::_run_queued
void _run_queued()
Definition: CellStore.cc:311
SWC::DB::Cell::Key::encoded_length
constexpr uint32_t encoded_length() const noexcept
Definition: CellKey.h:323
SWC::LOG_ERROR
@ LOG_ERROR
Definition: Logger.h:32
SWC::Core::Buffer::free
SWC_CAN_INLINE void free() noexcept
Definition: Buffer.h:85
SWC::Ranger::CellStore::Read::csid
const csid_t csid
Definition: CellStore.h:68
CellStore.h
SWC::Ranger::CellStore::Write::encoder
const DB::Types::Encoder encoder
Definition: CellStore.h:134
SWC::Ranger::CellStore::Read::size_bytes
size_t size_bytes(bool only_loaded=false) const
Definition: CellStore.cc:370
SWC::Ranger::CellStore::Read::m_queue
Core::QueueSafeStated< Block::Read::Ptr > m_queue
Definition: CellStore.h:122
SWC::Core::Vector::shrink_to_fit
SWC_CAN_INLINE void shrink_to_fit(size_type sz=0)
Definition: Vector.h:276
SWC::Core::Vector
Definition: Vector.h:14
SWC::DB::Cell::Key::free
SWC_CAN_INLINE void free() noexcept
Definition: CellKey.h:73
SWC::Ranger::CellStore::Block::Write
Definition: CellStoreBlock.h:109
SWC::DB::Types::Encoder
Core::Encoder::Type Encoder
Definition: Encoder.h:15
SWC::FS::SmartFd::Ptr
std::shared_ptr< SmartFd > Ptr
Definition: SmartFd.h:37
SWC::Ranger::CellStore::Write::write_blocks_index
void write_blocks_index(int &err, uint32_t &blks_idx_count)
Definition: CellStore.cc:469
SWC::Error::CHECKSUM_MISMATCH
@ CHECKSUM_MISMATCH
Definition: Error.h:62
SWC::Ranger::CellStore::Read::_release_fd
void _release_fd()
Definition: CellStore.cc:335
SWC::Core::Vector::cend
constexpr SWC_CAN_INLINE const_iterator cend() const noexcept
Definition: Vector.h:232
SWC::Ranger::CellStore::Block::Read::load
bool load(BlockLoader *loader)
Definition: CellStoreBlock.cc:105
SWC::Ranger::Block::is_consist
bool is_consist(const DB::Cells::Interval &intval) const
Definition: RangeBlock.cc:96
SWC::FS::FLUSH
@ FLUSH
Definition: FileSystem.h:43
SWC::Serialization::encode_vi32
constexpr SWC_CAN_INLINE void encode_vi32(uint8_t **bufp, uint32_t val)
Definition: Serialization.h:243
SWC::Core::Encoder::to_string
const char *SWC_CONST_FUNC to_string(Type typ) noexcept
Definition: Encoder.cc:31
SWC::Core::checksum_i32
SWC_CAN_INLINE void checksum_i32(const uint8_t *start, size_t len, uint8_t **ptr) noexcept
Definition: Checksum.h:62
SWC::Ranger::CellStore::Write::write_trailer
void write_trailer(int &err)
Definition: CellStore.cc:542
SWC::Core::Encoder::encode
void encode(int &err, Type encoder, const uint8_t *src, size_t src_sz, size_t *sz_enc, DynamicBuffer &output, uint32_t reserve, bool no_plain_out=false, bool ok_more=false)
Definition: Encoder.cc:222
SWC::Common::Files::Schema::filepath
std::string filepath(cid_t cid)
Definition: Schema.h:34
SWC::LOG_WARN
@ LOG_WARN
Definition: Logger.h:33
SWC::Ranger::CellStore::Write::close_and_validate
void close_and_validate(int &err)
Definition: CellStore.cc:568
SWC::Ranger::CellStore::Write::remove
void remove(int &err)
Definition: CellStore.cc:588
SWC::Ranger::CellStore::Read::blocks_count
size_t blocks_count() const
Definition: CellStore.cc:386
SWC::DB::Cells::Interval
Definition: Interval.h:17
SWC::Ranger::CellStore::Block::Header::ANY_END
static const uint8_t ANY_END
Definition: CellStoreBlockHeader.h:27
SWC::Core::Vector::push_back
SWC_CAN_INLINE void push_back(ArgsT &&... args)
Definition: Vector.h:331
SWC::Error::print
void print(std::ostream &out, int err)
Definition: Error.cc:191
SWC::Core::Vector::cbegin
constexpr SWC_CAN_INLINE const_iterator cbegin() const noexcept
Definition: Vector.h:216
SWC::Serialization::decode_i8
constexpr SWC_CAN_INLINE uint8_t decode_i8(const uint8_t **bufp, size_t *remainp)
Definition: Serialization.h:91
SWC::Serialization::decode_i64
SWC_CAN_INLINE uint64_t decode_i64(const uint8_t **bufp, size_t *remainp)
Definition: Serialization.h:156
SWC::Core::Vector::size
constexpr SWC_CAN_INLINE size_type size() const noexcept
Definition: Vector.h:189
SWC::Ranger::CellStore::Write::print
void print(std::ostream &out) const
Definition: CellStore.cc:593
SWC::Core::Vector::emplace_back
SWC_CAN_INLINE reference emplace_back(ArgsT &&... args)
Definition: Vector.h:349
SWC::Ranger::CellStore::Block::Write::Ptr
std::shared_ptr< Write > Ptr
Definition: CellStoreBlock.h:111
SWC::Error::Exception
Definition: Exception.h:21
SWC::Serialization::decode_i32
SWC_CAN_INLINE uint32_t decode_i32(const uint8_t **bufp, size_t *remainp)
Definition: Serialization.h:143
SWC::Core::Vector::insert
SWC_CAN_INLINE iterator insert(size_type offset, ArgsT &&... args)
Definition: Vector.h:367
SWC::Core::Vector::reserve
SWC_CAN_INLINE void reserve(size_type cap)
Definition: Vector.h:288
SWC::Ranger::CellStore::Write::prev_key_end
const DB::Cell::Key prev_key_end
Definition: CellStore.h:137
SWC::DB::Cell::Key::encode
void encode(uint8_t **bufp) const
Definition: CellKey.h:328
SWC::DB::Cells::Interval::key_begin
DB::Cell::Key key_begin
Definition: Interval.h:224
SWC::Ranger::CellStore::Read::print
void print(std::ostream &out, bool minimal=true) const
Definition: CellStore.cc:390
SWC::Ranger::CellStore::Read::filepath
const std::string & filepath() const
Definition: CellStore.cc:291
SWC::Serialization::decode_vi32
constexpr SWC_CAN_INLINE uint32_t decode_vi32(const uint8_t **bufp, size_t *remainp)
Definition: Serialization.h:254
SWC::Ranger::CellStore::Write
Definition: CellStore.h:128
SWC::Core::Buffer::set
void set(value_type *data, size_t len, bool take_ownership) noexcept
Definition: Buffer.h:109