提交 c130de62 编写于 作者: P peng.xu

Merge branch 'branch-0.5.0' into 'branch-0.5.0'

MS-558 refine status code

See merge request megasearch/milvus!573

Former-commit-id: 6ab9c4368b362273d6a9c8176ba5c3f9d0b0faec
...@@ -11,6 +11,7 @@ Please mark all change in change log and use the ticket from JIRA. ...@@ -11,6 +11,7 @@ Please mark all change in change log and use the ticket from JIRA.
- MS-553 - Refine cache code - MS-553 - Refine cache code
- MS-557 - Merge Log.h - MS-557 - Merge Log.h
- MS-556 - Add Job Definition in Scheduler - MS-556 - Add Job Definition in Scheduler
- MS-558 - Refine status code
## New Feature ## New Feature
......
...@@ -15,12 +15,13 @@ ...@@ -15,12 +15,13 @@
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
#pragma once #pragma once
#include "Options.h" #include "Options.h"
#include "meta/Meta.h"
#include "Status.h"
#include "Types.h" #include "Types.h"
#include "meta/Meta.h"
#include "utils/Status.h"
#include <string> #include <string>
#include <memory> #include <memory>
......
...@@ -15,10 +15,11 @@ ...@@ -15,10 +15,11 @@
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
#pragma once #pragma once
#include "db/Status.h"
#include "ExecutionEngine.h" #include "ExecutionEngine.h"
#include "utils/Status.h"
namespace zilliz { namespace zilliz {
namespace milvus { namespace milvus {
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#pragma once #pragma once
#include "db/Status.h" #include "utils/Status.h"
#include <vector> #include <vector>
#include <memory> #include <memory>
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#pragma once #pragma once
#include "db/Status.h" #include "utils/Status.h"
#include "db/Types.h" #include "db/Types.h"
#include <set> #include <set>
......
...@@ -18,10 +18,10 @@ ...@@ -18,10 +18,10 @@
#pragma once #pragma once
#include "db/meta/Meta.h"
#include "MemTable.h" #include "MemTable.h"
#include "db/Status.h"
#include "MemManager.h" #include "MemManager.h"
#include "db/meta/Meta.h"
#include "utils/Status.h"
#include <map> #include <map>
#include <string> #include <string>
......
...@@ -18,9 +18,9 @@ ...@@ -18,9 +18,9 @@
#pragma once #pragma once
#include "db/Status.h"
#include "MemTableFile.h" #include "MemTableFile.h"
#include "VectorSource.h" #include "VectorSource.h"
#include "utils/Status.h"
#include <mutex> #include <mutex>
......
...@@ -18,10 +18,10 @@ ...@@ -18,10 +18,10 @@
#pragma once #pragma once
#include "db/Status.h"
#include "db/meta/Meta.h"
#include "VectorSource.h" #include "VectorSource.h"
#include "db/meta/Meta.h"
#include "db/engine/ExecutionEngine.h" #include "db/engine/ExecutionEngine.h"
#include "utils/Status.h"
namespace zilliz { namespace zilliz {
......
...@@ -18,10 +18,10 @@ ...@@ -18,10 +18,10 @@
#pragma once #pragma once
#include "db/Status.h"
#include "db/meta/Meta.h" #include "db/meta/Meta.h"
#include "db/IDGenerator.h" #include "db/IDGenerator.h"
#include "db/engine/ExecutionEngine.h" #include "db/engine/ExecutionEngine.h"
#include "utils/Status.h"
namespace zilliz { namespace zilliz {
......
...@@ -15,12 +15,13 @@ ...@@ -15,12 +15,13 @@
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
#pragma once #pragma once
#include "MetaTypes.h" #include "MetaTypes.h"
#include "db/Options.h" #include "db/Options.h"
#include "db/Status.h"
#include "db/Types.h" #include "db/Types.h"
#include "utils/Status.h"
#include <cstddef> #include <cstddef>
#include <memory> #include <memory>
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
#pragma once #pragma once
#include "MetricBase.h" #include "MetricBase.h"
...@@ -63,7 +64,7 @@ protected: ...@@ -63,7 +64,7 @@ protected:
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class CollectInsertMetrics : CollectMetricsBase { class CollectInsertMetrics : CollectMetricsBase {
public: public:
CollectInsertMetrics(size_t n, engine::Status& status) : n_(n), status_(status) { CollectInsertMetrics(size_t n, Status& status) : n_(n), status_(status) {
} }
~CollectInsertMetrics() { ~CollectInsertMetrics() {
...@@ -87,7 +88,7 @@ public: ...@@ -87,7 +88,7 @@ public:
private: private:
size_t n_; size_t n_;
engine::Status& status_; Status& status_;
}; };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
......
...@@ -20,8 +20,6 @@ ...@@ -20,8 +20,6 @@
aux_source_directory(interface interface_files) aux_source_directory(interface interface_files)
aux_source_directory(util util_files)
include_directories(/usr/include) include_directories(/usr/include)
include_directories(include) include_directories(include)
include_directories(/usr/local/include) include_directories(/usr/local/include)
...@@ -42,12 +40,15 @@ set(grpc_service_files ...@@ -42,12 +40,15 @@ set(grpc_service_files
add_library(milvus_sdk STATIC add_library(milvus_sdk STATIC
${interface_files} ${interface_files}
${grpc_client_files} ${grpc_client_files}
${util_files}
${grpc_service_files} ${grpc_service_files}
) )
target_link_libraries(milvus_sdk target_link_libraries(milvus_sdk
${third_party_libs} ${client_grpc_lib}
bzip2
lz4
snappy
zlib
) )
install(TARGETS milvus_sdk DESTINATION lib) install(TARGETS milvus_sdk DESTINATION lib)
......
...@@ -36,10 +36,10 @@ const std::string TABLE_NAME = GetTableName(); ...@@ -36,10 +36,10 @@ const std::string TABLE_NAME = GetTableName();
constexpr int64_t TABLE_DIMENSION = 512; constexpr int64_t TABLE_DIMENSION = 512;
constexpr int64_t TABLE_INDEX_FILE_SIZE = 1024; constexpr int64_t TABLE_INDEX_FILE_SIZE = 1024;
constexpr int64_t BATCH_ROW_COUNT = 100000; constexpr int64_t BATCH_ROW_COUNT = 100000;
constexpr int64_t NQ = 100; constexpr int64_t NQ = 5;
constexpr int64_t TOP_K = 1; constexpr int64_t TOP_K = 10;
constexpr int64_t SEARCH_TARGET = 5000; //change this value, result is different constexpr int64_t SEARCH_TARGET = 5000; //change this value, result is different
constexpr int64_t ADD_VECTOR_LOOP = 1; constexpr int64_t ADD_VECTOR_LOOP = 10;
constexpr int64_t SECONDS_EACH_HOUR = 3600; constexpr int64_t SECONDS_EACH_HOUR = 3600;
#define BLOCK_SPLITER std::cout << "===========================================" << std::endl; #define BLOCK_SPLITER std::cout << "===========================================" << std::endl;
......
...@@ -51,7 +51,7 @@ ClientProxy::Connect(const ConnectParam &param) { ...@@ -51,7 +51,7 @@ ClientProxy::Connect(const ConnectParam &param) {
Status Status
ClientProxy::Connect(const std::string &uri) { ClientProxy::Connect(const std::string &uri) {
if (!UriCheck(uri)) { if (!UriCheck(uri)) {
return Status::Invalid("Invalid uri"); return Status(StatusCode::InvalidAgument, "Invalid uri");
} }
size_t index = uri.find_first_of(':', 0); size_t index = uri.find_first_of(':', 0);
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
#pragma once #pragma once
#include <string> #include <string>
#include <sstream>
/** \brief Milvus SDK namespace /** \brief Milvus SDK namespace
*/ */
...@@ -30,345 +29,61 @@ namespace milvus { ...@@ -30,345 +29,61 @@ namespace milvus {
*/ */
enum class StatusCode { enum class StatusCode {
OK = 0, OK = 0,
// system error section // system error section
UnknownError = 1, UnknownError = 1,
NotSupported, NotSupported,
NotConnected, NotConnected,
// function error section // function error section
InvalidAgument = 1000, InvalidAgument = 1000,
RPCFailed, RPCFailed,
ServerFailed, ServerFailed,
}; };
using ErrorCode = StatusCode;
/** /**
* @brief Status for SDK interface return * @brief Status for SDK interface return
*/ */
class Status { class Status {
public: public:
/** Status(ErrorCode code, const std::string &msg);
* @brief Status Status();
* ~Status();
* Default constructor.
*
*/
Status() = default;
/**
* @brief Status
*
* Destructor.
*
*/
~Status() noexcept;
/**
* @brief Status
*
* Constructor
*
* @param code, status code.
* @param message, status message.
*
*/
Status(StatusCode code, const std::string &message);
/**
* @brief Status
*
* Copy constructor
*
* @param status, status to be copied.
*
*/
inline
Status(const Status &status);
/**
* @brief Status
*
* Assignment operator
*
* @param status, status to be copied.
* @return, the status is assigned.
*
*/
Status
&operator=(const Status &s);
/** Status(const Status &s);
* @brief Status
*
* Move constructor
*
* @param status, status to be moved.
*
*/
Status(Status &&s) noexcept ;
/** Status &
* @brief Status operator=(const Status &s);
*
* Move assignment operator
*
* @param status, status to be moved.
* @return, the status is moved.
*
*/
Status
&operator=(Status &&s) noexcept;
/** Status(Status &&s);
* @brief Status
*
* AND operator
*
* @param status, status to be AND.
* @return, the status after AND operation.
*
*/
inline
Status operator&(const Status &s) const noexcept;
/** Status &
* @brief Status operator=(Status &&s);
*
* AND operator
*
* @param status, status to be AND.
* @return, the status after AND operation.
*
*/
inline
Status operator&(Status &&s) const noexcept;
/**
* @brief Status
*
* AND operator
*
* @param status, status to be AND.
* @return, the status after AND operation.
*
*/
inline
Status &operator&=(const Status &s) noexcept;
/**
* @brief Status
*
* AND operator
*
* @param status, status to be AND.
* @return, the status after AND operation.
*
*/
inline
Status &operator&=(Status &&s) noexcept;
/**
* @brief OK
*
* static OK status constructor
*
* @return, the status with OK.
*
*/
static
Status OK() { return Status(); }
/**
* @brief OK
*
* static OK status constructor with a specific message
*
* @param, serveral specific messages
* @return, the status with OK.
*
*/
template<typename... Args>
static Status static Status
OK(Args &&... args) { OK() { return Status(); }
return Status(StatusCode::OK, MessageBuilder(std::forward<Args>(args)...));
}
/**
* @brief Invalid
*
* static Invalid status constructor with a specific message
*
* @param, serveral specific messages
* @return, the status with Invalid.
*
*/
template<typename... Args>
static Status
Invalid(Args &&... args) {
return Status(StatusCode::InvalidAgument,
MessageBuilder(std::forward<Args>(args)...));
}
/**
* @brief Unknown Error
*
* static unknown error status constructor with a specific message
*
* @param, serveral specific messages
* @return, the status with unknown error.
*
*/
template<typename... Args>
static Status
UnknownError(Args &&... args) {
return Status(StatusCode::UnknownError, MessageBuilder(std::forward<Args>(args)...));
}
/**
* @brief not supported Error
*
* static not supported status constructor with a specific message
*
* @param, serveral specific messages
* @return, the status with not supported error.
*
*/
template<typename... Args>
static Status
NotSupported(Args &&... args) {
return Status(StatusCode::NotSupported, MessageBuilder(std::forward<Args>(args)...));
}
/**
* @brief ok
*
* Return true iff the status indicates success.
*
* @return, if the status indicates success.
*
*/
bool
ok() const { return (state_ == nullptr); }
/**
* @brief IsInvalid
*
* Return true iff the status indicates invalid.
*
* @return, if the status indicates invalid.
*
*/
bool
IsInvalid() const { return code() == StatusCode::InvalidAgument; }
/** bool
* @brief IsUnknownError ok() const { return state_ == nullptr || code() == StatusCode::OK; }
*
* Return true iff the status indicates unknown error.
*
* @return, if the status indicates unknown error.
*
*/
bool
IsUnknownError() const { return code() == StatusCode::UnknownError; }
/**
* @brief IsNotSupported
*
* Return true iff the status indicates not supported.
*
* @return, if the status indicates not supported.
*
*/
bool
IsNotSupported() const { return code() == StatusCode::NotSupported; }
/**
* @brief ToString
*
* Return error message string.
*
* @return, error message string.
*
*/
std::string
ToString() const;
/** std::string
* @brief CodeAsString ToString() const;
*
* Return a string representation of the status code.
*
* @return, a string representation of the status code.
*
*/
std::string
CodeAsString() const;
/**
* @brief code
*
* Return the StatusCode value attached to this status.
*
* @return, the status code value attached to this status.
*
*/
StatusCode
code() const { return ok() ? StatusCode::OK : state_->code; }
/** ErrorCode
* @brief message code() const {
* return (state_ == nullptr) ? StatusCode::OK : *(ErrorCode*)(state_);
* Return the specific error message attached to this status. }
*
* @return, the specific error message attached to this status.
*
*/
std::string
message() const { return ok() ? "" : state_->message; }
private: private:
struct State { inline void
StatusCode code; CopyFrom(const Status &s);
std::string message;
};
// OK status has a `nullptr` state_. Otherwise, `state_` points to
// a `State` structure containing the error code and message.
State *state_ = nullptr;
void
DeleteState() {
delete state_;
state_ = nullptr;
}
void
CopyFrom(const Status &s);
inline void
MoveFrom(Status &s);
template<typename Head> inline void
static void MoveFrom(Status &s);
MessageBuilderRecursive(std::stringstream &stream, Head &&head) {
stream << head;
}
template<typename Head, typename... Tail> private:
static void const char *state_ = nullptr;
MessageBuilderRecursive(std::stringstream &stream, Head &&head, Tail &&... tail) { }; // Status
MessageBuilderRecursive(stream, std::forward<Head>(head));
MessageBuilderRecursive(stream, std::forward<Tail>(tail)...);
}
template<typename... Args>
static std::string
MessageBuilder(Args &&... args) {
std::stringstream stream;
MessageBuilderRecursive(stream, std::forward<Args>(args)...);
return stream.str(); } //Milvus
} \ No newline at end of file
};
}
\ No newline at end of file
...@@ -17,126 +17,113 @@ ...@@ -17,126 +17,113 @@
#include "Status.h" #include "Status.h"
#include <cstring>
namespace milvus { namespace milvus {
Status::~Status() noexcept { constexpr int CODE_WIDTH = sizeof(ErrorCode);
if (state_ != nullptr) {
delete state_; Status::Status(ErrorCode code, const std::string& msg) {
state_ = nullptr; //4 bytes store code
} //4 bytes store message length
//the left bytes store message string
const uint32_t length = (uint32_t)msg.size();
char* result = new char[length + sizeof(length) + CODE_WIDTH];
memcpy(result, &code, CODE_WIDTH);
memcpy(result + CODE_WIDTH, &length, sizeof(length));
memcpy(result + sizeof(length) + CODE_WIDTH, msg.data(), length);
state_ = result;
} }
static inline std::ostream &operator<<(std::ostream &os, const Status &x) { Status::Status()
os << x.ToString(); : state_(nullptr) {
return os;
} }
void Status::MoveFrom(Status &s) { Status::~Status() {
delete state_; delete state_;
state_ = s.state_;
s.state_ = nullptr;
} }
Status::Status(const Status &s) Status::Status(const Status &s)
: state_((s.state_ == nullptr) ? nullptr : new State(*s.state_)) {} : state_(nullptr) {
CopyFrom(s);
Status::Status(Status &&s) noexcept {
MoveFrom(s);
} }
Status &Status::operator=(const Status &s) { Status &Status::operator=(const Status &s) {
if (state_ != s.state_) { CopyFrom(s);
CopyFrom(s);
}
return *this; return *this;
} }
Status &Status::operator=(Status &&s) noexcept { Status::Status(Status &&s)
: state_(nullptr) {
MoveFrom(s); MoveFrom(s);
return *this;
}
Status Status::operator&(const Status &status) const noexcept {
if (ok()) {
return status;
} else {
return *this;
}
} }
Status Status::operator&(Status &&s) const noexcept { Status &Status::operator=(Status &&s) {
if (ok()) { MoveFrom(s);
return std::move(s);
} else {
return *this;
}
}
Status &Status::operator&=(const Status &s) noexcept {
if (ok() && !s.ok()) {
CopyFrom(s);
}
return *this; return *this;
} }
Status &Status::operator&=(Status &&s) noexcept { void Status::CopyFrom(const Status &s) {
if (ok() && !s.ok()) { delete state_;
MoveFrom(s); state_ = nullptr;
if(s.state_ == nullptr) {
return;
} }
return *this;
}
Status::Status(StatusCode code, const std::string &message) { uint32_t length = 0;
state_ = new State; std::memcpy(&length, s.state_ + CODE_WIDTH, sizeof(length));
state_->code = code; int buff_len = length + sizeof(length) + CODE_WIDTH;
state_->message = message; state_ = new char[buff_len];
memcpy((void*)state_, (void*)s.state_, buff_len);
} }
void Status::CopyFrom(const Status &status) { void Status::MoveFrom(Status &s) {
delete state_; delete state_;
if (status.state_ == nullptr) { state_ = s.state_;
state_ = nullptr; s.state_ = nullptr;
} else {
state_ = new State(*status.state_);
}
} }
std::string Status::CodeAsString() const { std::string Status::ToString() const {
if (state_ == nullptr) { if (state_ == nullptr) {
return "OK"; return "OK";
} }
const char *type = nullptr; std::string result;
switch (code()) { switch (code()) {
case StatusCode::OK: case StatusCode::OK:
type = "OK"; result = "OK ";
break;
case StatusCode::InvalidAgument:
type = "Invalid agument";
break; break;
case StatusCode::UnknownError: case StatusCode::UnknownError:
type = "Unknown error"; result = "Unknown error: ";
break; break;
case StatusCode::NotSupported: case StatusCode::NotSupported:
type = "Not Supported"; result = "Not supported: ";
break; break;
case StatusCode::NotConnected: case StatusCode::NotConnected:
type = "Not Connected"; result = "Not connected: ";
break;
case StatusCode::InvalidAgument:
result = "Invalid agument: ";
break;
case StatusCode::RPCFailed:
result = "Remote call failed: ";
break;
case StatusCode::ServerFailed:
result = "Service error: ";
break; break;
default: default:
type = "Unknown"; result = "Error code(" + std::to_string((int)code()) + "): ";
break; break;
} }
return std::string(type);
}
std::string Status::ToString() const { uint32_t length = 0;
std::string result(CodeAsString()); memcpy(&length, state_ + CODE_WIDTH, sizeof(length));
if (state_ == nullptr) { if(length > 0) {
return result; result.append(state_ + sizeof(length) + CODE_WIDTH, length);
} }
result += ": ";
result += state_->message;
return result; return result;
} }
......
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
#pragma once
#include "Status.h"
#include <exception>
namespace milvus {
class Exception : public std::exception {
public:
Exception(StatusCode error_code,
const std::string &message = std::string())
: error_code_(error_code), message_(message) {}
public:
StatusCode error_code() const {
return error_code_;
}
virtual const char *what() const noexcept {
return message_.c_str();
}
private:
StatusCode error_code_;
std::string message_;
};
}
\ No newline at end of file
...@@ -170,7 +170,7 @@ CreateTableTask::OnExecute() { ...@@ -170,7 +170,7 @@ CreateTableTask::OnExecute() {
table_info.metric_type_ = schema_->metric_type(); table_info.metric_type_ = schema_->metric_type();
//step 3: create table //step 3: create table
engine::Status stat = DBWrapper::DB()->CreateTable(table_info); auto stat = DBWrapper::DB()->CreateTable(table_info);
if (!stat.ok()) { if (!stat.ok()) {
//table could exist //table could exist
if(stat.code() == DB_ALREADY_EXIST) { if(stat.code() == DB_ALREADY_EXIST) {
...@@ -214,7 +214,7 @@ DescribeTableTask::OnExecute() { ...@@ -214,7 +214,7 @@ DescribeTableTask::OnExecute() {
//step 2: get table info //step 2: get table info
engine::meta::TableSchema table_info; engine::meta::TableSchema table_info;
table_info.table_id_ = table_name_; table_info.table_id_ = table_name_;
engine::Status stat = DBWrapper::DB()->DescribeTable(table_info); auto stat = DBWrapper::DB()->DescribeTable(table_info);
if (!stat.ok()) { if (!stat.ok()) {
return SetError(DB_META_TRANSACTION_FAILED, stat.ToString()); return SetError(DB_META_TRANSACTION_FAILED, stat.ToString());
} }
...@@ -261,7 +261,7 @@ CreateIndexTask::OnExecute() { ...@@ -261,7 +261,7 @@ CreateIndexTask::OnExecute() {
} }
bool has_table = false; bool has_table = false;
engine::Status stat = DBWrapper::DB()->HasTable(table_name_, has_table); auto stat = DBWrapper::DB()->HasTable(table_name_, has_table);
if (!stat.ok()) { if (!stat.ok()) {
return SetError(DB_META_TRANSACTION_FAILED, stat.ToString()); return SetError(DB_META_TRANSACTION_FAILED, stat.ToString());
} }
...@@ -323,7 +323,7 @@ HasTableTask::OnExecute() { ...@@ -323,7 +323,7 @@ HasTableTask::OnExecute() {
} }
//step 2: check table existence //step 2: check table existence
engine::Status stat = DBWrapper::DB()->HasTable(table_name_, has_table_); auto stat = DBWrapper::DB()->HasTable(table_name_, has_table_);
if (!stat.ok()) { if (!stat.ok()) {
return SetError(DB_META_TRANSACTION_FAILED, stat.ToString()); return SetError(DB_META_TRANSACTION_FAILED, stat.ToString());
} }
...@@ -362,7 +362,7 @@ DropTableTask::OnExecute() { ...@@ -362,7 +362,7 @@ DropTableTask::OnExecute() {
//step 2: check table existence //step 2: check table existence
engine::meta::TableSchema table_info; engine::meta::TableSchema table_info;
table_info.table_id_ = table_name_; table_info.table_id_ = table_name_;
engine::Status stat = DBWrapper::DB()->DescribeTable(table_info); auto stat = DBWrapper::DB()->DescribeTable(table_info);
if (!stat.ok()) { if (!stat.ok()) {
if (stat.code() == DB_NOT_FOUND) { if (stat.code() == DB_NOT_FOUND) {
return SetError(SERVER_TABLE_NOT_EXIST, "Table " + table_name_ + " not exists"); return SetError(SERVER_TABLE_NOT_EXIST, "Table " + table_name_ + " not exists");
...@@ -403,7 +403,7 @@ ShowTablesTask::Create(::grpc::ServerWriter<::milvus::grpc::TableName> *writer) ...@@ -403,7 +403,7 @@ ShowTablesTask::Create(::grpc::ServerWriter<::milvus::grpc::TableName> *writer)
ErrorCode ErrorCode
ShowTablesTask::OnExecute() { ShowTablesTask::OnExecute() {
std::vector<engine::meta::TableSchema> schema_array; std::vector<engine::meta::TableSchema> schema_array;
engine::Status stat = DBWrapper::DB()->AllTables(schema_array); auto stat = DBWrapper::DB()->AllTables(schema_array);
if (!stat.ok()) { if (!stat.ok()) {
return SetError(DB_META_TRANSACTION_FAILED, stat.ToString()); return SetError(DB_META_TRANSACTION_FAILED, stat.ToString());
} }
...@@ -460,7 +460,7 @@ InsertTask::OnExecute() { ...@@ -460,7 +460,7 @@ InsertTask::OnExecute() {
//step 2: check table existence //step 2: check table existence
engine::meta::TableSchema table_info; engine::meta::TableSchema table_info;
table_info.table_id_ = insert_param_->table_name(); table_info.table_id_ = insert_param_->table_name();
engine::Status stat = DBWrapper::DB()->DescribeTable(table_info); auto stat = DBWrapper::DB()->DescribeTable(table_info);
if (!stat.ok()) { if (!stat.ok()) {
if (stat.code() == DB_NOT_FOUND) { if (stat.code() == DB_NOT_FOUND) {
return SetError(SERVER_TABLE_NOT_EXIST, return SetError(SERVER_TABLE_NOT_EXIST,
...@@ -599,7 +599,7 @@ SearchTask::OnExecute() { ...@@ -599,7 +599,7 @@ SearchTask::OnExecute() {
//step 2: check table existence //step 2: check table existence
engine::meta::TableSchema table_info; engine::meta::TableSchema table_info;
table_info.table_id_ = table_name_; table_info.table_id_ = table_name_;
engine::Status stat = DBWrapper::DB()->DescribeTable(table_info); auto stat = DBWrapper::DB()->DescribeTable(table_info);
if (!stat.ok()) { if (!stat.ok()) {
if (stat.code() == DB_NOT_FOUND) { if (stat.code() == DB_NOT_FOUND) {
return SetError(SERVER_TABLE_NOT_EXIST, "Table " + table_name_ + " not exists"); return SetError(SERVER_TABLE_NOT_EXIST, "Table " + table_name_ + " not exists");
...@@ -746,7 +746,7 @@ CountTableTask::OnExecute() { ...@@ -746,7 +746,7 @@ CountTableTask::OnExecute() {
//step 2: get row count //step 2: get row count
uint64_t row_count = 0; uint64_t row_count = 0;
engine::Status stat = DBWrapper::DB()->GetTableRowCount(table_name_, row_count); auto stat = DBWrapper::DB()->GetTableRowCount(table_name_, row_count);
if (!stat.ok()) { if (!stat.ok()) {
return SetError(DB_META_TRANSACTION_FAILED, stat.ToString()); return SetError(DB_META_TRANSACTION_FAILED, stat.ToString());
} }
...@@ -819,7 +819,7 @@ DeleteByRangeTask::OnExecute() { ...@@ -819,7 +819,7 @@ DeleteByRangeTask::OnExecute() {
//step 2: check table existence //step 2: check table existence
engine::meta::TableSchema table_info; engine::meta::TableSchema table_info;
table_info.table_id_ = table_name; table_info.table_id_ = table_name;
engine::Status stat = DBWrapper::DB()->DescribeTable(table_info); auto stat = DBWrapper::DB()->DescribeTable(table_info);
if (!stat.ok()) { if (!stat.ok()) {
if (stat.code(), DB_NOT_FOUND) { if (stat.code(), DB_NOT_FOUND) {
return SetError(SERVER_TABLE_NOT_EXIST, "Table " + table_name + " not exists"); return SetError(SERVER_TABLE_NOT_EXIST, "Table " + table_name + " not exists");
...@@ -846,8 +846,8 @@ DeleteByRangeTask::OnExecute() { ...@@ -846,8 +846,8 @@ DeleteByRangeTask::OnExecute() {
std::string fname = "/tmp/search_nq_" + this->delete_by_range_param_->table_name() + ".profiling"; std::string fname = "/tmp/search_nq_" + this->delete_by_range_param_->table_name() + ".profiling";
ProfilerStart(fname.c_str()); ProfilerStart(fname.c_str());
#endif #endif
engine::Status status = DBWrapper::DB()->DeleteTable(table_name, dates); stat = DBWrapper::DB()->DeleteTable(table_name, dates);
if (!status.ok()) { if (!stat.ok()) {
return SetError(DB_META_TRANSACTION_FAILED, stat.ToString()); return SetError(DB_META_TRANSACTION_FAILED, stat.ToString());
} }
...@@ -882,7 +882,7 @@ PreloadTableTask::OnExecute() { ...@@ -882,7 +882,7 @@ PreloadTableTask::OnExecute() {
} }
//step 2: check table existence //step 2: check table existence
engine::Status stat = DBWrapper::DB()->PreloadTable(table_name_); auto stat = DBWrapper::DB()->PreloadTable(table_name_);
if (!stat.ok()) { if (!stat.ok()) {
return SetError(DB_META_TRANSACTION_FAILED, stat.ToString()); return SetError(DB_META_TRANSACTION_FAILED, stat.ToString());
} }
...@@ -923,7 +923,7 @@ DescribeIndexTask::OnExecute() { ...@@ -923,7 +923,7 @@ DescribeIndexTask::OnExecute() {
//step 2: check table existence //step 2: check table existence
engine::TableIndex index; engine::TableIndex index;
engine::Status stat = DBWrapper::DB()->DescribeIndex(table_name_, index); auto stat = DBWrapper::DB()->DescribeIndex(table_name_, index);
if (!stat.ok()) { if (!stat.ok()) {
return SetError(DB_META_TRANSACTION_FAILED, stat.ToString()); return SetError(DB_META_TRANSACTION_FAILED, stat.ToString());
} }
......
...@@ -14,15 +14,12 @@ ...@@ -14,15 +14,12 @@
// KIND, either express or implied. See the License for the // KIND, either express or implied. See the License for the
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
#include "Status.h"
#include <stdio.h>
#include <cstring> #include <cstring>
#include <assert.h>
#include "Status.h"
namespace zilliz { namespace zilliz {
namespace milvus { namespace milvus {
namespace engine {
constexpr int CODE_WIDTH = sizeof(ErrorCode); constexpr int CODE_WIDTH = sizeof(ErrorCode);
...@@ -45,55 +42,87 @@ Status::Status() ...@@ -45,55 +42,87 @@ Status::Status()
} }
Status::~Status() { Status::~Status() {
delete[] state_; delete state_;
}
Status::Status(const Status &s)
: state_(nullptr) {
CopyFrom(s);
} }
const char* Status::CopyState(const char* state) { Status &Status::operator=(const Status &s) {
CopyFrom(s);
return *this;
}
Status::Status(Status &&s)
: state_(nullptr) {
MoveFrom(s);
}
Status &Status::operator=(Status &&s) {
MoveFrom(s);
return *this;
}
void Status::CopyFrom(const Status &s) {
delete state_;
state_ = nullptr;
if(s.state_ == nullptr) {
return;
}
uint32_t length = 0; uint32_t length = 0;
std::memcpy(&length, state + CODE_WIDTH, sizeof(length)); std::memcpy(&length, s.state_ + CODE_WIDTH, sizeof(length));
int buff_len = length + sizeof(length) + CODE_WIDTH; int buff_len = length + sizeof(length) + CODE_WIDTH;
char* result = new char[buff_len]; state_ = new char[buff_len];
memcpy(result, state, buff_len); memcpy((void*)state_, (void*)s.state_, buff_len);
return result; }
void Status::MoveFrom(Status &s) {
delete state_;
state_ = s.state_;
s.state_ = nullptr;
} }
std::string Status::ToString() const { std::string Status::ToString() const {
if (state_ == nullptr) return "OK"; if (state_ == nullptr) {
char tmp[32]; return "OK";
const char* type; }
std::string result;
switch (code()) { switch (code()) {
case DB_SUCCESS: case DB_SUCCESS:
type = "OK"; result = "OK ";
break; break;
case DB_ERROR: case DB_ERROR:
type = "Error: "; result = "Error: ";
break; break;
case DB_META_TRANSACTION_FAILED: case DB_META_TRANSACTION_FAILED:
type = "DBTransactionError: "; result = "Database error: ";
break; break;
case DB_NOT_FOUND: case DB_NOT_FOUND:
type = "NotFound: "; result = "Not found: ";
break; break;
case DB_ALREADY_EXIST: case DB_ALREADY_EXIST:
type = "AlreadyExist: "; result = "Already exist: ";
break; break;
case DB_INVALID_PATH: case DB_INVALID_PATH:
type = "InvalidPath: "; result = "Invalid path: ";
break; break;
default: default:
snprintf(tmp, sizeof(tmp), "Error code(0x%x): ", result = "Error code(" + std::to_string(code()) + "): ";
static_cast<int>(code()));
type = tmp;
break; break;
} }
std::string result(type);
uint32_t length = 0; uint32_t length = 0;
memcpy(&length, state_ + CODE_WIDTH, sizeof(length)); memcpy(&length, state_ + CODE_WIDTH, sizeof(length));
result.append(state_ + sizeof(length) + CODE_WIDTH, length); if(length > 0) {
result.append(state_ + sizeof(length) + CODE_WIDTH, length);
}
return result; return result;
} }
} // namespace engine
} // namespace milvus } // namespace milvus
} // namespace zilliz } // namespace zilliz
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
#pragma once #pragma once
#include "utils/Error.h" #include "utils/Error.h"
...@@ -23,7 +24,6 @@ ...@@ -23,7 +24,6 @@
namespace zilliz { namespace zilliz {
namespace milvus { namespace milvus {
namespace engine {
class Status { class Status {
public: public:
...@@ -31,51 +31,40 @@ class Status { ...@@ -31,51 +31,40 @@ class Status {
Status(); Status();
~Status(); ~Status();
Status(const Status &rhs); Status(const Status &s);
Status & Status &
operator=(const Status &rhs); operator=(const Status &s);
Status(Status &&rhs) noexcept : state_(rhs.state_) { rhs.state_ = nullptr; } Status(Status &&s);
Status & Status &
operator=(Status &&rhs_) noexcept; operator=(Status &&s);
static Status static Status
OK() { return Status(); } OK() { return Status(); }
bool ok() const { return state_ == nullptr || code() == DB_SUCCESS; } bool
ok() const { return state_ == nullptr || code() == 0; }
std::string ToString() const; std::string
ToString() const;
ErrorCode code() const { ErrorCode
return (state_ == nullptr) ? DB_SUCCESS : *(ErrorCode*)(state_); code() const {
return (state_ == nullptr) ? 0 : *(ErrorCode*)(state_);
} }
private: private:
const char *state_ = nullptr; inline void
CopyFrom(const Status &s);
static const char *CopyState(const char *s); inline void
MoveFrom(Status &s);
private:
const char *state_ = nullptr;
}; // Status }; // Status
inline Status::Status(const Status &rhs) {
state_ = (rhs.state_ == nullptr) ? nullptr : CopyState(rhs.state_);
}
inline Status &Status::operator=(const Status &rhs) {
if (state_ != rhs.state_) {
delete[] state_;
state_ = (rhs.state_ == nullptr) ? nullptr : CopyState(rhs.state_);
}
return *this;
}
inline Status &Status::operator=(Status &&rhs) noexcept {
std::swap(state_, rhs.state_);
return *this;
}
} // namespace engine
} // namespace milvus } // namespace milvus
} // namespace zilliz } // namespace zilliz
...@@ -33,9 +33,9 @@ aux_source_directory(${MILVUS_ENGINE_SRC}/scheduler scheduler_srcs) ...@@ -33,9 +33,9 @@ aux_source_directory(${MILVUS_ENGINE_SRC}/scheduler scheduler_srcs)
aux_source_directory(./ test_srcs) aux_source_directory(./ test_srcs)
set(util_files set(util_files
${MILVUS_ENGINE_SRC}/utils/Status.cpp
${MILVUS_ENGINE_SRC}/utils/ValidationUtil.cpp ${MILVUS_ENGINE_SRC}/utils/ValidationUtil.cpp
${MILVUS_ENGINE_SRC}/utils/easylogging++.cc ${MILVUS_ENGINE_SRC}/utils/easylogging++.cc)
${MILVUS_ENGINE_SRC}/utils/easylogging++.h)
aux_source_directory(${MILVUS_ENGINE_SRC}/db/scheduler scheduler_files) aux_source_directory(${MILVUS_ENGINE_SRC}/db/scheduler scheduler_files)
aux_source_directory(${MILVUS_ENGINE_SRC}/db/scheduler/context scheduler_context_files) aux_source_directory(${MILVUS_ENGINE_SRC}/db/scheduler/context scheduler_context_files)
......
...@@ -154,7 +154,7 @@ TEST_F(DBTest, CONFIG_TEST) { ...@@ -154,7 +154,7 @@ TEST_F(DBTest, CONFIG_TEST) {
TEST_F(DBTest, DB_TEST) { TEST_F(DBTest, DB_TEST) {
engine::meta::TableSchema table_info = BuildTableSchema(); engine::meta::TableSchema table_info = BuildTableSchema();
engine::Status stat = db_->CreateTable(table_info); auto stat = db_->CreateTable(table_info);
engine::meta::TableSchema table_info_get; engine::meta::TableSchema table_info_get;
table_info_get.table_id_ = TABLE_NAME; table_info_get.table_id_ = TABLE_NAME;
...@@ -230,7 +230,7 @@ TEST_F(DBTest, DB_TEST) { ...@@ -230,7 +230,7 @@ TEST_F(DBTest, DB_TEST) {
TEST_F(DBTest, SEARCH_TEST) { TEST_F(DBTest, SEARCH_TEST) {
engine::meta::TableSchema table_info = BuildTableSchema(); engine::meta::TableSchema table_info = BuildTableSchema();
engine::Status stat = db_->CreateTable(table_info); auto stat = db_->CreateTable(table_info);
engine::meta::TableSchema table_info_get; engine::meta::TableSchema table_info_get;
table_info_get.table_id_ = TABLE_NAME; table_info_get.table_id_ = TABLE_NAME;
...@@ -296,7 +296,7 @@ TEST_F(DBTest, SEARCH_TEST) { ...@@ -296,7 +296,7 @@ TEST_F(DBTest, SEARCH_TEST) {
TEST_F(DBTest, PRELOADTABLE_TEST) { TEST_F(DBTest, PRELOADTABLE_TEST) {
engine::meta::TableSchema table_info = BuildTableSchema(); engine::meta::TableSchema table_info = BuildTableSchema();
engine::Status stat = db_->CreateTable(table_info); auto stat = db_->CreateTable(table_info);
engine::meta::TableSchema table_info_get; engine::meta::TableSchema table_info_get;
table_info_get.table_id_ = TABLE_NAME; table_info_get.table_id_ = TABLE_NAME;
...@@ -331,7 +331,7 @@ TEST_F(DBTest, SHUTDOWN_TEST) { ...@@ -331,7 +331,7 @@ TEST_F(DBTest, SHUTDOWN_TEST) {
db_->Stop(); db_->Stop();
engine::meta::TableSchema table_info = BuildTableSchema(); engine::meta::TableSchema table_info = BuildTableSchema();
engine::Status stat = db_->CreateTable(table_info); auto stat = db_->CreateTable(table_info);
ASSERT_FALSE(stat.ok()); ASSERT_FALSE(stat.ok());
stat = db_->DescribeTable(table_info); stat = db_->DescribeTable(table_info);
...@@ -373,7 +373,7 @@ TEST_F(DBTest, SHUTDOWN_TEST) { ...@@ -373,7 +373,7 @@ TEST_F(DBTest, SHUTDOWN_TEST) {
TEST_F(DBTest, INDEX_TEST) { TEST_F(DBTest, INDEX_TEST) {
engine::meta::TableSchema table_info = BuildTableSchema(); engine::meta::TableSchema table_info = BuildTableSchema();
engine::Status stat = db_->CreateTable(table_info); auto stat = db_->CreateTable(table_info);
int64_t nb = VECTOR_COUNT; int64_t nb = VECTOR_COUNT;
std::vector<float> xb; std::vector<float> xb;
...@@ -403,7 +403,7 @@ TEST_F(DBTest, INDEX_TEST) { ...@@ -403,7 +403,7 @@ TEST_F(DBTest, INDEX_TEST) {
TEST_F(DBTest2, ARHIVE_DISK_CHECK) { TEST_F(DBTest2, ARHIVE_DISK_CHECK) {
engine::meta::TableSchema table_info = BuildTableSchema(); engine::meta::TableSchema table_info = BuildTableSchema();
engine::Status stat = db_->CreateTable(table_info); auto stat = db_->CreateTable(table_info);
std::vector<engine::meta::TableSchema> table_schema_array; std::vector<engine::meta::TableSchema> table_schema_array;
stat = db_->AllTables(table_schema_array); stat = db_->AllTables(table_schema_array);
...@@ -446,7 +446,7 @@ TEST_F(DBTest2, ARHIVE_DISK_CHECK) { ...@@ -446,7 +446,7 @@ TEST_F(DBTest2, ARHIVE_DISK_CHECK) {
TEST_F(DBTest2, DELETE_TEST) { TEST_F(DBTest2, DELETE_TEST) {
engine::meta::TableSchema table_info = BuildTableSchema(); engine::meta::TableSchema table_info = BuildTableSchema();
engine::Status stat = db_->CreateTable(table_info); auto stat = db_->CreateTable(table_info);
engine::meta::TableSchema table_info_get; engine::meta::TableSchema table_info_get;
table_info_get.table_id_ = TABLE_NAME; table_info_get.table_id_ = TABLE_NAME;
...@@ -480,7 +480,7 @@ TEST_F(DBTest2, DELETE_TEST) { ...@@ -480,7 +480,7 @@ TEST_F(DBTest2, DELETE_TEST) {
TEST_F(DBTest2, DELETE_BY_RANGE_TEST) { TEST_F(DBTest2, DELETE_BY_RANGE_TEST) {
engine::meta::TableSchema table_info = BuildTableSchema(); engine::meta::TableSchema table_info = BuildTableSchema();
engine::Status stat = db_->CreateTable(table_info); auto stat = db_->CreateTable(table_info);
engine::meta::TableSchema table_info_get; engine::meta::TableSchema table_info_get;
table_info_get.table_id_ = TABLE_NAME; table_info_get.table_id_ = TABLE_NAME;
......
...@@ -216,7 +216,7 @@ TEST_F(MemManagerTest, MEM_TABLE_TEST) { ...@@ -216,7 +216,7 @@ TEST_F(MemManagerTest, MEM_TABLE_TEST) {
TEST_F(MemManagerTest2, SERIAL_INSERT_SEARCH_TEST) { TEST_F(MemManagerTest2, SERIAL_INSERT_SEARCH_TEST) {
engine::meta::TableSchema table_info = BuildTableSchema(); engine::meta::TableSchema table_info = BuildTableSchema();
engine::Status stat = db_->CreateTable(table_info); auto stat = db_->CreateTable(table_info);
engine::meta::TableSchema table_info_get; engine::meta::TableSchema table_info_get;
table_info_get.table_id_ = TABLE_NAME; table_info_get.table_id_ = TABLE_NAME;
...@@ -230,8 +230,8 @@ TEST_F(MemManagerTest2, SERIAL_INSERT_SEARCH_TEST) { ...@@ -230,8 +230,8 @@ TEST_F(MemManagerTest2, SERIAL_INSERT_SEARCH_TEST) {
int64_t nb = 100000; int64_t nb = 100000;
std::vector<float> xb; std::vector<float> xb;
BuildVectors(nb, xb); BuildVectors(nb, xb);
engine::Status status = db_->InsertVectors(TABLE_NAME, nb, xb.data(), vector_ids); stat = db_->InsertVectors(TABLE_NAME, nb, xb.data(), vector_ids);
ASSERT_TRUE(status.ok()); ASSERT_TRUE(stat.ok());
std::this_thread::sleep_for(std::chrono::seconds(3)); std::this_thread::sleep_for(std::chrono::seconds(3));
...@@ -262,7 +262,7 @@ TEST_F(MemManagerTest2, SERIAL_INSERT_SEARCH_TEST) { ...@@ -262,7 +262,7 @@ TEST_F(MemManagerTest2, SERIAL_INSERT_SEARCH_TEST) {
TEST_F(MemManagerTest2, INSERT_TEST) { TEST_F(MemManagerTest2, INSERT_TEST) {
engine::meta::TableSchema table_info = BuildTableSchema(); engine::meta::TableSchema table_info = BuildTableSchema();
engine::Status stat = db_->CreateTable(table_info); auto stat = db_->CreateTable(table_info);
engine::meta::TableSchema table_info_get; engine::meta::TableSchema table_info_get;
table_info_get.table_id_ = TABLE_NAME; table_info_get.table_id_ = TABLE_NAME;
...@@ -278,8 +278,8 @@ TEST_F(MemManagerTest2, INSERT_TEST) { ...@@ -278,8 +278,8 @@ TEST_F(MemManagerTest2, INSERT_TEST) {
std::vector<float> xb; std::vector<float> xb;
BuildVectors(nb, xb); BuildVectors(nb, xb);
engine::IDNumbers vector_ids; engine::IDNumbers vector_ids;
engine::Status status = db_->InsertVectors(TABLE_NAME, nb, xb.data(), vector_ids); stat = db_->InsertVectors(TABLE_NAME, nb, xb.data(), vector_ids);
ASSERT_TRUE(status.ok()); ASSERT_TRUE(stat.ok());
} }
auto end_time = METRICS_NOW_TIME; auto end_time = METRICS_NOW_TIME;
auto total_time = METRICS_MICROSECONDS(start_time, end_time); auto total_time = METRICS_MICROSECONDS(start_time, end_time);
...@@ -288,7 +288,7 @@ TEST_F(MemManagerTest2, INSERT_TEST) { ...@@ -288,7 +288,7 @@ TEST_F(MemManagerTest2, INSERT_TEST) {
TEST_F(MemManagerTest2, CONCURRENT_INSERT_SEARCH_TEST) { TEST_F(MemManagerTest2, CONCURRENT_INSERT_SEARCH_TEST) {
engine::meta::TableSchema table_info = BuildTableSchema(); engine::meta::TableSchema table_info = BuildTableSchema();
engine::Status stat = db_->CreateTable(table_info); auto stat = db_->CreateTable(table_info);
engine::meta::TableSchema table_info_get; engine::meta::TableSchema table_info_get;
table_info_get.table_id_ = TABLE_NAME; table_info_get.table_id_ = TABLE_NAME;
...@@ -359,7 +359,7 @@ TEST_F(MemManagerTest2, CONCURRENT_INSERT_SEARCH_TEST) { ...@@ -359,7 +359,7 @@ TEST_F(MemManagerTest2, CONCURRENT_INSERT_SEARCH_TEST) {
TEST_F(MemManagerTest2, VECTOR_IDS_TEST) { TEST_F(MemManagerTest2, VECTOR_IDS_TEST) {
engine::meta::TableSchema table_info = BuildTableSchema(); engine::meta::TableSchema table_info = BuildTableSchema();
engine::Status stat = db_->CreateTable(table_info); auto stat = db_->CreateTable(table_info);
engine::meta::TableSchema table_info_get; engine::meta::TableSchema table_info_get;
table_info_get.table_id_ = TABLE_NAME; table_info_get.table_id_ = TABLE_NAME;
......
...@@ -15,11 +15,11 @@ ...@@ -15,11 +15,11 @@
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
#include "db/Status.h"
#include "db/Options.h" #include "db/Options.h"
#include "db/meta/SqliteMetaImpl.h" #include "db/meta/SqliteMetaImpl.h"
#include "db/engine/EngineFactory.h" #include "db/engine/EngineFactory.h"
#include "db/Utils.h" #include "db/Utils.h"
#include "utils/Status.h"
#include "utils/Exception.h" #include "utils/Exception.h"
#include "utils/easylogging++.h" #include "utils/easylogging++.h"
...@@ -30,13 +30,6 @@ ...@@ -30,13 +30,6 @@
using namespace zilliz::milvus; using namespace zilliz::milvus;
namespace {
void CopyStatus(engine::Status& st1, engine::Status& st2) {
st1 = st2;
}
}
TEST(DBMiscTest, EXCEPTION_TEST) { TEST(DBMiscTest, EXCEPTION_TEST) {
Exception ex1(""); Exception ex1("");
std::string what = ex1.what(); std::string what = ex1.what();
...@@ -47,36 +40,6 @@ TEST(DBMiscTest, EXCEPTION_TEST) { ...@@ -47,36 +40,6 @@ TEST(DBMiscTest, EXCEPTION_TEST) {
ASSERT_FALSE(what.empty()); ASSERT_FALSE(what.empty());
} }
TEST(DBMiscTest, STATUS_TEST) {
engine::Status status = engine::Status::OK();
std::string str = status.ToString();
ASSERT_FALSE(str.empty());
status = engine::Status(DB_ERROR, "mistake");
ASSERT_EQ(status.code(), DB_ERROR);
str = status.ToString();
ASSERT_FALSE(str.empty());
status = engine::Status(DB_NOT_FOUND, "mistake");
ASSERT_EQ(status.code(), DB_NOT_FOUND);
str = status.ToString();
ASSERT_FALSE(str.empty());
status = engine::Status(DB_ALREADY_EXIST, "mistake");
ASSERT_EQ(status.code(), DB_ALREADY_EXIST);
str = status.ToString();
ASSERT_FALSE(str.empty());
status = engine::Status(DB_META_TRANSACTION_FAILED, "mistake");
ASSERT_EQ(status.code(), DB_META_TRANSACTION_FAILED);
str = status.ToString();
ASSERT_FALSE(str.empty());
engine::Status status_copy = engine::Status::OK();
CopyStatus(status_copy, status);
ASSERT_EQ(status.code(), DB_META_TRANSACTION_FAILED);
}
TEST(DBMiscTest, OPTIONS_TEST) { TEST(DBMiscTest, OPTIONS_TEST) {
try { try {
engine::ArchiveConf archive("$$##"); engine::ArchiveConf archive("$$##");
......
...@@ -59,7 +59,7 @@ namespace { ...@@ -59,7 +59,7 @@ namespace {
TEST_F(MySqlDBTest, DB_TEST) { TEST_F(MySqlDBTest, DB_TEST) {
engine::meta::TableSchema table_info = BuildTableSchema(); engine::meta::TableSchema table_info = BuildTableSchema();
engine::Status stat = db_->CreateTable(table_info); auto stat = db_->CreateTable(table_info);
engine::meta::TableSchema table_info_get; engine::meta::TableSchema table_info_get;
table_info_get.table_id_ = TABLE_NAME; table_info_get.table_id_ = TABLE_NAME;
...@@ -144,7 +144,7 @@ TEST_F(MySqlDBTest, DB_TEST) { ...@@ -144,7 +144,7 @@ TEST_F(MySqlDBTest, DB_TEST) {
TEST_F(MySqlDBTest, SEARCH_TEST) { TEST_F(MySqlDBTest, SEARCH_TEST) {
engine::meta::TableSchema table_info = BuildTableSchema(); engine::meta::TableSchema table_info = BuildTableSchema();
engine::Status stat = db_->CreateTable(table_info); auto stat = db_->CreateTable(table_info);
engine::meta::TableSchema table_info_get; engine::meta::TableSchema table_info_get;
table_info_get.table_id_ = TABLE_NAME; table_info_get.table_id_ = TABLE_NAME;
...@@ -196,7 +196,7 @@ TEST_F(MySqlDBTest, SEARCH_TEST) { ...@@ -196,7 +196,7 @@ TEST_F(MySqlDBTest, SEARCH_TEST) {
TEST_F(MySqlDBTest, ARHIVE_DISK_CHECK) { TEST_F(MySqlDBTest, ARHIVE_DISK_CHECK) {
engine::meta::TableSchema table_info = BuildTableSchema(); engine::meta::TableSchema table_info = BuildTableSchema();
engine::Status stat = db_->CreateTable(table_info); auto stat = db_->CreateTable(table_info);
std::vector<engine::meta::TableSchema> table_schema_array; std::vector<engine::meta::TableSchema> table_schema_array;
stat = db_->AllTables(table_schema_array); stat = db_->AllTables(table_schema_array);
...@@ -241,7 +241,7 @@ TEST_F(MySqlDBTest, ARHIVE_DISK_CHECK) { ...@@ -241,7 +241,7 @@ TEST_F(MySqlDBTest, ARHIVE_DISK_CHECK) {
TEST_F(MySqlDBTest, DELETE_TEST) { TEST_F(MySqlDBTest, DELETE_TEST) {
engine::meta::TableSchema table_info = BuildTableSchema(); engine::meta::TableSchema table_info = BuildTableSchema();
engine::Status stat = db_->CreateTable(table_info); auto stat = db_->CreateTable(table_info);
// std::cout << stat.ToString() << std::endl; // std::cout << stat.ToString() << std::endl;
engine::meta::TableSchema table_info_get; engine::meta::TableSchema table_info_get;
......
...@@ -37,9 +37,9 @@ aux_source_directory(${MILVUS_ENGINE_SRC}/src/metrics metrics_src) ...@@ -37,9 +37,9 @@ aux_source_directory(${MILVUS_ENGINE_SRC}/src/metrics metrics_src)
aux_source_directory(./ test_srcs) aux_source_directory(./ test_srcs)
set(util_files set(util_files
${MILVUS_ENGINE_SRC}/utils/Status.cpp
${MILVUS_ENGINE_SRC}/utils/ValidationUtil.cpp ${MILVUS_ENGINE_SRC}/utils/ValidationUtil.cpp
${MILVUS_ENGINE_SRC}/utils/easylogging++.cc ${MILVUS_ENGINE_SRC}/utils/easylogging++.cc)
${MILVUS_ENGINE_SRC}/utils/easylogging++.h)
aux_source_directory(${MILVUS_ENGINE_SRC}/db/scheduler scheduler_files) aux_source_directory(${MILVUS_ENGINE_SRC}/db/scheduler scheduler_files)
aux_source_directory(${MILVUS_ENGINE_SRC}/db/scheduler/context scheduler_context_files) aux_source_directory(${MILVUS_ENGINE_SRC}/db/scheduler/context scheduler_context_files)
......
...@@ -57,7 +57,7 @@ TEST_F(MetricTest, METRIC_TEST) { ...@@ -57,7 +57,7 @@ TEST_F(MetricTest, METRIC_TEST) {
engine::meta::TableSchema group_info; engine::meta::TableSchema group_info;
group_info.dimension_ = group_dim; group_info.dimension_ = group_dim;
group_info.table_id_ = group_name; group_info.table_id_ = group_name;
engine::Status stat = db_->CreateTable(group_info); auto stat = db_->CreateTable(group_info);
engine::meta::TableSchema group_info_get; engine::meta::TableSchema group_info_get;
group_info_get.table_id_ = group_name; group_info_get.table_id_ = group_name;
...@@ -134,9 +134,9 @@ TEST_F(MetricTest, METRIC_TEST) { ...@@ -134,9 +134,9 @@ TEST_F(MetricTest, METRIC_TEST) {
}; };
TEST_F(MetricTest, COLLECTOR_METRICS_TEST){ TEST_F(MetricTest, COLLECTOR_METRICS_TEST){
engine::Status status = engine::Status::OK(); auto status = Status::OK();
server::CollectInsertMetrics insert_metrics0(0, status); server::CollectInsertMetrics insert_metrics0(0, status);
status = engine::Status(DB_ERROR, "error"); status = Status(DB_ERROR, "error");
server::CollectInsertMetrics insert_metrics1(0, status); server::CollectInsertMetrics insert_metrics1(0, status);
server::CollectQueryMetrics query_metrics(10); server::CollectQueryMetrics query_metrics(10);
......
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
#define STOP_TIMER(name) #define STOP_TIMER(name)
#endif #endif
void ASSERT_STATS(zilliz::milvus::engine::Status& stat); void ASSERT_STATS(zilliz::milvus::Status& stat);
//class TestEnv : public ::testing::Environment { //class TestEnv : public ::testing::Environment {
//public: //public:
......
...@@ -36,9 +36,9 @@ aux_source_directory(${MILVUS_ENGINE_SRC}/scheduler scheduler_srcs) ...@@ -36,9 +36,9 @@ aux_source_directory(${MILVUS_ENGINE_SRC}/scheduler scheduler_srcs)
aux_source_directory(./ test_srcs) aux_source_directory(./ test_srcs)
set(util_files set(util_files
${MILVUS_ENGINE_SRC}/utils/Status.cpp
${MILVUS_ENGINE_SRC}/utils/ValidationUtil.cpp ${MILVUS_ENGINE_SRC}/utils/ValidationUtil.cpp
${MILVUS_ENGINE_SRC}/utils/easylogging++.cc ${MILVUS_ENGINE_SRC}/utils/easylogging++.cc)
${MILVUS_ENGINE_SRC}/utils/easylogging++.h)
set(db_scheduler_srcs set(db_scheduler_srcs
${scheduler_files} ${scheduler_files}
......
...@@ -54,9 +54,9 @@ set(db_scheduler_srcs ...@@ -54,9 +54,9 @@ set(db_scheduler_srcs
) )
set(util_files set(util_files
${MILVUS_ENGINE_SRC}/utils/Status.cpp
${MILVUS_ENGINE_SRC}/utils/ValidationUtil.cpp ${MILVUS_ENGINE_SRC}/utils/ValidationUtil.cpp
${MILVUS_ENGINE_SRC}/utils/easylogging++.cc ${MILVUS_ENGINE_SRC}/utils/easylogging++.cc)
${MILVUS_ENGINE_SRC}/utils/easylogging++.h)
set(db_src set(db_src
${config_files} ${config_files}
......
...@@ -37,6 +37,10 @@ namespace { ...@@ -37,6 +37,10 @@ namespace {
static const char* LOG_FILE_PATH = "./milvus/conf/log_config.conf"; static const char* LOG_FILE_PATH = "./milvus/conf/log_config.conf";
void CopyStatus(Status& st1, Status& st2) {
st1 = st2;
}
} }
TEST(UtilTest, EXCEPTION_TEST) { TEST(UtilTest, EXCEPTION_TEST) {
...@@ -183,6 +187,44 @@ TEST(UtilTest, TIMERECORDER_TEST) { ...@@ -183,6 +187,44 @@ TEST(UtilTest, TIMERECORDER_TEST) {
} }
} }
TEST(UtilTest, STATUS_TEST) {
auto status = Status::OK();
std::string str = status.ToString();
ASSERT_FALSE(str.empty());
status = Status(DB_ERROR, "mistake");
ASSERT_EQ(status.code(), DB_ERROR);
str = status.ToString();
ASSERT_FALSE(str.empty());
status = Status(DB_NOT_FOUND, "mistake");
ASSERT_EQ(status.code(), DB_NOT_FOUND);
str = status.ToString();
ASSERT_FALSE(str.empty());
status = Status(DB_ALREADY_EXIST, "mistake");
ASSERT_EQ(status.code(), DB_ALREADY_EXIST);
str = status.ToString();
ASSERT_FALSE(str.empty());
status = Status(DB_META_TRANSACTION_FAILED, "mistake");
ASSERT_EQ(status.code(), DB_META_TRANSACTION_FAILED);
str = status.ToString();
ASSERT_FALSE(str.empty());
auto status_copy = Status::OK();
CopyStatus(status_copy, status);
ASSERT_EQ(status.code(), DB_META_TRANSACTION_FAILED);
auto status_ref(status);
ASSERT_EQ(status_ref.code(), status.code());
ASSERT_EQ(status_ref.ToString(), status.ToString());
auto status_move = std::move(status);
ASSERT_EQ(status_move.code(), status_ref.code());
ASSERT_EQ(status_move.ToString(), status_ref.ToString());
}
TEST(ValidationUtilTest, VALIDATE_TABLENAME_TEST) { TEST(ValidationUtilTest, VALIDATE_TABLENAME_TEST) {
std::string table_name = "Normal123_"; std::string table_name = "Normal123_";
ErrorCode res = server::ValidationUtil::ValidateTableName(table_name); ErrorCode res = server::ValidationUtil::ValidateTableName(table_name);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册