From 74e0c373d8a698e117c549059359f20c53e02ad2 Mon Sep 17 00:00:00 2001 From: yukun Date: Wed, 30 Dec 2020 10:04:40 +0800 Subject: [PATCH] restful api /collections/{collection_name}/partitions (DELETE) didn't work (#4539) Signed-off-by: fishpenguin Signed-off-by: shengjun.li --- CHANGELOG.md | 1 + core/src/server/web_impl/README.md | 13 ++++--------- .../server/web_impl/controller/WebController.hpp | 6 +++--- .../server/web_impl/handler/WebRequestHandler.cpp | 12 ++---------- 4 files changed, 10 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 389f8cb3f3..6f60709ecb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,7 @@ Please mark all changes in change log and use the issue from GitHub - \#4418 Fix search when there are multiple vector fields - \#4488 get_entity_by_id() performance is poor in 0.11.0 - \#4511 Insert should be failed if field type not matched +- \#4536 restful api /collections/{collection_name}/partitions (DELETE) didn't work ## Feature - \#4163 Update C++ sdk search interface diff --git a/core/src/server/web_impl/README.md b/core/src/server/web_impl/README.md index ee3ae44da7..f21aa72366 100644 --- a/core/src/server/web_impl/README.md +++ b/core/src/server/web_impl/README.md @@ -18,7 +18,7 @@ - [`/collections/{collection_name}/partitions` (GET)](#collectionscollection_namepartitions-get) - [`/collections/{collection_name}/partitions` (POST)](#collectionscollection_namepartitions-post) - [`/collections/{collection_name}/partitions` (OPTIONS)](#collectionscollection_namepartitions-options) - - [`/collections/{collection_name}/partitions` (DELETE)](#collectionscollection_namepartitions-delete) + - [`/collections/{collection_name}/partitions/{partition_tag}` (DELETE)](#collectionscollection_namepartitions-delete) - [`/collections/{collection_name}/segments/{segment_name}/ids` (GET)](#collectionscollection_namesegmentssegment_nameids-get) - [`/collections/{collection_name}/entities` (POST)](#collectionscollection_nameentities-post) - [`/collections/{collection_name}/entities` (DELETE)](#collectionscollection_nameentities-delete) @@ -644,7 +644,7 @@ Use this API for Cross-Origin Resource Sharing (CORS). $ curl -X OPTIONS "http://127.0.0.1:19121/collections/test_collection/partitions" ``` -### `/collections/{collection_name}/partitions` (DELETE) +### `/collections/{collection_name}/partitions/{partition_tag}` (DELETE) Deletes a partition by tag. @@ -652,13 +652,8 @@ Deletes a partition by tag. - + -
Request ComponentValue
Name
/collections/{collection_name}/partitions
Name
/collections/{collection_name}/partitions/{partition_tag}
Header
accept: application/json
Body

-{
-  "partition_tag": string
-}
-
MethodPOST
@@ -683,7 +678,7 @@ Deletes a partition by tag. ##### Request ```shell -$ curl -X DELETE "http://127.0.0.1:19121/collections/test_collection/partitions" -H "accept: application/json" -d "{\"partition_tag\": \"tags_01\"}" +$ curl -X DELETE "http://127.0.0.1:19121/collections/test_collection/partitions/test_partition" -H "accept: application/json" ``` The deletion is successful if no information is returned. diff --git a/core/src/server/web_impl/controller/WebController.hpp b/core/src/server/web_impl/controller/WebController.hpp index 693d20ab6e..90a6802725 100644 --- a/core/src/server/web_impl/controller/WebController.hpp +++ b/core/src/server/web_impl/controller/WebController.hpp @@ -529,8 +529,8 @@ class WebController : public oatpp::web::server::api::ApiController { ADD_DEFAULT_CORS(DropPartition) - ENDPOINT("DELETE", "/collections/{collection_name}/partitions", DropPartition, PATH(String, collection_name), - BODY_STRING(String, body)) { + ENDPOINT("DELETE", "/collections/{collection_name}/partitions/{partition_tag}", DropPartition, + PATH(String, collection_name), PATH(String, partition_tag)) { TimeRecorder tr(std::string(WEB_LOG_PREFIX) + "DELETE \'/collections/" + collection_name->std_str() + "/partitions\'"); tr.RecordSection("Received request."); @@ -538,7 +538,7 @@ class WebController : public oatpp::web::server::api::ApiController { auto handler = WebRequestHandler(); std::shared_ptr response; - auto status_dto = handler.DropPartition(collection_name, body); + auto status_dto = handler.DropPartition(collection_name, partition_tag); switch (*(status_dto->code)) { case StatusCode::SUCCESS: response = createDtoResponse(Status::CODE_204, status_dto); diff --git a/core/src/server/web_impl/handler/WebRequestHandler.cpp b/core/src/server/web_impl/handler/WebRequestHandler.cpp index fd8f97dff1..5bbeee116f 100644 --- a/core/src/server/web_impl/handler/WebRequestHandler.cpp +++ b/core/src/server/web_impl/handler/WebRequestHandler.cpp @@ -1495,16 +1495,8 @@ WebRequestHandler::ShowPartitions(const OString& collection_name, const OQueryPa } StatusDtoT -WebRequestHandler::DropPartition(const OString& collection_name, const OString& body) { - std::string tag; - try { - auto json = milvus::json::parse(body->std_str()); - tag = json["partition_tag"].get(); - } catch (nlohmann::detail::parse_error& e) { - RETURN_STATUS_DTO(BODY_PARSE_FAIL, e.what()) - } catch (nlohmann::detail::type_error& e) { - RETURN_STATUS_DTO(BODY_PARSE_FAIL, e.what()) - } +WebRequestHandler::DropPartition(const OString& collection_name, const OString& partition_tag) { + std::string tag = partition_tag->std_str(); auto status = req_handler_.DropPartition(context_ptr_, collection_name->std_str(), tag); ASSIGN_RETURN_STATUS_DTO(status)