SWC-DB  v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
RangeQuerySelectUpdating.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_ranger_callbacks_RangeQuerySelectUpdating_h
7 #define swcdb_ranger_callbacks_RangeQuerySelectUpdating_h
8 
9 
11 
12 
13 namespace SWC { namespace Ranger { namespace Callback {
14 
15 
17  public:
18 
19  typedef std::shared_ptr<RangeQuerySelectUpdating> Ptr;
20 
23  const Comm::Event::Ptr& ev,
24  DB::Specs::Interval&& req_spec,
25  const RangePtr& a_range)
27  conn, ev, std::move(req_spec), a_range) {
28  }
29 
30  virtual ~RangeQuerySelectUpdating() noexcept { }
31 
32  bool has_update() const noexcept override {
33  return true;
34  }
35 
36  void update(DB::Cells::Mutable& blk_cells) override {
37  if(cells.ptr == cells.mark)
38  return;
39 
40  const bool auto_ts(spec.updating->timestamp == DB::Cells::TIMESTAMP_AUTO);
41  const bool set_ts(spec.updating->timestamp != DB::Cells::TIMESTAMP_NULL);
42 
43  const uint8_t* ptr = cells.mark;
44  size_t remain = cells.fill() - (cells.mark - cells.base);
45 
46  size_t log_offset_it = 0;
47  size_t log_offset_hint = 0;
48  size_t blk_offset_hint = 0;
49 
50  auto& commitlog = range->blocks.commitlog;
51  {
52  Core::ScopedLock commitlog_lock(commitlog.cells_mutex());
53 
54  if(expired(remain/100000))
56 
57  for(DB::Cells::Cell updated_cell; remain; ) {
58  updated_cell.read(&ptr, &remain, false);
59 
60  update_cell_value(updated_cell);
61 
62  auto ts = Time::now_ns();
63  if(auto_ts) {
64  updated_cell.set_timestamp_with_rev_is_ts(ts);
65  } else {
66  if(set_ts)
67  updated_cell.set_timestamp(spec.updating->timestamp);
68  updated_cell.set_revision(ts);
69  }
70 
71  commitlog._add(updated_cell, &log_offset_it, &log_offset_hint);
72  blk_cells.add_raw(updated_cell, &blk_offset_hint, true);
73  }
74  }
75  commitlog.commit();
76 
77  cells.set_mark();
78  }
79 
80  virtual void update_cell_value(DB::Cells::Cell& cell) {
81  if(spec.updating->encoder == DB::Types::Encoder::DEFAULT ||
82  DB::Types::is_counter(range->cfg->col_type)) {
83  cell.value = spec.updating->value;
84  cell.vlen = spec.updating->vlen;
86  } else {
87  cell.set_value(
88  spec.updating->encoder,
89  spec.updating->value,
90  spec.updating->vlen
91  );
92  }
93  }
94 
95 };
96 
97 
98 }}}
99 #endif // swcdb_ranger_callbacks_RangeQuerySelectUpdating_h
SWC::Core::BufferDyn::ptr
value_type * ptr
Definition: Buffer.h:293
SWC::DB::Cells::Mutable::add_raw
SWC_CAN_INLINE void add_raw(const DynamicBuffer &cells, bool finalized)
Definition: Mutable.h:436
SWC::DB::Cells::Cell::set_value
SWC_CAN_INLINE void set_value(uint8_t *v, uint32_t len, bool owner)
Definition: Cell.h:223
SWC::Error::REQUEST_TIMEOUT
@ REQUEST_TIMEOUT
Definition: Error.h:73
SWC::Ranger::Callback::RangeQuerySelect::cells
DynamicBuffer cells
Definition: RangeQuerySelect.h:139
SWC::Time::now_ns
SWC_CAN_INLINE int64_t now_ns() noexcept
Definition: Time.h:43
SWC::Core::ScopedLock
Definition: MutexLock.h:41
SWC::Core::BufferDyn::mark
value_type * mark
Definition: Buffer.h:294
SWC::Ranger::Callback::RangeQuerySelectUpdating::RangeQuerySelectUpdating
SWC_CAN_INLINE RangeQuerySelectUpdating(const Comm::ConnHandlerPtr &conn, const Comm::Event::Ptr &ev, DB::Specs::Interval &&req_spec, const RangePtr &a_range)
Definition: RangeQuerySelectUpdating.h:22
SWC::DB::Cells::TIMESTAMP_AUTO
constexpr const int64_t TIMESTAMP_AUTO
Definition: Cell.h:73
SWC::DB::Cells::Cell
Definition: Cell.h:92
SWC::Ranger::Callback::RangeQuerySelectUpdating::update_cell_value
virtual void update_cell_value(DB::Cells::Cell &cell)
Definition: RangeQuerySelectUpdating.h:80
SWC::Core::Encoder::Type::DEFAULT
@ DEFAULT
RangeQuerySelect.h
SWC::DB::Cells::MASK_HAVE_ENCODER
constexpr const uint8_t MASK_HAVE_ENCODER
Definition: Cell.h:86
SWC::Ranger::RangePtr
std::shared_ptr< Range > RangePtr
Definition: Columns.h:15
SWC_CAN_INLINE
#define SWC_CAN_INLINE
Definition: Compat.h:102
SWC::Core::Buffer::base
value_type * base
Definition: Buffer.h:131
SWC
The SWC-DB C++ namespace 'SWC'.
Definition: main.cc:12
SWC::Core::BufferDyn::set_mark
constexpr SWC_CAN_INLINE void set_mark() noexcept
Definition: Buffer.h:202
SWC::DB::Types::is_counter
bool SWC_CONST_FUNC is_counter(const Column typ) noexcept
Definition: Column.cc:26
SWC::Ranger::Callback::RangeQuerySelectUpdating::update
void update(DB::Cells::Mutable &blk_cells) override
Definition: RangeQuerySelectUpdating.h:36
SWC::Ranger::Callback::RangeQuerySelectUpdating::~RangeQuerySelectUpdating
virtual ~RangeQuerySelectUpdating() noexcept
Definition: RangeQuerySelectUpdating.h:30
SWC::Ranger::Callback::RangeQuerySelect
Definition: RangeQuerySelect.h:14
SWC::DB::Cells::Cell::value
uint8_t * value
Definition: Cell.h:362
SWC::DB::Cells::Cell::control
uint8_t control
Definition: Cell.h:360
SWC::DB::Cells::TIMESTAMP_NULL
constexpr const int64_t TIMESTAMP_NULL
Definition: Cell.h:72
SWC::Comm::ConnHandlerPtr
std::shared_ptr< ConnHandler > ConnHandlerPtr
Definition: AppContext.h:17
SWC::DB::Cells::Cell::vlen
uint32_t vlen
Definition: Cell.h:361
SWC::DB::Cells::ReqScan::spec
DB::Specs::Interval spec
Definition: ReqScan.h:106
SWC::Core::BufferDyn::fill
constexpr SWC_CAN_INLINE size_t fill() const noexcept
Definition: Buffer.h:192
SWC::DB::Specs::Interval::updating
IntervalUpdate::Ptr updating
Definition: SpecsInterval.h:249
SWC::DB::Specs::Interval
Definition: SpecsInterval.h:25
SWC::Comm::ResponseCallback::expired
virtual bool expired(int64_t within=0) const noexcept
Definition: ResponseCallback.cc:13
SWC::Ranger::Callback::RangeQuerySelectUpdating::Ptr
std::shared_ptr< RangeQuerySelectUpdating > Ptr
Definition: RangeQuerySelectUpdating.h:19
SWC::Comm::Event::Ptr
std::shared_ptr< Event > Ptr
Definition: Event.h:33
SWC::Ranger::Callback::RangeQuerySelectUpdating
Definition: RangeQuerySelectUpdating.h:16
SWC::Ranger::Callback::RangeQuerySelect::range
RangePtr range
Definition: RangeQuerySelect.h:138
SWC::Error::Exception
Definition: Exception.h:21
SWC::DB::Cells::Mutable
Definition: Mutable.h:21
SWC::Ranger::Callback::RangeQuerySelectUpdating::has_update
bool has_update() const noexcept override
Definition: RangeQuerySelectUpdating.h:32