提交 f3df1530 编写于 作者: G groot

MS-331 Crate Table : when table exists, error code is META_FAILED


Former-commit-id: 5c59553557db4457ed93c695a592af5aa938f0c2
上级 6786109d
...@@ -12,6 +12,8 @@ Please mark all change in change log and use the ticket from JIRA. ...@@ -12,6 +12,8 @@ Please mark all change in change log and use the ticket from JIRA.
- MS-413 - Create index failed and server exited - MS-413 - Create index failed and server exited
- MS-427 - Describe index error after drop index - MS-427 - Describe index error after drop index
- MS-432 - Search vectors params nprobe need to check max number - MS-432 - Search vectors params nprobe need to check max number
- MS-431 - Search vectors params nprobe: 0/-1, expected result: raise exception
- MS-331 - Crate Table : when table exists, error code is META_FAILED(code=15) rather than ILLEGAL TABLE NAME(code=9))
## Improvement ## Improvement
- MS-327 - Clean code for milvus - MS-327 - Clean code for milvus
......
...@@ -48,6 +48,21 @@ std::string Status::ToString() const { ...@@ -48,6 +48,21 @@ std::string Status::ToString() const {
case kNotFound: case kNotFound:
type = "NotFound: "; type = "NotFound: ";
break; break;
case kError:
type = "Error: ";
break;
case kInvalidDBPath:
type = "InvalidDBPath: ";
break;
case kGroupError:
type = "GroupError: ";
break;
case kDBTransactionError:
type = "DBTransactionError: ";
break;
case kAlreadyExist:
type = "AlreadyExist: ";
break;
default: default:
snprintf(tmp, sizeof(tmp), "Unkown code(%d): ", snprintf(tmp, sizeof(tmp), "Unkown code(%d): ",
static_cast<int>(code())); static_cast<int>(code()));
......
...@@ -153,7 +153,10 @@ CreateTableTask::OnExecute() { ...@@ -153,7 +153,10 @@ CreateTableTask::OnExecute() {
engine::Status stat = DBWrapper::DB()->CreateTable(table_info); engine::Status stat = DBWrapper::DB()->CreateTable(table_info);
if (!stat.ok()) { if (!stat.ok()) {
//table could exist //table could exist
return SetError(DB_META_TRANSACTION_FAILED, "Engine failed: " + stat.ToString()); if(stat.IsAlreadyExist()) {
return SetError(SERVER_INVALID_TABLE_NAME, stat.ToString());
}
return SetError(DB_META_TRANSACTION_FAILED, stat.ToString());
} }
} catch (std::exception &ex) { } catch (std::exception &ex) {
...@@ -193,7 +196,7 @@ DescribeTableTask::OnExecute() { ...@@ -193,7 +196,7 @@ DescribeTableTask::OnExecute() {
table_info.table_id_ = table_name_; table_info.table_id_ = table_name_;
engine::Status stat = DBWrapper::DB()->DescribeTable(table_info); engine::Status stat = DBWrapper::DB()->DescribeTable(table_info);
if (!stat.ok()) { if (!stat.ok()) {
return SetError(DB_META_TRANSACTION_FAILED, "Engine failed: " + stat.ToString()); return SetError(DB_META_TRANSACTION_FAILED, stat.ToString());
} }
schema_->mutable_table_name()->set_table_name(table_info.table_id_); schema_->mutable_table_name()->set_table_name(table_info.table_id_);
...@@ -238,7 +241,7 @@ CreateIndexTask::OnExecute() { ...@@ -238,7 +241,7 @@ CreateIndexTask::OnExecute() {
bool has_table = false; bool has_table = false;
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()) {
return SetError(DB_META_TRANSACTION_FAILED, "Engine failed: " + stat.ToString()); return SetError(DB_META_TRANSACTION_FAILED, stat.ToString());
} }
if (!has_table) { if (!has_table) {
...@@ -268,7 +271,7 @@ CreateIndexTask::OnExecute() { ...@@ -268,7 +271,7 @@ CreateIndexTask::OnExecute() {
index.metric_type_ = grpc_index.metric_type(); index.metric_type_ = grpc_index.metric_type();
stat = DBWrapper::DB()->CreateIndex(table_name_, index); stat = DBWrapper::DB()->CreateIndex(table_name_, index);
if (!stat.ok()) { if (!stat.ok()) {
return SetError(SERVER_BUILD_INDEX_ERROR, "Engine failed: " + stat.ToString()); return SetError(SERVER_BUILD_INDEX_ERROR, stat.ToString());
} }
rc.ElapseFromBegin("totally cost"); rc.ElapseFromBegin("totally cost");
...@@ -306,7 +309,7 @@ HasTableTask::OnExecute() { ...@@ -306,7 +309,7 @@ HasTableTask::OnExecute() {
//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()) {
return SetError(DB_META_TRANSACTION_FAILED, "Engine failed: " + stat.ToString()); return SetError(DB_META_TRANSACTION_FAILED, stat.ToString());
} }
rc.ElapseFromBegin("totally cost"); rc.ElapseFromBegin("totally cost");
...@@ -348,7 +351,7 @@ DropTableTask::OnExecute() { ...@@ -348,7 +351,7 @@ DropTableTask::OnExecute() {
if (stat.IsNotFound()) { if (stat.IsNotFound()) {
return SetError(SERVER_TABLE_NOT_EXIST, "Table " + table_name_ + " not exists"); return SetError(SERVER_TABLE_NOT_EXIST, "Table " + table_name_ + " not exists");
} else { } else {
return SetError(DB_META_TRANSACTION_FAILED, "Engine failed: " + stat.ToString()); return SetError(DB_META_TRANSACTION_FAILED, stat.ToString());
} }
} }
...@@ -358,7 +361,7 @@ DropTableTask::OnExecute() { ...@@ -358,7 +361,7 @@ DropTableTask::OnExecute() {
std::vector<DB_DATE> dates; std::vector<DB_DATE> dates;
stat = DBWrapper::DB()->DeleteTable(table_name_, dates); stat = DBWrapper::DB()->DeleteTable(table_name_, dates);
if (!stat.ok()) { if (!stat.ok()) {
return SetError(DB_META_TRANSACTION_FAILED, "Engine failed: " + stat.ToString()); return SetError(DB_META_TRANSACTION_FAILED, stat.ToString());
} }
rc.ElapseFromBegin("total cost"); rc.ElapseFromBegin("total cost");
...@@ -386,7 +389,7 @@ ShowTablesTask::OnExecute() { ...@@ -386,7 +389,7 @@ ShowTablesTask::OnExecute() {
std::vector<engine::meta::TableSchema> schema_array; std::vector<engine::meta::TableSchema> schema_array;
engine::Status stat = DBWrapper::DB()->AllTables(schema_array); engine::Status stat = DBWrapper::DB()->AllTables(schema_array);
if (!stat.ok()) { if (!stat.ok()) {
return SetError(DB_META_TRANSACTION_FAILED, "Engine failed: " + stat.ToString()); return SetError(DB_META_TRANSACTION_FAILED, stat.ToString());
} }
for (auto &schema : schema_array) { for (auto &schema : schema_array) {
...@@ -448,7 +451,7 @@ InsertTask::OnExecute() { ...@@ -448,7 +451,7 @@ InsertTask::OnExecute() {
return SetError(SERVER_TABLE_NOT_EXIST, return SetError(SERVER_TABLE_NOT_EXIST,
"Table " + insert_param_->table_name() + " not exists"); "Table " + insert_param_->table_name() + " not exists");
} else { } else {
return SetError(DB_META_TRANSACTION_FAILED, "Engine failed: " + stat.ToString()); return SetError(DB_META_TRANSACTION_FAILED, stat.ToString());
} }
} }
...@@ -588,7 +591,7 @@ SearchTask::OnExecute() { ...@@ -588,7 +591,7 @@ SearchTask::OnExecute() {
if (stat.IsNotFound()) { if (stat.IsNotFound()) {
return SetError(SERVER_TABLE_NOT_EXIST, "Table " + table_name_ + " not exists"); return SetError(SERVER_TABLE_NOT_EXIST, "Table " + table_name_ + " not exists");
} else { } else {
return SetError(DB_META_TRANSACTION_FAILED, "Engine failed: " + stat.ToString()); return SetError(DB_META_TRANSACTION_FAILED, stat.ToString());
} }
} }
...@@ -667,7 +670,7 @@ SearchTask::OnExecute() { ...@@ -667,7 +670,7 @@ SearchTask::OnExecute() {
rc.ElapseFromBegin("search vectors from engine"); rc.ElapseFromBegin("search vectors from engine");
if (!stat.ok()) { if (!stat.ok()) {
return SetError(DB_META_TRANSACTION_FAILED, "Engine failed: " + stat.ToString()); return SetError(DB_META_TRANSACTION_FAILED, stat.ToString());
} }
if (results.empty()) { if (results.empty()) {
...@@ -742,7 +745,7 @@ CountTableTask::OnExecute() { ...@@ -742,7 +745,7 @@ CountTableTask::OnExecute() {
uint64_t row_count = 0; uint64_t row_count = 0;
engine::Status stat = DBWrapper::DB()->GetTableRowCount(table_name_, row_count); engine::Status stat = DBWrapper::DB()->GetTableRowCount(table_name_, row_count);
if (!stat.ok()) { if (!stat.ok()) {
return SetError(DB_META_TRANSACTION_FAILED, "Engine failed: " + stat.ToString()); return SetError(DB_META_TRANSACTION_FAILED, stat.ToString());
} }
row_count_ = (int64_t) row_count; row_count_ = (int64_t) row_count;
...@@ -818,7 +821,7 @@ DeleteByRangeTask::OnExecute() { ...@@ -818,7 +821,7 @@ DeleteByRangeTask::OnExecute() {
if (stat.IsNotFound()) { if (stat.IsNotFound()) {
return SetError(SERVER_TABLE_NOT_EXIST, "Table " + table_name + " not exists"); return SetError(SERVER_TABLE_NOT_EXIST, "Table " + table_name + " not exists");
} else { } else {
return SetError(DB_META_TRANSACTION_FAILED, "Engine failed: " + stat.ToString()); return SetError(DB_META_TRANSACTION_FAILED, stat.ToString());
} }
} }
...@@ -844,7 +847,7 @@ DeleteByRangeTask::OnExecute() { ...@@ -844,7 +847,7 @@ DeleteByRangeTask::OnExecute() {
#endif #endif
engine::Status status = DBWrapper::DB()->DeleteTable(table_name, dates); engine::Status status = DBWrapper::DB()->DeleteTable(table_name, dates);
if (!status.ok()) { if (!status.ok()) {
return SetError(DB_META_TRANSACTION_FAILED, "Engine failed: " + stat.ToString()); return SetError(DB_META_TRANSACTION_FAILED, stat.ToString());
} }
} catch (std::exception &ex) { } catch (std::exception &ex) {
...@@ -880,7 +883,7 @@ PreloadTableTask::OnExecute() { ...@@ -880,7 +883,7 @@ PreloadTableTask::OnExecute() {
//step 2: check table existence //step 2: check table existence
engine::Status stat = DBWrapper::DB()->PreloadTable(table_name_); engine::Status stat = DBWrapper::DB()->PreloadTable(table_name_);
if (!stat.ok()) { if (!stat.ok()) {
return SetError(DB_META_TRANSACTION_FAILED, "Engine failed: " + stat.ToString()); return SetError(DB_META_TRANSACTION_FAILED, stat.ToString());
} }
rc.ElapseFromBegin("totally cost"); rc.ElapseFromBegin("totally cost");
...@@ -921,7 +924,7 @@ DescribeIndexTask::OnExecute() { ...@@ -921,7 +924,7 @@ DescribeIndexTask::OnExecute() {
engine::TableIndex index; engine::TableIndex index;
engine::Status stat = DBWrapper::DB()->DescribeIndex(table_name_, index); engine::Status stat = DBWrapper::DB()->DescribeIndex(table_name_, index);
if (!stat.ok()) { if (!stat.ok()) {
return SetError(DB_META_TRANSACTION_FAILED, "Engine failed: " + stat.ToString()); return SetError(DB_META_TRANSACTION_FAILED, stat.ToString());
} }
index_param_->mutable_table_name()->set_table_name(table_name_); index_param_->mutable_table_name()->set_table_name(table_name_);
...@@ -963,7 +966,7 @@ DropIndexTask::OnExecute() { ...@@ -963,7 +966,7 @@ DropIndexTask::OnExecute() {
//step 2: check table existence //step 2: check table existence
engine::Status stat = DBWrapper::DB()->DropIndex(table_name_); engine::Status stat = DBWrapper::DB()->DropIndex(table_name_);
if (!stat.ok()) { if (!stat.ok()) {
return SetError(DB_META_TRANSACTION_FAILED, "Engine failed: " + stat.ToString()); return SetError(DB_META_TRANSACTION_FAILED, stat.ToString());
} }
rc.ElapseFromBegin("totally cost"); rc.ElapseFromBegin("totally cost");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册