From f8e6468a7b2eb6f02026840a77fa7b9e586690b3 Mon Sep 17 00:00:00 2001 From: Kishore Nallan Date: Mon, 21 Aug 2023 12:29:40 +0530 Subject: [PATCH] Better guards for top_k truncation. --- src/collection.cpp | 4 ++++ src/index.cpp | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/collection.cpp b/src/collection.cpp index 5d92b5b9..50aa82fe 100644 --- a/src/collection.cpp +++ b/src/collection.cpp @@ -4953,9 +4953,13 @@ void Collection::hide_credential(nlohmann::json& json, const std::string& creden } } Option Collection::truncate_after_top_k(const string &field_name, size_t k) { + std::shared_lock slock(mutex); + std::vector seq_ids; auto op = index->seq_ids_outside_top_k(field_name, k, seq_ids); + slock.unlock(); + if(!op.ok()) { return op; } diff --git a/src/index.cpp b/src/index.cpp index 2f8be825..84e9f6ed 100644 --- a/src/index.cpp +++ b/src/index.cpp @@ -6315,9 +6315,10 @@ size_t Index::num_seq_ids() const { Option Index::seq_ids_outside_top_k(const std::string& field_name, size_t k, std::vector& outside_seq_ids) { + std::shared_lock lock(mutex); auto field_it = numerical_index.find(field_name); - if(field_it == sort_index.end()) { + if(field_it == numerical_index.end()) { return Option(400, "Field not found in numerical index."); }