 |
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.
9 namespace SWC {
namespace Ranger {
namespace CommitLog {
69 uint32_t& cell_revs, uint32_t& cells_count,
70 uint32_t& data_checksum, uint32_t& offset_data) {
81 fs_if->close(err, smartfd);
85 if(!smartfd->valid() && !fs_if->open(err, smartfd) && err)
106 if(fs->pread(err, smartfd,
HEADER_SIZE, &buf, header_extlen)
111 remain = header_extlen;
122 buf.
base, header_extlen-4)) {
131 fs_if->close(tmperr, smartfd);
138 const uint32_t cell_revs,
139 const uint32_t cells_count,
170 frag->m_buffer.set(cells);
180 const uint32_t cell_revs,
const uint32_t cells_count,
181 uint32_t& data_checksum, uint32_t& offset_data,
196 encoder = DB::Types::Encoder::PLAIN;
199 uint8_t * bufp = output.
base;
204 uint8_t * header_extptr = bufp;
222 const uint8_t a_version,
225 const size_t a_size_plain,
const size_t a_size_enc,
226 const uint32_t a_cell_revs,
const uint32_t a_cells_count,
227 const uint32_t a_data_checksum,
228 const uint32_t a_offset_data,
230 :
version(a_version), interval(std::move(a_interval)),
232 size_plain(a_size_plain), size_enc(a_size_enc),
233 cell_revs(a_cell_revs), cells_count(a_cells_count),
234 data_checksum(a_data_checksum),
235 offset_data(a_offset_data),
237 m_state(state), m_marked_removed(
false), m_err(
Error::OK),
238 m_processing(m_state == State::WRITING),
239 m_cells_remain(cells_count),
240 m_smartfd(smartfd), m_buffer(), m_queue() {
253 return shared_from_this();
272 [frag=
ptr(), blk_replicas, sem]
279 uint8_t blk_replicas;
281 Task(
Ptr&& a_frag, uint8_t a_blk_replicas,
284 : frag(std::move(a_frag)),
285 buff_w(std::move(a_buff_w)), sem(a_sem),
287 blk_replicas(a_blk_replicas) {
290 Task(Task&& other) noexcept
291 : frag(std::move(other.frag)),
292 buff_w(std::move(other.buff_w)),
293 sem(other.sem), error(other.error),
294 blk_replicas(other.blk_replicas) {
296 Task(
const Task&) =
delete;
301 frag->
write(error, blk_replicas, std::move(buff_w), sem);
306 std::move(frag), blk_replicas, std::move(buff_w), sem, _err
310 m_smartfd, blk_replicas, std::move(buff_write)
337 Task(
Ptr&& a_frag) noexcept : frag(std::move(a_frag)) { }
339 Task(Task&& other) noexcept : frag(std::move(other.frag)) { }
340 Task(
const Task&) =
delete;
359 :
frag(std::move(a_frag)),
err(a_err),
360 buffer(std::move(a_buffer)) { }
363 :
frag(std::move(other.frag)),
err(other.err),
364 buffer(std::move(other.buffer)) {
378 if(at != State::LOADED)
388 Task(
Ptr&& a_frag) noexcept : frag(std::move(a_frag)) { }
390 Task(Task&& other) noexcept : frag(std::move(other.frag)) { }
391 Task(
const Task&) =
delete;
402 frag->m_smartfd, frag->offset_data, frag->size_enc
419 ssize_t remain_hint(0);
442 SWC_SHOULD_NOT_INLINE
447 bool synced = cells.
empty();
448 size_t offset_hint = 0;
449 size_t offset_it = 0;
453 cell.read(&buf, &remain,
false);
456 : cells.
add_raw(cell, &offset_it, &offset_hint,
false);
461 <<
"Cell trunclated at count=" << count <<
'/' <<
cells_count
462 <<
" remain=" << remain <<
' ';
486 cell.read(&buf, &remain,
false);
488 ? log_right->
add(cell)
489 : log_left->
add(cell);
494 <<
"Cell trunclated at count=" << count <<
'/' <<
cells_count
495 <<
" remain=" << remain <<
' ';
527 State at = State::LOADED;
547 return !(err = m_err) && m_state == State::LOADED;
573 busy =
m_state == State::WRITING ||
612 [sem, frag=
ptr()](
int err) {
619 [sem, frag=
ptr()](
int) noexcept { sem->
release(); },
626 out <<
"Fragment(version=" << int(
version)
635 out <<
" queue=" <<
m_queue.size();
641 out <<
" MARKED-REMOVED";
682 if(
encoder != DB::Types::Encoder::PLAIN) {
716 bool _marked_removed;
719 if(!(_marked_removed =
m_state == State::LOADED))
723 if(err && !_marked_removed)
const uint32_t offset_data
size_t SWC_PURE_FUNC encoded_length() const noexcept
void load_finish(int err)
std::shared_ptr< Fragment > Ptr
constexpr SWC_CAN_INLINE bool compare_exchange_weak(T &at, T value) noexcept
static SWC_CAN_INLINE System::Resources & res() noexcept
SWC_CAN_INLINE TaskLoadRead(Ptr &&a_frag, int a_err, StaticBuffer &&a_buffer) noexcept
size_t load_cells(const uint8_t *buf, size_t remain, uint32_t revs, size_t avail, bool &was_splitted, bool synced=false)
void load_read(int err, StaticBuffer &&buffer)
TaskLoadRead & operator=(TaskLoadRead &&)=delete
#define SWC_LOG_OUT(pr, _code_)
const uint32_t cells_count
static Ptr make_read(int &err, std::string &&filepath, const DB::Types::KeySeq key_seq)
static const char *SWC_CONST_FUNC to_string(State state) noexcept
SWC_CAN_INLINE void encode_i32(uint8_t **bufp, uint32_t val) noexcept
static SWC_CAN_INLINE FS::Interface::Ptr & interface() noexcept
SWC_CAN_INLINE void more_mem_future(size_t sz) noexcept
static SWC_CAN_INLINE Ptr make_ptr(const std::string &filepath, uint32_t flags, int32_t fd=-1, uint64_t pos=0)
void encode(uint8_t **ptr) const
const Types::KeySeq key_seq
SWC_CAN_INLINE bool checksum_i32_chk(uint32_t checksum, const uint8_t *base, uint32_t len)
void decode(const uint8_t **ptr, size_t *remain, bool owner)
const DB::Types::Encoder encoder
SWC_CAN_INLINE TaskLoadRead(TaskLoadRead &&other) noexcept
SWC_CAN_INLINE void unlock(const bool &support) noexcept
bool processing() noexcept
const DB::Cells::Interval interval
Core::Atomic< uint32_t > m_cells_remain
constexpr SWC_CAN_INLINE void encode_i8(uint8_t **bufp, uint8_t val) noexcept
void split(int &err, const DB::Cell::Key &key, FragmentsPtr log_left, FragmentsPtr log_right)
bool loaded(int &err) noexcept
constexpr SWC_CAN_INLINE T sub_rslt(T v) noexcept
SWC_CAN_INLINE bool empty() const noexcept
constexpr SWC_CAN_INLINE void store(T v) noexcept
bool mark_removed() noexcept
SWC_CAN_INLINE void more_mem_releasable(size_t sz) noexcept
SWC_CAN_INLINE void less_mem_releasable(size_t sz) noexcept
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 print(std::ostream &out)
virtual void loaded(Ptr &&frag)=0
SWC_CAN_INLINE size_t need_ram() const noexcept
static SWC_CAN_INLINE FS::FileSystem::Ptr & fs() noexcept
void add_raw(const Cell &cell, bool finalized)
size_t size_bytes() const noexcept
FS::SmartFd::Ptr m_smartfd
SWC_CAN_INLINE void less_mem_future(size_t sz) noexcept
bool marked_removed() const noexcept
SWC_CAN_INLINE void free() noexcept
std::queue< LoadCallback * > m_queue
constexpr SWC_CAN_INLINE T exchange(T value) noexcept
static void write(int &err, const uint8_t version, const DB::Cells::Interval &interval, DB::Types::Encoder &encoder, const size_t size_plain, size_t &size_enc, const uint32_t cell_revs, const uint32_t cells_count, uint32_t &data_checksum, uint32_t &offset_data, DynamicBuffer &cells, StaticBuffer &buffer)
Core::Encoder::Type Encoder
Core::Atomic< bool > m_marked_removed
constexpr SWC_CAN_INLINE size_t fill() const noexcept
std::shared_ptr< SmartFd > Ptr
void load(LoadCallback *cb)
constexpr SWC_CAN_INLINE T load() const noexcept
void add(const DB::Cells::Cell &cell)
void processing_decrement() noexcept
static const uint8_t VERSION
void processing_increment() noexcept
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
const uint32_t data_checksum
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)
void load_cells(int &err, Ranger::Block::Ptr cells_block)
static const uint8_t HEADER_EXT_FIXED_SIZE
std::string filepath(cid_t cid)
const std::string & get_filepath() const noexcept
TaskLoadRead(const TaskLoadRead &)=delete
Core::Atomic< size_t > m_processing
void add_sorted(const Cell &cell)
static SWC_CAN_INLINE void post(T_Handler &&handler)
size_t size_bytes_encoded() const noexcept
constexpr SWC_CAN_INLINE T fetch_sub(T v) noexcept
void print(std::ostream &out, int err)
Core::Atomic< State > m_state
constexpr SWC_CAN_INLINE T fetch_add(T v) noexcept
constexpr SWC_CAN_INLINE uint8_t decode_i8(const uint8_t **bufp, size_t *remainp)
static const uint8_t HEADER_SIZE
TaskLoadRead & operator=(const TaskLoadRead &)=delete
static Ptr make_write(int &err, std::string &&filepath, DB::Cells::Interval &&interval, DB::Types::Encoder encoder, const uint32_t cell_revs, const uint32_t cells_count, DynamicBuffer &cells, StaticBuffer &buffer)
Fragment & operator=(const Fragment &)=delete
bool try_full_lock(bool &support) noexcept
Fragment(const FS::SmartFd::Ptr &smartfd, const uint8_t version, DB::Cells::Interval &&interval, const DB::Types::Encoder encoder, const size_t size_plain, const size_t size_enc, const uint32_t cell_revs, const uint32_t cells_count, const uint32_t data_checksum, const uint32_t offset_data, Fragment::State state) noexcept
static void load_header(int &err, FS::SmartFd::Ptr &smartfd, uint8_t &version, DB::Cells::Interval &interval, DB::Types::Encoder &encoder, size_t &size_plain, size_t &size_enc, uint32_t &cell_revs, uint32_t &cells_count, uint32_t &data_checksum, uint32_t &offset_data)
SWC_CAN_INLINE uint32_t decode_i32(const uint8_t **bufp, size_t *remainp)
Condition::Comp compare(const Types::KeySeq seq, const Cell::Key &key, const Cell::Key &other) SWC_ATTRIBS((SWC_ATTRIB_O3))
void set(value_type *data, size_t len, bool take_ownership) noexcept