提交 a21ad0b7 编写于 作者: G groot

fix task bug


Former-commit-id: f5debab3ff1c4000596f4cf625f37ba83ec54296
上级 a2780a90
...@@ -72,11 +72,15 @@ ServerError AddGroupTask::OnExecute() { ...@@ -72,11 +72,15 @@ ServerError AddGroupTask::OnExecute() {
engine::Status stat = DB()->add_group(group_info); engine::Status stat = DB()->add_group(group_info);
if(!stat.ok()) { if(!stat.ok()) {
SERVER_LOG_ERROR << "Engine failed: " << stat.ToString(); SERVER_LOG_ERROR << "Engine failed: " << stat.ToString();
return SERVER_UNEXPECTED_ERROR;
} }
} catch (std::exception& ex) { } catch (std::exception& ex) {
SERVER_LOG_ERROR << ex.what(); SERVER_LOG_ERROR << ex.what();
return SERVER_UNEXPECTED_ERROR;
} }
return SERVER_SUCCESS;
} }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
...@@ -100,13 +104,17 @@ ServerError GetGroupTask::OnExecute() { ...@@ -100,13 +104,17 @@ ServerError GetGroupTask::OnExecute() {
engine::Status stat = DB()->get_group(group_info); engine::Status stat = DB()->get_group(group_info);
if(!stat.ok()) { if(!stat.ok()) {
SERVER_LOG_ERROR << "Engine failed: " << stat.ToString(); SERVER_LOG_ERROR << "Engine failed: " << stat.ToString();
return SERVER_UNEXPECTED_ERROR;
} else { } else {
dimension_ = (int32_t)group_info.dimension; dimension_ = (int32_t)group_info.dimension;
} }
} catch (std::exception& ex) { } catch (std::exception& ex) {
SERVER_LOG_ERROR << ex.what(); SERVER_LOG_ERROR << ex.what();
return SERVER_UNEXPECTED_ERROR;
} }
return SERVER_SUCCESS;
} }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
...@@ -127,6 +135,8 @@ ServerError DeleteGroupTask::OnExecute() { ...@@ -127,6 +135,8 @@ ServerError DeleteGroupTask::OnExecute() {
} catch (std::exception& ex) { } catch (std::exception& ex) {
SERVER_LOG_ERROR << ex.what(); SERVER_LOG_ERROR << ex.what();
} }
return SERVER_SUCCESS;
} }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
...@@ -150,9 +160,11 @@ ServerError AddSingleVectorTask::OnExecute() { ...@@ -150,9 +160,11 @@ ServerError AddSingleVectorTask::OnExecute() {
engine::Status stat = DB()->add_vectors(group_id_, 1, vec_f.data(), vector_ids); engine::Status stat = DB()->add_vectors(group_id_, 1, vec_f.data(), vector_ids);
if(!stat.ok()) { if(!stat.ok()) {
SERVER_LOG_ERROR << "Engine failed: " << stat.ToString(); SERVER_LOG_ERROR << "Engine failed: " << stat.ToString();
return SERVER_UNEXPECTED_ERROR;
} else { } else {
if(vector_ids.empty()) { if(vector_ids.empty()) {
SERVER_LOG_ERROR << "Vector ID not returned"; SERVER_LOG_ERROR << "Vector ID not returned";
return SERVER_UNEXPECTED_ERROR;
} else { } else {
std::string nid = group_id_ + "_" + std::to_string(vector_ids[0]); std::string nid = group_id_ + "_" + std::to_string(vector_ids[0]);
IVecIdMapper::GetInstance()->Put(nid, tensor_.uid); IVecIdMapper::GetInstance()->Put(nid, tensor_.uid);
...@@ -162,7 +174,10 @@ ServerError AddSingleVectorTask::OnExecute() { ...@@ -162,7 +174,10 @@ ServerError AddSingleVectorTask::OnExecute() {
} catch (std::exception& ex) { } catch (std::exception& ex) {
SERVER_LOG_ERROR << ex.what(); SERVER_LOG_ERROR << ex.what();
return SERVER_UNEXPECTED_ERROR;
} }
return SERVER_SUCCESS;
} }
...@@ -192,16 +207,23 @@ ServerError AddBatchVectorTask::OnExecute() { ...@@ -192,16 +207,23 @@ ServerError AddBatchVectorTask::OnExecute() {
return SERVER_UNEXPECTED_ERROR; return SERVER_UNEXPECTED_ERROR;
} }
uint64_t vec_dim = group_info.dimension;
uint64_t vec_count = tensor_list_.tensor_list.size();
std::vector<float> vec_f; std::vector<float> vec_f;
vec_f.reserve(tensor_list_.tensor_list.size()*group_info.dimension*4); vec_f.resize(vec_count*vec_dim);//allocate enough memory
for(const VecTensor& tensor : tensor_list_.tensor_list) { for(uint64_t i = 0; i < vec_count; i ++) {
if(tensor.tensor.size() != group_info.dimension) { const std::vector<double>& tensor = tensor_list_.tensor_list[i].tensor;
SERVER_LOG_ERROR << "Invalid vector data size: " << tensor.tensor.size() if(tensor.size() != group_info.dimension) {
<< " vs. group dimension:" << group_info.dimension; SERVER_LOG_ERROR << "Invalid vector data size: " << tensor.size()
<< " vs. group dimension:" << group_info.dimension;
return SERVER_UNEXPECTED_ERROR; 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"); rc.Record("prepare vectors data");
engine::IDNumbers vector_ids; engine::IDNumbers vector_ids;
...@@ -212,6 +234,7 @@ ServerError AddBatchVectorTask::OnExecute() { ...@@ -212,6 +234,7 @@ ServerError AddBatchVectorTask::OnExecute() {
} else { } else {
if(vector_ids.size() < tensor_list_.tensor_list.size()) { if(vector_ids.size() < tensor_list_.tensor_list.size()) {
SERVER_LOG_ERROR << "Vector ID not returned"; SERVER_LOG_ERROR << "Vector ID not returned";
return SERVER_UNEXPECTED_ERROR;
} else { } else {
std::string nid_prefix = group_id_ + "_"; std::string nid_prefix = group_id_ + "_";
for(size_t i = 0; i < tensor_list_.tensor_list.size(); i++) { for(size_t i = 0; i < tensor_list_.tensor_list.size(); i++) {
...@@ -224,7 +247,10 @@ ServerError AddBatchVectorTask::OnExecute() { ...@@ -224,7 +247,10 @@ ServerError AddBatchVectorTask::OnExecute() {
} catch (std::exception& ex) { } catch (std::exception& ex) {
SERVER_LOG_ERROR << ex.what(); SERVER_LOG_ERROR << ex.what();
return SERVER_UNEXPECTED_ERROR;
} }
return SERVER_SUCCESS;
} }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
...@@ -261,6 +287,7 @@ ServerError SearchVectorTask::OnExecute() { ...@@ -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); engine::Status stat = DB()->search(group_id_, (size_t)top_k_, tensor_list_.tensor_list.size(), vec_f.data(), results);
if(!stat.ok()) { if(!stat.ok()) {
SERVER_LOG_ERROR << "Engine failed: " << stat.ToString(); SERVER_LOG_ERROR << "Engine failed: " << stat.ToString();
return SERVER_UNEXPECTED_ERROR;
} else { } else {
for(engine::QueryResult& res : results){ for(engine::QueryResult& res : results){
VecSearchResult v_res; VecSearchResult v_res;
...@@ -282,7 +309,10 @@ ServerError SearchVectorTask::OnExecute() { ...@@ -282,7 +309,10 @@ ServerError SearchVectorTask::OnExecute() {
} catch (std::exception& ex) { } catch (std::exception& ex) {
SERVER_LOG_ERROR << ex.what(); SERVER_LOG_ERROR << ex.what();
return SERVER_UNEXPECTED_ERROR;
} }
return SERVER_SUCCESS;
} }
} }
......
...@@ -9,10 +9,27 @@ ...@@ -9,10 +9,27 @@
#include "server/ServerConfig.h" #include "server/ServerConfig.h"
#include "Log.h" #include "Log.h"
#include <time.h>
namespace zilliz { namespace zilliz {
namespace vecwise { namespace vecwise {
namespace client { 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) { void ClientApp::Run(const std::string &config_file) {
server::ServerConfig& config = server::ServerConfig::GetInstance(); server::ServerConfig& config = server::ServerConfig::GetInstance();
config.LoadConfigFile(config_file); config.LoadConfigFile(config_file);
...@@ -33,7 +50,7 @@ void ClientApp::Run(const std::string &config_file) { ...@@ -33,7 +50,7 @@ void ClientApp::Run(const std::string &config_file) {
//add group //add group
const int32_t dim = 256; const int32_t dim = 256;
VecGroup group; VecGroup group;
group.id = "test_group"; group.id = CurrentTime();
group.dimension = dim; group.dimension = dim;
group.index_type = 0; group.index_type = 0;
session.interface()->add_group(group); session.interface()->add_group(group);
...@@ -73,6 +90,8 @@ void ClientApp::Run(const std::string &config_file) { ...@@ -73,6 +90,8 @@ void ClientApp::Run(const std::string &config_file) {
rc.Elapse("done!"); rc.Elapse("done!");
} }
sleep(20);
//search vector //search vector
{ {
server::TimeRecorder rc("Search top_k"); server::TimeRecorder rc("Search top_k");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册