diff --git a/CHANGELOG.md b/CHANGELOG.md index aed0e3ad55..be60dce72a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ Please mark all change in change log and use the issue from GitHub - \#2194 Fix get collection info failed - \#2196 Fix server start failed if wal is disabled - \#2203 0.8.0 id=-1 is returned when total count < topk +- \#2228 Fix show partitions failed in http module - \#2231 Use server_config to define hard-delete delay time for segment files - \#2261 Re-define result returned by has_collection if collection in delete state diff --git a/core/src/server/web_impl/component/AppComponent.hpp b/core/src/server/web_impl/component/AppComponent.hpp index 6b04c51ae7..b4af0dab22 100644 --- a/core/src/server/web_impl/component/AppComponent.hpp +++ b/core/src/server/web_impl/component/AppComponent.hpp @@ -17,8 +17,8 @@ #include #include #include -#include #include +#include #include #include diff --git a/core/src/server/web_impl/handler/WebRequestHandler.cpp b/core/src/server/web_impl/handler/WebRequestHandler.cpp index 8571e66188..0b5f536bd6 100644 --- a/core/src/server/web_impl/handler/WebRequestHandler.cpp +++ b/core/src/server/web_impl/handler/WebRequestHandler.cpp @@ -1457,7 +1457,35 @@ WebRequestHandler::ShowSegments(const OString& collection_name, const OQueryPara ASSIGN_RETURN_STATUS_DTO(status) } - nlohmann::json result_json = nlohmann::json::parse(info); + nlohmann::json info_json = nlohmann::json::parse(info); + nlohmann::json segments_json = nlohmann::json::array(); + for (auto& par : info_json["partitions"]) { + if (!(all_required || tag.empty() || tag == par["tag"])) { + continue; + } + + auto segments = par["segments"]; + if (!segments.is_null()) { + for (auto& seg : segments) { + seg["partition_tag"] = par["tag"]; + segments_json.push_back(seg); + } + } + } + nlohmann::json result_json; + if (!all_required) { + int64_t size = segments_json.size(); + int iter_begin = std::min(size, offset); + int iter_end = std::min(size, offset + page_size); + + nlohmann::json segments_slice_json = nlohmann::json::array(); + segments_slice_json.insert(segments_slice_json.begin(), segments_json.begin() + iter_begin, + segments_json.begin() + iter_end); + result_json["segments"] = segments_slice_json; // segments_json; + } else { + result_json["segments"] = segments_json; + } + result_json["count"] = segments_json.size(); AddStatusToJson(result_json, status.code(), status.message()); response = result_json.dump().c_str(); @@ -1535,9 +1563,14 @@ WebRequestHandler::Insert(const OString& collection_name, const OString& body, V } auto& id_array = vectors.id_array_; id_array.clear(); - for (auto& id_str : ids_json) { - int64_t id = std::stol(id_str.get()); - id_array.emplace_back(id); + try { + for (auto& id_str : ids_json) { + int64_t id = std::stol(id_str.get()); + id_array.emplace_back(id); + } + } catch (std::exception& e) { + std::string err_msg = std::string("Cannot convert vectors id. details: ") + e.what(); + RETURN_STATUS_DTO(SERVER_UNEXPECTED_ERROR, err_msg.c_str()); } } diff --git a/core/thirdparty/versions.txt b/core/thirdparty/versions.txt index ad1ba3e299..ba5adc8cf9 100644 --- a/core/thirdparty/versions.txt +++ b/core/thirdparty/versions.txt @@ -11,7 +11,7 @@ GRPC_VERSION=master ZLIB_VERSION=v1.2.11 OPENTRACING_VERSION=v1.5.1 FIU_VERSION=1.00 -OATPP_VERSION=1.0.0 +OATPP_VERSION=1.0.1 AWS_VERSION=1.7.250 # vim: set filetype=sh: diff --git a/core/unittest/server/test_web.cpp b/core/unittest/server/test_web.cpp index 7135909730..02e0e38b98 100644 --- a/core/unittest/server/test_web.cpp +++ b/core/unittest/server/test_web.cpp @@ -1026,11 +1026,12 @@ TEST_F(WebControllerTest, SHOW_SEGMENTS) { std::string json_str = response->readBodyToString()->c_str(); auto result_json = nlohmann::json::parse(json_str); - ASSERT_TRUE(result_json.contains("row_count")); - - ASSERT_TRUE(result_json.contains("partitions")); - auto segments_json = result_json["partitions"]; + ASSERT_TRUE(result_json.contains("count")); + ASSERT_TRUE(result_json.contains("segments")); + auto segments_json = result_json["segments"]; ASSERT_TRUE(segments_json.is_array()); + auto seg0_json = segments_json[0]; + ASSERT_TRUE(seg0_json.contains("partition_tag")); // ASSERT_EQ(10, segments_json.size()); } @@ -1049,7 +1050,7 @@ TEST_F(WebControllerTest, GET_SEGMENT_INFO) { std::string json_str = response->readBodyToString()->c_str(); auto result_json = nlohmann::json::parse(json_str); - auto segment0_json = result_json["partitions"][0]["segments"][0]; + auto segment0_json = result_json["segments"][0]; std::string segment_name = segment0_json["name"]; // get segment ids @@ -1104,15 +1105,15 @@ TEST_F(WebControllerTest, SEGMENT_FILTER) { std::string json_str = response->readBodyToString()->c_str(); auto result_json = nlohmann::json::parse(json_str); - ASSERT_TRUE(result_json.contains("row_count")); + ASSERT_TRUE(result_json.contains("count")); - ASSERT_TRUE(result_json.contains("partitions")); - auto partitions_json = result_json["partitions"]; - ASSERT_TRUE(partitions_json.is_array()); - for (auto& part : partitions_json) { - ASSERT_TRUE(part.contains("tag")); + ASSERT_TRUE(result_json.contains("segments")); + auto segments_json = result_json["segments"]; + ASSERT_TRUE(segments_json.is_array()); + for (auto& part : segments_json) { + ASSERT_TRUE(part.contains("partition_tag")); } - ASSERT_EQ("_default", partitions_json[0]["tag"].get()); + ASSERT_EQ("_default", segments_json[0]["partition_tag"].get()); } TEST_F(WebControllerTest, SEARCH) {