 |
SWC-DB
v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
|
Go to the documentation of this file.
10 namespace SWC {
namespace Ranger {
namespace CellStore {
35 <<
" range(" << range->cfg->cid <<
'/' << range->rid <<
") ";
53 uint32_t& blks_idx_count,
54 uint64_t& blks_idx_offset,
55 bool close_after,
bool chk_base) {
71 if(!fs_if->exists(err,
smartfd->filepath())) {
87 const uint8_t *ptr = buf;
117 SWC_SHOULD_NOT_INLINE
125 uint32_t blks_idx_count = 0;
126 uint64_t offset_fixed = 0;
133 bool trailer =
false;
140 size_t idx_size_plain;
142 uint32_t idx_checksum_data;
163 offset = offset_fixed;
174 for(uint32_t i=0; i < blks_idx_count; ++i) {
176 if(fs->pread(err,
smartfd, offset, &read_buf,
197 if(fs->pread(err,
smartfd, offset, &read_buf,
198 idx_size_enc) != idx_size_enc) {
203 read_buf.
base, idx_size_enc)) {
208 offset += idx_size_enc;
210 if(idx_encoder != DB::Types::Encoder::PLAIN) {
213 decoded_buf.
base, idx_size_plain);
216 read_buf.
set(decoded_buf);
220 remain = idx_size_plain;
226 for(uint32_t blk_i = 0; blk_i < blks_count; ) {
229 if(++blk_i == blks_count && i + 1 == blks_idx_count)
241 if(!trailer || err) {
260 const uint32_t a_cell_revs,
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),
270 for(
auto blk : blocks)
300 if(blk->load(loader)) {
304 }
else if(!blk->header.interval.key_end.empty() &&
325 released += blk->release();
326 if(released >= bytes)
346 int32_t fd =
smartfd->invalidate();
364 if(blk->processing())
373 size += blk->size_bytes(only_loaded);
381 size += blk->size_bytes_enc(only_loaded);
391 out <<
"Read(v=" << int(
VERSION)
396 <<
" file=" <<
smartfd->filepath()
406 out <<
" queue=" <<
m_queue.size()
419 const RangePtr& range, uint32_t a_cell_revs,
423 FS::SmartFd::make_ptr(
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),
453 block(err, blk_buff);
474 uint32_t blks_count = 0;
475 uint32_t len_data = 0;
483 if(!blks_idx_count && !blks_count)
486 len_data += blk->header.encoded_length_idx();
492 uint8_t* ptr = raw_buffer.
base;
499 for(; it_last != it; ++it_last)
500 (*it_last)->header.encode_idx(&ptr);
513 _encoder = DB::Types::Encoder::PLAIN;
517 uint8_t* header_ptr = buffer_write.
base;
536 blks_count = len_data = 0;
543 uint64_t blks_idx_offset =
size;
544 uint32_t blks_idx_count = 0;
550 uint8_t* ptr = buff_write.
base;
612 1, range->get_path_cs(1), range, range->cfg->cell_versions(),
615 writer.
create(err, range->cfg->file_replication());
620 range->_get_interval(header.
interval);
628 writer.
block_encode(err, cells_buff, std::move(header));
Write(const csid_t csid, std::string &&filepath, const RangePtr &range, uint32_t cell_revs, const DB::Cell::Key &prev_key_end)
Core::Vector< Block::Write::Ptr > blocks
constexpr SWC_CAN_INLINE int code() const noexcept
const uint32_t block_size
static void encode(int &err, DynamicBuffer &cells, DynamicBuffer &output, Header &header)
size_t size_bytes_enc(bool only_loaded=false) const
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
SWC_CAN_INLINE void encode_i64(uint8_t **bufp, uint64_t val) noexcept
void get_blocks(int &err, Blocks &to) const
SWC_CAN_INLINE void clear() noexcept(_NoExceptDestructor)
#define SWC_LOG_OUT(pr, _code_)
SWC_CAN_INLINE bool align(const Interval &other)
constexpr SWC_CAN_INLINE uint8_t encoded_length_vi32(uint32_t val) noexcept
SWC_CAN_INLINE void encode_i32(uint8_t **bufp, uint32_t val) noexcept
static SWC_CAN_INLINE FS::Interface::Ptr & interface() noexcept
void print(std::ostream &out) const
static SWC_CAN_INLINE Ptr make_ptr(const std::string &filepath, uint32_t flags, int32_t fd=-1, uint64_t pos=0)
const Types::KeySeq key_seq
SWC_CAN_INLINE bool checksum_i32_chk(uint32_t checksum, const uint8_t *base, uint32_t len)
const DB::Cells::Interval interval
void add(const ReqScan::Ptr &req)
void expand(const Interval &other)
bool is_in_end(const DB::Cell::Key &key) const
const DB::Cell::Key key_end
constexpr SWC_CAN_INLINE void encode_i8(uint8_t **bufp, uint8_t val) noexcept
static const uint8_t IDX_BLKS_HEADER_SIZE
size_t release(size_t bytes)
void decode(const uint8_t **bufp, size_t *remainp, bool owner)
static Read::Ptr create_initial(int &err, const RangePtr &range)
void block_write(int &err, DynamicBuffer &blk_buff, Block::Header &&header)
const DB::Cell::Key prev_key_end
static const int8_t VERSION
constexpr SWC_CAN_INLINE bool empty() const noexcept
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)
constexpr SWC_CAN_INLINE bool empty() const noexcept
std::shared_ptr< Range > RangePtr
void block(int &err, DynamicBuffer &blk_buff)
void decode(int &err, Type encoder, const uint8_t *src, size_t sz_enc, uint8_t *dst, size_t sz)
#define SWC_CURRENT_EXCEPTION(_msg_)
The SWC-DB C++ namespace 'SWC'.
void block_encode(int &err, DynamicBuffer &cells_buff, Block::Header &&header)
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)
static Ptr make(int &err, const csid_t csid, const RangePtr &range, bool chk_base=false)
static SWC_CAN_INLINE FS::FileSystem::Ptr & fs() noexcept
void load_cells(BlockLoader *loader)
void copy(const Key &other)
void create(int &err, uint8_t blk_replicas=0)
static const uint8_t TRAILER_SIZE
bool processing() const noexcept
void length(const ConnHandlerPtr &conn, const Event::Ptr &ev)
constexpr uint32_t encoded_length() const noexcept
SWC_CAN_INLINE void free() noexcept
const DB::Types::Encoder encoder
size_t size_bytes(bool only_loaded=false) const
Core::QueueSafeStated< Block::Read::Ptr > m_queue
SWC_CAN_INLINE void shrink_to_fit(size_type sz=0)
SWC_CAN_INLINE void free() noexcept
Core::Encoder::Type Encoder
std::shared_ptr< SmartFd > Ptr
void write_blocks_index(int &err, uint32_t &blks_idx_count)
constexpr SWC_CAN_INLINE const_iterator cend() const noexcept
bool load(BlockLoader *loader)
bool is_consist(const DB::Cells::Interval &intval) const
constexpr SWC_CAN_INLINE void encode_vi32(uint8_t **bufp, uint32_t val)
const char *SWC_CONST_FUNC to_string(Type typ) noexcept
SWC_CAN_INLINE void checksum_i32(const uint8_t *start, size_t len, uint8_t **ptr) noexcept
void write_trailer(int &err)
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)
std::string filepath(cid_t cid)
void close_and_validate(int &err)
size_t blocks_count() const
SWC_CAN_INLINE void push_back(ArgsT &&... args)
void print(std::ostream &out, int err)
constexpr SWC_CAN_INLINE const_iterator cbegin() const noexcept
constexpr SWC_CAN_INLINE uint8_t decode_i8(const uint8_t **bufp, size_t *remainp)
SWC_CAN_INLINE uint64_t decode_i64(const uint8_t **bufp, size_t *remainp)
constexpr SWC_CAN_INLINE size_type size() const noexcept
void print(std::ostream &out) const
SWC_CAN_INLINE reference emplace_back(ArgsT &&... args)
std::shared_ptr< Write > Ptr
SWC_CAN_INLINE uint32_t decode_i32(const uint8_t **bufp, size_t *remainp)
SWC_CAN_INLINE iterator insert(size_type offset, ArgsT &&... args)
SWC_CAN_INLINE void reserve(size_type cap)
const DB::Cell::Key prev_key_end
void encode(uint8_t **bufp) const
void print(std::ostream &out, bool minimal=true) const
const std::string & filepath() const
constexpr SWC_CAN_INLINE uint32_t decode_vi32(const uint8_t **bufp, size_t *remainp)
void set(value_type *data, size_t len, bool take_ownership) noexcept