Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/core/detail/listpack_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//
#include "core/detail/listpack_wrap.h"

#include "server/container_utils.h"
#include "base/logging.h"

extern "C" {
#include "redis/listpack.h"
Expand All @@ -27,10 +27,9 @@ void ListpackWrap::Iterator::Read() {
if (!ptr_)
return;

using container_utils::LpGetView;
key_v_ = LpGetView(ptr_, intbuf_[0]);
key_v_ = GetView(ptr_, intbuf_[0]);
next_ptr_ = lpNext(lp_, ptr_);
value_v_ = LpGetView(next_ptr_, intbuf_[1]);
value_v_ = GetView(next_ptr_, intbuf_[1]);
next_ptr_ = lpNext(lp_, next_ptr_);
}

Expand Down Expand Up @@ -115,6 +114,13 @@ ListpackWrap::Iterator ListpackWrap::end() const {
return Iterator{lp_, nullptr, intbuf_};
}

std::string_view ListpackWrap::GetView(uint8_t* lp_it, uint8_t int_buf[]) {
int64_t ele_len = 0;
uint8_t* elem = lpGet(lp_it, &ele_len, int_buf);
DCHECK(elem);
return std::string_view{reinterpret_cast<char*>(elem), size_t(ele_len)};
}

bool ListpackWrap::Iterator::operator==(const Iterator& other) const {
return lp_ == other.lp_ && ptr_ == other.ptr_;
}
Expand Down
3 changes: 3 additions & 0 deletions src/core/detail/listpack_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ struct ListpackWrap {
Iterator end() const;
size_t size() const; // number of entries

// Get view from raw listpack iterator
static std::string_view GetView(uint8_t* lp_it, uint8_t int_buf[]);

private:
uint8_t* lp_; // the listpack itself
mutable IntBuf intbuf_; // buffer for integers decoded to strings
Expand Down
7 changes: 0 additions & 7 deletions src/server/container_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,6 @@ StringMap* GetStringMap(const PrimeValue& pv, const DbContext& db_context) {
return res;
}

string_view LpGetView(uint8_t* lp_it, uint8_t int_buf[]) {
int64_t ele_len = 0;
uint8_t* elem = lpGet(lp_it, &ele_len, int_buf);
DCHECK(elem);
return std::string_view{reinterpret_cast<char*>(elem), size_t(ele_len)};
}

OpResult<string> RunCbOnFirstNonEmptyBlocking(Transaction* trans, int req_obj_type,
BlockingResultCb func, unsigned limit_ms,
bool* block_flag, bool* pause_flag) {
Expand Down
3 changes: 0 additions & 3 deletions src/server/container_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ bool IterateMap(const PrimeValue& pv, const IterateKVFunc& func);
// Get StringMap pointer from primetable value. Sets expire time from db_context
StringMap* GetStringMap(const PrimeValue& pv, const DbContext& db_context);

// Get string_view from listpack poiner. Intbuf to store integer values as strings.
std::string_view LpGetView(uint8_t* lp_it, uint8_t int_buf[]);

using BlockingResultCb =
std::function<void(Transaction*, EngineShard*, std::string_view /* key */)>;

Expand Down
4 changes: 2 additions & 2 deletions src/server/rdb_load.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ extern "C" {
#include "base/flags.h"
#include "base/logging.h"
#include "core/bloom.h"
#include "core/detail/listpack_wrap.h"
#include "core/json/json_object.h"
#include "core/qlist.h"
#include "core/sorted_map.h"
#include "core/string_map.h"
#include "core/string_set.h"
#include "server/cluster/cluster_config.h"
#include "server/container_utils.h"
#include "server/engine_shard_set.h"
#include "server/error.h"
#include "server/family_utils.h"
Expand Down Expand Up @@ -893,7 +893,7 @@ void RdbLoaderBase::OpaqueObjLoader::HandleBlob(string_view blob) {
StringSet* set = CompactObj::AllocateMR<StringSet>();
for (unsigned char* cur = lpFirst(lp); cur != nullptr; cur = lpNext(lp, cur)) {
unsigned char field_buf[LP_INTBUF_SIZE];
string_view elem = container_utils::LpGetView(cur, field_buf);
string_view elem = detail::ListpackWrap::GetView(cur, field_buf);
if (!set->Add(elem)) {
LOG(ERROR) << "Duplicate member " << elem;
ec_ = RdbError(errc::duplicate_key);
Expand Down
Loading