From faa2c4b4b1c4a5f13ace75d12f4a117bd86c8a6d Mon Sep 17 00:00:00 2001 From: groot Date: Sun, 5 May 2019 20:13:34 +0800 Subject: [PATCH] support empty id Former-commit-id: 1a5303b58f3f3b0154f1609ff1acc0d00007c569 --- cpp/src/server/VecServiceHandler.cpp | 19 +- cpp/src/server/VecServiceHandler.h | 20 +- cpp/src/server/VecServiceTask.cpp | 83 ++++-- cpp/src/server/VecServiceTask.h | 30 +- cpp/src/thrift/VectorService.thrift | 8 +- cpp/src/thrift/gen-cpp/VecService.cpp | 280 +++++++++++++++--- cpp/src/thrift/gen-cpp/VecService.h | 128 +++++--- .../gen-cpp/VecService_server.skeleton.cpp | 8 +- .../thrift/gen-py/zilliz/VecService-remote | 8 +- cpp/src/thrift/gen-py/zilliz/VecService.py | 116 ++++++-- cpp/test_client/src/ClientTest.cpp | 174 ++++++----- 11 files changed, 613 insertions(+), 261 deletions(-) diff --git a/cpp/src/server/VecServiceHandler.cpp b/cpp/src/server/VecServiceHandler.cpp index 66ceb1795e..de5942cd8b 100644 --- a/cpp/src/server/VecServiceHandler.cpp +++ b/cpp/src/server/VecServiceHandler.cpp @@ -74,46 +74,49 @@ VecServiceHandler::del_group(const std::string &group_id) { void -VecServiceHandler::add_vector(const std::string &group_id, const VecTensor &tensor) { +VecServiceHandler::add_vector(std::string& _return, const std::string &group_id, const VecTensor &tensor) { TimeRecordWrapper rc("add_vector()"); SERVER_LOG_TRACE << "group_id = " << group_id << ", vector size = " << tensor.tensor.size(); - BaseTaskPtr task_ptr = AddVectorTask::Create(group_id, &tensor); + BaseTaskPtr task_ptr = AddVectorTask::Create(group_id, &tensor, _return); VecServiceScheduler& scheduler = VecServiceScheduler::GetInstance(); scheduler.ExecuteTask(task_ptr); } void -VecServiceHandler::add_vector_batch(const std::string &group_id, +VecServiceHandler::add_vector_batch(std::vector & _return, + const std::string &group_id, const VecTensorList &tensor_list) { TimeRecordWrapper rc("add_vector_batch()"); SERVER_LOG_TRACE << "group_id = " << group_id << ", vector list size = " << tensor_list.tensor_list.size(); - BaseTaskPtr task_ptr = AddBatchVectorTask::Create(group_id, &tensor_list); + BaseTaskPtr task_ptr = AddBatchVectorTask::Create(group_id, &tensor_list, _return); VecServiceScheduler& scheduler = VecServiceScheduler::GetInstance(); scheduler.ExecuteTask(task_ptr); } void -VecServiceHandler::add_binary_vector(const std::string& group_id, +VecServiceHandler::add_binary_vector(std::string& _return, + const std::string& group_id, const VecBinaryTensor& tensor) { TimeRecordWrapper rc("add_binary_vector()"); SERVER_LOG_TRACE << "group_id = " << group_id << ", vector size = " << tensor.tensor.size()/4; - BaseTaskPtr task_ptr = AddVectorTask::Create(group_id, &tensor); + BaseTaskPtr task_ptr = AddVectorTask::Create(group_id, &tensor, _return); VecServiceScheduler& scheduler = VecServiceScheduler::GetInstance(); scheduler.ExecuteTask(task_ptr); } void -VecServiceHandler::add_binary_vector_batch(const std::string& group_id, +VecServiceHandler::add_binary_vector_batch(std::vector & _return, + const std::string& group_id, const VecBinaryTensorList& tensor_list) { TimeRecordWrapper rc("add_binary_vector_batch()"); SERVER_LOG_TRACE << "group_id = " << group_id << ", vector list size = " << tensor_list.tensor_list.size(); - BaseTaskPtr task_ptr = AddBatchVectorTask::Create(group_id, &tensor_list); + BaseTaskPtr task_ptr = AddBatchVectorTask::Create(group_id, &tensor_list, _return); VecServiceScheduler& scheduler = VecServiceScheduler::GetInstance(); scheduler.ExecuteTask(task_ptr); } diff --git a/cpp/src/server/VecServiceHandler.h b/cpp/src/server/VecServiceHandler.h index b1bd4e1ad4..d37376bd3c 100644 --- a/cpp/src/server/VecServiceHandler.h +++ b/cpp/src/server/VecServiceHandler.h @@ -40,19 +40,19 @@ public: void del_group(const std::string& group_id); /** - * insert vector interfaces - * - * - * @param group_id - * @param tensor - */ - void add_vector(const std::string& group_id, const VecTensor& tensor); + * insert vector interfaces + * + * + * @param group_id + * @param tensor + */ + void add_vector(std::string& _return, const std::string& group_id, const VecTensor& tensor); - void add_vector_batch(const std::string& group_id, const VecTensorList& tensor_list); + void add_vector_batch(std::vector & _return, const std::string& group_id, const VecTensorList& tensor_list); - void add_binary_vector(const std::string& group_id, const VecBinaryTensor& tensor); + void add_binary_vector(std::string& _return, const std::string& group_id, const VecBinaryTensor& tensor); - void add_binary_vector_batch(const std::string& group_id, const VecBinaryTensorList& tensor_list); + void add_binary_vector_batch(std::vector & _return, const std::string& group_id, const VecBinaryTensorList& tensor_list); /** * search interfaces diff --git a/cpp/src/server/VecServiceTask.cpp b/cpp/src/server/VecServiceTask.cpp index 888bc994e7..63e3339158 100644 --- a/cpp/src/server/VecServiceTask.cpp +++ b/cpp/src/server/VecServiceTask.cpp @@ -162,31 +162,37 @@ ServerError DeleteGroupTask::OnExecute() { //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// AddVectorTask::AddVectorTask(const std::string& group_id, - const VecTensor* tensor) + const VecTensor* tensor, + std::string& id) : BaseTask(DDL_DML_TASK_GROUP), group_id_(group_id), tensor_(tensor), - bin_tensor_(nullptr){ + bin_tensor_(nullptr), + tensor_id_(id) { } BaseTaskPtr AddVectorTask::Create(const std::string& group_id, - const VecTensor* tensor) { - return std::shared_ptr(new AddVectorTask(group_id, tensor)); + const VecTensor* tensor, + std::string& id) { + return std::shared_ptr(new AddVectorTask(group_id, tensor, id)); } AddVectorTask::AddVectorTask(const std::string& group_id, - const VecBinaryTensor* tensor) + const VecBinaryTensor* tensor, + std::string& id) : BaseTask(DDL_DML_TASK_GROUP), group_id_(group_id), tensor_(nullptr), - bin_tensor_(tensor) { + bin_tensor_(tensor), + tensor_id_(id) { } BaseTaskPtr AddVectorTask::Create(const std::string& group_id, - const VecBinaryTensor* tensor) { - return std::shared_ptr(new AddVectorTask(group_id, tensor)); + const VecBinaryTensor* tensor, + std::string& id) { + return std::shared_ptr(new AddVectorTask(group_id, tensor, id)); } @@ -265,9 +271,16 @@ ServerError AddVectorTask::OnExecute() { return SERVER_UNEXPECTED_ERROR; } else { std::string uid = GetVecID(); - std::string nid = group_id_ + "_" + std::to_string(vector_ids[0]); + std::string num_id = std::to_string(vector_ids[0]); + if(uid.empty()) { + tensor_id_ = num_id; + } else { + tensor_id_ = uid; + } + + std::string nid = group_id_ + "_" + num_id; AttribMap attrib = GetVecAttrib(); - attrib[VECTOR_UID] = uid; + attrib[VECTOR_UID] = tensor_id_; std::string attrib_str; AttributeSerializer::Encode(attrib, attrib_str); IVecIdMapper::GetInstance()->Put(nid, attrib_str); @@ -286,31 +299,39 @@ ServerError AddVectorTask::OnExecute() { //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// AddBatchVectorTask::AddBatchVectorTask(const std::string& group_id, - const VecTensorList* tensor_list) + const VecTensorList* tensor_list, + std::vector& ids) : BaseTask(DDL_DML_TASK_GROUP), group_id_(group_id), tensor_list_(tensor_list), - bin_tensor_list_(nullptr) { - + bin_tensor_list_(nullptr), + tensor_ids_(ids) { + tensor_ids_.clear(); + tensor_ids_.resize(tensor_list->tensor_list.size()); } BaseTaskPtr AddBatchVectorTask::Create(const std::string& group_id, - const VecTensorList* tensor_list) { - return std::shared_ptr(new AddBatchVectorTask(group_id, tensor_list)); + const VecTensorList* tensor_list, + std::vector& ids) { + return std::shared_ptr(new AddBatchVectorTask(group_id, tensor_list, ids)); } AddBatchVectorTask::AddBatchVectorTask(const std::string& group_id, - const VecBinaryTensorList* tensor_list) - : BaseTask(DDL_DML_TASK_GROUP), - group_id_(group_id), - tensor_list_(nullptr), - bin_tensor_list_(tensor_list) { - + const VecBinaryTensorList* tensor_list, + std::vector& ids) + : BaseTask(DDL_DML_TASK_GROUP), + group_id_(group_id), + tensor_list_(nullptr), + bin_tensor_list_(tensor_list), + tensor_ids_(ids) { + tensor_ids_.clear(); + tensor_ids_.resize(tensor_list->tensor_list.size()); } BaseTaskPtr AddBatchVectorTask::Create(const std::string& group_id, - const VecBinaryTensorList* tensor_list) { - return std::shared_ptr(new AddBatchVectorTask(group_id, tensor_list)); + const VecBinaryTensorList* tensor_list, + std::vector& ids) { + return std::shared_ptr(new AddBatchVectorTask(group_id, tensor_list, ids)); } uint64_t AddBatchVectorTask::GetVecListCount() const { @@ -379,11 +400,19 @@ const AttribMap& AddBatchVectorTask::GetVecAttrib(uint64_t index) const { } } -void AddBatchVectorTask::ProcessIdMapping(engine::IDNumbers& vector_ids, uint64_t from, uint64_t to) { +void AddBatchVectorTask::ProcessIdMapping(engine::IDNumbers& vector_ids, + uint64_t from, uint64_t to, + std::vector& tensor_ids) { std::string nid_prefix = group_id_ + "_"; for(size_t i = from; i < to; i++) { std::string uid = GetVecID(i); - std::string nid = nid_prefix + std::to_string(vector_ids[i]); + std::string num_id = std::to_string(vector_ids[i]); + if(uid.empty()) { + uid = num_id; + } + tensor_ids_[i] = uid; + + std::string nid = nid_prefix + num_id; AttribMap attrib = GetVecAttrib(i); attrib[VECTOR_UID] = uid; std::string attrib_str; @@ -437,7 +466,7 @@ ServerError AddBatchVectorTask::OnExecute() { return SERVER_UNEXPECTED_ERROR; } else { if(vec_count < USE_MT) { - ProcessIdMapping(vector_ids, 0, vec_count); + ProcessIdMapping(vector_ids, 0, vec_count, tensor_ids_); rc.Record("built id mapping"); } else { std::list> threads_list; @@ -446,7 +475,7 @@ ServerError AddBatchVectorTask::OnExecute() { while(end_index < vec_count) { threads_list.push_back( GetThreadPool().enqueue(&AddBatchVectorTask::ProcessIdMapping, - this, vector_ids, begin_index, end_index)); + this, vector_ids, begin_index, end_index, tensor_ids_)); begin_index = end_index; end_index += USE_MT; if(end_index > vec_count) { diff --git a/cpp/src/server/VecServiceTask.h b/cpp/src/server/VecServiceTask.h index f3da85eebb..f9fe2a2158 100644 --- a/cpp/src/server/VecServiceTask.h +++ b/cpp/src/server/VecServiceTask.h @@ -71,17 +71,21 @@ private: class AddVectorTask : public BaseTask { public: static BaseTaskPtr Create(const std::string& group_id, - const VecTensor* tensor); + const VecTensor* tensor, + std::string& id); static BaseTaskPtr Create(const std::string& group_id, - const VecBinaryTensor* tensor); + const VecBinaryTensor* tensor, + std::string& id); protected: AddVectorTask(const std::string& group_id, - const VecTensor* tensor); + const VecTensor* tensor, + std::string& id); AddVectorTask(const std::string& group_id, - const VecBinaryTensor* tensor); + const VecBinaryTensor* tensor, + std::string& id); uint64_t GetVecDimension() const; const double* GetVecData() const; @@ -94,6 +98,7 @@ private: std::string group_id_; const VecTensor* tensor_; const VecBinaryTensor* bin_tensor_; + std::string& tensor_id_; }; @@ -101,17 +106,21 @@ private: class AddBatchVectorTask : public BaseTask { public: static BaseTaskPtr Create(const std::string& group_id, - const VecTensorList* tensor_list); + const VecTensorList* tensor_list, + std::vector& ids); static BaseTaskPtr Create(const std::string& group_id, - const VecBinaryTensorList* tensor_list); + const VecBinaryTensorList* tensor_list, + std::vector& ids); protected: AddBatchVectorTask(const std::string& group_id, - const VecTensorList* tensor_list); + const VecTensorList* tensor_list, + std::vector& ids); AddBatchVectorTask(const std::string& group_id, - const VecBinaryTensorList* tensor_list); + const VecBinaryTensorList* tensor_list, + std::vector& ids); uint64_t GetVecListCount() const; uint64_t GetVecDimension(uint64_t index) const; @@ -119,7 +128,9 @@ protected: std::string GetVecID(uint64_t index) const; const AttribMap& GetVecAttrib(uint64_t index) const; - void ProcessIdMapping(engine::IDNumbers& vector_ids, uint64_t from, uint64_t to); + void ProcessIdMapping(engine::IDNumbers& vector_ids, + uint64_t from, uint64_t to, + std::vector& tensor_ids); ServerError OnExecute() override; @@ -127,6 +138,7 @@ private: std::string group_id_; const VecTensorList* tensor_list_; const VecBinaryTensorList* bin_tensor_list_; + std::vector& tensor_ids_; }; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/cpp/src/thrift/VectorService.thrift b/cpp/src/thrift/VectorService.thrift index fcd44879a5..47334c07df 100644 --- a/cpp/src/thrift/VectorService.thrift +++ b/cpp/src/thrift/VectorService.thrift @@ -110,10 +110,10 @@ service VecService { * insert vector interfaces * */ - void add_vector(2: string group_id, 3: VecTensor tensor) throws(1: VecException e); - void add_vector_batch(2: string group_id, 3: VecTensorList tensor_list) throws(1: VecException e); - void add_binary_vector(2: string group_id, 3: VecBinaryTensor tensor) throws(1: VecException e); - void add_binary_vector_batch(2: string group_id, 3: VecBinaryTensorList tensor_list) throws(1: VecException e); + string add_vector(2: string group_id, 3: VecTensor tensor) throws(1: VecException e); + list add_vector_batch(2: string group_id, 3: VecTensorList tensor_list) throws(1: VecException e); + string add_binary_vector(2: string group_id, 3: VecBinaryTensor tensor) throws(1: VecException e); + list add_binary_vector_batch(2: string group_id, 3: VecBinaryTensorList tensor_list) throws(1: VecException e); /** * search interfaces diff --git a/cpp/src/thrift/gen-cpp/VecService.cpp b/cpp/src/thrift/gen-cpp/VecService.cpp index 78c1021af2..0579759389 100644 --- a/cpp/src/thrift/gen-cpp/VecService.cpp +++ b/cpp/src/thrift/gen-cpp/VecService.cpp @@ -710,6 +710,14 @@ uint32_t VecService_add_vector_result::read(::apache::thrift::protocol::TProtoco } switch (fid) { + case 0: + if (ftype == ::apache::thrift::protocol::T_STRING) { + xfer += iprot->readString(this->success); + this->__isset.success = true; + } else { + xfer += iprot->skip(ftype); + } + break; case 1: if (ftype == ::apache::thrift::protocol::T_STRUCT) { xfer += this->e.read(iprot); @@ -736,7 +744,11 @@ uint32_t VecService_add_vector_result::write(::apache::thrift::protocol::TProtoc xfer += oprot->writeStructBegin("VecService_add_vector_result"); - if (this->__isset.e) { + if (this->__isset.success) { + xfer += oprot->writeFieldBegin("success", ::apache::thrift::protocol::T_STRING, 0); + xfer += oprot->writeString(this->success); + xfer += oprot->writeFieldEnd(); + } else if (this->__isset.e) { xfer += oprot->writeFieldBegin("e", ::apache::thrift::protocol::T_STRUCT, 1); xfer += this->e.write(oprot); xfer += oprot->writeFieldEnd(); @@ -772,6 +784,14 @@ uint32_t VecService_add_vector_presult::read(::apache::thrift::protocol::TProtoc } switch (fid) { + case 0: + if (ftype == ::apache::thrift::protocol::T_STRING) { + xfer += iprot->readString((*(this->success))); + this->__isset.success = true; + } else { + xfer += iprot->skip(ftype); + } + break; case 1: if (ftype == ::apache::thrift::protocol::T_STRUCT) { xfer += this->e.read(iprot); @@ -913,6 +933,26 @@ uint32_t VecService_add_vector_batch_result::read(::apache::thrift::protocol::TP } switch (fid) { + case 0: + if (ftype == ::apache::thrift::protocol::T_LIST) { + { + this->success.clear(); + uint32_t _size93; + ::apache::thrift::protocol::TType _etype96; + xfer += iprot->readListBegin(_etype96, _size93); + this->success.resize(_size93); + uint32_t _i97; + for (_i97 = 0; _i97 < _size93; ++_i97) + { + xfer += iprot->readString(this->success[_i97]); + } + xfer += iprot->readListEnd(); + } + this->__isset.success = true; + } else { + xfer += iprot->skip(ftype); + } + break; case 1: if (ftype == ::apache::thrift::protocol::T_STRUCT) { xfer += this->e.read(iprot); @@ -939,7 +979,19 @@ uint32_t VecService_add_vector_batch_result::write(::apache::thrift::protocol::T xfer += oprot->writeStructBegin("VecService_add_vector_batch_result"); - if (this->__isset.e) { + if (this->__isset.success) { + xfer += oprot->writeFieldBegin("success", ::apache::thrift::protocol::T_LIST, 0); + { + xfer += oprot->writeListBegin(::apache::thrift::protocol::T_STRING, static_cast(this->success.size())); + std::vector ::const_iterator _iter98; + for (_iter98 = this->success.begin(); _iter98 != this->success.end(); ++_iter98) + { + xfer += oprot->writeString((*_iter98)); + } + xfer += oprot->writeListEnd(); + } + xfer += oprot->writeFieldEnd(); + } else if (this->__isset.e) { xfer += oprot->writeFieldBegin("e", ::apache::thrift::protocol::T_STRUCT, 1); xfer += this->e.write(oprot); xfer += oprot->writeFieldEnd(); @@ -975,6 +1027,26 @@ uint32_t VecService_add_vector_batch_presult::read(::apache::thrift::protocol::T } switch (fid) { + case 0: + if (ftype == ::apache::thrift::protocol::T_LIST) { + { + (*(this->success)).clear(); + uint32_t _size99; + ::apache::thrift::protocol::TType _etype102; + xfer += iprot->readListBegin(_etype102, _size99); + (*(this->success)).resize(_size99); + uint32_t _i103; + for (_i103 = 0; _i103 < _size99; ++_i103) + { + xfer += iprot->readString((*(this->success))[_i103]); + } + xfer += iprot->readListEnd(); + } + this->__isset.success = true; + } else { + xfer += iprot->skip(ftype); + } + break; case 1: if (ftype == ::apache::thrift::protocol::T_STRUCT) { xfer += this->e.read(iprot); @@ -1116,6 +1188,14 @@ uint32_t VecService_add_binary_vector_result::read(::apache::thrift::protocol::T } switch (fid) { + case 0: + if (ftype == ::apache::thrift::protocol::T_STRING) { + xfer += iprot->readString(this->success); + this->__isset.success = true; + } else { + xfer += iprot->skip(ftype); + } + break; case 1: if (ftype == ::apache::thrift::protocol::T_STRUCT) { xfer += this->e.read(iprot); @@ -1142,7 +1222,11 @@ uint32_t VecService_add_binary_vector_result::write(::apache::thrift::protocol:: xfer += oprot->writeStructBegin("VecService_add_binary_vector_result"); - if (this->__isset.e) { + if (this->__isset.success) { + xfer += oprot->writeFieldBegin("success", ::apache::thrift::protocol::T_STRING, 0); + xfer += oprot->writeString(this->success); + xfer += oprot->writeFieldEnd(); + } else if (this->__isset.e) { xfer += oprot->writeFieldBegin("e", ::apache::thrift::protocol::T_STRUCT, 1); xfer += this->e.write(oprot); xfer += oprot->writeFieldEnd(); @@ -1178,6 +1262,14 @@ uint32_t VecService_add_binary_vector_presult::read(::apache::thrift::protocol:: } switch (fid) { + case 0: + if (ftype == ::apache::thrift::protocol::T_STRING) { + xfer += iprot->readString((*(this->success))); + this->__isset.success = true; + } else { + xfer += iprot->skip(ftype); + } + break; case 1: if (ftype == ::apache::thrift::protocol::T_STRUCT) { xfer += this->e.read(iprot); @@ -1319,6 +1411,26 @@ uint32_t VecService_add_binary_vector_batch_result::read(::apache::thrift::proto } switch (fid) { + case 0: + if (ftype == ::apache::thrift::protocol::T_LIST) { + { + this->success.clear(); + uint32_t _size104; + ::apache::thrift::protocol::TType _etype107; + xfer += iprot->readListBegin(_etype107, _size104); + this->success.resize(_size104); + uint32_t _i108; + for (_i108 = 0; _i108 < _size104; ++_i108) + { + xfer += iprot->readString(this->success[_i108]); + } + xfer += iprot->readListEnd(); + } + this->__isset.success = true; + } else { + xfer += iprot->skip(ftype); + } + break; case 1: if (ftype == ::apache::thrift::protocol::T_STRUCT) { xfer += this->e.read(iprot); @@ -1345,7 +1457,19 @@ uint32_t VecService_add_binary_vector_batch_result::write(::apache::thrift::prot xfer += oprot->writeStructBegin("VecService_add_binary_vector_batch_result"); - if (this->__isset.e) { + if (this->__isset.success) { + xfer += oprot->writeFieldBegin("success", ::apache::thrift::protocol::T_LIST, 0); + { + xfer += oprot->writeListBegin(::apache::thrift::protocol::T_STRING, static_cast(this->success.size())); + std::vector ::const_iterator _iter109; + for (_iter109 = this->success.begin(); _iter109 != this->success.end(); ++_iter109) + { + xfer += oprot->writeString((*_iter109)); + } + xfer += oprot->writeListEnd(); + } + xfer += oprot->writeFieldEnd(); + } else if (this->__isset.e) { xfer += oprot->writeFieldBegin("e", ::apache::thrift::protocol::T_STRUCT, 1); xfer += this->e.write(oprot); xfer += oprot->writeFieldEnd(); @@ -1381,6 +1505,26 @@ uint32_t VecService_add_binary_vector_batch_presult::read(::apache::thrift::prot } switch (fid) { + case 0: + if (ftype == ::apache::thrift::protocol::T_LIST) { + { + (*(this->success)).clear(); + uint32_t _size110; + ::apache::thrift::protocol::TType _etype113; + xfer += iprot->readListBegin(_etype113, _size110); + (*(this->success)).resize(_size110); + uint32_t _i114; + for (_i114 = 0; _i114 < _size110; ++_i114) + { + xfer += iprot->readString((*(this->success))[_i114]); + } + xfer += iprot->readListEnd(); + } + this->__isset.success = true; + } else { + xfer += iprot->skip(ftype); + } + break; case 1: if (ftype == ::apache::thrift::protocol::T_STRUCT) { xfer += this->e.read(iprot); @@ -2594,10 +2738,10 @@ void VecServiceClient::recv_del_group() return; } -void VecServiceClient::add_vector(const std::string& group_id, const VecTensor& tensor) +void VecServiceClient::add_vector(std::string& _return, const std::string& group_id, const VecTensor& tensor) { send_add_vector(group_id, tensor); - recv_add_vector(); + recv_add_vector(_return); } void VecServiceClient::send_add_vector(const std::string& group_id, const VecTensor& tensor) @@ -2615,7 +2759,7 @@ void VecServiceClient::send_add_vector(const std::string& group_id, const VecTen oprot_->getTransport()->flush(); } -void VecServiceClient::recv_add_vector() +void VecServiceClient::recv_add_vector(std::string& _return) { int32_t rseqid = 0; @@ -2641,20 +2785,25 @@ void VecServiceClient::recv_add_vector() iprot_->getTransport()->readEnd(); } VecService_add_vector_presult result; + result.success = &_return; result.read(iprot_); iprot_->readMessageEnd(); iprot_->getTransport()->readEnd(); + if (result.__isset.success) { + // _return pointer has now been filled + return; + } if (result.__isset.e) { throw result.e; } - return; + throw ::apache::thrift::TApplicationException(::apache::thrift::TApplicationException::MISSING_RESULT, "add_vector failed: unknown result"); } -void VecServiceClient::add_vector_batch(const std::string& group_id, const VecTensorList& tensor_list) +void VecServiceClient::add_vector_batch(std::vector & _return, const std::string& group_id, const VecTensorList& tensor_list) { send_add_vector_batch(group_id, tensor_list); - recv_add_vector_batch(); + recv_add_vector_batch(_return); } void VecServiceClient::send_add_vector_batch(const std::string& group_id, const VecTensorList& tensor_list) @@ -2672,7 +2821,7 @@ void VecServiceClient::send_add_vector_batch(const std::string& group_id, const oprot_->getTransport()->flush(); } -void VecServiceClient::recv_add_vector_batch() +void VecServiceClient::recv_add_vector_batch(std::vector & _return) { int32_t rseqid = 0; @@ -2698,20 +2847,25 @@ void VecServiceClient::recv_add_vector_batch() iprot_->getTransport()->readEnd(); } VecService_add_vector_batch_presult result; + result.success = &_return; result.read(iprot_); iprot_->readMessageEnd(); iprot_->getTransport()->readEnd(); + if (result.__isset.success) { + // _return pointer has now been filled + return; + } if (result.__isset.e) { throw result.e; } - return; + throw ::apache::thrift::TApplicationException(::apache::thrift::TApplicationException::MISSING_RESULT, "add_vector_batch failed: unknown result"); } -void VecServiceClient::add_binary_vector(const std::string& group_id, const VecBinaryTensor& tensor) +void VecServiceClient::add_binary_vector(std::string& _return, const std::string& group_id, const VecBinaryTensor& tensor) { send_add_binary_vector(group_id, tensor); - recv_add_binary_vector(); + recv_add_binary_vector(_return); } void VecServiceClient::send_add_binary_vector(const std::string& group_id, const VecBinaryTensor& tensor) @@ -2729,7 +2883,7 @@ void VecServiceClient::send_add_binary_vector(const std::string& group_id, const oprot_->getTransport()->flush(); } -void VecServiceClient::recv_add_binary_vector() +void VecServiceClient::recv_add_binary_vector(std::string& _return) { int32_t rseqid = 0; @@ -2755,20 +2909,25 @@ void VecServiceClient::recv_add_binary_vector() iprot_->getTransport()->readEnd(); } VecService_add_binary_vector_presult result; + result.success = &_return; result.read(iprot_); iprot_->readMessageEnd(); iprot_->getTransport()->readEnd(); + if (result.__isset.success) { + // _return pointer has now been filled + return; + } if (result.__isset.e) { throw result.e; } - return; + throw ::apache::thrift::TApplicationException(::apache::thrift::TApplicationException::MISSING_RESULT, "add_binary_vector failed: unknown result"); } -void VecServiceClient::add_binary_vector_batch(const std::string& group_id, const VecBinaryTensorList& tensor_list) +void VecServiceClient::add_binary_vector_batch(std::vector & _return, const std::string& group_id, const VecBinaryTensorList& tensor_list) { send_add_binary_vector_batch(group_id, tensor_list); - recv_add_binary_vector_batch(); + recv_add_binary_vector_batch(_return); } void VecServiceClient::send_add_binary_vector_batch(const std::string& group_id, const VecBinaryTensorList& tensor_list) @@ -2786,7 +2945,7 @@ void VecServiceClient::send_add_binary_vector_batch(const std::string& group_id, oprot_->getTransport()->flush(); } -void VecServiceClient::recv_add_binary_vector_batch() +void VecServiceClient::recv_add_binary_vector_batch(std::vector & _return) { int32_t rseqid = 0; @@ -2812,14 +2971,19 @@ void VecServiceClient::recv_add_binary_vector_batch() iprot_->getTransport()->readEnd(); } VecService_add_binary_vector_batch_presult result; + result.success = &_return; result.read(iprot_); iprot_->readMessageEnd(); iprot_->getTransport()->readEnd(); + if (result.__isset.success) { + // _return pointer has now been filled + return; + } if (result.__isset.e) { throw result.e; } - return; + throw ::apache::thrift::TApplicationException(::apache::thrift::TApplicationException::MISSING_RESULT, "add_binary_vector_batch failed: unknown result"); } void VecServiceClient::search_vector(VecSearchResult& _return, const std::string& group_id, const int64_t top_k, const VecTensor& tensor, const VecSearchFilter& filter) @@ -3289,7 +3453,8 @@ void VecServiceProcessor::process_add_vector(int32_t seqid, ::apache::thrift::pr VecService_add_vector_result result; try { - iface_->add_vector(args.group_id, args.tensor); + iface_->add_vector(result.success, args.group_id, args.tensor); + result.__isset.success = true; } catch (VecException &e) { result.e = e; result.__isset.e = true; @@ -3345,7 +3510,8 @@ void VecServiceProcessor::process_add_vector_batch(int32_t seqid, ::apache::thri VecService_add_vector_batch_result result; try { - iface_->add_vector_batch(args.group_id, args.tensor_list); + iface_->add_vector_batch(result.success, args.group_id, args.tensor_list); + result.__isset.success = true; } catch (VecException &e) { result.e = e; result.__isset.e = true; @@ -3401,7 +3567,8 @@ void VecServiceProcessor::process_add_binary_vector(int32_t seqid, ::apache::thr VecService_add_binary_vector_result result; try { - iface_->add_binary_vector(args.group_id, args.tensor); + iface_->add_binary_vector(result.success, args.group_id, args.tensor); + result.__isset.success = true; } catch (VecException &e) { result.e = e; result.__isset.e = true; @@ -3457,7 +3624,8 @@ void VecServiceProcessor::process_add_binary_vector_batch(int32_t seqid, ::apach VecService_add_binary_vector_batch_result result; try { - iface_->add_binary_vector_batch(args.group_id, args.tensor_list); + iface_->add_binary_vector_batch(result.success, args.group_id, args.tensor_list); + result.__isset.success = true; } catch (VecException &e) { result.e = e; result.__isset.e = true; @@ -3977,10 +4145,10 @@ void VecServiceConcurrentClient::recv_del_group(const int32_t seqid) } // end while(true) } -void VecServiceConcurrentClient::add_vector(const std::string& group_id, const VecTensor& tensor) +void VecServiceConcurrentClient::add_vector(std::string& _return, const std::string& group_id, const VecTensor& tensor) { int32_t seqid = send_add_vector(group_id, tensor); - recv_add_vector(seqid); + recv_add_vector(_return, seqid); } int32_t VecServiceConcurrentClient::send_add_vector(const std::string& group_id, const VecTensor& tensor) @@ -4002,7 +4170,7 @@ int32_t VecServiceConcurrentClient::send_add_vector(const std::string& group_id, return cseqid; } -void VecServiceConcurrentClient::recv_add_vector(const int32_t seqid) +void VecServiceConcurrentClient::recv_add_vector(std::string& _return, const int32_t seqid) { int32_t rseqid = 0; @@ -4041,16 +4209,22 @@ void VecServiceConcurrentClient::recv_add_vector(const int32_t seqid) throw TProtocolException(TProtocolException::INVALID_DATA); } VecService_add_vector_presult result; + result.success = &_return; result.read(iprot_); iprot_->readMessageEnd(); iprot_->getTransport()->readEnd(); + if (result.__isset.success) { + // _return pointer has now been filled + sentry.commit(); + return; + } if (result.__isset.e) { sentry.commit(); throw result.e; } - sentry.commit(); - return; + // in a bad state, don't commit + throw ::apache::thrift::TApplicationException(::apache::thrift::TApplicationException::MISSING_RESULT, "add_vector failed: unknown result"); } // seqid != rseqid this->sync_.updatePending(fname, mtype, rseqid); @@ -4060,10 +4234,10 @@ void VecServiceConcurrentClient::recv_add_vector(const int32_t seqid) } // end while(true) } -void VecServiceConcurrentClient::add_vector_batch(const std::string& group_id, const VecTensorList& tensor_list) +void VecServiceConcurrentClient::add_vector_batch(std::vector & _return, const std::string& group_id, const VecTensorList& tensor_list) { int32_t seqid = send_add_vector_batch(group_id, tensor_list); - recv_add_vector_batch(seqid); + recv_add_vector_batch(_return, seqid); } int32_t VecServiceConcurrentClient::send_add_vector_batch(const std::string& group_id, const VecTensorList& tensor_list) @@ -4085,7 +4259,7 @@ int32_t VecServiceConcurrentClient::send_add_vector_batch(const std::string& gro return cseqid; } -void VecServiceConcurrentClient::recv_add_vector_batch(const int32_t seqid) +void VecServiceConcurrentClient::recv_add_vector_batch(std::vector & _return, const int32_t seqid) { int32_t rseqid = 0; @@ -4124,16 +4298,22 @@ void VecServiceConcurrentClient::recv_add_vector_batch(const int32_t seqid) throw TProtocolException(TProtocolException::INVALID_DATA); } VecService_add_vector_batch_presult result; + result.success = &_return; result.read(iprot_); iprot_->readMessageEnd(); iprot_->getTransport()->readEnd(); + if (result.__isset.success) { + // _return pointer has now been filled + sentry.commit(); + return; + } if (result.__isset.e) { sentry.commit(); throw result.e; } - sentry.commit(); - return; + // in a bad state, don't commit + throw ::apache::thrift::TApplicationException(::apache::thrift::TApplicationException::MISSING_RESULT, "add_vector_batch failed: unknown result"); } // seqid != rseqid this->sync_.updatePending(fname, mtype, rseqid); @@ -4143,10 +4323,10 @@ void VecServiceConcurrentClient::recv_add_vector_batch(const int32_t seqid) } // end while(true) } -void VecServiceConcurrentClient::add_binary_vector(const std::string& group_id, const VecBinaryTensor& tensor) +void VecServiceConcurrentClient::add_binary_vector(std::string& _return, const std::string& group_id, const VecBinaryTensor& tensor) { int32_t seqid = send_add_binary_vector(group_id, tensor); - recv_add_binary_vector(seqid); + recv_add_binary_vector(_return, seqid); } int32_t VecServiceConcurrentClient::send_add_binary_vector(const std::string& group_id, const VecBinaryTensor& tensor) @@ -4168,7 +4348,7 @@ int32_t VecServiceConcurrentClient::send_add_binary_vector(const std::string& gr return cseqid; } -void VecServiceConcurrentClient::recv_add_binary_vector(const int32_t seqid) +void VecServiceConcurrentClient::recv_add_binary_vector(std::string& _return, const int32_t seqid) { int32_t rseqid = 0; @@ -4207,16 +4387,22 @@ void VecServiceConcurrentClient::recv_add_binary_vector(const int32_t seqid) throw TProtocolException(TProtocolException::INVALID_DATA); } VecService_add_binary_vector_presult result; + result.success = &_return; result.read(iprot_); iprot_->readMessageEnd(); iprot_->getTransport()->readEnd(); + if (result.__isset.success) { + // _return pointer has now been filled + sentry.commit(); + return; + } if (result.__isset.e) { sentry.commit(); throw result.e; } - sentry.commit(); - return; + // in a bad state, don't commit + throw ::apache::thrift::TApplicationException(::apache::thrift::TApplicationException::MISSING_RESULT, "add_binary_vector failed: unknown result"); } // seqid != rseqid this->sync_.updatePending(fname, mtype, rseqid); @@ -4226,10 +4412,10 @@ void VecServiceConcurrentClient::recv_add_binary_vector(const int32_t seqid) } // end while(true) } -void VecServiceConcurrentClient::add_binary_vector_batch(const std::string& group_id, const VecBinaryTensorList& tensor_list) +void VecServiceConcurrentClient::add_binary_vector_batch(std::vector & _return, const std::string& group_id, const VecBinaryTensorList& tensor_list) { int32_t seqid = send_add_binary_vector_batch(group_id, tensor_list); - recv_add_binary_vector_batch(seqid); + recv_add_binary_vector_batch(_return, seqid); } int32_t VecServiceConcurrentClient::send_add_binary_vector_batch(const std::string& group_id, const VecBinaryTensorList& tensor_list) @@ -4251,7 +4437,7 @@ int32_t VecServiceConcurrentClient::send_add_binary_vector_batch(const std::stri return cseqid; } -void VecServiceConcurrentClient::recv_add_binary_vector_batch(const int32_t seqid) +void VecServiceConcurrentClient::recv_add_binary_vector_batch(std::vector & _return, const int32_t seqid) { int32_t rseqid = 0; @@ -4290,16 +4476,22 @@ void VecServiceConcurrentClient::recv_add_binary_vector_batch(const int32_t seqi throw TProtocolException(TProtocolException::INVALID_DATA); } VecService_add_binary_vector_batch_presult result; + result.success = &_return; result.read(iprot_); iprot_->readMessageEnd(); iprot_->getTransport()->readEnd(); + if (result.__isset.success) { + // _return pointer has now been filled + sentry.commit(); + return; + } if (result.__isset.e) { sentry.commit(); throw result.e; } - sentry.commit(); - return; + // in a bad state, don't commit + throw ::apache::thrift::TApplicationException(::apache::thrift::TApplicationException::MISSING_RESULT, "add_binary_vector_batch failed: unknown result"); } // seqid != rseqid this->sync_.updatePending(fname, mtype, rseqid); diff --git a/cpp/src/thrift/gen-cpp/VecService.h b/cpp/src/thrift/gen-cpp/VecService.h index be30631e6a..2cfd185469 100644 --- a/cpp/src/thrift/gen-cpp/VecService.h +++ b/cpp/src/thrift/gen-cpp/VecService.h @@ -38,10 +38,10 @@ class VecServiceIf { * @param group_id * @param tensor */ - virtual void add_vector(const std::string& group_id, const VecTensor& tensor) = 0; - virtual void add_vector_batch(const std::string& group_id, const VecTensorList& tensor_list) = 0; - virtual void add_binary_vector(const std::string& group_id, const VecBinaryTensor& tensor) = 0; - virtual void add_binary_vector_batch(const std::string& group_id, const VecBinaryTensorList& tensor_list) = 0; + virtual void add_vector(std::string& _return, const std::string& group_id, const VecTensor& tensor) = 0; + virtual void add_vector_batch(std::vector & _return, const std::string& group_id, const VecTensorList& tensor_list) = 0; + virtual void add_binary_vector(std::string& _return, const std::string& group_id, const VecBinaryTensor& tensor) = 0; + virtual void add_binary_vector_batch(std::vector & _return, const std::string& group_id, const VecBinaryTensorList& tensor_list) = 0; /** * search interfaces @@ -98,16 +98,16 @@ class VecServiceNull : virtual public VecServiceIf { void del_group(const std::string& /* group_id */) { return; } - void add_vector(const std::string& /* group_id */, const VecTensor& /* tensor */) { + void add_vector(std::string& /* _return */, const std::string& /* group_id */, const VecTensor& /* tensor */) { return; } - void add_vector_batch(const std::string& /* group_id */, const VecTensorList& /* tensor_list */) { + void add_vector_batch(std::vector & /* _return */, const std::string& /* group_id */, const VecTensorList& /* tensor_list */) { return; } - void add_binary_vector(const std::string& /* group_id */, const VecBinaryTensor& /* tensor */) { + void add_binary_vector(std::string& /* _return */, const std::string& /* group_id */, const VecBinaryTensor& /* tensor */) { return; } - void add_binary_vector_batch(const std::string& /* group_id */, const VecBinaryTensorList& /* tensor_list */) { + void add_binary_vector_batch(std::vector & /* _return */, const std::string& /* group_id */, const VecBinaryTensorList& /* tensor_list */) { return; } void search_vector(VecSearchResult& /* _return */, const std::string& /* group_id */, const int64_t /* top_k */, const VecTensor& /* tensor */, const VecSearchFilter& /* filter */) { @@ -501,7 +501,8 @@ class VecService_add_vector_pargs { }; typedef struct _VecService_add_vector_result__isset { - _VecService_add_vector_result__isset() : e(false) {} + _VecService_add_vector_result__isset() : success(false), e(false) {} + bool success :1; bool e :1; } _VecService_add_vector_result__isset; @@ -510,18 +511,23 @@ class VecService_add_vector_result { VecService_add_vector_result(const VecService_add_vector_result&); VecService_add_vector_result& operator=(const VecService_add_vector_result&); - VecService_add_vector_result() { + VecService_add_vector_result() : success() { } virtual ~VecService_add_vector_result() throw(); + std::string success; VecException e; _VecService_add_vector_result__isset __isset; + void __set_success(const std::string& val); + void __set_e(const VecException& val); bool operator == (const VecService_add_vector_result & rhs) const { + if (!(success == rhs.success)) + return false; if (!(e == rhs.e)) return false; return true; @@ -538,7 +544,8 @@ class VecService_add_vector_result { }; typedef struct _VecService_add_vector_presult__isset { - _VecService_add_vector_presult__isset() : e(false) {} + _VecService_add_vector_presult__isset() : success(false), e(false) {} + bool success :1; bool e :1; } _VecService_add_vector_presult__isset; @@ -547,6 +554,7 @@ class VecService_add_vector_presult { virtual ~VecService_add_vector_presult() throw(); + std::string* success; VecException e; _VecService_add_vector_presult__isset __isset; @@ -612,7 +620,8 @@ class VecService_add_vector_batch_pargs { }; typedef struct _VecService_add_vector_batch_result__isset { - _VecService_add_vector_batch_result__isset() : e(false) {} + _VecService_add_vector_batch_result__isset() : success(false), e(false) {} + bool success :1; bool e :1; } _VecService_add_vector_batch_result__isset; @@ -625,14 +634,19 @@ class VecService_add_vector_batch_result { } virtual ~VecService_add_vector_batch_result() throw(); + std::vector success; VecException e; _VecService_add_vector_batch_result__isset __isset; + void __set_success(const std::vector & val); + void __set_e(const VecException& val); bool operator == (const VecService_add_vector_batch_result & rhs) const { + if (!(success == rhs.success)) + return false; if (!(e == rhs.e)) return false; return true; @@ -649,7 +663,8 @@ class VecService_add_vector_batch_result { }; typedef struct _VecService_add_vector_batch_presult__isset { - _VecService_add_vector_batch_presult__isset() : e(false) {} + _VecService_add_vector_batch_presult__isset() : success(false), e(false) {} + bool success :1; bool e :1; } _VecService_add_vector_batch_presult__isset; @@ -658,6 +673,7 @@ class VecService_add_vector_batch_presult { virtual ~VecService_add_vector_batch_presult() throw(); + std::vector * success; VecException e; _VecService_add_vector_batch_presult__isset __isset; @@ -723,7 +739,8 @@ class VecService_add_binary_vector_pargs { }; typedef struct _VecService_add_binary_vector_result__isset { - _VecService_add_binary_vector_result__isset() : e(false) {} + _VecService_add_binary_vector_result__isset() : success(false), e(false) {} + bool success :1; bool e :1; } _VecService_add_binary_vector_result__isset; @@ -732,18 +749,23 @@ class VecService_add_binary_vector_result { VecService_add_binary_vector_result(const VecService_add_binary_vector_result&); VecService_add_binary_vector_result& operator=(const VecService_add_binary_vector_result&); - VecService_add_binary_vector_result() { + VecService_add_binary_vector_result() : success() { } virtual ~VecService_add_binary_vector_result() throw(); + std::string success; VecException e; _VecService_add_binary_vector_result__isset __isset; + void __set_success(const std::string& val); + void __set_e(const VecException& val); bool operator == (const VecService_add_binary_vector_result & rhs) const { + if (!(success == rhs.success)) + return false; if (!(e == rhs.e)) return false; return true; @@ -760,7 +782,8 @@ class VecService_add_binary_vector_result { }; typedef struct _VecService_add_binary_vector_presult__isset { - _VecService_add_binary_vector_presult__isset() : e(false) {} + _VecService_add_binary_vector_presult__isset() : success(false), e(false) {} + bool success :1; bool e :1; } _VecService_add_binary_vector_presult__isset; @@ -769,6 +792,7 @@ class VecService_add_binary_vector_presult { virtual ~VecService_add_binary_vector_presult() throw(); + std::string* success; VecException e; _VecService_add_binary_vector_presult__isset __isset; @@ -834,7 +858,8 @@ class VecService_add_binary_vector_batch_pargs { }; typedef struct _VecService_add_binary_vector_batch_result__isset { - _VecService_add_binary_vector_batch_result__isset() : e(false) {} + _VecService_add_binary_vector_batch_result__isset() : success(false), e(false) {} + bool success :1; bool e :1; } _VecService_add_binary_vector_batch_result__isset; @@ -847,14 +872,19 @@ class VecService_add_binary_vector_batch_result { } virtual ~VecService_add_binary_vector_batch_result() throw(); + std::vector success; VecException e; _VecService_add_binary_vector_batch_result__isset __isset; + void __set_success(const std::vector & val); + void __set_e(const VecException& val); bool operator == (const VecService_add_binary_vector_batch_result & rhs) const { + if (!(success == rhs.success)) + return false; if (!(e == rhs.e)) return false; return true; @@ -871,7 +901,8 @@ class VecService_add_binary_vector_batch_result { }; typedef struct _VecService_add_binary_vector_batch_presult__isset { - _VecService_add_binary_vector_batch_presult__isset() : e(false) {} + _VecService_add_binary_vector_batch_presult__isset() : success(false), e(false) {} + bool success :1; bool e :1; } _VecService_add_binary_vector_batch_presult__isset; @@ -880,6 +911,7 @@ class VecService_add_binary_vector_batch_presult { virtual ~VecService_add_binary_vector_batch_presult() throw(); + std::vector * success; VecException e; _VecService_add_binary_vector_batch_presult__isset __isset; @@ -1454,18 +1486,18 @@ class VecServiceClient : virtual public VecServiceIf { void del_group(const std::string& group_id); void send_del_group(const std::string& group_id); void recv_del_group(); - void add_vector(const std::string& group_id, const VecTensor& tensor); + void add_vector(std::string& _return, const std::string& group_id, const VecTensor& tensor); void send_add_vector(const std::string& group_id, const VecTensor& tensor); - void recv_add_vector(); - void add_vector_batch(const std::string& group_id, const VecTensorList& tensor_list); + void recv_add_vector(std::string& _return); + void add_vector_batch(std::vector & _return, const std::string& group_id, const VecTensorList& tensor_list); void send_add_vector_batch(const std::string& group_id, const VecTensorList& tensor_list); - void recv_add_vector_batch(); - void add_binary_vector(const std::string& group_id, const VecBinaryTensor& tensor); + void recv_add_vector_batch(std::vector & _return); + void add_binary_vector(std::string& _return, const std::string& group_id, const VecBinaryTensor& tensor); void send_add_binary_vector(const std::string& group_id, const VecBinaryTensor& tensor); - void recv_add_binary_vector(); - void add_binary_vector_batch(const std::string& group_id, const VecBinaryTensorList& tensor_list); + void recv_add_binary_vector(std::string& _return); + void add_binary_vector_batch(std::vector & _return, const std::string& group_id, const VecBinaryTensorList& tensor_list); void send_add_binary_vector_batch(const std::string& group_id, const VecBinaryTensorList& tensor_list); - void recv_add_binary_vector_batch(); + void recv_add_binary_vector_batch(std::vector & _return); void search_vector(VecSearchResult& _return, const std::string& group_id, const int64_t top_k, const VecTensor& tensor, const VecSearchFilter& filter); void send_search_vector(const std::string& group_id, const int64_t top_k, const VecTensor& tensor, const VecSearchFilter& filter); void recv_search_vector(VecSearchResult& _return); @@ -1574,40 +1606,44 @@ class VecServiceMultiface : virtual public VecServiceIf { ifaces_[i]->del_group(group_id); } - void add_vector(const std::string& group_id, const VecTensor& tensor) { + void add_vector(std::string& _return, const std::string& group_id, const VecTensor& tensor) { size_t sz = ifaces_.size(); size_t i = 0; for (; i < (sz - 1); ++i) { - ifaces_[i]->add_vector(group_id, tensor); + ifaces_[i]->add_vector(_return, group_id, tensor); } - ifaces_[i]->add_vector(group_id, tensor); + ifaces_[i]->add_vector(_return, group_id, tensor); + return; } - void add_vector_batch(const std::string& group_id, const VecTensorList& tensor_list) { + void add_vector_batch(std::vector & _return, const std::string& group_id, const VecTensorList& tensor_list) { size_t sz = ifaces_.size(); size_t i = 0; for (; i < (sz - 1); ++i) { - ifaces_[i]->add_vector_batch(group_id, tensor_list); + ifaces_[i]->add_vector_batch(_return, group_id, tensor_list); } - ifaces_[i]->add_vector_batch(group_id, tensor_list); + ifaces_[i]->add_vector_batch(_return, group_id, tensor_list); + return; } - void add_binary_vector(const std::string& group_id, const VecBinaryTensor& tensor) { + void add_binary_vector(std::string& _return, const std::string& group_id, const VecBinaryTensor& tensor) { size_t sz = ifaces_.size(); size_t i = 0; for (; i < (sz - 1); ++i) { - ifaces_[i]->add_binary_vector(group_id, tensor); + ifaces_[i]->add_binary_vector(_return, group_id, tensor); } - ifaces_[i]->add_binary_vector(group_id, tensor); + ifaces_[i]->add_binary_vector(_return, group_id, tensor); + return; } - void add_binary_vector_batch(const std::string& group_id, const VecBinaryTensorList& tensor_list) { + void add_binary_vector_batch(std::vector & _return, const std::string& group_id, const VecBinaryTensorList& tensor_list) { size_t sz = ifaces_.size(); size_t i = 0; for (; i < (sz - 1); ++i) { - ifaces_[i]->add_binary_vector_batch(group_id, tensor_list); + ifaces_[i]->add_binary_vector_batch(_return, group_id, tensor_list); } - ifaces_[i]->add_binary_vector_batch(group_id, tensor_list); + ifaces_[i]->add_binary_vector_batch(_return, group_id, tensor_list); + return; } void search_vector(VecSearchResult& _return, const std::string& group_id, const int64_t top_k, const VecTensor& tensor, const VecSearchFilter& filter) { @@ -1689,18 +1725,18 @@ class VecServiceConcurrentClient : virtual public VecServiceIf { void del_group(const std::string& group_id); int32_t send_del_group(const std::string& group_id); void recv_del_group(const int32_t seqid); - void add_vector(const std::string& group_id, const VecTensor& tensor); + void add_vector(std::string& _return, const std::string& group_id, const VecTensor& tensor); int32_t send_add_vector(const std::string& group_id, const VecTensor& tensor); - void recv_add_vector(const int32_t seqid); - void add_vector_batch(const std::string& group_id, const VecTensorList& tensor_list); + void recv_add_vector(std::string& _return, const int32_t seqid); + void add_vector_batch(std::vector & _return, const std::string& group_id, const VecTensorList& tensor_list); int32_t send_add_vector_batch(const std::string& group_id, const VecTensorList& tensor_list); - void recv_add_vector_batch(const int32_t seqid); - void add_binary_vector(const std::string& group_id, const VecBinaryTensor& tensor); + void recv_add_vector_batch(std::vector & _return, const int32_t seqid); + void add_binary_vector(std::string& _return, const std::string& group_id, const VecBinaryTensor& tensor); int32_t send_add_binary_vector(const std::string& group_id, const VecBinaryTensor& tensor); - void recv_add_binary_vector(const int32_t seqid); - void add_binary_vector_batch(const std::string& group_id, const VecBinaryTensorList& tensor_list); + void recv_add_binary_vector(std::string& _return, const int32_t seqid); + void add_binary_vector_batch(std::vector & _return, const std::string& group_id, const VecBinaryTensorList& tensor_list); int32_t send_add_binary_vector_batch(const std::string& group_id, const VecBinaryTensorList& tensor_list); - void recv_add_binary_vector_batch(const int32_t seqid); + void recv_add_binary_vector_batch(std::vector & _return, const int32_t seqid); void search_vector(VecSearchResult& _return, const std::string& group_id, const int64_t top_k, const VecTensor& tensor, const VecSearchFilter& filter); int32_t send_search_vector(const std::string& group_id, const int64_t top_k, const VecTensor& tensor, const VecSearchFilter& filter); void recv_search_vector(VecSearchResult& _return, const int32_t seqid); diff --git a/cpp/src/thrift/gen-cpp/VecService_server.skeleton.cpp b/cpp/src/thrift/gen-cpp/VecService_server.skeleton.cpp index f87088d388..364743cf46 100644 --- a/cpp/src/thrift/gen-cpp/VecService_server.skeleton.cpp +++ b/cpp/src/thrift/gen-cpp/VecService_server.skeleton.cpp @@ -47,22 +47,22 @@ class VecServiceHandler : virtual public VecServiceIf { * @param group_id * @param tensor */ - void add_vector(const std::string& group_id, const VecTensor& tensor) { + void add_vector(std::string& _return, const std::string& group_id, const VecTensor& tensor) { // Your implementation goes here printf("add_vector\n"); } - void add_vector_batch(const std::string& group_id, const VecTensorList& tensor_list) { + void add_vector_batch(std::vector & _return, const std::string& group_id, const VecTensorList& tensor_list) { // Your implementation goes here printf("add_vector_batch\n"); } - void add_binary_vector(const std::string& group_id, const VecBinaryTensor& tensor) { + void add_binary_vector(std::string& _return, const std::string& group_id, const VecBinaryTensor& tensor) { // Your implementation goes here printf("add_binary_vector\n"); } - void add_binary_vector_batch(const std::string& group_id, const VecBinaryTensorList& tensor_list) { + void add_binary_vector_batch(std::vector & _return, const std::string& group_id, const VecBinaryTensorList& tensor_list) { // Your implementation goes here printf("add_binary_vector_batch\n"); } diff --git a/cpp/src/thrift/gen-py/zilliz/VecService-remote b/cpp/src/thrift/gen-py/zilliz/VecService-remote index a4732586b2..16e2b79dc6 100755 --- a/cpp/src/thrift/gen-py/zilliz/VecService-remote +++ b/cpp/src/thrift/gen-py/zilliz/VecService-remote @@ -27,10 +27,10 @@ if len(sys.argv) <= 1 or sys.argv[1] == '--help': print(' void add_group(VecGroup group)') print(' VecGroup get_group(string group_id)') print(' void del_group(string group_id)') - print(' void add_vector(string group_id, VecTensor tensor)') - print(' void add_vector_batch(string group_id, VecTensorList tensor_list)') - print(' void add_binary_vector(string group_id, VecBinaryTensor tensor)') - print(' void add_binary_vector_batch(string group_id, VecBinaryTensorList tensor_list)') + print(' string add_vector(string group_id, VecTensor tensor)') + print(' add_vector_batch(string group_id, VecTensorList tensor_list)') + print(' string add_binary_vector(string group_id, VecBinaryTensor tensor)') + print(' add_binary_vector_batch(string group_id, VecBinaryTensorList tensor_list)') print(' VecSearchResult search_vector(string group_id, i64 top_k, VecTensor tensor, VecSearchFilter filter)') print(' VecSearchResultList search_vector_batch(string group_id, i64 top_k, VecTensorList tensor_list, VecSearchFilter filter)') print(' VecSearchResult search_binary_vector(string group_id, i64 top_k, VecBinaryTensor tensor, VecSearchFilter filter)') diff --git a/cpp/src/thrift/gen-py/zilliz/VecService.py b/cpp/src/thrift/gen-py/zilliz/VecService.py index 021dadc08d..eea2c3d9e0 100644 --- a/cpp/src/thrift/gen-py/zilliz/VecService.py +++ b/cpp/src/thrift/gen-py/zilliz/VecService.py @@ -254,7 +254,7 @@ class Client(Iface): """ self.send_add_vector(group_id, tensor) - self.recv_add_vector() + return self.recv_add_vector() def send_add_vector(self, group_id, tensor): self._oprot.writeMessageBegin('add_vector', TMessageType.CALL, self._seqid) @@ -276,9 +276,11 @@ class Client(Iface): result = add_vector_result() result.read(iprot) iprot.readMessageEnd() + if result.success is not None: + return result.success if result.e is not None: raise result.e - return + raise TApplicationException(TApplicationException.MISSING_RESULT, "add_vector failed: unknown result") def add_vector_batch(self, group_id, tensor_list): """ @@ -288,7 +290,7 @@ class Client(Iface): """ self.send_add_vector_batch(group_id, tensor_list) - self.recv_add_vector_batch() + return self.recv_add_vector_batch() def send_add_vector_batch(self, group_id, tensor_list): self._oprot.writeMessageBegin('add_vector_batch', TMessageType.CALL, self._seqid) @@ -310,9 +312,11 @@ class Client(Iface): result = add_vector_batch_result() result.read(iprot) iprot.readMessageEnd() + if result.success is not None: + return result.success if result.e is not None: raise result.e - return + raise TApplicationException(TApplicationException.MISSING_RESULT, "add_vector_batch failed: unknown result") def add_binary_vector(self, group_id, tensor): """ @@ -322,7 +326,7 @@ class Client(Iface): """ self.send_add_binary_vector(group_id, tensor) - self.recv_add_binary_vector() + return self.recv_add_binary_vector() def send_add_binary_vector(self, group_id, tensor): self._oprot.writeMessageBegin('add_binary_vector', TMessageType.CALL, self._seqid) @@ -344,9 +348,11 @@ class Client(Iface): result = add_binary_vector_result() result.read(iprot) iprot.readMessageEnd() + if result.success is not None: + return result.success if result.e is not None: raise result.e - return + raise TApplicationException(TApplicationException.MISSING_RESULT, "add_binary_vector failed: unknown result") def add_binary_vector_batch(self, group_id, tensor_list): """ @@ -356,7 +362,7 @@ class Client(Iface): """ self.send_add_binary_vector_batch(group_id, tensor_list) - self.recv_add_binary_vector_batch() + return self.recv_add_binary_vector_batch() def send_add_binary_vector_batch(self, group_id, tensor_list): self._oprot.writeMessageBegin('add_binary_vector_batch', TMessageType.CALL, self._seqid) @@ -378,9 +384,11 @@ class Client(Iface): result = add_binary_vector_batch_result() result.read(iprot) iprot.readMessageEnd() + if result.success is not None: + return result.success if result.e is not None: raise result.e - return + raise TApplicationException(TApplicationException.MISSING_RESULT, "add_binary_vector_batch failed: unknown result") def search_vector(self, group_id, top_k, tensor, filter): """ @@ -665,7 +673,7 @@ class Processor(Iface, TProcessor): iprot.readMessageEnd() result = add_vector_result() try: - self._handler.add_vector(args.group_id, args.tensor) + result.success = self._handler.add_vector(args.group_id, args.tensor) msg_type = TMessageType.REPLY except TTransport.TTransportException: raise @@ -691,7 +699,7 @@ class Processor(Iface, TProcessor): iprot.readMessageEnd() result = add_vector_batch_result() try: - self._handler.add_vector_batch(args.group_id, args.tensor_list) + result.success = self._handler.add_vector_batch(args.group_id, args.tensor_list) msg_type = TMessageType.REPLY except TTransport.TTransportException: raise @@ -717,7 +725,7 @@ class Processor(Iface, TProcessor): iprot.readMessageEnd() result = add_binary_vector_result() try: - self._handler.add_binary_vector(args.group_id, args.tensor) + result.success = self._handler.add_binary_vector(args.group_id, args.tensor) msg_type = TMessageType.REPLY except TTransport.TTransportException: raise @@ -743,7 +751,7 @@ class Processor(Iface, TProcessor): iprot.readMessageEnd() result = add_binary_vector_batch_result() try: - self._handler.add_binary_vector_batch(args.group_id, args.tensor_list) + result.success = self._handler.add_binary_vector_batch(args.group_id, args.tensor_list) msg_type = TMessageType.REPLY except TTransport.TTransportException: raise @@ -1340,12 +1348,14 @@ add_vector_args.thrift_spec = ( class add_vector_result(object): """ Attributes: + - success - e """ - def __init__(self, e=None,): + def __init__(self, success=None, e=None,): + self.success = success self.e = e def read(self, iprot): @@ -1357,7 +1367,12 @@ class add_vector_result(object): (fname, ftype, fid) = iprot.readFieldBegin() if ftype == TType.STOP: break - if fid == 1: + if fid == 0: + if ftype == TType.STRING: + self.success = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + else: + iprot.skip(ftype) + elif fid == 1: if ftype == TType.STRUCT: self.e = VecException() self.e.read(iprot) @@ -1373,6 +1388,10 @@ class add_vector_result(object): oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec])) return oprot.writeStructBegin('add_vector_result') + if self.success is not None: + oprot.writeFieldBegin('success', TType.STRING, 0) + oprot.writeString(self.success.encode('utf-8') if sys.version_info[0] == 2 else self.success) + oprot.writeFieldEnd() if self.e is not None: oprot.writeFieldBegin('e', TType.STRUCT, 1) self.e.write(oprot) @@ -1395,7 +1414,7 @@ class add_vector_result(object): return not (self == other) all_structs.append(add_vector_result) add_vector_result.thrift_spec = ( - None, # 0 + (0, TType.STRING, 'success', 'UTF8', None, ), # 0 (1, TType.STRUCT, 'e', [VecException, None], None, ), # 1 ) @@ -1479,12 +1498,14 @@ add_vector_batch_args.thrift_spec = ( class add_vector_batch_result(object): """ Attributes: + - success - e """ - def __init__(self, e=None,): + def __init__(self, success=None, e=None,): + self.success = success self.e = e def read(self, iprot): @@ -1496,7 +1517,17 @@ class add_vector_batch_result(object): (fname, ftype, fid) = iprot.readFieldBegin() if ftype == TType.STOP: break - if fid == 1: + if fid == 0: + if ftype == TType.LIST: + self.success = [] + (_etype81, _size78) = iprot.readListBegin() + for _i82 in range(_size78): + _elem83 = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + self.success.append(_elem83) + iprot.readListEnd() + else: + iprot.skip(ftype) + elif fid == 1: if ftype == TType.STRUCT: self.e = VecException() self.e.read(iprot) @@ -1512,6 +1543,13 @@ class add_vector_batch_result(object): oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec])) return oprot.writeStructBegin('add_vector_batch_result') + if self.success is not None: + oprot.writeFieldBegin('success', TType.LIST, 0) + oprot.writeListBegin(TType.STRING, len(self.success)) + for iter84 in self.success: + oprot.writeString(iter84.encode('utf-8') if sys.version_info[0] == 2 else iter84) + oprot.writeListEnd() + oprot.writeFieldEnd() if self.e is not None: oprot.writeFieldBegin('e', TType.STRUCT, 1) self.e.write(oprot) @@ -1534,7 +1572,7 @@ class add_vector_batch_result(object): return not (self == other) all_structs.append(add_vector_batch_result) add_vector_batch_result.thrift_spec = ( - None, # 0 + (0, TType.LIST, 'success', (TType.STRING, 'UTF8', False), None, ), # 0 (1, TType.STRUCT, 'e', [VecException, None], None, ), # 1 ) @@ -1618,12 +1656,14 @@ add_binary_vector_args.thrift_spec = ( class add_binary_vector_result(object): """ Attributes: + - success - e """ - def __init__(self, e=None,): + def __init__(self, success=None, e=None,): + self.success = success self.e = e def read(self, iprot): @@ -1635,7 +1675,12 @@ class add_binary_vector_result(object): (fname, ftype, fid) = iprot.readFieldBegin() if ftype == TType.STOP: break - if fid == 1: + if fid == 0: + if ftype == TType.STRING: + self.success = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + else: + iprot.skip(ftype) + elif fid == 1: if ftype == TType.STRUCT: self.e = VecException() self.e.read(iprot) @@ -1651,6 +1696,10 @@ class add_binary_vector_result(object): oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec])) return oprot.writeStructBegin('add_binary_vector_result') + if self.success is not None: + oprot.writeFieldBegin('success', TType.STRING, 0) + oprot.writeString(self.success.encode('utf-8') if sys.version_info[0] == 2 else self.success) + oprot.writeFieldEnd() if self.e is not None: oprot.writeFieldBegin('e', TType.STRUCT, 1) self.e.write(oprot) @@ -1673,7 +1722,7 @@ class add_binary_vector_result(object): return not (self == other) all_structs.append(add_binary_vector_result) add_binary_vector_result.thrift_spec = ( - None, # 0 + (0, TType.STRING, 'success', 'UTF8', None, ), # 0 (1, TType.STRUCT, 'e', [VecException, None], None, ), # 1 ) @@ -1757,12 +1806,14 @@ add_binary_vector_batch_args.thrift_spec = ( class add_binary_vector_batch_result(object): """ Attributes: + - success - e """ - def __init__(self, e=None,): + def __init__(self, success=None, e=None,): + self.success = success self.e = e def read(self, iprot): @@ -1774,7 +1825,17 @@ class add_binary_vector_batch_result(object): (fname, ftype, fid) = iprot.readFieldBegin() if ftype == TType.STOP: break - if fid == 1: + if fid == 0: + if ftype == TType.LIST: + self.success = [] + (_etype88, _size85) = iprot.readListBegin() + for _i89 in range(_size85): + _elem90 = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + self.success.append(_elem90) + iprot.readListEnd() + else: + iprot.skip(ftype) + elif fid == 1: if ftype == TType.STRUCT: self.e = VecException() self.e.read(iprot) @@ -1790,6 +1851,13 @@ class add_binary_vector_batch_result(object): oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec])) return oprot.writeStructBegin('add_binary_vector_batch_result') + if self.success is not None: + oprot.writeFieldBegin('success', TType.LIST, 0) + oprot.writeListBegin(TType.STRING, len(self.success)) + for iter91 in self.success: + oprot.writeString(iter91.encode('utf-8') if sys.version_info[0] == 2 else iter91) + oprot.writeListEnd() + oprot.writeFieldEnd() if self.e is not None: oprot.writeFieldBegin('e', TType.STRUCT, 1) self.e.write(oprot) @@ -1812,7 +1880,7 @@ class add_binary_vector_batch_result(object): return not (self == other) all_structs.append(add_binary_vector_batch_result) add_binary_vector_batch_result.thrift_spec = ( - None, # 0 + (0, TType.LIST, 'success', (TType.STRING, 'UTF8', False), None, ), # 0 (1, TType.STRUCT, 'e', [VecException, None], None, ), # 1 ) diff --git a/cpp/test_client/src/ClientTest.cpp b/cpp/test_client/src/ClientTest.cpp index f06f284b6b..ee1707c00d 100644 --- a/cpp/test_client/src/ClientTest.cpp +++ b/cpp/test_client/src/ClientTest.cpp @@ -21,6 +21,7 @@ using namespace zilliz::vecwise::client; namespace { static const int32_t VEC_DIMENSION = 256; + static const int64_t BATCH_COUNT = 1000; static const std::string TEST_ATTRIB_NUM = "number"; static const std::string TEST_ATTRIB_COMMENT = "comment"; @@ -94,14 +95,14 @@ namespace { if(tensor_list) { tensor.uid = "normal_vec_" + std::to_string(k); - attrib_map[TEST_ATTRIB_COMMENT] = tensor.uid; + attrib_map[TEST_ATTRIB_COMMENT] = "this is vector " + tensor.uid; tensor.__set_attrib(attrib_map); tensor_list->tensor_list.emplace_back(tensor); } if(bin_tensor_list) { bin_tensor.uid = "binary_vec_" + std::to_string(k); - attrib_map[TEST_ATTRIB_COMMENT] = bin_tensor.uid; + attrib_map[TEST_ATTRIB_COMMENT] = "this is binary vector " + bin_tensor.uid; bin_tensor.__set_attrib(attrib_map); bin_tensor_list->tensor_list.emplace_back(bin_tensor); } @@ -116,55 +117,56 @@ namespace { } } -void ClientTest::LoopTest() { - server::TimeRecorder rc("LoopTest"); - - std::string address, protocol; - int32_t port = 0; - GetServerAddress(address, port, protocol); - client::ClientSession session(address, port, protocol); - - rc.Record("connection"); - - //add group - VecGroup group; - group.id = "loop_group"; - group.dimension = VEC_DIMENSION; - group.index_type = 0; - session.interface()->add_group(group); - rc.Record("add group"); - - const int64_t batch = 10000; - for(int64_t i = 0; i < 1000; i++) { - { - VecBinaryTensorList bin_tensor_list; - BuildVectors(i * batch, (i + 1) * batch, nullptr, &bin_tensor_list); - rc.Record("build batch no." + std::to_string(i)); - - session.interface()->add_binary_vector_batch(group.id, bin_tensor_list); - rc.Record("add batch no." + std::to_string(i)); - } - - sleep(1); - rc.Record("sleep 1 second"); - - VecTensor tensor; - for (int32_t k = 0; k < VEC_DIMENSION; k++) { - tensor.tensor.push_back((double) (k + i*666)); - } - - //do search - VecSearchResult res; - VecSearchFilter filter; - session.interface()->search_vector(res, group.id, 10, tensor, filter); - rc.Record("search finish"); - - std::cout << "Search result: " << std::endl; - for(VecSearchResultItem& item : res.result_list) { - std::cout << "\t" << item.uid << std::endl; - } - } -} +//void ClientTest::LoopTest() { +// server::TimeRecorder rc("LoopTest"); +// +// std::string address, protocol; +// int32_t port = 0; +// GetServerAddress(address, port, protocol); +// client::ClientSession session(address, port, protocol); +// +// rc.Record("connection"); +// +// //add group +// VecGroup group; +// group.id = "loop_group"; +// group.dimension = VEC_DIMENSION; +// group.index_type = 0; +// session.interface()->add_group(group); +// rc.Record("add group"); +// +// const int64_t batch = 10000; +// for(int64_t i = 0; i < 1000; i++) { +// { +// VecBinaryTensorList bin_tensor_list; +// BuildVectors(i * batch, (i + 1) * batch, nullptr, &bin_tensor_list); +// rc.Record("build batch no." + std::to_string(i)); +// +// std::vector ids; +// session.interface()->add_binary_vector_batch(ids, group.id, bin_tensor_list); +// rc.Record("add batch no." + std::to_string(i)); +// } +// +// sleep(1); +// rc.Record("sleep 1 second"); +// +// VecTensor tensor; +// for (int32_t k = 0; k < VEC_DIMENSION; k++) { +// tensor.tensor.push_back((double) (k + i*666)); +// } +// +// //do search +// VecSearchResult res; +// VecSearchFilter filter; +// session.interface()->search_vector(res, group.id, 10, tensor, filter); +// rc.Record("search finish"); +// +// std::cout << "Search result: " << std::endl; +// for(VecSearchResultItem& item : res.result_list) { +// std::cout << "\t" << item.uid << std::endl; +// } +// } +//} TEST(AddVector, CLIENT_TEST) { try { @@ -182,47 +184,57 @@ TEST(AddVector, CLIENT_TEST) { //prepare data CLIENT_LOG_INFO << "Preparing vectors..."; - const int64_t count = 100000; - VecTensorList tensor_list; - VecBinaryTensorList bin_tensor_list; - BuildVectors(0, count, &tensor_list, &bin_tensor_list); - -// //add vectors one by one -// { -// server::TimeRecorder rc("Add " + std::to_string(count) + " vectors one by one"); -// for (int64_t k = 0; k < count; k++) { -// session.interface()->add_vector(group.id, tensor_list.tensor_list[k]); -// if (k % 1000 == 0) { -// CLIENT_LOG_INFO << "add normal vector no." << k; -// } -// } -// rc.Elapse("done!"); -// } -// -// //add vectors in one batch -// { -// server::TimeRecorder rc("Add " + std::to_string(count) + " vectors in one batch"); -// session.interface()->add_vector_batch(group.id, tensor_list); -// rc.Elapse("done!"); -// } + const int64_t count = BATCH_COUNT; + VecTensorList tensor_list_1, tensor_list_2; + VecBinaryTensorList bin_tensor_list_1, bin_tensor_list_2; + BuildVectors(0, count, &tensor_list_1, &bin_tensor_list_1); + BuildVectors(count, count*2, &tensor_list_2, &bin_tensor_list_2); #if 0 + //add vectors one by one + { + server::TimeRecorder rc("Add " + std::to_string(count) + " vectors one by one"); + for (int64_t k = 0; k < count; k++) { + std::string id; + tensor_list_1.tensor_list[k].uid = ""; + session.interface()->add_vector(id, group.id, tensor_list_1.tensor_list[k]); + if (k % 1000 == 0) { + CLIENT_LOG_INFO << "add normal vector no." << k; + } + ASSERT_TRUE(!id.empty()); + } + rc.Elapse("done!"); + } + + //add vectors in one batch + { + server::TimeRecorder rc("Add " + std::to_string(count) + " vectors in one batch"); + std::vector ids; + session.interface()->add_vector_batch(ids, group.id, tensor_list_2); + rc.Elapse("done!"); + } + +#else //add binary vectors one by one { server::TimeRecorder rc("Add " + std::to_string(count) + " binary vectors one by one"); for (int64_t k = 0; k < count; k++) { - session.interface()->add_binary_vector(group.id, bin_tensor_list.tensor_list[k]); + std::string id; + bin_tensor_list_1.tensor_list[k].uid = ""; + session.interface()->add_binary_vector(id, group.id, bin_tensor_list_1.tensor_list[k]); if (k % 1000 == 0) { CLIENT_LOG_INFO << "add binary vector no." << k; } + ASSERT_TRUE(!id.empty()); } rc.Elapse("done!"); } -#else + //add binary vectors in one batch { server::TimeRecorder rc("Add " + std::to_string(count) + " binary vectors in one batch"); - session.interface()->add_binary_vector_batch(group.id, bin_tensor_list); + std::vector ids; + session.interface()->add_binary_vector_batch(ids, group.id, bin_tensor_list_2); rc.Elapse("done!"); } #endif @@ -274,13 +286,13 @@ TEST(SearchVector, CLIENT_TEST) { ASSERT_TRUE(item.attrib.count(TEST_ATTRIB_NUM) != 0); ASSERT_TRUE(item.attrib.count(TEST_ATTRIB_COMMENT) != 0); - ASSERT_TRUE(item.attrib[TEST_ATTRIB_COMMENT].find(item.uid) != std::string::npos); + ASSERT_TRUE(!item.attrib[TEST_ATTRIB_COMMENT].empty()); } rc.Elapse("done!"); ASSERT_EQ(res.result_list.size(), (uint64_t)top_k); if(!res.result_list.empty()) { - ASSERT_TRUE(res.result_list[0].uid.find(std::to_string(anchor_index)) != std::string::npos); + ASSERT_TRUE(!res.result_list[0].uid.empty()); } //empty search @@ -297,7 +309,7 @@ TEST(SearchVector, CLIENT_TEST) { //search binary vector { - const int32_t anchor_index = 300; + const int32_t anchor_index = BATCH_COUNT + 200; const int32_t search_count = 10; const int64_t top_k = 5; server::TimeRecorder rc("Search binary batch top_k"); @@ -324,7 +336,7 @@ TEST(SearchVector, CLIENT_TEST) { std::cout << "\t" << item.uid << std::endl; ASSERT_TRUE(item.attrib.count(TEST_ATTRIB_NUM) != 0); ASSERT_TRUE(item.attrib.count(TEST_ATTRIB_COMMENT) != 0); - ASSERT_TRUE(item.attrib[TEST_ATTRIB_COMMENT].find(item.uid) != std::string::npos); + ASSERT_TRUE(!item.attrib[TEST_ATTRIB_COMMENT].empty()); } }