From decdfdae1082e93506242b308b8de2e81052f9ab Mon Sep 17 00:00:00 2001 From: Chun Han <116052805+MrPresent-Han@users.noreply.github.com> Date: Tue, 17 Dec 2024 08:05:12 -0500 Subject: [PATCH] fix: growing-groupby-crush(#38533) (#38538) related: #38533 Signed-off-by: MrPresent-Han Co-authored-by: MrPresent-Han --- .../src/exec/operator/groupby/SearchGroupByOperator.h | 8 +++++--- internal/core/src/mmap/ChunkVector.h | 10 +++++++++- internal/core/src/segcore/ConcurrentVector.h | 5 +++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/internal/core/src/exec/operator/groupby/SearchGroupByOperator.h b/internal/core/src/exec/operator/groupby/SearchGroupByOperator.h index 80116de12be3a..481080902a4fa 100644 --- a/internal/core/src/exec/operator/groupby/SearchGroupByOperator.h +++ b/internal/core/src/exec/operator/groupby/SearchGroupByOperator.h @@ -51,10 +51,12 @@ class GrowingDataGetter : public DataGetter { T Get(int64_t idx) const { if constexpr (std::is_same_v) { - return T(growing_raw_data_->view_element(idx)); - } else { - return growing_raw_data_->operator[](idx); + if (growing_raw_data_->is_mmap()) { + // when scalar data is mapped, it's needed to get the scalar data view and reconstruct string from the view + return T(growing_raw_data_->view_element(idx)); + } } + return growing_raw_data_->operator[](idx); } }; diff --git a/internal/core/src/mmap/ChunkVector.h b/internal/core/src/mmap/ChunkVector.h index cc485b238fddb..74341195c8edc 100644 --- a/internal/core/src/mmap/ChunkVector.h +++ b/internal/core/src/mmap/ChunkVector.h @@ -47,6 +47,9 @@ class ChunkVectorBase { virtual SpanBase get_span(int64_t chunk_id) = 0; + virtual bool + is_mmap() const = 0; + protected: std::atomic counter_ = 0; }; @@ -107,7 +110,7 @@ class ThreadSafeChunkVector : public ChunkVectorBase { ChunkViewType view_element(int64_t chunk_id, int64_t chunk_offset) override { std::shared_lock lck(mutex_); - auto chunk = vec_[chunk_id]; + auto& chunk = vec_[chunk_id]; if constexpr (IsMmap) { return chunk.view(chunk_offset); } else if constexpr (std::is_same_v) { @@ -184,6 +187,11 @@ class ThreadSafeChunkVector : public ChunkVectorBase { } } + bool + is_mmap() const override { + return mmap_descriptor_ != nullptr; + } + private: mutable std::shared_mutex mutex_; storage::MmapChunkDescriptorPtr mmap_descriptor_ = nullptr; diff --git a/internal/core/src/segcore/ConcurrentVector.h b/internal/core/src/segcore/ConcurrentVector.h index 484ff7d293c04..67675e4515276 100644 --- a/internal/core/src/segcore/ConcurrentVector.h +++ b/internal/core/src/segcore/ConcurrentVector.h @@ -318,6 +318,11 @@ class ConcurrentVectorImpl : public VectorBase { chunks_ptr_->clear(); } + bool + is_mmap() const { + return chunks_ptr_->is_mmap(); + } + private: void set_data(ssize_t element_offset,