From db790a39cf733bbcf1256206d5a8103a445197f1 Mon Sep 17 00:00:00 2001 From: Vladislav Oleshko Date: Wed, 19 Nov 2025 13:22:41 +0300 Subject: [PATCH] fix(server): Move LpGetView to core target --- src/core/detail/listpack_wrap.cc | 14 ++++++++++---- src/core/detail/listpack_wrap.h | 3 +++ src/server/container_utils.cc | 7 ------- src/server/container_utils.h | 3 --- src/server/rdb_load.cc | 4 ++-- 5 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/core/detail/listpack_wrap.cc b/src/core/detail/listpack_wrap.cc index 3f261dace8ef..e08bdfa5caff 100644 --- a/src/core/detail/listpack_wrap.cc +++ b/src/core/detail/listpack_wrap.cc @@ -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" @@ -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_); } @@ -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(elem), size_t(ele_len)}; +} + bool ListpackWrap::Iterator::operator==(const Iterator& other) const { return lp_ == other.lp_ && ptr_ == other.ptr_; } diff --git a/src/core/detail/listpack_wrap.h b/src/core/detail/listpack_wrap.h index 7c009251307e..de11dd0874c6 100644 --- a/src/core/detail/listpack_wrap.h +++ b/src/core/detail/listpack_wrap.h @@ -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 diff --git a/src/server/container_utils.cc b/src/server/container_utils.cc index 541cd041b019..95529eef7239 100644 --- a/src/server/container_utils.cc +++ b/src/server/container_utils.cc @@ -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(elem), size_t(ele_len)}; -} - OpResult RunCbOnFirstNonEmptyBlocking(Transaction* trans, int req_obj_type, BlockingResultCb func, unsigned limit_ms, bool* block_flag, bool* pause_flag) { diff --git a/src/server/container_utils.h b/src/server/container_utils.h index 5eeb9dc0bc38..9177bce328be 100644 --- a/src/server/container_utils.h +++ b/src/server/container_utils.h @@ -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; diff --git a/src/server/rdb_load.cc b/src/server/rdb_load.cc index 883e4e3e6fc8..cfec42a73b45 100644 --- a/src/server/rdb_load.cc +++ b/src/server/rdb_load.cc @@ -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" @@ -893,7 +893,7 @@ void RdbLoaderBase::OpaqueObjLoader::HandleBlob(string_view blob) { StringSet* set = CompactObj::AllocateMR(); 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);