diff --git a/cpp/CHANGELOG.md b/cpp/CHANGELOG.md index cbcc6b2786..08cd89d6de 100644 --- a/cpp/CHANGELOG.md +++ b/cpp/CHANGELOG.md @@ -18,6 +18,7 @@ Please mark all change in change log and use the ticket from JIRA. - MS-443 - Create index hang again - MS-436 - Delete vectors failed if index created with index_type: IVF_FLAT/IVF_SQ8 - MS-450 - server hang after run stop_server.sh +- MS-449 - Add vectors twice success, once with ids, the other no ids ## Improvement - MS-327 - Clean code for milvus diff --git a/cpp/src/db/Utils.cpp b/cpp/src/db/Utils.cpp index 61675b9dc3..efe238d86f 100644 --- a/cpp/src/db/Utils.cpp +++ b/cpp/src/db/Utils.cpp @@ -152,10 +152,6 @@ bool IsSameIndex(const TableIndex& index1, const TableIndex& index2) { && index1.metric_type_ == index2.metric_type_; } -bool UserDefinedId(int64_t flag) { - return flag & meta::FLAG_MASK_USERID; -} - meta::DateT GetDate(const std::time_t& t, int day_delta) { struct tm ltm; localtime_r(&t, <m); diff --git a/cpp/src/db/Utils.h b/cpp/src/db/Utils.h index d2b8a751f1..2094250a1f 100644 --- a/cpp/src/db/Utils.h +++ b/cpp/src/db/Utils.h @@ -28,8 +28,6 @@ Status DeleteTableFilePath(const DBMetaOptions& options, meta::TableFileSchema& bool IsSameIndex(const TableIndex& index1, const TableIndex& index2); -bool UserDefinedId(int64_t flag); - meta::DateT GetDate(const std::time_t &t, int day_delta = 0); meta::DateT GetDate(); meta::DateT GetDateWithDelta(int day_delta); diff --git a/cpp/src/db/meta/MetaTypes.h b/cpp/src/db/meta/MetaTypes.h index e4c68decbc..e31be40ddc 100644 --- a/cpp/src/db/meta/MetaTypes.h +++ b/cpp/src/db/meta/MetaTypes.h @@ -22,7 +22,8 @@ constexpr int32_t DEFAULT_NLIST = 16384; constexpr int32_t DEFAULT_METRIC_TYPE = (int)MetricType::L2; constexpr int32_t DEFAULT_INDEX_FILE_SIZE = ONE_GB; -constexpr int64_t FLAG_MASK_USERID = 1; +constexpr int64_t FLAG_MASK_NO_USERID = 0x1; +constexpr int64_t FLAG_MASK_HAS_USERID = 0x1<<1; typedef int DateT; const DateT EmptyDate = -1; diff --git a/cpp/src/server/grpc_impl/GrpcRequestTask.cpp b/cpp/src/server/grpc_impl/GrpcRequestTask.cpp index 12390256af..1b9bc935fa 100644 --- a/cpp/src/server/grpc_impl/GrpcRequestTask.cpp +++ b/cpp/src/server/grpc_impl/GrpcRequestTask.cpp @@ -457,21 +457,17 @@ InsertTask::OnExecute() { } } + //step 3: check table flag //all user provide id, or all internal id - uint64_t row_count = 0; - DBWrapper::DB()->GetTableRowCount(table_info.table_id_, row_count); - bool empty_table = (row_count == 0); bool user_provide_ids = !insert_param_->row_id_array().empty(); - if(!empty_table) { - //user already provided id before, all insert action require user id - if(engine::utils::UserDefinedId(table_info.flag_) && !user_provide_ids) { - return SetError(SERVER_INVALID_ARGUMENT, "Table vector ids are user defined, please provide id for this batch"); - } + //user already provided id before, all insert action require user id + if((table_info.flag_ & engine::meta::FLAG_MASK_HAS_USERID) && !user_provide_ids) { + return SetError(SERVER_INVALID_ARGUMENT, "Table vector ids are user defined, please provide id for this batch"); + } - //user didn't provided id before, no need to provide user id - if(!engine::utils::UserDefinedId(table_info.flag_) && user_provide_ids) { - return SetError(SERVER_INVALID_ARGUMENT, "Table vector ids are auto generated, no need to provide id for this batch"); - } + //user didn't provided id before, no need to provide user id + if((table_info.flag_ & engine::meta::FLAG_MASK_NO_USERID) && user_provide_ids) { + return SetError(SERVER_INVALID_ARGUMENT, "Table vector ids are auto generated, no need to provide id for this batch"); } rc.RecordSection("check validation"); @@ -482,7 +478,7 @@ InsertTask::OnExecute() { ProfilerStart(fname.c_str()); #endif - //step 3: prepare float data + //step 4: prepare float data std::vector vec_f(insert_param_->row_record_array_size() * table_info.dimension_, 0); // TODO: change to one dimension array in protobuf or use multiple-thread to copy the data @@ -505,7 +501,7 @@ InsertTask::OnExecute() { rc.ElapseFromBegin("prepare vectors data"); - //step 4: insert vectors + //step 5: insert vectors auto vec_count = (uint64_t) insert_param_->row_record_array_size(); std::vector vec_ids(insert_param_->row_id_array_size(), 0); if(!insert_param_->row_id_array().empty()) { @@ -530,11 +526,10 @@ InsertTask::OnExecute() { return SetError(SERVER_ILLEGAL_VECTOR_ID, msg); } - //step 5: update table flag - if(empty_table && user_provide_ids) { - stat = DBWrapper::DB()->UpdateTableFlag(insert_param_->table_name(), - table_info.flag_ | engine::meta::FLAG_MASK_USERID); - } + //step 6: update table flag + user_provide_ids ? table_info.flag_ |= engine::meta::FLAG_MASK_HAS_USERID + : table_info.flag_ |= engine::meta::FLAG_MASK_NO_USERID; + stat = DBWrapper::DB()->UpdateTableFlag(insert_param_->table_name(), table_info.flag_); #ifdef MILVUS_ENABLE_PROFILING ProfilerStop();