diff --git a/db/compaction_dispatcher.cc b/db/compaction_dispatcher.cc index 3f642b5dd0387bbf7e328c4993b2f7e01a20810c..1ebc064bf8ec4cc49780d90b8a7c009e57d3c58c 100644 --- a/db/compaction_dispatcher.cc +++ b/db/compaction_dispatcher.cc @@ -140,7 +140,7 @@ using TMap = std::unordered_map; template using STMap = std::unordered_map>; -class WorkerSeparateHelper : public SeparateHelper, public LazyBufferController { +class WorkerSeparateHelper : public SeparateHelper, public LazyBufferState { public: void destroy(LazyBuffer* /*buffer*/) const override {} @@ -148,7 +148,7 @@ class WorkerSeparateHelper : public SeparateHelper, public LazyBufferController Status fetch_buffer(LazyBuffer* buffer) const override { return inplace_decode_callback_(inplace_decode_arg_, buffer, - get_rep(buffer)); + get_context(buffer)); } void TransToCombined(const Slice& user_key, uint64_t sequence, @@ -156,7 +156,7 @@ class WorkerSeparateHelper : public SeparateHelper, public LazyBufferController auto s = value.fetch(); if (s.ok()) { uint64_t file_number = - SeparateHelper::DecodeFileNumber(value.get_slice()); + SeparateHelper::DecodeFileNumber(value.slice()); value.reset(this, {reinterpret_cast(user_key.data()), user_key.size(), sequence, 0}, Slice::Invalid(), file_number); @@ -165,10 +165,10 @@ class WorkerSeparateHelper : public SeparateHelper, public LazyBufferController } } - WorkerSeparateHelper(DependenceMap* dependence_map, void* inplace_decode_arg, - Status (*inplace_decode_callback)(void* arg, - LazyBuffer* buffer, - LazyBufferRep* rep)) + WorkerSeparateHelper( + DependenceMap* dependence_map, void* inplace_decode_arg, + Status (*inplace_decode_callback)(void* arg, LazyBuffer* buffer, + LazyBufferContext* rep)) : dependence_map_(dependence_map), inplace_decode_arg_(inplace_decode_arg), inplace_decode_callback_(inplace_decode_callback) {} @@ -176,7 +176,7 @@ class WorkerSeparateHelper : public SeparateHelper, public LazyBufferController DependenceMap* dependence_map_; void* inplace_decode_arg_; Status (*inplace_decode_callback_)(void* arg, LazyBuffer* buffer, - LazyBufferRep* rep); + LazyBufferContext* rep); }; std::function @@ -526,7 +526,7 @@ std::string RemoteCompactionDispatcher::Worker::DoCompaction( c_style_new_iterator.arg = &new_iterator; c_style_new_iterator.callback = c_style_callback(new_iterator); - auto separate_inplace_decode = [&](LazyBuffer* buffer, LazyBufferRep* rep) { + auto separate_inplace_decode = [&](LazyBuffer* buffer, LazyBufferContext* rep) { Slice user_key(reinterpret_cast(rep->data[0]), rep->data[1]); uint64_t sequence = rep->data[2]; uint64_t file_number = buffer->file_number(); diff --git a/db/compaction_job.cc b/db/compaction_job.cc index 7c72ca24f2a76ada7172d6301a7000d1c43e6711..53c879bd3438b63120143bbbd031da368d4a0002 100644 --- a/db/compaction_job.cc +++ b/db/compaction_job.cc @@ -1350,7 +1350,7 @@ void CompactionJob::ProcessKeyValueCompaction(SubcompactionState* sub_compact) { if (!status.ok()) { break; } - for (const auto& data_elmt : {key, value.get_slice()}) { + for (const auto& data_elmt : {key, value.slice()}) { size_t data_end_offset = data_begin_offset + data_elmt.size(); while (sample_begin_offset_iter != sample_begin_offsets.cend() && *sample_begin_offset_iter < data_end_offset) { @@ -1646,7 +1646,7 @@ void CompactionJob::ProcessGarbageCollection(SubcompactionState* sub_compact) { break; } uint64_t file_number = - SeparateHelper::DecodeFileNumber(value.get_slice()); + SeparateHelper::DecodeFileNumber(value.slice()); auto find = dependence_map.find(file_number); if (find == dependence_map.end()) { status = Status::Corruption("Separate value dependence missing"); diff --git a/db/compaction_picker.cc b/db/compaction_picker.cc index a8561bc8dc7cde0df3c1284e795a73651748447b..06dc495dd3c399bf5532ce3c1fd6758e36eda46f 100644 --- a/db/compaction_picker.cc +++ b/db/compaction_picker.cc @@ -749,7 +749,7 @@ void CompactionPicker::InitFilesBeingCompact( iter->Valid(); iter->Next()) { LazyBuffer value = iter->value(); if (!value.fetch().ok() || - !element.Decode(iter->key(), value.get_slice())) { + !element.Decode(iter->key(), value.slice())) { // TODO: log error ? break; } diff --git a/db/compaction_picker_universal.cc b/db/compaction_picker_universal.cc index 01ed456032b084fb5e85ca0ae3886940930f30c4..46cd2a427787d991d9626b398ef1ccce7edfb03d 100644 --- a/db/compaction_picker_universal.cc +++ b/db/compaction_picker_universal.cc @@ -128,7 +128,7 @@ bool ReadMapElement(MapSstElement& map_element, InternalIterator* iter, cf_name.c_str(), s.ToString().c_str()); return false; } - if (!map_element.Decode(iter->key(), value.get_slice())) { + if (!map_element.Decode(iter->key(), value.slice())) { ROCKS_LOG_BUFFER( log_buffer, "[%s] UniversalCompactionPicker MapSstElement Decode fail\n", diff --git a/db/db_iter.cc b/db/db_iter.cc index 145aa5d0a931e3e4363910b51f359038e19fd4fd..465148db8bb9fea74b5840fdb8165acf464d39bc 100644 --- a/db/db_iter.cc +++ b/db/db_iter.cc @@ -183,7 +183,7 @@ class DBIter final: public Iterator { status_ = s; return Slice::Invalid(); } - return value_.get_slice(); + return value_.slice(); } virtual Status status() const override { if (status_.ok()) { diff --git a/db/db_test_util.h b/db/db_test_util.h index 4e645ca30e431020e0d2b0697090e6219812913b..cc6563729201fd8d1f9bb10a31b8e9485122f105 100644 --- a/db/db_test_util.h +++ b/db/db_test_util.h @@ -626,7 +626,7 @@ class TestPutOperator : public MergeOperator { if (!Fetch(*merge_in.existing_value, &merge_out->new_value)) { return true; } - if (merge_in.existing_value->get_slice() == "corrupted") { + if (merge_in.existing_value->slice() == "corrupted") { return false; } } @@ -634,7 +634,7 @@ class TestPutOperator : public MergeOperator { if (!Fetch(value, &merge_out->new_value)) { return true; } - if (value.get_slice() == "corrupted") { + if (value.slice() == "corrupted") { return false; } } diff --git a/db/map_builder.cc b/db/map_builder.cc index ac48deb2daada4a325c893d91e5ee103ce2919a9..7914f811507e4a69c4244353702436297e5f8564 100644 --- a/db/map_builder.cc +++ b/db/map_builder.cc @@ -356,7 +356,7 @@ Status LoadRangeWithDepend(std::vector& ranges, if (!s.ok()) { return s; } - if (!map_element.Decode(iter->key(), value.get_slice())) { + if (!map_element.Decode(iter->key(), value.slice())) { return Status::Corruption("Map sst invalid key or value"); } ranges.emplace_back(map_element); diff --git a/db/memtable.cc b/db/memtable.cc index 4318ab6aa690a14e9fb3b8b814817dc4afe54796..e32e8df61cf81bfdebda33cb242142658b896640 100644 --- a/db/memtable.cc +++ b/db/memtable.cc @@ -393,12 +393,12 @@ class MemTableTombstoneIterator : public MemTableIteratorBase { assert(valid_); LazyBuffer v = iter_->value(); assert(v.fetch().ok()); - return v.fetch().ok() ? v.get_slice() : Slice::Invalid(); + return v.fetch().ok() ? v.slice() : Slice::Invalid(); } }; class MemTableIterator - : public MemTableIteratorBase, public LazyBufferController { + : public MemTableIteratorBase, public LazyBufferState { using Base = MemTableIteratorBase; using Base::iter_; using Base::valid_; @@ -411,7 +411,7 @@ class MemTableIterator void pin_buffer(LazyBuffer* buffer) const override { if (!value_pinned_ || !iter_->IsValuePinned()) { - LazyBufferController::pin_buffer(buffer); + LazyBufferState::pin_buffer(buffer); } else { *buffer = iter_->value(); buffer->pin(); diff --git a/db/memtablerep.cc b/db/memtablerep.cc index 3d3635555ff020e869f075e9723d5407a8ded354..9336e3f49f8a6ceaa6bcfc2435b820f1b8ec6feb 100644 --- a/db/memtablerep.cc +++ b/db/memtablerep.cc @@ -39,15 +39,15 @@ void MemTableRep::EncodeKeyValue(const Slice& key, const Slice& value, LazyBuffer MemTableRep::DecodeToLazyValue(const char* key) { - struct SliceControllerImpl : public LazyBufferController { + struct SliceControllerImpl : public LazyBufferState { void destroy(LazyBuffer* /*buffer*/) const override {} void pin_buffer(LazyBuffer* /*buffer*/) const override {} Status fetch_buffer(LazyBuffer* buffer) const override { - auto rep = get_rep(buffer); - const char* k = reinterpret_cast(rep->data[0]); + auto context = get_context(buffer); + const char* k = reinterpret_cast(context->data[0]); Slice key_slice = GetLengthPrefixedSlice(k); set_slice(buffer, GetLengthPrefixedSlice(key_slice.data() + key_slice.size())); diff --git a/db/merge_operator.cc b/db/merge_operator.cc index 234205e050439caf724d21fd59fd7ba650c6dde1..2c92a2ed9b3ac6741a3ab2469ee69150f73b179f 100644 --- a/db/merge_operator.cc +++ b/db/merge_operator.cc @@ -28,7 +28,7 @@ bool MergeOperator::FullMergeV2(const MergeOperationInput& merge_in, if (!Fetch(*merge_in.existing_value, &merge_out->new_value)) { return true; } - existing_value = &merge_in.existing_value->get_slice(); + existing_value = &merge_in.existing_value->slice(); } return FullMerge(merge_in.key, existing_value, operand_list_str, merge_out->new_value.trans_to_string(), merge_in.logger); @@ -75,8 +75,8 @@ bool AssociativeMergeOperator::FullMergeV2( } temp_value.clear(); const Slice* existing_value_slice = - existing_value == nullptr ? nullptr : &existing_value->get_slice(); - if (!Merge(merge_in.key, existing_value_slice, operand.get_slice(), + existing_value == nullptr ? nullptr : &existing_value->slice(); + if (!Merge(merge_in.key, existing_value_slice, operand.slice(), temp_value.trans_to_string(), merge_in.logger)) { return false; } @@ -98,7 +98,7 @@ bool AssociativeMergeOperator::PartialMerge(const Slice& key, if (!Fetch(left_operand, new_value) || !Fetch(right_operand, new_value)) { return true; } - return Merge(key, &left_operand.get_slice(), right_operand.get_slice(), + return Merge(key, &left_operand.slice(), right_operand.slice(), new_value->trans_to_string(), logger); } diff --git a/db/table_cache.cc b/db/table_cache.cc index 963e739b56f94553d20ca7f2eab52de76b85ef4b..cab962596f41655020a464003de2e93b2b6b09eb 100644 --- a/db/table_cache.cc +++ b/db/table_cache.cc @@ -391,7 +391,7 @@ Status TableCache::Get(const ReadOptions& options, } // Manual inline MapSstElement::Decode const char* err_msg = "Map sst invalid link_value"; - Slice map_input = map_value.get_slice(); + Slice map_input = map_value.slice(); Slice smallest_key; uint64_t link_count; uint64_t flags; diff --git a/db/version_set.cc b/db/version_set.cc index b1cb6f97d2b311ccfeb2e160c87eaf125a72189c..e3de2d81b3dce640e0feaa432f649327f510938f 100644 --- a/db/version_set.cc +++ b/db/version_set.cc @@ -1203,11 +1203,12 @@ Version::Version(ColumnFamilyData* column_family_data, VersionSet* vset, version_number_(version_number) {} Status Version::fetch_buffer(LazyBuffer* buffer) const { - auto rep = get_rep(buffer); - Slice user_key(reinterpret_cast(rep->data[0]), rep->data[1]); - uint64_t sequence = rep->data[2]; + auto context = get_context(buffer); + Slice user_key(reinterpret_cast(context->data[0]), + context->data[1]); + uint64_t sequence = context->data[2]; const FileMetaData* file_metadata = - reinterpret_cast(rep->data[3]); + reinterpret_cast(context->data[3]); bool value_found = false; SequenceNumber context_seq; GetContext get_context(cfd_->internal_comparator().user_comparator(), nullptr, @@ -1246,7 +1247,7 @@ void Version::TransToCombined(const Slice& user_key, uint64_t sequence, value.reset(std::move(s)); return; } - uint64_t file_number = SeparateHelper::DecodeFileNumber(value.get_slice()); + uint64_t file_number = SeparateHelper::DecodeFileNumber(value.slice()); auto& dependence_map = storage_info_.dependence_map(); auto find = dependence_map.find(file_number); if (find == dependence_map.end()) { diff --git a/db/version_set.h b/db/version_set.h index f563c4e5001f6d9555e949a088dc683f3128f545..64a86b2dcdc52a0bf8675e8053e2711f5400dd8e 100644 --- a/db/version_set.h +++ b/db/version_set.h @@ -572,7 +572,7 @@ class VersionStorageInfo { void operator=(const VersionStorageInfo&) = delete; }; -class Version : public SeparateHelper, private LazyBufferController { +class Version : public SeparateHelper, private LazyBufferState { public: // Append to *iters a sequence of iterators that will // yield the contents of this Version when merged together. diff --git a/db/write_batch.cc b/db/write_batch.cc index 7ce12f4fdbb04a3f430cd145315ba6bcc8b7466b..363fc1e398429653e4569a71a7183d7d858f28ac 100644 --- a/db/write_batch.cc +++ b/db/write_batch.cc @@ -1524,7 +1524,7 @@ class MemTableInserter : public WriteBatch::Handler { auto s = new_value.fetch(); if (s.ok()) { bool mem_res = - mem->Add(sequence_, kTypeValue, key, new_value.get_slice()); + mem->Add(sequence_, kTypeValue, key, new_value.slice()); if (UNLIKELY(!mem_res)) { assert(seq_per_batch_); ret_status = Status::TryAgain("key+seq exists"); diff --git a/include/rocksdb/compaction_filter.h b/include/rocksdb/compaction_filter.h index 493704d2654d9a858122506972b436f30f395285..866593e30a1dbad3f32a40178f95f3aa7b3c7b41 100644 --- a/include/rocksdb/compaction_filter.h +++ b/include/rocksdb/compaction_filter.h @@ -167,7 +167,7 @@ class CompactionFilter { switch (value_type) { case ValueType::kValue: { bool value_changed = false; - bool rv = Filter(level, key, existing_value.get_slice(), + bool rv = Filter(level, key, existing_value.slice(), new_value->trans_to_string(), &value_changed); if (rv) { return Decision::kRemove; @@ -175,7 +175,7 @@ class CompactionFilter { return value_changed ? Decision::kChangeValue : Decision::kKeep; } case ValueType::kMergeOperand: { - bool rv = FilterMergeOperand(level, key, existing_value.get_slice()); + bool rv = FilterMergeOperand(level, key, existing_value.slice()); return rv ? Decision::kRemove : Decision::kKeep; } } diff --git a/include/rocksdb/lazy_buffer.h b/include/rocksdb/lazy_buffer.h index 93a4ec54f1bc853b2f61f5bc4cc7f9399ae4287f..7c5714486acf103bcc56c32358a51a05f015dec8 100644 --- a/include/rocksdb/lazy_buffer.h +++ b/include/rocksdb/lazy_buffer.h @@ -18,10 +18,12 @@ namespace rocksdb { +// State pattern + class LazyBuffer; -class LazyBufferEditor; +class LazyBufferBuilder; -struct LazyBufferRep { +struct LazyBufferContext { uint64_t data[4]; }; @@ -30,9 +32,9 @@ struct LazyBufferCustomizeBuffer { void* (*uninitialized_resize)(void* handle, size_t size); }; -class LazyBufferController { +class LazyBufferState { public: - virtual ~LazyBufferController() = default; + virtual ~LazyBufferState() = default; // Release resource virtual void destroy(LazyBuffer* buffer) const = 0; @@ -46,7 +48,7 @@ class LazyBufferController { // Save error into buffer virtual void assign_error(LazyBuffer* buffer, Status&& status) const; - // Pin the buffer, turn the controller into editable + // Pin the buffer, turn the state into editable virtual void pin_buffer(LazyBuffer* buffer) const; // Fetch buffer and dump to target, the buffer may be destroyed @@ -55,39 +57,39 @@ class LazyBufferController { // Fetch buffer virtual Status fetch_buffer(LazyBuffer* buffer) const = 0; - // Use LazyBufferRep as local storage + // Use LazyBufferContext as local storage // data -> 32 bytes - static const LazyBufferController* light_controller(); + static const LazyBufferState* light_state(); - // Use LazyBufferRep as buffer + // Use LazyBufferContext as buffer // data[0] -> handle // data[1] -> uninitialized_resize call // data[2 - 3] -> Status - static const LazyBufferController* buffer_controller(); + static const LazyBufferState* buffer_state(); - // Use LazyBufferRep as string holder + // Use LazyBufferContext as string holder // data[0] -> string ptr // data[1] -> is owner // data[2 - 3] -> Status - static const LazyBufferController* string_controller(); + static const LazyBufferState* string_state(); - // Use LazyBufferRep as LazuBuffer reference + // Use LazyBufferContext as LazuBuffer reference // data[0] -> ptr to LazyBuffer - static const LazyBufferController* reference_controller(); + static const LazyBufferState* reference_state(); - // Use LazyBufferRep as Cleanable - // rep -> Cleanable - static const LazyBufferController* cleanable_controller(); + // Use LazyBufferContext as Cleanable + // context -> Cleanable + static const LazyBufferState* cleanable_state(); // Set buffer->slice_ = slice static void set_slice(LazyBuffer* buffer, const Slice& slice); - // Get &buffer->rep_ - static LazyBufferRep* get_rep(LazyBuffer* buffer); + // Get &buffer->context_ + static LazyBufferContext* get_context(LazyBuffer* buffer); }; class LazyBuffer { - friend LazyBufferController; + friend LazyBufferState; protected: union { struct { @@ -96,18 +98,18 @@ class LazyBuffer { }; Slice slice_ = Slice(); }; - const LazyBufferController* controller_; - LazyBufferRep rep_; + const LazyBufferState* state_; + LazyBufferContext context_; uint64_t file_number_; - // Call LazyBufferController::destroy if controller_ not nullptr + // Call LazyBufferState::destroy if state_ not nullptr void destroy(); - // Call LazyBufferController::assign_error if _status not ok + // Call LazyBufferState::assign_error if _status not ok void assign_error(Status&& _status); - // Fix light_controller local storage - void fix_light_controller(const LazyBuffer& other); + // Fix light_state local storage + void fix_light_state(const LazyBuffer& other); public: @@ -142,9 +144,9 @@ public: LazyBuffer(const Slice& _slice, Cleanable&& _cleanable, uint64_t _file_number = uint64_t(-1)) noexcept; - // Init from customize controller - LazyBuffer(const LazyBufferController* _controller, - const LazyBufferRep& _rep, const Slice& _slice = Slice::Invalid(), + // Init from customize state + LazyBuffer(const LazyBufferState* _state, const LazyBufferContext& _context, + const Slice& _slice = Slice::Invalid(), uint64_t _file_number = uint64_t(-1)) noexcept; ~LazyBuffer() { @@ -162,7 +164,7 @@ public: // Get inner slice // REQUIRES: valid() - const Slice& get_slice() const { assert(valid()); return slice_; } + const Slice& slice() const { assert(valid()); return slice_; } // Return a pointer to the beginning of the referenced data // REQUIRES: valid() @@ -249,16 +251,16 @@ public: void reset(const Slice& _slice, Cleanable&& _cleanable, uint64_t _file_number = uint64_t(-1)); - // Reset to customize controller - void reset(const LazyBufferController* _controller, const LazyBufferRep& _rep, + // Reset to customize state + void reset(const LazyBufferState* _state, const LazyBufferContext& _context, const Slice& _slice = Slice::Invalid(), uint64_t _file_number = uint64_t(-1)); // Fetch source and copy it void assign(const LazyBuffer& _source); - // Trans to editable buffer and get editor - LazyBufferEditor* get_editor(); + // Trans to editable buffer and get builder + LazyBufferBuilder* get_builder(); // Trans buffer to string for modification std::string* trans_to_string(); @@ -266,7 +268,7 @@ public: // Return the certain file number of SST, -1 for unknown uint64_t file_number() const { return file_number_; } - // Pin this buffer, turn the controller into editable + // Pin this buffer, turn the state into editable void pin(); // Dump buffer to customize buffer @@ -282,13 +284,13 @@ public: Status fetch() const; // For test - const LazyBufferController* TEST_controller() const { return controller_; } + const LazyBufferState* TEST_state() const { return state_; } // For test - const LazyBufferRep* TEST_rep() const { return &rep_; } + const LazyBufferContext* TEST_context() const { return &context_; } }; -class LazyBufferEditor : private LazyBuffer { +class LazyBufferBuilder : private LazyBuffer { public: char* data() const { return data_; } using LazyBuffer::size; @@ -303,85 +305,85 @@ class LazyBufferEditor : private LazyBuffer { bool uninitialized_resize(size_t _size); }; -inline void LazyBufferController::set_slice(LazyBuffer* buffer, - const Slice& slice) { +inline void LazyBufferState::set_slice(LazyBuffer* buffer, const Slice& slice) { buffer->slice_ = slice; } -inline LazyBufferRep* LazyBufferController::get_rep(LazyBuffer* buffer) { - return &buffer->rep_; +inline LazyBufferContext* LazyBufferState::get_context(LazyBuffer* buffer) { + return &buffer->context_; } inline LazyBuffer::LazyBuffer() noexcept - : controller_(LazyBufferController::light_controller()), - rep_{}, + : state_(LazyBufferState::light_state()), + context_{}, file_number_(uint64_t(-1)) {} inline LazyBuffer::LazyBuffer(LazyBuffer&& _buffer) noexcept : slice_(_buffer.slice_), - controller_(_buffer.controller_), - rep_(_buffer.rep_), + state_(_buffer.state_), + context_(_buffer.context_), file_number_(_buffer.file_number_) { - if (controller_ == LazyBufferController::light_controller() && - _buffer.size_ <= sizeof(LazyBufferRep)) { - fix_light_controller(_buffer); + if (state_ == LazyBufferState::light_state() && + _buffer.size_ <= sizeof(LazyBufferContext)) { + fix_light_state(_buffer); } _buffer.slice_ = Slice::Invalid(); - _buffer.controller_ = nullptr; + _buffer.state_ = nullptr; } inline LazyBuffer::LazyBuffer(const Slice& _slice, bool _copy, uint64_t _file_number) : slice_(_slice), - controller_(LazyBufferController::light_controller()), - rep_{}, + state_(LazyBufferState::light_state()), + context_{}, file_number_(_file_number) { assert(_slice.valid()); if (_copy) { - controller_->assign_slice(this, _slice); + state_->assign_slice(this, _slice); } } inline LazyBuffer::LazyBuffer(const Slice& _slice, Cleanable&& _cleanable, uint64_t _file_number) noexcept : slice_(_slice), - controller_(LazyBufferController::cleanable_controller()), - rep_{}, + state_(LazyBufferState::cleanable_state()), + context_{}, file_number_(_file_number) { assert(_slice.valid()); - static_assert(sizeof _cleanable == sizeof rep_, ""); - static_assert(alignof(Cleanable) == alignof(LazyBufferRep), ""); - ::new(&rep_) Cleanable(std::move(_cleanable)); + static_assert(sizeof _cleanable == sizeof context_, ""); + static_assert(alignof(Cleanable) == alignof(LazyBufferContext), ""); + ::new(&context_) Cleanable(std::move(_cleanable)); } -inline LazyBuffer::LazyBuffer(const LazyBufferController* _controller, - const LazyBufferRep& _rep, const Slice& _slice, +inline LazyBuffer::LazyBuffer(const LazyBufferState* _state, + const LazyBufferContext& _context, + const Slice& _slice, uint64_t _file_number) noexcept : slice_(_slice), - controller_(_controller), - rep_(_rep), + state_(_state), + context_(_context), file_number_(_file_number) { - assert(_controller != nullptr); + assert(_state != nullptr); } inline void LazyBuffer::destroy() { - if (controller_ != nullptr) { - controller_->destroy(this); + if (state_ != nullptr) { + state_->destroy(this); } } inline void LazyBuffer::assign_error(Status&& _status) { if (_status.ok()) { - controller_->assign_slice(this, Slice()); + state_->assign_slice(this, Slice()); } else { - controller_->assign_error(this, std::move(_status)); + state_->assign_error(this, std::move(_status)); assert(!slice_.valid()); } file_number_ = uint64_t(-1); } inline void LazyBuffer::clear() { - controller_->assign_slice(this, Slice()); + state_->assign_slice(this, Slice()); assert(size_ == 0); file_number_ = uint64_t(-1); } @@ -390,15 +392,15 @@ inline void LazyBuffer::reset(LazyBuffer&& _buffer) { if (this != &_buffer) { destroy(); slice_ = _buffer.slice_; - controller_ = _buffer.controller_; - rep_ = _buffer.rep_; + state_ = _buffer.state_; + context_ = _buffer.context_; file_number_ = _buffer.file_number_; - if (controller_ == LazyBufferController::light_controller() && - _buffer.size_ <= sizeof(LazyBufferRep)) { - fix_light_controller(_buffer); + if (state_ == LazyBufferState::light_state() && + _buffer.size_ <= sizeof(LazyBufferContext)) { + fix_light_state(_buffer); } _buffer.slice_ = Slice::Invalid(); - _buffer.controller_ = nullptr; + _buffer.state_ = nullptr; } } @@ -406,13 +408,13 @@ inline void LazyBuffer::reset(const Slice& _slice, bool _copy, uint64_t _file_number) { assert(_slice.valid()); if (_copy) { - controller_->assign_slice(this, _slice); + state_->assign_slice(this, _slice); assert(slice_ == _slice); } else { destroy(); slice_ = _slice; - controller_ = LazyBufferController::light_controller(); - rep_ = {}; + state_ = LazyBufferState::light_state(); + context_ = {}; } file_number_ = _file_number; } @@ -421,40 +423,40 @@ inline void LazyBuffer::reset(const Slice& _slice, Cleanable&& _cleanable, uint64_t _file_number) { assert(_slice.valid()); destroy(); - controller_ = LazyBufferController::cleanable_controller(); + state_ = LazyBufferState::cleanable_state(); slice_ = _slice; - new(&rep_) Cleanable(std::move(_cleanable)); + new(&context_) Cleanable(std::move(_cleanable)); file_number_ = _file_number; } -inline void LazyBuffer::reset(const LazyBufferController* _controller, - const LazyBufferRep& _rep, const Slice& _slice, - uint64_t _file_number) { - assert(_controller != nullptr); +inline void LazyBuffer::reset(const LazyBufferState* _state, + const LazyBufferContext& _context, + const Slice& _slice, uint64_t _file_number) { + assert(_state != nullptr); destroy(); slice_ = _slice; - controller_ = _controller; - rep_ = _rep; + state_ = _state; + context_ = _context; file_number_ = _file_number; } inline void LazyBuffer::pin() { - assert(controller_ != nullptr); - return controller_->pin_buffer(this); + assert(state_ != nullptr); + return state_->pin_buffer(this); } -inline Status LazyBuffer::dump(LazyBuffer& _target) && { - assert(controller_ != nullptr); +inline Status LazyBuffer::dump(LazyBuffer& _target)&& { + assert(state_ != nullptr); assert(this != &_target); - return controller_->dump_buffer(this, &_target); + return state_->dump_buffer(this, &_target); } inline Status LazyBuffer::fetch() const { - assert(controller_ != nullptr); + assert(state_ != nullptr); if (slice_.valid()) { return Status::OK(); } - return controller_->fetch_buffer(const_cast(this)); + return state_->fetch_buffer(const_cast(this)); } // make a slice reference diff --git a/memtable/terark_zip_memtable.cc b/memtable/terark_zip_memtable.cc index 85225f1389b74beeb69c4cced1c5e427a1d7d374..d854d1a1885cb3a5f28eb45ccba1e21d083ed3ad 100644 --- a/memtable/terark_zip_memtable.cc +++ b/memtable/terark_zip_memtable.cc @@ -124,7 +124,7 @@ void PatriciaTrieRep::Get( valvec buffer; }; - class Controller : public LazyBufferController { + class Controller : public LazyBufferState { public: virtual void destroy(LazyBuffer* /*buffer*/) const override {} diff --git a/memtable/terark_zip_memtable.h b/memtable/terark_zip_memtable.h index 1bf37a30bceb18537cfa0e31bb58908caf6f7296..d41c29d6977397bc0440fbff794040c759207059 100644 --- a/memtable/terark_zip_memtable.h +++ b/memtable/terark_zip_memtable.h @@ -140,7 +140,7 @@ public: template class PatriciaRepIterator : public MemTableRep::Iterator, - public LazyBufferController, + public LazyBufferState, boost::noncopyable { typedef terark::Patricia::ReaderToken token_t; @@ -228,17 +228,17 @@ public: virtual ~PatriciaRepIterator(); - // LazyBufferController override + // LazyBufferState override virtual void destroy(LazyBuffer* /*buffer*/) const override {} - // LazyBufferController override + // LazyBufferState override virtual void pin_buffer(LazyBuffer* buffer) const override { if (!buffer->valid()) { buffer->reset(GetValue()); } } - // LazyBufferController override + // LazyBufferState override Status fetch_buffer(LazyBuffer* buffer) const override { set_slice(buffer, GetValue()); return Status::OK(); diff --git a/table/block_based_table_builder.cc b/table/block_based_table_builder.cc index 1308d005ce1bb7a80d66cd3b34ff7d712e43d0a9..8935fdd4ee9f2614d9cf9907130fe464ed619d89 100644 --- a/table/block_based_table_builder.cc +++ b/table/block_based_table_builder.cc @@ -425,7 +425,7 @@ void BlockBasedTableBuilder::Add(const Slice& key, r->status = s; return; } - const Slice& value = lazy_value.get_slice(); + const Slice& value = lazy_value.slice(); ValueType value_type = ExtractValueType(key); if (r->ignore_key_type || IsValueType(value_type)) { if (r->props.num_entries > 0) { diff --git a/table/block_based_table_reader.h b/table/block_based_table_reader.h index 6f3b4df62f64560130886599812031ab1aeefa9b..9d0575c365c84a56ff93b57309cf313b30a77ea0 100644 --- a/table/block_based_table_reader.h +++ b/table/block_based_table_reader.h @@ -680,7 +680,7 @@ class BlockBasedTableIterator template <> class BlockBasedTableIterator : public BlockBasedTableIteratorBase, - public LazyBufferController { + public LazyBufferState { using Base = BlockBasedTableIteratorBase; using Base::block_iter_; using Base::icomp_; diff --git a/table/cuckoo_table_builder.cc b/table/cuckoo_table_builder.cc index 9aefb5be6346453279dd39f7fe19867b1fdf0ede..23508fba9425ce378ad9410733af3d8ea8a6dd63 100644 --- a/table/cuckoo_table_builder.cc +++ b/table/cuckoo_table_builder.cc @@ -88,7 +88,7 @@ void CuckooTableBuilder::Add(const Slice& key, const LazyBuffer& lazy_value) { status_ = s; return; } - const Slice& value = lazy_value.get_slice(); + const Slice& value = lazy_value.slice(); if (num_entries_ >= kMaxVectorIdx - 1) { status_ = Status::NotSupported("Number of keys in a file must be < 2^32-1"); return; diff --git a/table/plain_table_builder.cc b/table/plain_table_builder.cc index fcd862fc97197457cf796a41b20073b6691107cc..efa9b760d63d3434f3ec13859258479144ee50d2 100644 --- a/table/plain_table_builder.cc +++ b/table/plain_table_builder.cc @@ -122,7 +122,7 @@ void PlainTableBuilder::Add(const Slice& key, const LazyBuffer& lazy_value) { status_ = s; return; } - const Slice& value = lazy_value.get_slice(); + const Slice& value = lazy_value.slice(); // temp buffer for metadata bytes between key and value. char meta_bytes_buf[6]; size_t meta_bytes_buf_size = 0; diff --git a/table/terark_zip_table_builder.cc b/table/terark_zip_table_builder.cc index 29143aaa4de98ae4d4c303475de79ec274935d60..88f76d75f9b7206356eaaf1e6665c5831baf6656 100644 --- a/table/terark_zip_table_builder.cc +++ b/table/terark_zip_table_builder.cc @@ -382,7 +382,7 @@ void TerarkZipTableBuilder::Add(const Slice& key, status_ = s; return; } - const Slice& value = lazy_value.get_slice(); + const Slice& value = lazy_value.slice(); if (table_options_.debugLevel == 3) { rocksdb::ParsedInternalKey ikey; rocksdb::ParseInternalKey(key, &ikey); @@ -1495,7 +1495,7 @@ TerarkZipTableBuilder::BuilderWriteValues(KeyValueStatus& kvs, std::functionkey(); - curVal = lazy_value.get_slice(); + curVal = lazy_value.slice(); TERARK_RT_assert(ParseInternalKey(curKey, &pIKey), std::logic_error); if (debugDumpKeyValue) { dumpKeyValueFunc(pIKey, curVal); @@ -1553,7 +1553,7 @@ TerarkZipTableBuilder::BuilderWriteValues(KeyValueStatus& kvs, std::functionkey(); - curVal = lazy_value.get_slice(); + curVal = lazy_value.slice(); TERARK_RT_assert(ParseInternalKey(curKey, &pIKey), std::logic_error); if (debugDumpKeyValue) { dumpKeyValueFunc(pIKey, curVal); diff --git a/table/terark_zip_table_reader.cc b/table/terark_zip_table_reader.cc index f8a832a8be68343bb940f3af73e67857aa64c970..08cba45f68506c6acfa5a034effc3cbd9db20be0 100644 --- a/table/terark_zip_table_reader.cc +++ b/table/terark_zip_table_reader.cc @@ -238,7 +238,7 @@ public: template class TerarkZipTableIterator : public TerarkZipTableIndexIterator, - public LazyBufferController { + public LazyBufferState { protected: const TableReaderOptions* table_reader_options_; SequenceNumber global_seqno_; diff --git a/table/two_level_iterator.cc b/table/two_level_iterator.cc index 5b2efe10ad07d7d580e1465c052c410009c1bbcb..6845afc105c1cdac4967b0c87c76a503a87ffd2e 100644 --- a/table/two_level_iterator.cc +++ b/table/two_level_iterator.cc @@ -255,7 +255,7 @@ class MapSstIterator final : public InternalIterator { if (!status_.ok()) { return kInitFirstIterInvalid; } - Slice map_input = first_level_value_.get_slice(); + Slice map_input = first_level_value_.slice(); link_.clear(); largest_key_ = first_level_iter_->key(); uint64_t flags; diff --git a/util/lazy_buffer.cc b/util/lazy_buffer.cc index f6972dd592ac061bb5a15de7adbc0349eebcc31f..23c2e44d7073c0094826b61be7521906f0f64f24 100644 --- a/util/lazy_buffer.cc +++ b/util/lazy_buffer.cc @@ -26,48 +26,49 @@ T* union_cast(S* src) { } } -class DefaultLazyBufferControllerImpl : public LazyBufferController { -public: - struct alignas(LazyBufferRep) Rep { - char data[sizeof(LazyBufferRep)]; +class LightLazyBufferState : public LazyBufferState { + public: + struct alignas(LazyBufferContext) Context { + char data[sizeof(LazyBufferContext)]; }; void destroy(LazyBuffer* /*buffer*/) const override {} void uninitialized_resize(LazyBuffer* buffer, size_t size) const override { - auto rep = union_cast(get_rep(buffer)); - if (size <= sizeof(Rep)) { - if (buffer->data() != rep->data) { - ::memmove(rep->data, buffer->data(), std::min(buffer->size(), size)); + auto context = union_cast(get_context(buffer)); + if (size <= sizeof(Context)) { + if (buffer->data() != context->data) { + ::memmove(context->data, buffer->data(), + std::min(buffer->size(), size)); } - set_slice(buffer, Slice(rep->data, size)); + set_slice(buffer, Slice(context->data, size)); } else { - LazyBufferController::uninitialized_resize(buffer, size); + LazyBufferState::uninitialized_resize(buffer, size); } } void assign_slice(LazyBuffer* buffer, const Slice& slice) const override { - auto rep = union_cast(get_rep(buffer)); - if (slice.size() <= sizeof(Rep)) { - ::memmove(rep->data, slice.data(), slice.size()); - set_slice(buffer, Slice(rep->data, slice.size())); + auto context = union_cast(get_context(buffer)); + if (slice.size() <= sizeof(Context)) { + ::memmove(context->data, slice.data(), slice.size()); + set_slice(buffer, Slice(context->data, slice.size())); } else { - LazyBufferController::assign_slice(buffer, slice); + LazyBufferState::assign_slice(buffer, slice); } } void pin_buffer(LazyBuffer* buffer) const override { - auto rep = union_cast(get_rep(buffer)); - if (buffer->size() > sizeof(Rep)) { - LazyBufferController::assign_slice(buffer, buffer->get_slice()); - } else if (buffer->data() != rep->data) { - ::memmove(rep->data, buffer->data(), buffer->size()); - set_slice(buffer, Slice(rep->data, buffer->size())); + auto context = union_cast(get_context(buffer)); + if (buffer->size() > sizeof(Context)) { + LazyBufferState::assign_slice(buffer, buffer->slice()); + } else if (buffer->data() != context->data) { + ::memmove(context->data, buffer->data(), buffer->size()); + set_slice(buffer, Slice(context->data, buffer->size())); } } Status dump_buffer(LazyBuffer* buffer, LazyBuffer* target) const override { - target->reset(buffer->get_slice(), true, buffer->file_number()); + target->reset(buffer->slice(), true, buffer->file_number()); return Status::OK(); } @@ -77,42 +78,42 @@ public: } }; -class BufferLazyBufferControllerImpl : public LazyBufferController { +class BufferLazyBufferState : public LazyBufferState { public: - struct alignas(LazyBufferRep) Rep { + struct alignas(LazyBufferContext) Context { LazyBufferCustomizeBuffer buffer; Status status; }; void destroy(LazyBuffer* buffer) const override { - auto rep = union_cast(get_rep(buffer)); - if (rep->buffer.uninitialized_resize == nullptr && - rep->buffer.handle != nullptr) { - ::free(rep->buffer.handle); + auto context = union_cast(get_context(buffer)); + if (context->buffer.uninitialized_resize == nullptr && + context->buffer.handle != nullptr) { + ::free(context->buffer.handle); } - rep->status.~Status(); + context->status.~Status(); } void uninitialized_resize(LazyBuffer* buffer, size_t size) const override { - auto rep = union_cast(get_rep(buffer)); - if (rep->buffer.uninitialized_resize == nullptr) { - char* ptr = (char*)::realloc(rep->buffer.handle, size); + auto context = union_cast(get_context(buffer)); + if (context->buffer.uninitialized_resize == nullptr) { + char* ptr = (char*)::realloc(context->buffer.handle, size); if (ptr != nullptr || size == 0) { - rep->buffer.handle = ptr; - rep->status = Status::OK(); + context->buffer.handle = ptr; + context->status = Status::OK(); set_slice(buffer, Slice(ptr, size)); } else { - rep->status = Status::BadAlloc(); + context->status = Status::BadAlloc(); set_slice(buffer, Slice::Invalid()); } } else { - char* ptr = - (char*)rep->buffer.uninitialized_resize(rep->buffer.handle, size); + char* ptr = (char*)context->buffer.uninitialized_resize( + context->buffer.handle, size); if (ptr != nullptr || size == 0) { - rep->status = Status::OK(); + context->status = Status::OK(); set_slice(buffer, Slice(ptr, size)); } else { - rep->status = Status::BadAlloc(); + context->status = Status::BadAlloc(); set_slice(buffer, Slice::Invalid()); } } @@ -127,10 +128,9 @@ class BufferLazyBufferControllerImpl : public LazyBufferController { ::memmove(ptr, slice.data(), slice.size()); set_slice(buffer, Slice(ptr, slice.size())); } else { - BufferLazyBufferControllerImpl::uninitialized_resize(buffer, - slice.size()); - auto rep = union_cast(get_rep(buffer)); - if (rep->status.ok() && slice.empty()) { + BufferLazyBufferState::uninitialized_resize(buffer, slice.size()); + auto context = union_cast(get_context(buffer)); + if (context->status.ok() && slice.empty()) { assert(buffer->data() != nullptr); assert(buffer->size() == slice.size()); char* ptr = (char*)buffer->data(); @@ -140,127 +140,127 @@ class BufferLazyBufferControllerImpl : public LazyBufferController { } void assign_error(LazyBuffer* buffer, Status&& status) const override { - auto rep = union_cast(get_rep(buffer)); - rep->status = std::move(status); + auto context = union_cast(get_context(buffer)); + context->status = std::move(status); set_slice(buffer, Slice::Invalid()); } void pin_buffer(LazyBuffer* /*buffer*/) const override {} Status dump_buffer(LazyBuffer* buffer, LazyBuffer* target) const override { - auto rep = union_cast(get_rep(buffer)); - if (rep->status.ok()) { + auto context = union_cast(get_context(buffer)); + if (context->status.ok()) { assert(buffer->valid()); - target->reset(buffer->get_slice(), true, buffer->file_number()); + target->reset(buffer->slice(), true, buffer->file_number()); return Status::OK(); } else { assert(!buffer->valid()); - return std::move(rep->status); + return std::move(context->status); } } Status fetch_buffer(LazyBuffer* buffer) const override { - auto rep = union_cast(get_rep(buffer)); - assert(!rep->status.ok()); - return rep->status; + auto context = union_cast(get_context(buffer)); + assert(!context->status.ok()); + return context->status; } }; -struct StringLazyBufferControllerImpl : public LazyBufferController { +struct StringLazyBufferState : public LazyBufferState { public: - struct alignas(LazyBufferRep) Rep { + struct alignas(LazyBufferContext) Context { std::string* string; uint64_t is_owner; Status status; }; void destroy(LazyBuffer* buffer) const override { - auto rep = union_cast(get_rep(buffer)); - if (rep->is_owner) { - delete rep->string; + auto context = union_cast(get_context(buffer)); + if (context->is_owner) { + delete context->string; } - rep->status.~Status(); + context->status.~Status(); } void uninitialized_resize(LazyBuffer* buffer, size_t size) const override { - auto rep = union_cast(get_rep(buffer)); + auto context = union_cast(get_context(buffer)); try { - rep->string->resize(size); - set_slice(buffer, *rep->string); - rep->status = Status::OK(); + context->string->resize(size); + set_slice(buffer, *context->string); + context->status = Status::OK(); return; } catch (const std::bad_alloc&) { - rep->status = Status::BadAlloc(); + context->status = Status::BadAlloc(); } catch (const std::exception& ex) { - rep->status = Status::Aborted(ex.what()); + context->status = Status::Aborted(ex.what()); } set_slice(buffer, Slice::Invalid()); } void assign_slice(LazyBuffer* buffer, const Slice& slice) const override { - auto rep = union_cast(get_rep(buffer)); - rep->string->assign(slice.data(), slice.size()); - rep->status = Status::OK(); - set_slice(buffer, *rep->string); + auto context = union_cast(get_context(buffer)); + context->string->assign(slice.data(), slice.size()); + context->status = Status::OK(); + set_slice(buffer, *context->string); } void assign_error(LazyBuffer* buffer, Status&& status) const override { - auto rep = union_cast(get_rep(buffer)); - rep->status = std::move(status); + auto context = union_cast(get_context(buffer)); + context->status = std::move(status); set_slice(buffer, Slice::Invalid()); } void pin_buffer(LazyBuffer* /*buffer*/) const override {} Status dump_buffer(LazyBuffer* buffer, LazyBuffer* target) const override { - auto rep = union_cast(get_rep(buffer)); - if (rep->status.ok()) { - target->reset(*rep->string, true, buffer->file_number()); + auto context = union_cast(get_context(buffer)); + if (context->status.ok()) { + target->reset(*context->string, true, buffer->file_number()); return Status::OK(); } else { assert(!buffer->valid()); - return std::move(rep->status); + return std::move(context->status); } } Status fetch_buffer(LazyBuffer* buffer) const override { - auto rep = union_cast(get_rep(buffer)); - if (rep->status.ok()) { - set_slice(buffer, *rep->string); + auto context = union_cast(get_context(buffer)); + if (context->status.ok()) { + set_slice(buffer, *context->string); return Status::OK(); } else { - return rep->status; + return context->status; } } }; // 0 -> pointer to slice -struct ReferenceLazyBufferControllerImpl : public LazyBufferController { - +struct ReferenceLazyBufferState : public LazyBufferState { + public: void destroy(LazyBuffer* /*buffer*/) const override {} Status fetch_buffer(LazyBuffer* buffer) const override { const LazyBuffer& buffer_ref = - *reinterpret_cast(get_rep(buffer)->data[0]); + *reinterpret_cast(get_context(buffer)->data[0]); auto s = buffer_ref.fetch(); if (s.ok()) { - set_slice(buffer, buffer_ref.get_slice()); + set_slice(buffer, buffer_ref.slice()); } return s; } }; -struct CleanableLazyBufferControllerImpl : public LazyBufferController { - +struct CleanableLazyBufferState : public LazyBufferState { + public: void destroy(LazyBuffer* buffer) const override { - union_cast(get_rep(buffer))->Reset(); + union_cast(get_context(buffer))->Reset(); } void pin_buffer(LazyBuffer* /*buffer*/) const override {} Status dump_buffer(LazyBuffer* buffer, LazyBuffer* target) const override { - target->reset(buffer->get_slice(), true, buffer->file_number()); - union_cast(get_rep(buffer))->Reset(); + target->reset(buffer->slice(), true, buffer->file_number()); + union_cast(get_context(buffer))->Reset(); return Status::OK(); } @@ -270,76 +270,75 @@ struct CleanableLazyBufferControllerImpl : public LazyBufferController { } }; -void LazyBufferController::uninitialized_resize(LazyBuffer* buffer, - size_t size) const { - if (buffer->valid() && size <= sizeof(LazyBufferRep)) { - DefaultLazyBufferControllerImpl::Rep tmp_rep{}; - ::memcpy(tmp_rep.data, buffer->data_, std::min(buffer->size_, size)); +void LazyBufferState::uninitialized_resize(LazyBuffer* buffer, + size_t size) const { + if (buffer->valid() && size <= sizeof(LazyBufferContext)) { + LightLazyBufferState::Context tmp_context{}; + ::memcpy(tmp_context.data, buffer->data_, std::min(buffer->size_, size)); destroy(buffer); - buffer->controller_ = light_controller(); - auto rep = - union_cast(&buffer->rep_); - *rep = tmp_rep; - buffer->data_ = rep->data; + buffer->state_ = light_state(); + auto context = union_cast(&buffer->context_); + *context = tmp_context; + buffer->data_ = context->data; buffer->size_ = size; } else { LazyBuffer tmp(size); - assert(tmp.controller_ == buffer_controller()); - auto rep = union_cast(&tmp.rep_); - if (rep->status.ok()) { + assert(tmp.state_ == buffer_state()); + auto context = union_cast(&tmp.context_); + if (context->status.ok()) { auto s = dump_buffer(buffer, &tmp); - assert(tmp.controller_ == buffer_controller()); + assert(tmp.state_ == buffer_state()); if (!s.ok()) { - rep->status = std::move(s); + context->status = std::move(s); set_slice(&tmp, Slice::Invalid()); } } destroy(buffer); buffer->slice_ = tmp.slice_; - buffer->controller_ = tmp.controller_; - tmp.controller_ = nullptr; - buffer->rep_ = tmp.rep_; + buffer->state_ = tmp.state_; + tmp.state_ = nullptr; + buffer->context_ = tmp.context_; } } -void LazyBufferController::assign_slice(LazyBuffer* buffer, - const Slice& slice) const { - buffer->controller_->destroy(buffer); - if (slice.size() <= sizeof(LazyBufferRep)) { - buffer->controller_ = light_controller(); - auto rep = - union_cast(&buffer->rep_); - ::memcpy(rep->data, slice.data(), slice.size()); - buffer->data_ = rep->data; +void LazyBufferState::assign_slice(LazyBuffer* buffer, + const Slice& slice) const { + buffer->state_->destroy(buffer); + if (slice.size() <= sizeof(LazyBufferContext)) { + buffer->state_ = light_state(); + auto context = union_cast(&buffer->context_); + ::memcpy(context->data, slice.data(), slice.size()); + buffer->data_ = context->data; buffer->size_ = slice.size(); } else { - buffer->controller_ = buffer_controller(); - auto rep = union_cast(&buffer->rep_); - rep->buffer.handle = ::malloc(slice.size()); - rep->buffer.uninitialized_resize = nullptr; - if (rep->buffer.handle == nullptr) { - ::new(&rep->status) Status(Status::BadAlloc()); + buffer->state_ = buffer_state(); + auto context = + union_cast(&buffer->context_); + context->buffer.handle = ::malloc(slice.size()); + context->buffer.uninitialized_resize = nullptr; + if (context->buffer.handle == nullptr) { + ::new(&context->status) Status(Status::BadAlloc()); } else { - ::new(&rep->status) Status; - ::memcpy(rep->buffer.handle, slice.data(), slice.size()); - buffer->data_ = (char*)rep->buffer.handle; + ::new(&context->status) Status; + ::memcpy(context->buffer.handle, slice.data(), slice.size()); + buffer->data_ = (char*)context->buffer.handle; buffer->size_ = slice.size(); } } } -void LazyBufferController::assign_error(LazyBuffer* buffer, - Status&& status) const { +void LazyBufferState::assign_error(LazyBuffer* buffer, + Status&& status) const { destroy(buffer); - buffer->controller_ = buffer_controller(); - auto rep = union_cast(&buffer->rep_); - rep->buffer.handle = nullptr; - rep->buffer.uninitialized_resize = nullptr; - ::new(&rep->status) Status(std::move(status)); + buffer->state_ = buffer_state(); + auto context = union_cast(&buffer->context_); + context->buffer.handle = nullptr; + context->buffer.uninitialized_resize = nullptr; + ::new(&context->status) Status(std::move(status)); buffer->slice_ = Slice::Invalid(); } -void LazyBufferController::pin_buffer(LazyBuffer* buffer) const { +void LazyBufferState::pin_buffer(LazyBuffer* buffer) const { LazyBuffer tmp; auto s = dump_buffer(buffer, &tmp); if (s.ok()) { @@ -350,103 +349,103 @@ void LazyBufferController::pin_buffer(LazyBuffer* buffer) const { } } -Status LazyBufferController::dump_buffer(LazyBuffer* buffer, - LazyBuffer* target) const { +Status LazyBufferState::dump_buffer(LazyBuffer* buffer, + LazyBuffer* target) const { if (!buffer->valid()) { auto s = fetch_buffer(buffer); if (!s.ok()) { return s; } } - target->controller_->assign_slice(target, buffer->slice_); + target->state_->assign_slice(target, buffer->slice_); assert(target->slice_ == buffer->slice_); target->file_number_ = buffer->file_number_; destroy(buffer); return Status::OK(); } -const LazyBufferController* LazyBufferController::light_controller() { - static DefaultLazyBufferControllerImpl controller_impl; - return &controller_impl; +const LazyBufferState* LazyBufferState::light_state() { + static LightLazyBufferState static_state; + return &static_state; } -const LazyBufferController* LazyBufferController::buffer_controller() { - static BufferLazyBufferControllerImpl controller_impl; - return &controller_impl; +const LazyBufferState* LazyBufferState::buffer_state() { + static BufferLazyBufferState static_state; + return &static_state; } -const LazyBufferController* LazyBufferController::string_controller() { - static StringLazyBufferControllerImpl controller_impl; - return &controller_impl; +const LazyBufferState* LazyBufferState::string_state() { + static StringLazyBufferState static_state; + return &static_state; } -const LazyBufferController* LazyBufferController::reference_controller() { - static ReferenceLazyBufferControllerImpl controller_impl; - return &controller_impl; +const LazyBufferState* LazyBufferState::reference_state() { + static ReferenceLazyBufferState static_state; + return &static_state; } -const LazyBufferController* LazyBufferController::cleanable_controller() { - static CleanableLazyBufferControllerImpl controller_impl; - return &controller_impl; +const LazyBufferState* LazyBufferState::cleanable_state() { + static CleanableLazyBufferState static_state; + return &static_state; } LazyBuffer::LazyBuffer(size_t _size) noexcept - : rep_{}, + : context_{}, file_number_(uint64_t(-1)) { - if (_size <= sizeof(LazyBufferRep)) { - controller_ = LazyBufferController::light_controller(); - data_ = union_cast(&rep_)->data; + if (_size <= sizeof(LazyBufferContext)) { + state_ = LazyBufferState::light_state(); + data_ = union_cast(&context_)->data; size_ = _size; } else { - controller_ = LazyBufferController::buffer_controller(); - auto rep = union_cast(&rep_); - rep->buffer.handle = ::malloc(_size); - if (rep->buffer.handle == nullptr) { - ::new(&rep->status) Status(Status::BadAlloc()); + state_ = LazyBufferState::buffer_state(); + auto context = union_cast(&context_); + context->buffer.handle = ::malloc(_size); + if (context->buffer.handle == nullptr) { + ::new(&context->status) Status(Status::BadAlloc()); slice_ = Slice::Invalid(); } else { - ::new(&rep->status) Status; - data_ = (char*)rep->buffer.handle; + ::new(&context->status) Status; + data_ = (char*)context->buffer.handle; size_ = _size; } } } -void LazyBuffer::fix_light_controller(const LazyBuffer& other) { - assert(controller_ == LazyBufferController::light_controller()); - assert(other.size_ <= sizeof(LazyBufferRep)); - data_ = union_cast(&rep_)->data; +void LazyBuffer::fix_light_state(const LazyBuffer& other) { + assert(state_ == LazyBufferState::light_state()); + assert(other.size_ <= sizeof(LazyBufferContext)); + data_ = union_cast(&context_)->data; size_ = other.size_; ::memmove(data_, other.data_, size_); } LazyBuffer::LazyBuffer(LazyBufferCustomizeBuffer _buffer) noexcept - : controller_(LazyBufferController::buffer_controller()), - rep_{reinterpret_cast(_buffer.handle), - reinterpret_cast(_buffer.uninitialized_resize)}, + : state_(LazyBufferState::buffer_state()), + context_{reinterpret_cast(_buffer.handle), + reinterpret_cast(_buffer.uninitialized_resize)}, file_number_(uint64_t(-1)) { assert(_buffer.handle != nullptr); assert(_buffer.uninitialized_resize != nullptr); - ::new(&union_cast(&rep_)->status) Status; + ::new(&union_cast(&context_)->status) Status; } LazyBuffer::LazyBuffer(std::string* _string) noexcept : slice_(*_string), - controller_(LazyBufferController::string_controller()), - rep_{reinterpret_cast(_string)}, + state_(LazyBufferState::string_state()), + context_{reinterpret_cast(_string)}, file_number_(uint64_t(-1)) { assert(_string != nullptr); - ::new(&union_cast(&rep_)->status) Status; + ::new(&union_cast(&context_)->status) Status; } void LazyBuffer::reset(LazyBufferCustomizeBuffer _buffer) { assert(_buffer.handle != nullptr); assert(_buffer.uninitialized_resize != nullptr); destroy(); - controller_ = LazyBufferController::buffer_controller(); - auto rep = union_cast(&rep_); - rep->buffer = _buffer; - ::new(&rep->status) Status; + state_ = LazyBufferState::buffer_state(); + auto context = union_cast(&context_); + context->buffer = _buffer; + ::new(&context->status) Status; slice_ = Slice(); file_number_ = uint64_t(-1); } @@ -454,102 +453,103 @@ void LazyBuffer::reset(LazyBufferCustomizeBuffer _buffer) { void LazyBuffer::reset(std::string* _string) { assert(_string != nullptr); slice_ = *_string; - auto rep = union_cast(&rep_); - if (controller_ == LazyBufferController::string_controller()) { - if (rep->string != _string) { - if (rep->is_owner) { - delete rep->string; - rep->is_owner = 0; + auto context = union_cast(&context_); + if (state_ == LazyBufferState::string_state()) { + if (context->string != _string) { + if (context->is_owner) { + delete context->string; + context->is_owner = 0; } - rep->string = _string; + context->string = _string; } - rep->status = Status::OK(); + context->status = Status::OK(); } else { destroy(); - controller_ = LazyBufferController::string_controller(); - rep->string = _string; - rep->is_owner = 0; - ::new(&rep->status) Status; + state_ = LazyBufferState::string_state(); + context->string = _string; + context->is_owner = 0; + ::new(&context->status) Status; } - slice_ = *rep->string; + slice_ = *context->string; } void LazyBuffer::assign(const LazyBuffer& source) { Status s; if (source.valid() || (s = source.fetch()).ok()) { - reset(source.get_slice(), true, source.file_number()); + reset(source.slice(), true, source.file_number()); } else { - controller_->assign_error(this, std::move(std::move(s))); + state_->assign_error(this, std::move(std::move(s))); assert(!slice_.valid()); } } -LazyBufferEditor* LazyBuffer::get_editor() { - assert(controller_ != nullptr); +LazyBufferBuilder* LazyBuffer::get_builder() { + assert(state_ != nullptr); file_number_ = uint64_t(-1); - controller_->uninitialized_resize(this, size_); - return reinterpret_cast(this); + state_->uninitialized_resize(this, valid() ? size_ : 0); + return reinterpret_cast(this); } std::string* LazyBuffer::trans_to_string() { - assert(controller_ != nullptr); + assert(state_ != nullptr); file_number_ = uint64_t(-1); - if (controller_ == LazyBufferController::string_controller()) { - auto rep = union_cast(&rep_); - assert(!slice_.valid() || (data_ == rep->string->data() && - size_ == rep->string->size())); + if (state_ == LazyBufferState::string_state()) { + auto context = union_cast(&context_); + assert(!slice_.valid() || (data_ == context->string->data() && + size_ == context->string->size())); slice_ = Slice::Invalid(); - return rep->string; + return context->string; } else { - LazyBuffer tmp(LazyBufferController::string_controller(), + LazyBuffer tmp(LazyBufferState::string_state(), {reinterpret_cast(new std::string), 1}); - auto s = controller_->dump_buffer(this, &tmp); + auto s = state_->dump_buffer(this, &tmp); destroy(); slice_ = Slice::Invalid(); - controller_ = tmp.controller_; - tmp.controller_ = nullptr; - rep_ = tmp.rep_; - auto rep = union_cast(&rep_); + state_ = tmp.state_; + tmp.state_ = nullptr; + context_ = tmp.context_; + auto context = union_cast(&context_); if (!s.ok()) { - rep->status = std::move(s); + context->status = std::move(s); } - return rep->string; + return context->string; } } -Status LazyBuffer::dump(LazyBufferCustomizeBuffer _buffer) && { - assert(controller_ != nullptr); +Status LazyBuffer::dump(LazyBufferCustomizeBuffer _buffer)&& { + assert(state_ != nullptr); if (slice_.valid()) { - if (controller_ != LazyBufferController::buffer_controller() || - reinterpret_cast(rep_.data[0]) != _buffer.handle) { + if (state_ != LazyBufferState::buffer_state() || + reinterpret_cast(context_.data[0]) != _buffer.handle) { void* ptr = _buffer.uninitialized_resize(_buffer.handle, slice_.size()); if (ptr == nullptr) { return Status::BadAlloc(); } ::memcpy(ptr, slice_.data(), slice_.size()); } else { - assert(rep_.data[1] == + assert(context_.data[1] == reinterpret_cast(_buffer.uninitialized_resize)); } } else { LazyBuffer buffer(_buffer); - auto s = controller_->dump_buffer(this, &buffer); + auto s = state_->dump_buffer(this, &buffer); if (!s.ok()) { return s; } - assert(buffer.controller_ == LazyBufferController::buffer_controller()); - assert(buffer.rep_.data[0] == reinterpret_cast(_buffer.handle)); - assert(buffer.rep_.data[1] == + assert(buffer.state_ == LazyBufferState::buffer_state()); + assert(buffer.context_.data[0] == + reinterpret_cast(_buffer.handle)); + assert(buffer.context_.data[1] == reinterpret_cast(_buffer.uninitialized_resize)); } return Status::OK(); } -Status LazyBuffer::dump(std::string* _string) && { - assert(controller_ != nullptr); +Status LazyBuffer::dump(std::string* _string)&& { + assert(state_ != nullptr); if (slice_.valid()) { - if (controller_ != LazyBufferController::string_controller() || - reinterpret_cast(rep_.data[0]) != _string) { + if (state_ != LazyBufferState::string_state() || + reinterpret_cast(context_.data[0]) != _string) { _string->assign(slice_.data(), slice_.size()); } else { assert(slice_.data() == _string->data()); @@ -557,20 +557,20 @@ Status LazyBuffer::dump(std::string* _string) && { } } else { LazyBuffer buffer(_string); - auto s = controller_->dump_buffer(this, &buffer); + auto s = state_->dump_buffer(this, &buffer); if (!s.ok()) { return s; } - assert(buffer.controller_ == LazyBufferController::string_controller()); - assert(reinterpret_cast(buffer.rep_.data[0]) == _string); + assert(buffer.state_ == LazyBufferState::string_state()); + assert(reinterpret_cast(buffer.context_.data[0]) == _string); } return Status::OK(); } -bool LazyBufferEditor::resize(size_t _size) { +bool LazyBufferBuilder::resize(size_t _size) { size_t old_size = slice_.valid() ? size_ : 0; - controller_->uninitialized_resize(this, _size); - if (data_ == nullptr) { + state_->uninitialized_resize(this, _size); + if (data_ == nullptr && _size > 0) { return false; } if (_size > old_size) { @@ -579,30 +579,30 @@ bool LazyBufferEditor::resize(size_t _size) { return true; } -bool LazyBufferEditor::uninitialized_resize(size_t _size) { - controller_->uninitialized_resize(this, _size); - return data_ != nullptr; +bool LazyBufferBuilder::uninitialized_resize(size_t _size) { + state_->uninitialized_resize(this, _size); + return data_ != nullptr && _size > 0; } LazyBuffer LazyBufferReference(const LazyBuffer& buffer) { if (buffer.valid()) { - return LazyBuffer(buffer.get_slice(), false, buffer.file_number()); + return LazyBuffer(buffer.slice(), false, buffer.file_number()); } else { - return LazyBuffer(LazyBufferController::reference_controller(), + return LazyBuffer(LazyBufferState::reference_state(), {reinterpret_cast(&buffer)}, Slice::Invalid(), buffer.file_number()); } } LazyBuffer LazyBufferRemoveSuffix(const LazyBuffer* buffer, size_t fixed_len) { - struct LazyBufferControllerImpl : public LazyBufferController { + struct RemoveSuffixLazyBufferState : public LazyBufferState { void destroy(LazyBuffer* /*buffer*/) const override {} Status fetch_buffer(LazyBuffer* buffer) const override { - auto rep = get_rep(buffer); + auto context = get_context(buffer); const LazyBuffer& buffer_ref = - *reinterpret_cast(rep->data[0]); - uint64_t len = rep->data[1]; + *reinterpret_cast(context->data[0]); + uint64_t len = context->data[1]; auto s = buffer_ref.fetch(); if (!s.ok()) { return s; @@ -614,13 +614,13 @@ LazyBuffer LazyBufferRemoveSuffix(const LazyBuffer* buffer, size_t fixed_len) { return s; } }; - static LazyBufferControllerImpl controller_impl; + static RemoveSuffixLazyBufferState static_state; assert(buffer != nullptr); if (buffer->valid()) { return LazyBuffer(Slice(buffer->data(), buffer->size() - fixed_len)); } else { - return LazyBuffer(&controller_impl, {reinterpret_cast(buffer), - fixed_len}, + return LazyBuffer(&static_state, {reinterpret_cast(buffer), + fixed_len}, Slice::Invalid(), uint64_t(-1)); } } diff --git a/util/lazy_buffer_test.cc b/util/lazy_buffer_test.cc index 398aa5357d3960584aaf3c4a69384dcbc870a0a5..d9ecf303a3ed0adb8557fff1b25dde07a8841d3d 100644 --- a/util/lazy_buffer_test.cc +++ b/util/lazy_buffer_test.cc @@ -20,55 +20,51 @@ TEST_F(LazyBufferTest, Basic) { LazyBuffer empty; ASSERT_OK(empty.fetch()); - ASSERT_EQ(empty.get_slice(), ""); + ASSERT_EQ(empty.slice(), ""); LazyBuffer abc("abc"); ASSERT_OK(abc.fetch()); - ASSERT_EQ(abc.get_slice(), "abc"); + ASSERT_EQ(abc.slice(), "abc"); LazyBuffer abc2(std::move(abc)); ASSERT_OK(abc2.fetch()); - ASSERT_EQ(abc2.get_slice(), "abc"); + ASSERT_EQ(abc2.slice(), "abc"); LazyBuffer abc3 = std::move(abc2); ASSERT_OK(abc3.fetch()); - ASSERT_EQ(abc3.get_slice(), "abc"); + ASSERT_EQ(abc3.slice(), "abc"); } TEST_F(LazyBufferTest, LightColtroller) { LazyBuffer buffer; - ASSERT_EQ(buffer.TEST_controller(), - LazyBufferController::light_controller()); + ASSERT_EQ(buffer.TEST_state(), LazyBufferState::light_state()); std::string string('a', 33); buffer.reset(string, false); - ASSERT_EQ(buffer.TEST_controller(), - LazyBufferController::light_controller()); + ASSERT_EQ(buffer.TEST_state(), LazyBufferState::light_state()); for (auto &c : string) { c = 'b'; }; ASSERT_OK(buffer.fetch()); - ASSERT_EQ(buffer.get_slice(), string); + ASSERT_EQ(buffer.slice(), string); buffer.reset(Slice(string.data(), 32), true); - ASSERT_EQ(buffer.TEST_controller(), - LazyBufferController::light_controller()); + ASSERT_EQ(buffer.TEST_state(), LazyBufferState::light_state()); buffer.reset(string, true); - ASSERT_EQ(buffer.TEST_controller(), - LazyBufferController::buffer_controller()); + ASSERT_EQ(buffer.TEST_state(), LazyBufferState::buffer_state()); string = "abc"; buffer.reset(string); for (auto &c : string) { c = 'a'; }; ASSERT_OK(buffer.fetch()); - ASSERT_EQ(buffer.get_slice(), "aaa"); + ASSERT_EQ(buffer.slice(), "aaa"); buffer.reset(string, true); for (auto &c : string) { c = 'b'; }; ASSERT_OK(buffer.fetch()); - ASSERT_EQ(buffer.get_slice(), "aaa"); + ASSERT_EQ(buffer.slice(), "aaa"); } @@ -76,24 +72,23 @@ TEST_F(LazyBufferTest, LightColtroller) { TEST_F(LazyBufferTest, BufferColtroller) { auto test = [](LazyBuffer& b) { - auto editor = b.get_editor(); - ASSERT_FALSE(editor->resize(size_t(-1))); - ASSERT_NOK(editor->fetch()); - ASSERT_TRUE(editor->resize(4)); - ASSERT_EQ(b.get_slice(), Slice("\0\0\0\0", 4)); - ::memcpy(editor->data(), "abcd", 4); - ASSERT_TRUE(editor->resize(3)); - ASSERT_EQ(b.get_slice(), "abc"); + auto builder = b.get_builder(); + ASSERT_FALSE(builder->resize(size_t(-1))); + ASSERT_NOK(builder->fetch()); + ASSERT_TRUE(builder->resize(4)); + ASSERT_EQ(b.slice(), Slice("\0\0\0\0", 4)); + ::memcpy(builder->data(), "abcd", 4); + ASSERT_TRUE(builder->resize(3)); + ASSERT_EQ(b.slice(), "abc"); }; LazyBuffer buffer(size_t(-1)); - ASSERT_EQ(buffer.TEST_controller(), - LazyBufferController::buffer_controller()); + ASSERT_EQ(buffer.TEST_state(), LazyBufferState::buffer_state()); ASSERT_NOK(buffer.fetch()); test(buffer); buffer.clear(); - ASSERT_EQ(buffer.TEST_controller(), - LazyBufferController::buffer_controller()); + ASSERT_EQ(buffer.TEST_state(), + LazyBufferState::buffer_state()); test(buffer); buffer = LazyBuffer("123"); @@ -121,30 +116,28 @@ TEST_F(LazyBufferTest, StringColtroller) { std::string string = "abc"; LazyBuffer buffer(&string); - ASSERT_EQ(buffer.TEST_controller(), - LazyBufferController::string_controller()); - ASSERT_EQ(buffer.get_slice(), "abc"); + ASSERT_EQ(buffer.TEST_state(), LazyBufferState::string_state()); + ASSERT_EQ(buffer.slice(), "abc"); buffer.reset("aaa", true); buffer.trans_to_string()->append("bbb"); ASSERT_OK(buffer.fetch()); - ASSERT_EQ(buffer.get_slice(), "aaabbb"); - ASSERT_EQ(buffer.TEST_rep()->data[1], 0); + ASSERT_EQ(buffer.slice(), "aaabbb"); + ASSERT_EQ(buffer.TEST_context()->data[1], 0); - buffer.get_editor()->resize(buffer.size() - 1); - ASSERT_EQ(buffer.TEST_controller(), - LazyBufferController::string_controller()); + buffer.get_builder()->resize(buffer.size() - 1); + ASSERT_EQ(buffer.TEST_state(), LazyBufferState::string_state()); ASSERT_OK(std::move(buffer).dump(&string)); ASSERT_EQ(string, "aaabb"); buffer.reset(string); buffer.trans_to_string()->resize(string.size() - 1); ASSERT_OK(std::move(buffer).dump(&string)); - ASSERT_EQ(buffer.TEST_rep()->data[1], 1); + ASSERT_EQ(buffer.TEST_context()->data[1], 1); ASSERT_EQ(string, "aaab"); buffer.reset(string); - buffer.get_editor()->resize(string.size() - 1); + buffer.get_builder()->resize(string.size() - 1); ASSERT_OK(std::move(buffer).dump(&string)); ASSERT_EQ(string, "aaa"); diff --git a/utilities/merge_operators/max.cc b/utilities/merge_operators/max.cc index 072cd36dc8d9145ff4655fd8c8aee9d991d2c19a..d08c6d9e04853c6539dc69dcee0545de46fc4ff4 100644 --- a/utilities/merge_operators/max.cc +++ b/utilities/merge_operators/max.cc @@ -36,7 +36,7 @@ class MaxOperator : public MergeOperator { max = nullptr; return true; } - if (max == nullptr || max->get_slice().compare(op.get_slice()) < 0) { + if (max == nullptr || max->slice().compare(op.slice()) < 0) { max = &op; } } @@ -52,7 +52,7 @@ class MaxOperator : public MergeOperator { if (!Fetch(left_operand, new_value) || !Fetch(right_operand, new_value)) { return true; } - if (left_operand.get_slice().compare(right_operand.get_slice()) >= 0) { + if (left_operand.slice().compare(right_operand.slice()) >= 0) { new_value->assign(left_operand); } else { new_value->assign(right_operand); @@ -70,8 +70,8 @@ class MaxOperator : public MergeOperator { if (!Fetch(operand, new_value)) { return true; } - if (max.get_slice().compare(operand.get_slice()) < 0) { - max.reset(operand.get_slice()); + if (max.slice().compare(operand.slice()) < 0) { + max.reset(operand.slice()); } } diff --git a/utilities/transactions/write_prepared_txn.cc b/utilities/transactions/write_prepared_txn.cc index 5bb7a7bc5cfb8c85a554b2bb071d7d2bdedd34d2..52a33482809545e5e8e46be92217217c0621a2b6 100644 --- a/utilities/transactions/write_prepared_txn.cc +++ b/utilities/transactions/write_prepared_txn.cc @@ -263,7 +263,7 @@ Status WritePreparedTxn::RollbackInternal() { &callback); assert(s.ok() ? lazy_val.valid() : s.IsNotFound()); if (s.ok()) { - s = rollback_batch_->Put(cf_handle, key, lazy_val.get_slice()); + s = rollback_batch_->Put(cf_handle, key, lazy_val.slice()); assert(s.ok()); } else if (s.IsNotFound()) { // There has been no readable value before txn. By adding a delete we diff --git a/utilities/transactions/write_unprepared_txn.cc b/utilities/transactions/write_unprepared_txn.cc index d6c22fb5da48bb101e227dfa205ac164ee13854c..e5a44255cd80c01d441c99e05bb7ca1989dd5a0a 100644 --- a/utilities/transactions/write_unprepared_txn.cc +++ b/utilities/transactions/write_unprepared_txn.cc @@ -386,7 +386,7 @@ Status WriteUnpreparedTxn::RollbackInternal() { &callback); if (s.ok()) { assert(lazy_val.valid()); - s = rollback_batch.Put(cf_handle, key, lazy_val.get_slice()); + s = rollback_batch.Put(cf_handle, key, lazy_val.slice()); assert(s.ok()); } else if (s.IsNotFound()) { s = rollback_batch.Delete(cf_handle, key); diff --git a/utilities/transactions/write_unprepared_txn_db.cc b/utilities/transactions/write_unprepared_txn_db.cc index cb2d51c2d41751001087a3f51c224a232f1ecda2..3c254a5cfddb284564220958efc48f241b64ae4f 100644 --- a/utilities/transactions/write_unprepared_txn_db.cc +++ b/utilities/transactions/write_unprepared_txn_db.cc @@ -78,7 +78,7 @@ Status WriteUnpreparedTxnDB::RollbackRecoveredTransaction( &callback); assert(s.ok() ? lazy_val.valid() : s.IsNotFound()); if (s.ok()) { - s = rollback_batch_->Put(cf_handle, key, lazy_val.get_slice()); + s = rollback_batch_->Put(cf_handle, key, lazy_val.slice()); assert(s.ok()); } else if (s.IsNotFound()) { // There has been no readable value before txn. By adding a delete we diff --git a/utilities/ttl/db_ttl_impl.cc b/utilities/ttl/db_ttl_impl.cc index 5349f38b99d29980d863f0edebabc219b8a5abf0..02b0c0e8740b62adabe86acd5b0b36b40a3cf7aa 100644 --- a/utilities/ttl/db_ttl_impl.cc +++ b/utilities/ttl/db_ttl_impl.cc @@ -181,9 +181,9 @@ Status DBWithTTLImpl::StripTS(LazyBuffer* lazy_val) { return Status::Corruption("Bad timestamp in key-value"); } // Erasing characters which hold the TS - auto editor = lazy_val->get_editor(); - if (!editor->resize(size - kTSLength)) { - return editor->fetch(); + auto builder = lazy_val->get_builder(); + if (!builder->resize(size - kTSLength)) { + return builder->fetch(); } return st; } @@ -214,7 +214,7 @@ Status DBWithTTLImpl::Get(const ReadOptions& options, if (!st.ok()) { return st; } - st = SanityCheckTimestamp(value->get_slice()); + st = SanityCheckTimestamp(value->slice()); if (!st.ok()) { return st; }