diff --git a/cpp/CHANGELOG.md b/cpp/CHANGELOG.md index dab772d02f032a06a986efff37f68e60317b5bc5..96745a8cdff0c54bc07ea79af096cce85a2c5ef9 100644 --- a/cpp/CHANGELOG.md +++ b/cpp/CHANGELOG.md @@ -107,6 +107,7 @@ Please mark all change in change log and use the ticket from JIRA. - MS-525 - Disable parallel reduce in SearchTask - MS-527 - Update scheduler_test and enable it - MS-528 - Hide some config used future +- MS-530 - Add unittest for SearchTask->Load ## New Feature - MS-343 - Implement ResourceMgr diff --git a/cpp/src/scheduler/task/SearchTask.cpp b/cpp/src/scheduler/task/SearchTask.cpp index 47d553292120ad77acb7cecd11757006a80f49ee..8d76075014984902992cddfa5663ecfdda966be4 100644 --- a/cpp/src/scheduler/task/SearchTask.cpp +++ b/cpp/src/scheduler/task/SearchTask.cpp @@ -96,33 +96,31 @@ XSearchTask::XSearchTask(TableFileSchemaPtr file) void XSearchTask::Load(LoadType type, uint8_t device_id) { server::TimeRecorder rc(""); + Status stat = Status::OK(); + std::string error_msg; try { if (type == LoadType::DISK2CPU) { - auto stat = index_engine_->Load(); - if(!stat.ok()) { - //typical error: file not available - ENGINE_LOG_ERROR << "Failed to load index file: file not available"; - - for(auto& context : search_contexts_) { - context->IndexSearchDone(file_->id_);//mark as done avoid dead lock, even failed - } - - return; - } + stat = index_engine_->Load(); } else if (type == LoadType::CPU2GPU) { - index_engine_->CopyToGpu(device_id); + stat = index_engine_->CopyToGpu(device_id); } else if (type == LoadType::GPU2CPU) { - index_engine_->CopyToCpu(); + stat = index_engine_->CopyToCpu(); } else { - // TODO: exception - std::string msg = "Wrong load type"; - ENGINE_LOG_ERROR << msg; + error_msg = "Wrong load type"; + stat = Status(SERVER_UNEXPECTED_ERROR, error_msg); } } catch (std::exception &ex) { //typical error: out of disk space or permition denied - std::string msg = "Failed to load index file: " + std::string(ex.what()); - ENGINE_LOG_ERROR << msg; + error_msg = "Failed to load index file: " + std::string(ex.what()); + stat = Status(SERVER_UNEXPECTED_ERROR, error_msg); + } + + if (!stat.ok()) { + if (error_msg.empty()) + error_msg = std::string("Failed to load index file: file not available"); + //typical error: file not available + ENGINE_LOG_ERROR << error_msg; for (auto &context : search_contexts_) { context->IndexSearchDone(file_->id_);//mark as done avoid dead lock, even failed @@ -241,7 +239,7 @@ Status XSearchTask::ClusterResult(const std::vector &output_ids, // if (NeedParallelReduce(nq, topk)) { // ParallelReduce(reduce_worker, nq); // } else { - reduce_worker(0, nq); + reduce_worker(0, nq); // } return Status::OK(); @@ -346,7 +344,7 @@ Status XSearchTask::TopkResult(SearchContext::ResultSet &result_src, // if (NeedParallelReduce(result_src.size(), topk)) { // ParallelReduce(ReduceWorker, result_src.size()); // } else { - ReduceWorker(0, result_src.size()); + ReduceWorker(0, result_src.size()); // } return Status::OK(); diff --git a/cpp/unittest/scheduler/normal_test.cpp b/cpp/unittest/scheduler/normal_test.cpp index bb438ab9148710a6a9fecd82172b401a7e7347d7..c679a356bd8d5435dc623a3c2ca6df181eb6539d 100644 --- a/cpp/unittest/scheduler/normal_test.cpp +++ b/cpp/unittest/scheduler/normal_test.cpp @@ -11,7 +11,7 @@ using namespace zilliz::milvus::engine; -TEST(normal_test, DISABLED_inst_test) { +TEST(normal_test, inst_test) { // ResourceMgr only compose resources, provide unified event auto res_mgr = ResMgrInst::GetInstance(); diff --git a/cpp/unittest/scheduler/task_test.cpp b/cpp/unittest/scheduler/task_test.cpp index b3c29af367c76e0fb775e4f890616f693be30f5f..f42006fc5269a839458a62df2ccdc6b2426b5674 100644 --- a/cpp/unittest/scheduler/task_test.cpp +++ b/cpp/unittest/scheduler/task_test.cpp @@ -1,4 +1,23 @@ -// -// Created by wxyu on 19-9-9. -// +/******************************************************************************* + * Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved + * Unauthorized copying of this file, via any medium is strictly prohibited. + * Proprietary and confidential. + ******************************************************************************/ +#include "scheduler/task/SearchTask.h" +#include + + +namespace zilliz { +namespace milvus { +namespace engine { + + +TEST(TaskTest, invalid_index) { + auto search_task = std::make_shared(nullptr); + search_task->Load(LoadType::TEST, 10); +} + +} +} +}