Merge branch 'branch-0.3.1' into 'branch-0.3.1'

MS-207 build_index return success when table not existed

See merge request megasearch/milvus!213

Former-commit-id: 9c981e423fd3d2664518f8904a0f5bc4694c04b4
This commit is contained in:
peng.xu 2019-07-15 15:24:15 +08:00
commit dae5e256b1
4 changed files with 35 additions and 28 deletions

View File

@ -19,6 +19,7 @@ enum class EngineType {
FAISS_IDMAP = 1, FAISS_IDMAP = 1,
FAISS_IVFFLAT, FAISS_IVFFLAT,
FAISS_IVFSQ8, FAISS_IVFSQ8,
MAX_VALUE = FAISS_IVFSQ8,
}; };
class ExecutionEngine { class ExecutionEngine {

View File

@ -148,17 +148,17 @@ ServerError CreateTableTask::OnExecute() {
ServerError res = SERVER_SUCCESS; ServerError res = SERVER_SUCCESS;
res = ValidateTableName(schema_.table_name); res = ValidateTableName(schema_.table_name);
if(res != SERVER_SUCCESS) { if(res != SERVER_SUCCESS) {
return res; return SetError(res, "Invalid table name: " + schema_.table_name);
} }
res = ValidateTableDimension(schema_.dimension); res = ValidateTableDimension(schema_.dimension);
if(res != SERVER_SUCCESS) { if(res != SERVER_SUCCESS) {
return res; return SetError(res, "Invalid table dimension: " + std::to_string(schema_.dimension));
} }
res = ValidateTableIndexType(schema_.index_type); res = ValidateTableIndexType(schema_.index_type);
if(res != SERVER_SUCCESS) { if(res != SERVER_SUCCESS) {
return res; return SetError(res, "Invalid index type: " + std::to_string(schema_.index_type));
} }
//step 2: construct table schema //step 2: construct table schema
@ -203,7 +203,7 @@ ServerError DescribeTableTask::OnExecute() {
ServerError res = SERVER_SUCCESS; ServerError res = SERVER_SUCCESS;
res = ValidateTableName(table_name_); res = ValidateTableName(table_name_);
if(res != SERVER_SUCCESS) { if(res != SERVER_SUCCESS) {
return res; return SetError(res, "Invalid table name: " + table_name_);
} }
//step 2: get table info //step 2: get table info
@ -243,12 +243,20 @@ ServerError BuildIndexTask::OnExecute() {
TimeRecorder rc("BuildIndexTask"); TimeRecorder rc("BuildIndexTask");
//step 1: check arguments //step 1: check arguments
if(table_name_.empty()) { ServerError res = SERVER_SUCCESS;
return SetError(SERVER_INVALID_TABLE_NAME, "Empty table name"); res = ValidateTableName(table_name_);
if(res != SERVER_SUCCESS) {
return SetError(res, "Invalid table name: " + table_name_);
}
bool has_table = false;
engine::Status stat = DBWrapper::DB()->HasTable(table_name_, has_table);
if(!has_table) {
return SetError(SERVER_TABLE_NOT_EXIST, "Table " + table_name_ + " not exists");
} }
//step 2: check table existence //step 2: check table existence
engine::Status stat = DBWrapper::DB()->BuildIndex(table_name_); stat = DBWrapper::DB()->BuildIndex(table_name_);
if(!stat.ok()) { if(!stat.ok()) {
return SetError(SERVER_BUILD_INDEX_ERROR, "Engine failed: " + stat.ToString()); return SetError(SERVER_BUILD_INDEX_ERROR, "Engine failed: " + stat.ToString());
} }
@ -281,8 +289,9 @@ ServerError HasTableTask::OnExecute() {
ServerError res = SERVER_SUCCESS; ServerError res = SERVER_SUCCESS;
res = ValidateTableName(table_name_); res = ValidateTableName(table_name_);
if(res != SERVER_SUCCESS) { if(res != SERVER_SUCCESS) {
return res; return SetError(res, "Invalid table name: " + table_name_);
} }
//step 2: check table existence //step 2: check table existence
engine::Status stat = DBWrapper::DB()->HasTable(table_name_, has_table_); engine::Status stat = DBWrapper::DB()->HasTable(table_name_, has_table_);
if(!stat.ok()) { if(!stat.ok()) {
@ -316,7 +325,7 @@ ServerError DeleteTableTask::OnExecute() {
ServerError res = SERVER_SUCCESS; ServerError res = SERVER_SUCCESS;
res = ValidateTableName(table_name_); res = ValidateTableName(table_name_);
if(res != SERVER_SUCCESS) { if(res != SERVER_SUCCESS) {
return res; return SetError(res, "Invalid table name: " + table_name_);
} }
//step 2: check table existence //step 2: check table existence
@ -400,7 +409,7 @@ ServerError AddVectorTask::OnExecute() {
ServerError res = SERVER_SUCCESS; ServerError res = SERVER_SUCCESS;
res = ValidateTableName(table_name_); res = ValidateTableName(table_name_);
if(res != SERVER_SUCCESS) { if(res != SERVER_SUCCESS) {
return res; return SetError(res, "Invalid table name: " + table_name_);
} }
if(record_array_.empty()) { if(record_array_.empty()) {
@ -491,7 +500,7 @@ ServerError SearchVectorTask::OnExecute() {
ServerError res = SERVER_SUCCESS; ServerError res = SERVER_SUCCESS;
res = ValidateTableName(table_name_); res = ValidateTableName(table_name_);
if(res != SERVER_SUCCESS) { if(res != SERVER_SUCCESS) {
return res; return SetError(res, "Invalid table name: " + table_name_);
} }
if(top_k_ <= 0) { if(top_k_ <= 0) {
@ -606,7 +615,7 @@ ServerError GetTableRowCountTask::OnExecute() {
ServerError res = SERVER_SUCCESS; ServerError res = SERVER_SUCCESS;
res = ValidateTableName(table_name_); res = ValidateTableName(table_name_);
if(res != SERVER_SUCCESS) { if(res != SERVER_SUCCESS) {
return res; return SetError(res, "Invalid table name: " + table_name_);
} }
//step 2: get row count //step 2: get row count

View File

@ -56,18 +56,13 @@ ValidateTableDimension(int64_t dimension) {
ServerError ServerError
ValidateTableIndexType(int32_t index_type) { ValidateTableIndexType(int32_t index_type) {
auto engine_type = engine::EngineType(index_type); int engine_type = (int)engine::EngineType(index_type);
switch (engine_type) { if(engine_type <= 0 || engine_type > (int)engine::EngineType::MAX_VALUE) {
case engine::EngineType::FAISS_IDMAP:
case engine::EngineType::FAISS_IVFFLAT:
case engine::EngineType::FAISS_IVFSQ8:{
SERVER_LOG_DEBUG << "Index type: " << index_type;
return SERVER_SUCCESS;
}
default: {
return SERVER_INVALID_INDEX_TYPE; return SERVER_INVALID_INDEX_TYPE;
} }
}
SERVER_LOG_DEBUG << "Index type: " << index_type;
return SERVER_SUCCESS;
} }
} }

View File

@ -7,9 +7,11 @@
#include "utils/ValidationUtil.h" #include "utils/ValidationUtil.h"
#include "utils/Error.h" #include "utils/Error.h"
#include "db/ExecutionEngine.h"
#include <string> #include <string>
using namespace zilliz::milvus;
using namespace zilliz::milvus::server; using namespace zilliz::milvus::server;
TEST(ValidationUtilTest, TableNameTest) { TEST(ValidationUtilTest, TableNameTest) {
@ -53,9 +55,9 @@ TEST(ValidationUtilTest, TableDimensionTest) {
} }
TEST(ValidationUtilTest, TableIndexTypeTest) { TEST(ValidationUtilTest, TableIndexTypeTest) {
ASSERT_EQ(ValidateTableIndexType(0), SERVER_INVALID_INDEX_TYPE); ASSERT_EQ(ValidateTableIndexType((int)engine::EngineType::INVALID), SERVER_INVALID_INDEX_TYPE);
ASSERT_EQ(ValidateTableIndexType(1), SERVER_SUCCESS); for(int i = 1; i <= (int)engine::EngineType::MAX_VALUE; i++) {
ASSERT_EQ(ValidateTableIndexType(2), SERVER_SUCCESS); ASSERT_EQ(ValidateTableIndexType(i), SERVER_SUCCESS);
ASSERT_EQ(ValidateTableIndexType(3), SERVER_INVALID_INDEX_TYPE); }
ASSERT_EQ(ValidateTableIndexType(4), SERVER_INVALID_INDEX_TYPE); ASSERT_EQ(ValidateTableIndexType((int)engine::EngineType::MAX_VALUE + 1), SERVER_INVALID_INDEX_TYPE);
} }