From a21ad0b7432a524800fb3cca33c1cb2df885a02c Mon Sep 17 00:00:00 2001 From: groot Date: Fri, 26 Apr 2019 15:37:10 +0800 Subject: [PATCH] fix task bug Former-commit-id: f5debab3ff1c4000596f4cf625f37ba83ec54296 --- cpp/src/server/VecServiceTask.cpp | 42 ++++++++++++++++++++++++++----- cpp/test_client/src/ClientApp.cpp | 21 +++++++++++++++- 2 files changed, 56 insertions(+), 7 deletions(-) diff --git a/cpp/src/server/VecServiceTask.cpp b/cpp/src/server/VecServiceTask.cpp index b5c0f4c6..0739817c 100644 --- a/cpp/src/server/VecServiceTask.cpp +++ b/cpp/src/server/VecServiceTask.cpp @@ -72,11 +72,15 @@ ServerError AddGroupTask::OnExecute() { engine::Status stat = DB()->add_group(group_info); if(!stat.ok()) { SERVER_LOG_ERROR << "Engine failed: " << stat.ToString(); + return SERVER_UNEXPECTED_ERROR; } } catch (std::exception& ex) { SERVER_LOG_ERROR << ex.what(); + return SERVER_UNEXPECTED_ERROR; } + + return SERVER_SUCCESS; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -100,13 +104,17 @@ ServerError GetGroupTask::OnExecute() { engine::Status stat = DB()->get_group(group_info); if(!stat.ok()) { SERVER_LOG_ERROR << "Engine failed: " << stat.ToString(); + return SERVER_UNEXPECTED_ERROR; } else { dimension_ = (int32_t)group_info.dimension; } } catch (std::exception& ex) { SERVER_LOG_ERROR << ex.what(); + return SERVER_UNEXPECTED_ERROR; } + + return SERVER_SUCCESS; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -127,6 +135,8 @@ ServerError DeleteGroupTask::OnExecute() { } catch (std::exception& ex) { SERVER_LOG_ERROR << ex.what(); } + + return SERVER_SUCCESS; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -150,9 +160,11 @@ ServerError AddSingleVectorTask::OnExecute() { engine::Status stat = DB()->add_vectors(group_id_, 1, vec_f.data(), vector_ids); if(!stat.ok()) { SERVER_LOG_ERROR << "Engine failed: " << stat.ToString(); + return SERVER_UNEXPECTED_ERROR; } else { if(vector_ids.empty()) { SERVER_LOG_ERROR << "Vector ID not returned"; + return SERVER_UNEXPECTED_ERROR; } else { std::string nid = group_id_ + "_" + std::to_string(vector_ids[0]); IVecIdMapper::GetInstance()->Put(nid, tensor_.uid); @@ -162,7 +174,10 @@ ServerError AddSingleVectorTask::OnExecute() { } catch (std::exception& ex) { SERVER_LOG_ERROR << ex.what(); + return SERVER_UNEXPECTED_ERROR; } + + return SERVER_SUCCESS; } @@ -192,16 +207,23 @@ ServerError AddBatchVectorTask::OnExecute() { return SERVER_UNEXPECTED_ERROR; } + uint64_t vec_dim = group_info.dimension; + uint64_t vec_count = tensor_list_.tensor_list.size(); std::vector vec_f; - vec_f.reserve(tensor_list_.tensor_list.size()*group_info.dimension*4); - for(const VecTensor& tensor : tensor_list_.tensor_list) { - if(tensor.tensor.size() != group_info.dimension) { - SERVER_LOG_ERROR << "Invalid vector data size: " << tensor.tensor.size() - << " vs. group dimension:" << group_info.dimension; + vec_f.resize(vec_count*vec_dim);//allocate enough memory + for(uint64_t i = 0; i < vec_count; i ++) { + const std::vector& tensor = tensor_list_.tensor_list[i].tensor; + if(tensor.size() != group_info.dimension) { + SERVER_LOG_ERROR << "Invalid vector data size: " << tensor.size() + << " vs. group dimension:" << group_info.dimension; return SERVER_UNEXPECTED_ERROR; } - vec_f.insert(vec_f.begin(), tensor.tensor.begin(), tensor.tensor.end()); + + for(uint64_t d = 0; d < vec_dim; d++) { + vec_f[i*vec_dim + d] = (float)(tensor[d]); + } } + rc.Record("prepare vectors data"); engine::IDNumbers vector_ids; @@ -212,6 +234,7 @@ ServerError AddBatchVectorTask::OnExecute() { } else { if(vector_ids.size() < tensor_list_.tensor_list.size()) { SERVER_LOG_ERROR << "Vector ID not returned"; + return SERVER_UNEXPECTED_ERROR; } else { std::string nid_prefix = group_id_ + "_"; for(size_t i = 0; i < tensor_list_.tensor_list.size(); i++) { @@ -224,7 +247,10 @@ ServerError AddBatchVectorTask::OnExecute() { } catch (std::exception& ex) { SERVER_LOG_ERROR << ex.what(); + return SERVER_UNEXPECTED_ERROR; } + + return SERVER_SUCCESS; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -261,6 +287,7 @@ ServerError SearchVectorTask::OnExecute() { engine::Status stat = DB()->search(group_id_, (size_t)top_k_, tensor_list_.tensor_list.size(), vec_f.data(), results); if(!stat.ok()) { SERVER_LOG_ERROR << "Engine failed: " << stat.ToString(); + return SERVER_UNEXPECTED_ERROR; } else { for(engine::QueryResult& res : results){ VecSearchResult v_res; @@ -282,7 +309,10 @@ ServerError SearchVectorTask::OnExecute() { } catch (std::exception& ex) { SERVER_LOG_ERROR << ex.what(); + return SERVER_UNEXPECTED_ERROR; } + + return SERVER_SUCCESS; } } diff --git a/cpp/test_client/src/ClientApp.cpp b/cpp/test_client/src/ClientApp.cpp index b951908e..6b1b89c0 100644 --- a/cpp/test_client/src/ClientApp.cpp +++ b/cpp/test_client/src/ClientApp.cpp @@ -9,10 +9,27 @@ #include "server/ServerConfig.h" #include "Log.h" +#include + namespace zilliz { namespace vecwise { namespace client { +namespace { + std::string CurrentTime() { + time_t tt; + time( &tt ); + tt = tt + 8*3600; + tm* t= gmtime( &tt ); + + std::string str = std::to_string(t->tm_year + 1900) + "_" + std::to_string(t->tm_mon + 1) + + "_" + std::to_string(t->tm_mday) + "_" + std::to_string(t->tm_hour) + + "_" + std::to_string(t->tm_min) + "_" + std::to_string(t->tm_sec); + + return str; + } +} + void ClientApp::Run(const std::string &config_file) { server::ServerConfig& config = server::ServerConfig::GetInstance(); config.LoadConfigFile(config_file); @@ -33,7 +50,7 @@ void ClientApp::Run(const std::string &config_file) { //add group const int32_t dim = 256; VecGroup group; - group.id = "test_group"; + group.id = CurrentTime(); group.dimension = dim; group.index_type = 0; session.interface()->add_group(group); @@ -73,6 +90,8 @@ void ClientApp::Run(const std::string &config_file) { rc.Elapse("done!"); } + sleep(20); + //search vector { server::TimeRecorder rc("Search top_k"); -- GitLab