mirror of
https://gitee.com/milvus-io/milvus.git
synced 2025-12-31 07:55:38 +08:00
Merge branch 'branch-0.5.0' into 'branch-0.5.0'
MS-558 refine status code See merge request megasearch/milvus!576 Former-commit-id: 84c716e051e4049733eb956c59507e8514ea37c0
This commit is contained in:
commit
73ff79dbb8
@ -104,6 +104,8 @@ ${LCOV_CMD} -r "${FILE_INFO_OUTPUT}" -o "${FILE_INFO_OUTPUT_NEW}" \
|
||||
"src/server/Server.cpp"\
|
||||
"src/server/DBWrapper.cpp"\
|
||||
"src/server/grpc_impl/GrpcMilvusServer.cpp"\
|
||||
"src/utils/easylogging++.h"\
|
||||
"src/utils/easylogging++.cc"\
|
||||
|
||||
# gen html report
|
||||
${LCOV_GEN_CMD} "${FILE_INFO_OUTPUT_NEW}" --output-directory ${DIR_LCOV_OUTPUT}/
|
||||
@ -80,17 +80,17 @@ Status CreateTablePath(const DBMetaOptions& options, const std::string& table_id
|
||||
std::string db_path = options.path;
|
||||
std::string table_path = db_path + TABLES_FOLDER + table_id;
|
||||
auto status = server::CommonUtil::CreateDirectory(table_path);
|
||||
if (status != 0) {
|
||||
ENGINE_LOG_ERROR << "Create directory " << table_path << " Error";
|
||||
return Status(DB_ERROR, "Failed to create table path");
|
||||
if (!status.ok()) {
|
||||
ENGINE_LOG_ERROR << status.message();
|
||||
return status;
|
||||
}
|
||||
|
||||
for(auto& path : options.slave_paths) {
|
||||
table_path = path + TABLES_FOLDER + table_id;
|
||||
status = server::CommonUtil::CreateDirectory(table_path);
|
||||
if (status != 0) {
|
||||
ENGINE_LOG_ERROR << "Create directory " << table_path << " Error";
|
||||
return Status(DB_ERROR, "Failed to create table path");
|
||||
if (!status.ok()) {
|
||||
ENGINE_LOG_ERROR << status.message();
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
@ -120,9 +120,9 @@ Status CreateTableFilePath(const DBMetaOptions& options, meta::TableFileSchema&
|
||||
std::string parent_path = GetTableFileParentFolder(options, table_file);
|
||||
|
||||
auto status = server::CommonUtil::CreateDirectory(parent_path);
|
||||
if (status != 0) {
|
||||
ENGINE_LOG_ERROR << "Create directory " << parent_path << " Error";
|
||||
return Status(DB_ERROR, "Failed to create partition directory");
|
||||
if (!status.ok()) {
|
||||
ENGINE_LOG_ERROR << status.message();
|
||||
return status;
|
||||
}
|
||||
|
||||
table_file.location_ = parent_path + "/" + table_file.file_id_;
|
||||
|
||||
@ -54,7 +54,7 @@ Status MemTable::Add(VectorSourcePtr &source, IDNumbers &vector_ids) {
|
||||
}
|
||||
|
||||
if (!status.ok()) {
|
||||
std::string err_msg = "MemTable::Add failed: " + status.ToString();
|
||||
std::string err_msg = "Insert failed: " + status.ToString();
|
||||
ENGINE_LOG_ERROR << err_msg;
|
||||
return Status(DB_ERROR, err_msg);
|
||||
}
|
||||
@ -74,7 +74,7 @@ Status MemTable::Serialize() {
|
||||
for (auto mem_table_file = mem_table_file_list_.begin(); mem_table_file != mem_table_file_list_.end();) {
|
||||
auto status = (*mem_table_file)->Serialize();
|
||||
if (!status.ok()) {
|
||||
std::string err_msg = "MemTable::Serialize failed: " + status.ToString();
|
||||
std::string err_msg = "Insert data serialize failed: " + status.ToString();
|
||||
ENGINE_LOG_ERROR << err_msg;
|
||||
return Status(DB_ERROR, err_msg);
|
||||
}
|
||||
|
||||
@ -67,7 +67,7 @@ Status MemTableFile::Add(const VectorSourcePtr &source, IDNumbers& vector_ids) {
|
||||
std::string err_msg = "MemTableFile::Add: table_file_schema dimension = " +
|
||||
std::to_string(table_file_schema_.dimension_) + ", table_id = " + table_file_schema_.table_id_;
|
||||
ENGINE_LOG_ERROR << err_msg;
|
||||
return Status(DB_ERROR, "not able to create table file");
|
||||
return Status(DB_ERROR, "Not able to create table file");
|
||||
}
|
||||
|
||||
size_t single_vector_mem_size = table_file_schema_.dimension_ * VECTOR_TYPE_SIZE;
|
||||
|
||||
@ -190,7 +190,7 @@ void DoSearch(std::shared_ptr<Connection> conn,
|
||||
{
|
||||
TimeRecorder rc(phase_name);
|
||||
Status stat = conn->Search(TABLE_NAME, record_array, query_range_array, TOP_K, 32, topk_query_result_array);
|
||||
std::cout << "SearchVector function call status: " << stat.ToString() << std::endl;
|
||||
std::cout << "SearchVector function call status: " << stat.message() << std::endl;
|
||||
}
|
||||
auto finish = std::chrono::high_resolution_clock::now();
|
||||
std::cout << "SEARCHVECTOR COST: " << std::chrono::duration_cast<std::chrono::duration<double>>(finish - start).count() << "s\n";
|
||||
@ -207,7 +207,7 @@ ClientTest::Test(const std::string& address, const std::string& port) {
|
||||
{//connect server
|
||||
ConnectParam param = {address, port};
|
||||
Status stat = conn->Connect(param);
|
||||
std::cout << "Connect function call status: " << stat.ToString() << std::endl;
|
||||
std::cout << "Connect function call status: " << stat.message() << std::endl;
|
||||
}
|
||||
|
||||
{//server version
|
||||
@ -223,7 +223,7 @@ ClientTest::Test(const std::string& address, const std::string& port) {
|
||||
{
|
||||
std::vector<std::string> tables;
|
||||
Status stat = conn->ShowTables(tables);
|
||||
std::cout << "ShowTables function call status: " << stat.ToString() << std::endl;
|
||||
std::cout << "ShowTables function call status: " << stat.message() << std::endl;
|
||||
std::cout << "All tables: " << std::endl;
|
||||
for(auto& table : tables) {
|
||||
int64_t row_count = 0;
|
||||
@ -236,7 +236,7 @@ ClientTest::Test(const std::string& address, const std::string& port) {
|
||||
{//create table
|
||||
TableSchema tb_schema = BuildTableSchema();
|
||||
Status stat = conn->CreateTable(tb_schema);
|
||||
std::cout << "CreateTable function call status: " << stat.ToString() << std::endl;
|
||||
std::cout << "CreateTable function call status: " << stat.message() << std::endl;
|
||||
PrintTableSchema(tb_schema);
|
||||
|
||||
bool has_table = conn->HasTable(tb_schema.table_name);
|
||||
@ -248,7 +248,7 @@ ClientTest::Test(const std::string& address, const std::string& port) {
|
||||
{//describe table
|
||||
TableSchema tb_schema;
|
||||
Status stat = conn->DescribeTable(TABLE_NAME, tb_schema);
|
||||
std::cout << "DescribeTable function call status: " << stat.ToString() << std::endl;
|
||||
std::cout << "DescribeTable function call status: " << stat.message() << std::endl;
|
||||
PrintTableSchema(tb_schema);
|
||||
}
|
||||
|
||||
@ -279,7 +279,7 @@ ClientTest::Test(const std::string& address, const std::string& port) {
|
||||
std::cout << "InsertVector cost: " << std::chrono::duration_cast<std::chrono::duration<double>>(finish - start).count() << "s\n";
|
||||
|
||||
|
||||
std::cout << "InsertVector function call status: " << stat.ToString() << std::endl;
|
||||
std::cout << "InsertVector function call status: " << stat.message() << std::endl;
|
||||
std::cout << "Returned id array count: " << record_ids.size() << std::endl;
|
||||
|
||||
if(search_record_array.size() < NQ) {
|
||||
@ -305,16 +305,16 @@ ClientTest::Test(const std::string& address, const std::string& port) {
|
||||
index.index_type = IndexType::gpu_ivfsq8;
|
||||
index.nlist = 16384;
|
||||
Status stat = conn->CreateIndex(index);
|
||||
std::cout << "CreateIndex function call status: " << stat.ToString() << std::endl;
|
||||
std::cout << "CreateIndex function call status: " << stat.message() << std::endl;
|
||||
|
||||
IndexParam index2;
|
||||
stat = conn->DescribeIndex(TABLE_NAME, index2);
|
||||
std::cout << "DescribeIndex function call status: " << stat.ToString() << std::endl;
|
||||
std::cout << "DescribeIndex function call status: " << stat.message() << std::endl;
|
||||
}
|
||||
|
||||
{//preload table
|
||||
Status stat = conn->PreloadTable(TABLE_NAME);
|
||||
std::cout << "PreloadTable function call status: " << stat.ToString() << std::endl;
|
||||
std::cout << "PreloadTable function call status: " << stat.message() << std::endl;
|
||||
}
|
||||
|
||||
{//search vectors after build index finish
|
||||
@ -326,7 +326,7 @@ ClientTest::Test(const std::string& address, const std::string& port) {
|
||||
|
||||
{//delete index
|
||||
Status stat = conn->DropIndex(TABLE_NAME);
|
||||
std::cout << "DropIndex function call status: " << stat.ToString() << std::endl;
|
||||
std::cout << "DropIndex function call status: " << stat.message() << std::endl;
|
||||
|
||||
int64_t row_count = 0;
|
||||
stat = conn->CountTable(TABLE_NAME, row_count);
|
||||
@ -339,12 +339,12 @@ ClientTest::Test(const std::string& address, const std::string& port) {
|
||||
rg.end_value = CurrentTmDate(-3);
|
||||
|
||||
Status stat = conn->DeleteByRange(rg, TABLE_NAME);
|
||||
std::cout << "DeleteByRange function call status: " << stat.ToString() << std::endl;
|
||||
std::cout << "DeleteByRange function call status: " << stat.message() << std::endl;
|
||||
}
|
||||
|
||||
{//delete table
|
||||
Status stat = conn->DropTable(TABLE_NAME);
|
||||
std::cout << "DeleteTable function call status: " << stat.ToString() << std::endl;
|
||||
std::cout << "DeleteTable function call status: " << stat.message() << std::endl;
|
||||
}
|
||||
|
||||
{//server status
|
||||
|
||||
@ -40,14 +40,12 @@ enum class StatusCode {
|
||||
ServerFailed,
|
||||
};
|
||||
|
||||
using ErrorCode = StatusCode;
|
||||
|
||||
/**
|
||||
* @brief Status for SDK interface return
|
||||
*/
|
||||
class Status {
|
||||
public:
|
||||
Status(ErrorCode code, const std::string &msg);
|
||||
Status(StatusCode code, const std::string &msg);
|
||||
Status();
|
||||
~Status();
|
||||
|
||||
@ -67,14 +65,14 @@ public:
|
||||
bool
|
||||
ok() const { return state_ == nullptr || code() == StatusCode::OK; }
|
||||
|
||||
std::string
|
||||
ToString() const;
|
||||
|
||||
ErrorCode
|
||||
StatusCode
|
||||
code() const {
|
||||
return (state_ == nullptr) ? StatusCode::OK : *(ErrorCode*)(state_);
|
||||
return (state_ == nullptr) ? StatusCode::OK : *(StatusCode*)(state_);
|
||||
}
|
||||
|
||||
std::string
|
||||
message() const;
|
||||
|
||||
private:
|
||||
inline void
|
||||
CopyFrom(const Status &s);
|
||||
|
||||
@ -21,9 +21,9 @@
|
||||
|
||||
namespace milvus {
|
||||
|
||||
constexpr int CODE_WIDTH = sizeof(ErrorCode);
|
||||
constexpr int CODE_WIDTH = sizeof(StatusCode);
|
||||
|
||||
Status::Status(ErrorCode code, const std::string& msg) {
|
||||
Status::Status(StatusCode code, const std::string& msg) {
|
||||
//4 bytes store code
|
||||
//4 bytes store message length
|
||||
//the left bytes store message string
|
||||
@ -50,7 +50,8 @@ Status::Status(const Status &s)
|
||||
CopyFrom(s);
|
||||
}
|
||||
|
||||
Status &Status::operator=(const Status &s) {
|
||||
Status&
|
||||
Status::operator=(const Status &s) {
|
||||
CopyFrom(s);
|
||||
return *this;
|
||||
}
|
||||
@ -60,12 +61,14 @@ Status::Status(Status &&s)
|
||||
MoveFrom(s);
|
||||
}
|
||||
|
||||
Status &Status::operator=(Status &&s) {
|
||||
Status&
|
||||
Status::operator=(Status &&s) {
|
||||
MoveFrom(s);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Status::CopyFrom(const Status &s) {
|
||||
void
|
||||
Status::CopyFrom(const Status &s) {
|
||||
delete state_;
|
||||
state_ = nullptr;
|
||||
if(s.state_ == nullptr) {
|
||||
@ -73,58 +76,33 @@ void Status::CopyFrom(const Status &s) {
|
||||
}
|
||||
|
||||
uint32_t length = 0;
|
||||
std::memcpy(&length, s.state_ + CODE_WIDTH, sizeof(length));
|
||||
memcpy(&length, s.state_ + CODE_WIDTH, sizeof(length));
|
||||
int buff_len = length + sizeof(length) + CODE_WIDTH;
|
||||
state_ = new char[buff_len];
|
||||
memcpy((void*)state_, (void*)s.state_, buff_len);
|
||||
}
|
||||
|
||||
void Status::MoveFrom(Status &s) {
|
||||
void
|
||||
Status::MoveFrom(Status &s) {
|
||||
delete state_;
|
||||
state_ = s.state_;
|
||||
s.state_ = nullptr;
|
||||
}
|
||||
|
||||
std::string Status::ToString() const {
|
||||
std::string
|
||||
Status::message() const {
|
||||
if (state_ == nullptr) {
|
||||
return "OK";
|
||||
}
|
||||
|
||||
std::string result;
|
||||
switch (code()) {
|
||||
case StatusCode::OK:
|
||||
result = "OK ";
|
||||
break;
|
||||
case StatusCode::UnknownError:
|
||||
result = "Unknown error: ";
|
||||
break;
|
||||
case StatusCode::NotSupported:
|
||||
result = "Not supported: ";
|
||||
break;
|
||||
case StatusCode::NotConnected:
|
||||
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;
|
||||
default:
|
||||
result = "Error code(" + std::to_string((int)code()) + "): ";
|
||||
break;
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string msg;
|
||||
uint32_t length = 0;
|
||||
memcpy(&length, state_ + CODE_WIDTH, sizeof(length));
|
||||
if(length > 0) {
|
||||
result.append(state_ + sizeof(length) + CODE_WIDTH, length);
|
||||
msg.append(state_ + sizeof(length) + CODE_WIDTH, length);
|
||||
}
|
||||
|
||||
return result;
|
||||
return msg;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@ DBWrapper::DBWrapper() {
|
||||
|
||||
}
|
||||
|
||||
ErrorCode DBWrapper::StartService() {
|
||||
Status DBWrapper::StartService() {
|
||||
//db config
|
||||
zilliz::milvus::engine::Options opt;
|
||||
ConfigNode& db_config = ServerConfig::GetInstance().GetConfig(CONFIG_DB);
|
||||
@ -60,7 +60,7 @@ ErrorCode DBWrapper::StartService() {
|
||||
opt.mode = zilliz::milvus::engine::Options::MODE::READ_ONLY;
|
||||
}
|
||||
else {
|
||||
std::cout << "ERROR: mode specified in server_config is not one of ['single', 'cluster', 'read_only']" << std::endl;
|
||||
std::cerr << "ERROR: mode specified in server_config is not one of ['single', 'cluster', 'read_only']" << std::endl;
|
||||
kill(0, SIGUSR1);
|
||||
}
|
||||
|
||||
@ -91,16 +91,16 @@ ErrorCode DBWrapper::StartService() {
|
||||
opt.meta.archive_conf.SetCriterias(criterial);
|
||||
|
||||
//create db root folder
|
||||
ErrorCode err = CommonUtil::CreateDirectory(opt.meta.path);
|
||||
if(err != SERVER_SUCCESS) {
|
||||
std::cout << "ERROR! Failed to create database root path: " << opt.meta.path << std::endl;
|
||||
Status status = CommonUtil::CreateDirectory(opt.meta.path);
|
||||
if(!status.ok()) {
|
||||
std::cerr << "ERROR! Failed to create database root path: " << opt.meta.path << std::endl;
|
||||
kill(0, SIGUSR1);
|
||||
}
|
||||
|
||||
for(auto& path : opt.meta.slave_paths) {
|
||||
err = CommonUtil::CreateDirectory(path);
|
||||
if(err != SERVER_SUCCESS) {
|
||||
std::cout << "ERROR! Failed to create database slave path: " << path << std::endl;
|
||||
status = CommonUtil::CreateDirectory(path);
|
||||
if(!status.ok()) {
|
||||
std::cerr << "ERROR! Failed to create database slave path: " << path << std::endl;
|
||||
kill(0, SIGUSR1);
|
||||
}
|
||||
}
|
||||
@ -114,21 +114,21 @@ ErrorCode DBWrapper::StartService() {
|
||||
}
|
||||
|
||||
if(db_ == nullptr) {
|
||||
std::cout << "ERROR! Failed to open database: " << msg << std::endl;
|
||||
std::cerr << "ERROR! Failed to open database: " << msg << std::endl;
|
||||
kill(0, SIGUSR1);
|
||||
}
|
||||
|
||||
db_->Start();
|
||||
|
||||
return SERVER_SUCCESS;
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
ErrorCode DBWrapper::StopService() {
|
||||
Status DBWrapper::StopService() {
|
||||
if(db_) {
|
||||
db_->Stop();
|
||||
}
|
||||
|
||||
return SERVER_SUCCESS;
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "utils/Error.h"
|
||||
#include "utils/Status.h"
|
||||
#include "db/DB.h"
|
||||
|
||||
#include <memory>
|
||||
@ -41,8 +41,8 @@ public:
|
||||
return GetInstance().EngineDB();
|
||||
}
|
||||
|
||||
ErrorCode StartService();
|
||||
ErrorCode StopService();
|
||||
Status StartService();
|
||||
Status StopService();
|
||||
|
||||
engine::DBPtr EngineDB() {
|
||||
return db_;
|
||||
|
||||
@ -138,11 +138,11 @@ Server::Daemonize() {
|
||||
if (!pid_filename_.empty()) {
|
||||
pid_fd = open(pid_filename_.c_str(), O_RDWR | O_CREAT, 0640);
|
||||
if (pid_fd < 0) {
|
||||
std::cout << "Can't open filename: " + pid_filename_ + ", Error: " + strerror(errno);
|
||||
std::cerr << "Can't open filename: " + pid_filename_ + ", Error: " + strerror(errno);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (lockf(pid_fd, F_TLOCK, 0) < 0) {
|
||||
std::cout << "Can't lock filename: " + pid_filename_ + ", Error: " + strerror(errno);
|
||||
std::cerr << "Can't lock filename: " + pid_filename_ + ", Error: " + strerror(errno);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@ -216,18 +216,18 @@ Server::Start() {
|
||||
|
||||
void
|
||||
Server::Stop() {
|
||||
std::cout << "Milvus server is going to shutdown ..." << std::endl;
|
||||
std::cerr << "Milvus server is going to shutdown ..." << std::endl;
|
||||
|
||||
// Unlock and close lockfile
|
||||
if (pid_fd != -1) {
|
||||
int ret = lockf(pid_fd, F_ULOCK, 0);
|
||||
if (ret != 0) {
|
||||
std::cout << "Can't lock file: " << strerror(errno) << std::endl;
|
||||
std::cerr << "Can't lock file: " << strerror(errno) << std::endl;
|
||||
exit(0);
|
||||
}
|
||||
ret = close(pid_fd);
|
||||
if (ret != 0) {
|
||||
std::cout << "Can't close file: " << strerror(errno) << std::endl;
|
||||
std::cerr << "Can't close file: " << strerror(errno) << std::endl;
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
@ -236,24 +236,23 @@ Server::Stop() {
|
||||
if (!pid_filename_.empty()) {
|
||||
int ret = unlink(pid_filename_.c_str());
|
||||
if (ret != 0) {
|
||||
std::cout << "Can't unlink file: " << strerror(errno) << std::endl;
|
||||
std::cerr << "Can't unlink file: " << strerror(errno) << std::endl;
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
running_ = 0;
|
||||
|
||||
StopService();
|
||||
|
||||
std::cout << "Milvus server is closed!" << std::endl;
|
||||
std::cerr << "Milvus server is closed!" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
ErrorCode
|
||||
Server::LoadConfig() {
|
||||
ServerConfig::GetInstance().LoadConfigFile(config_filename_);
|
||||
ErrorCode err = ServerConfig::GetInstance().ValidateConfig();
|
||||
if (err != SERVER_SUCCESS) {
|
||||
auto status = ServerConfig::GetInstance().ValidateConfig();
|
||||
if (!status.ok()) {
|
||||
std::cerr << "Failed to load config file: " << config_filename_ << std::endl;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "utils/Error.h"
|
||||
#include "utils/Status.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
@ -40,7 +40,6 @@ class Server {
|
||||
|
||||
void Daemonize();
|
||||
|
||||
static void HandleSignal(int signal);
|
||||
ErrorCode LoadConfig();
|
||||
|
||||
void StartService();
|
||||
@ -48,7 +47,6 @@ class Server {
|
||||
|
||||
private:
|
||||
int64_t daemonized_ = 0;
|
||||
int64_t running_ = 1;
|
||||
int pid_fd = -1;
|
||||
std::string pid_filename_;
|
||||
std::string config_filename_;
|
||||
|
||||
@ -41,17 +41,17 @@ ServerConfig::GetInstance() {
|
||||
return config;
|
||||
}
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
ServerConfig::LoadConfigFile(const std::string &config_filename) {
|
||||
std::string filename = config_filename;
|
||||
if (filename.empty()) {
|
||||
std::cout << "ERROR: a config file is required" << std::endl;
|
||||
std::cerr << "ERROR: a config file is required" << std::endl;
|
||||
exit(1);//directly exit program if config file not specified
|
||||
}
|
||||
struct stat directoryStat;
|
||||
int statOK = stat(filename.c_str(), &directoryStat);
|
||||
if (statOK != 0) {
|
||||
std::cout << "ERROR: " << filename << " not found!" << std::endl;
|
||||
std::cerr << "ERROR: " << filename << " not found!" << std::endl;
|
||||
exit(1);//directly exit program if config file not found
|
||||
}
|
||||
|
||||
@ -59,43 +59,44 @@ ServerConfig::LoadConfigFile(const std::string &config_filename) {
|
||||
ConfigMgr *mgr = const_cast<ConfigMgr *>(ConfigMgr::GetInstance());
|
||||
ErrorCode err = mgr->LoadConfigFile(filename);
|
||||
if (err != 0) {
|
||||
std::cout << "Server failed to load config file" << std::endl;
|
||||
std::cerr << "Server failed to load config file" << std::endl;
|
||||
exit(1);//directly exit program if the config file is illegal
|
||||
}
|
||||
}
|
||||
catch (YAML::Exception &e) {
|
||||
std::cout << "Server failed to load config file: " << std::endl;
|
||||
return SERVER_UNEXPECTED_ERROR;
|
||||
std::cerr << "Server failed to load config file: " << std::endl;
|
||||
exit(1);//directly exit program if the config file is illegal
|
||||
}
|
||||
|
||||
return SERVER_SUCCESS;
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
ErrorCode ServerConfig::ValidateConfig() {
|
||||
Status
|
||||
ServerConfig::ValidateConfig() {
|
||||
|
||||
bool okay = true;
|
||||
if (CheckServerConfig() != SERVER_SUCCESS) {
|
||||
if (!CheckServerConfig().ok()) {
|
||||
okay = false;
|
||||
}
|
||||
if (CheckDBConfig() != SERVER_SUCCESS) {
|
||||
if (!CheckDBConfig().ok()) {
|
||||
okay = false;
|
||||
}
|
||||
if (CheckMetricConfig() != SERVER_SUCCESS) {
|
||||
if (!CheckMetricConfig().ok()) {
|
||||
okay = false;
|
||||
}
|
||||
if (CheckCacheConfig() != SERVER_SUCCESS) {
|
||||
if (!CheckCacheConfig().ok()) {
|
||||
okay = false;
|
||||
}
|
||||
if (CheckEngineConfig() != SERVER_SUCCESS) {
|
||||
if (!CheckEngineConfig().ok()) {
|
||||
okay = false;
|
||||
}
|
||||
if (CheckResourceConfig() != SERVER_SUCCESS) {
|
||||
if (!CheckResourceConfig().ok()) {
|
||||
okay = false;
|
||||
}
|
||||
return (okay ? SERVER_SUCCESS : SERVER_INVALID_ARGUMENT);
|
||||
return (okay ? Status::OK() : Status(SERVER_INVALID_ARGUMENT, "Config validation not pass"));
|
||||
}
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
ServerConfig::CheckServerConfig() {
|
||||
/*
|
||||
server_config:
|
||||
@ -109,13 +110,13 @@ ServerConfig::CheckServerConfig() {
|
||||
ConfigNode server_config = GetConfig(CONFIG_SERVER);
|
||||
|
||||
std::string ip_address = server_config.GetValue(CONFIG_SERVER_ADDRESS, "127.0.0.1");
|
||||
if (ValidationUtil::ValidateIpAddress(ip_address) != SERVER_SUCCESS) {
|
||||
if (!ValidationUtil::ValidateIpAddress(ip_address).ok()) {
|
||||
std::cerr << "ERROR: invalid server IP address: " << ip_address << std::endl;
|
||||
okay = false;
|
||||
}
|
||||
|
||||
std::string port_str = server_config.GetValue(CONFIG_SERVER_PORT, "19530");
|
||||
if (ValidationUtil::ValidateStringIsNumber(port_str) != SERVER_SUCCESS) {
|
||||
if (!ValidationUtil::ValidateStringIsNumber(port_str).ok()) {
|
||||
std::cerr << "ERROR: port " << port_str << " is not a number" << std::endl;
|
||||
okay = false;
|
||||
} else {
|
||||
@ -151,10 +152,10 @@ ServerConfig::CheckServerConfig() {
|
||||
okay = false;
|
||||
}
|
||||
|
||||
return (okay ? SERVER_SUCCESS : SERVER_INVALID_ARGUMENT);
|
||||
return (okay ? Status::OK() : Status(SERVER_INVALID_ARGUMENT, "Server config is illegal"));
|
||||
}
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
ServerConfig::CheckDBConfig() {
|
||||
/*
|
||||
db_config:
|
||||
@ -182,25 +183,25 @@ ServerConfig::CheckDBConfig() {
|
||||
}
|
||||
|
||||
std::string db_backend_url = db_config.GetValue(CONFIG_DB_URL);
|
||||
if (ValidationUtil::ValidateDbURI(db_backend_url) != SERVER_SUCCESS) {
|
||||
if (!ValidationUtil::ValidateDbURI(db_backend_url).ok()) {
|
||||
std::cerr << "ERROR: invalid db_backend_url: " << db_backend_url << std::endl;
|
||||
okay = false;
|
||||
}
|
||||
|
||||
std::string archive_disk_threshold_str = db_config.GetValue(CONFIG_DB_INSERT_BUFFER_SIZE, "0");
|
||||
if (ValidationUtil::ValidateStringIsNumber(archive_disk_threshold_str) != SERVER_SUCCESS) {
|
||||
if (!ValidationUtil::ValidateStringIsNumber(archive_disk_threshold_str).ok()) {
|
||||
std::cerr << "ERROR: archive_disk_threshold " << archive_disk_threshold_str << " is not a number" << std::endl;
|
||||
okay = false;
|
||||
}
|
||||
|
||||
std::string archive_days_threshold_str = db_config.GetValue(CONFIG_DB_INSERT_BUFFER_SIZE, "0");
|
||||
if (ValidationUtil::ValidateStringIsNumber(archive_days_threshold_str) != SERVER_SUCCESS) {
|
||||
if (!ValidationUtil::ValidateStringIsNumber(archive_days_threshold_str).ok()) {
|
||||
std::cerr << "ERROR: archive_days_threshold " << archive_days_threshold_str << " is not a number" << std::endl;
|
||||
okay = false;
|
||||
}
|
||||
|
||||
std::string insert_buffer_size_str = db_config.GetValue(CONFIG_DB_INSERT_BUFFER_SIZE, "4");
|
||||
if (ValidationUtil::ValidateStringIsNumber(insert_buffer_size_str) != SERVER_SUCCESS) {
|
||||
if (!ValidationUtil::ValidateStringIsNumber(insert_buffer_size_str).ok()) {
|
||||
std::cerr << "ERROR: insert_buffer_size " << insert_buffer_size_str << " is not a number" << std::endl;
|
||||
okay = false;
|
||||
}
|
||||
@ -216,21 +217,21 @@ ServerConfig::CheckDBConfig() {
|
||||
}
|
||||
|
||||
std::string gpu_index_str = db_config.GetValue(CONFIG_DB_BUILD_INDEX_GPU, "0");
|
||||
if (ValidationUtil::ValidateStringIsNumber(gpu_index_str) != SERVER_SUCCESS) {
|
||||
if (!ValidationUtil::ValidateStringIsNumber(gpu_index_str).ok()) {
|
||||
std::cerr << "ERROR: gpu_index " << gpu_index_str << " is not a number" << std::endl;
|
||||
okay = false;
|
||||
} else {
|
||||
int32_t gpu_index = std::stol(gpu_index_str);
|
||||
if (ValidationUtil::ValidateGpuIndex(gpu_index) != SERVER_SUCCESS) {
|
||||
if (!ValidationUtil::ValidateGpuIndex(gpu_index).ok()) {
|
||||
std::cerr << "ERROR: invalid gpu_index " << gpu_index_str << std::endl;
|
||||
okay = false;
|
||||
}
|
||||
}
|
||||
|
||||
return (okay ? SERVER_SUCCESS : SERVER_INVALID_ARGUMENT);
|
||||
return (okay ? Status::OK() : Status(SERVER_INVALID_ARGUMENT, "DB config is illegal"));
|
||||
}
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
ServerConfig::CheckMetricConfig() {
|
||||
/*
|
||||
metric_config:
|
||||
@ -245,21 +246,21 @@ ServerConfig::CheckMetricConfig() {
|
||||
ConfigNode metric_config = GetConfig(CONFIG_METRIC);
|
||||
|
||||
std::string is_startup_str = metric_config.GetValue(CONFIG_METRIC_IS_STARTUP, "off");
|
||||
if (ValidationUtil::ValidateStringIsBool(is_startup_str) != SERVER_SUCCESS) {
|
||||
if (!ValidationUtil::ValidateStringIsBool(is_startup_str).ok()) {
|
||||
std::cerr << "ERROR: invalid is_startup config: " << is_startup_str << std::endl;
|
||||
okay = false;
|
||||
}
|
||||
|
||||
std::string port_str = metric_config.GetChild(CONFIG_PROMETHEUS).GetValue(CONFIG_METRIC_PROMETHEUS_PORT, "8080");
|
||||
if (ValidationUtil::ValidateStringIsNumber(port_str) != SERVER_SUCCESS) {
|
||||
if (!ValidationUtil::ValidateStringIsNumber(port_str).ok()) {
|
||||
std::cerr << "ERROR: port specified in prometheus_config " << port_str << " is not a number" << std::endl;
|
||||
okay = false;
|
||||
}
|
||||
|
||||
return (okay ? SERVER_SUCCESS : SERVER_INVALID_ARGUMENT);
|
||||
return (okay ? Status::OK() : Status(SERVER_INVALID_ARGUMENT, "Metric config is illegal"));
|
||||
}
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
ServerConfig::CheckCacheConfig() {
|
||||
/*
|
||||
cache_config:
|
||||
@ -274,7 +275,7 @@ ServerConfig::CheckCacheConfig() {
|
||||
ConfigNode cache_config = GetConfig(CONFIG_CACHE);
|
||||
|
||||
std::string cpu_cache_capacity_str = cache_config.GetValue(CONFIG_CPU_CACHE_CAPACITY, "16");
|
||||
if (ValidationUtil::ValidateStringIsNumber(cpu_cache_capacity_str) != SERVER_SUCCESS) {
|
||||
if (!ValidationUtil::ValidateStringIsNumber(cpu_cache_capacity_str).ok()) {
|
||||
std::cerr << "ERROR: cpu_cache_capacity " << cpu_cache_capacity_str << " is not a number" << std::endl;
|
||||
okay = false;
|
||||
}
|
||||
@ -301,7 +302,7 @@ ServerConfig::CheckCacheConfig() {
|
||||
|
||||
std::string cpu_cache_free_percent_str = cache_config.GetValue(CACHE_FREE_PERCENT, "0.85");
|
||||
double cpu_cache_free_percent;
|
||||
if (ValidationUtil::ValidateStringIsDouble(cpu_cache_free_percent_str, cpu_cache_free_percent) != SERVER_SUCCESS) {
|
||||
if (!ValidationUtil::ValidateStringIsDouble(cpu_cache_free_percent_str, cpu_cache_free_percent).ok()) {
|
||||
std::cerr << "ERROR: cpu_cache_free_percent " << cpu_cache_free_percent_str << " is not a double" << std::endl;
|
||||
okay = false;
|
||||
}
|
||||
@ -311,13 +312,13 @@ ServerConfig::CheckCacheConfig() {
|
||||
}
|
||||
|
||||
std::string insert_cache_immediately_str = cache_config.GetValue(CONFIG_INSERT_CACHE_IMMEDIATELY, "false");
|
||||
if (ValidationUtil::ValidateStringIsBool(insert_cache_immediately_str) != SERVER_SUCCESS) {
|
||||
if (!ValidationUtil::ValidateStringIsBool(insert_cache_immediately_str).ok()) {
|
||||
std::cerr << "ERROR: invalid insert_cache_immediately config: " << insert_cache_immediately_str << std::endl;
|
||||
okay = false;
|
||||
}
|
||||
|
||||
std::string gpu_cache_capacity_str = cache_config.GetValue(CONFIG_GPU_CACHE_CAPACITY, "0");
|
||||
if (ValidationUtil::ValidateStringIsNumber(gpu_cache_capacity_str) != SERVER_SUCCESS) {
|
||||
if (!ValidationUtil::ValidateStringIsNumber(gpu_cache_capacity_str).ok()) {
|
||||
std::cerr << "ERROR: gpu_cache_capacity " << gpu_cache_capacity_str << " is not a number" << std::endl;
|
||||
okay = false;
|
||||
}
|
||||
@ -326,7 +327,7 @@ ServerConfig::CheckCacheConfig() {
|
||||
gpu_cache_capacity *= GB;
|
||||
int gpu_index = GetConfig(CONFIG_DB).GetInt32Value(CONFIG_DB_BUILD_INDEX_GPU, 0);
|
||||
size_t gpu_memory;
|
||||
if (ValidationUtil::GetGpuMemory(gpu_index, gpu_memory) != SERVER_SUCCESS) {
|
||||
if (!ValidationUtil::GetGpuMemory(gpu_index, gpu_memory).ok()) {
|
||||
std::cerr << "ERROR: could not get gpu memory for device " << gpu_index << std::endl;
|
||||
okay = false;
|
||||
}
|
||||
@ -342,7 +343,7 @@ ServerConfig::CheckCacheConfig() {
|
||||
|
||||
std::string gpu_cache_free_percent_str = cache_config.GetValue(GPU_CACHE_FREE_PERCENT, "0.85");
|
||||
double gpu_cache_free_percent;
|
||||
if (ValidationUtil::ValidateStringIsDouble(gpu_cache_free_percent_str, gpu_cache_free_percent) != SERVER_SUCCESS) {
|
||||
if (!ValidationUtil::ValidateStringIsDouble(gpu_cache_free_percent_str, gpu_cache_free_percent).ok()) {
|
||||
std::cerr << "ERROR: gpu_cache_free_percent " << gpu_cache_free_percent_str << " is not a double" << std::endl;
|
||||
okay = false;
|
||||
}
|
||||
@ -351,10 +352,10 @@ ServerConfig::CheckCacheConfig() {
|
||||
okay = false;
|
||||
}
|
||||
|
||||
return (okay ? SERVER_SUCCESS : SERVER_INVALID_ARGUMENT);
|
||||
return (okay ? Status::OK() : Status(SERVER_INVALID_ARGUMENT, "Cache config is illegal"));
|
||||
}
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
ServerConfig::CheckEngineConfig() {
|
||||
/*
|
||||
engine_config:
|
||||
@ -365,13 +366,13 @@ ServerConfig::CheckEngineConfig() {
|
||||
ConfigNode engine_config = GetConfig(CONFIG_ENGINE);
|
||||
|
||||
std::string use_blas_threshold_str = engine_config.GetValue(CONFIG_DCBT, "20");
|
||||
if (ValidationUtil::ValidateStringIsNumber(use_blas_threshold_str) != SERVER_SUCCESS) {
|
||||
if (!ValidationUtil::ValidateStringIsNumber(use_blas_threshold_str).ok()) {
|
||||
std::cerr << "ERROR: use_blas_threshold " << use_blas_threshold_str << " is not a number" << std::endl;
|
||||
okay = false;
|
||||
}
|
||||
|
||||
std::string omp_thread_num_str = engine_config.GetValue(CONFIG_OMP_THREAD_NUM, "0");
|
||||
if (ValidationUtil::ValidateStringIsNumber(omp_thread_num_str) != SERVER_SUCCESS) {
|
||||
if (!ValidationUtil::ValidateStringIsNumber(omp_thread_num_str).ok()) {
|
||||
std::cerr << "ERROR: omp_thread_num " << omp_thread_num_str << " is not a number" << std::endl;
|
||||
okay = false;
|
||||
} else {
|
||||
@ -384,10 +385,10 @@ ServerConfig::CheckEngineConfig() {
|
||||
}
|
||||
}
|
||||
|
||||
return (okay ? SERVER_SUCCESS : SERVER_INVALID_ARGUMENT);
|
||||
return (okay ? Status::OK() : Status(SERVER_INVALID_ARGUMENT, "Engine config is illegal"));
|
||||
}
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
ServerConfig::CheckResourceConfig() {
|
||||
/*
|
||||
resource_config:
|
||||
@ -410,10 +411,10 @@ ServerConfig::CheckResourceConfig() {
|
||||
okay = false;
|
||||
}
|
||||
|
||||
return (okay ? SERVER_SUCCESS : SERVER_INVALID_ARGUMENT);
|
||||
return (okay ? Status::OK() : Status(SERVER_INVALID_ARGUMENT, "Resource config is illegal"));
|
||||
}
|
||||
|
||||
//ErrorCode
|
||||
//Status
|
||||
//ServerConfig::CheckResourceConfig() {
|
||||
/*
|
||||
resource_config:
|
||||
@ -484,7 +485,7 @@ ServerConfig::CheckResourceConfig() {
|
||||
//
|
||||
// std::string device_id_str = resource_conf.GetValue(CONFIG_RESOURCE_DEVICE_ID, "0");
|
||||
// int32_t device_id = -1;
|
||||
// if (ValidationUtil::ValidateStringIsNumber(device_id_str) != SERVER_SUCCESS) {
|
||||
// if (!ValidationUtil::ValidateStringIsNumber(device_id_str).ok()) {
|
||||
// std::cerr << "ERROR: device_id " << device_id_str << " is not a number" << std::endl;
|
||||
// okay = false;
|
||||
// } else {
|
||||
@ -492,7 +493,7 @@ ServerConfig::CheckResourceConfig() {
|
||||
// }
|
||||
//
|
||||
// std::string enable_executor_str = resource_conf.GetValue(CONFIG_RESOURCE_ENABLE_EXECUTOR, "off");
|
||||
// if (ValidationUtil::ValidateStringIsBool(enable_executor_str) != SERVER_SUCCESS) {
|
||||
// if (!ValidationUtil::ValidateStringIsBool(enable_executor_str).ok()) {
|
||||
// std::cerr << "ERROR: invalid enable_executor config: " << enable_executor_str << std::endl;
|
||||
// okay = false;
|
||||
// }
|
||||
@ -514,26 +515,26 @@ ServerConfig::CheckResourceConfig() {
|
||||
// hasExecutor = true;
|
||||
// }
|
||||
// std::string gpu_resource_num_str = resource_conf.GetValue(CONFIG_RESOURCE_NUM, "2");
|
||||
// if (ValidationUtil::ValidateStringIsNumber(gpu_resource_num_str) != SERVER_SUCCESS) {
|
||||
// if (!ValidationUtil::ValidateStringIsNumber(gpu_resource_num_str).ok()) {
|
||||
// std::cerr << "ERROR: gpu_resource_num " << gpu_resource_num_str << " is not a number" << std::endl;
|
||||
// okay = false;
|
||||
// }
|
||||
// bool mem_valid = true;
|
||||
// std::string pinned_memory_str = resource_conf.GetValue(CONFIG_RESOURCE_PIN_MEMORY, "300");
|
||||
// if (ValidationUtil::ValidateStringIsNumber(pinned_memory_str) != SERVER_SUCCESS) {
|
||||
// if (!ValidationUtil::ValidateStringIsNumber(pinned_memory_str).ok()) {
|
||||
// std::cerr << "ERROR: pinned_memory " << pinned_memory_str << " is not a number" << std::endl;
|
||||
// okay = false;
|
||||
// mem_valid = false;
|
||||
// }
|
||||
// std::string temp_memory_str = resource_conf.GetValue(CONFIG_RESOURCE_TEMP_MEMORY, "300");
|
||||
// if (ValidationUtil::ValidateStringIsNumber(temp_memory_str) != SERVER_SUCCESS) {
|
||||
// if (!ValidationUtil::ValidateStringIsNumber(temp_memory_str).ok()) {
|
||||
// std::cerr << "ERROR: temp_memory " << temp_memory_str << " is not a number" << std::endl;
|
||||
// okay = false;
|
||||
// mem_valid = false;
|
||||
// }
|
||||
// if (mem_valid) {
|
||||
// size_t gpu_memory;
|
||||
// if (ValidationUtil::GetGpuMemory(device_id, gpu_memory) != SERVER_SUCCESS) {
|
||||
// if (!ValidationUtil::GetGpuMemory(device_id, gpu_memory).ok()) {
|
||||
// std::cerr << "ERROR: could not get gpu memory for device " << device_id << std::endl;
|
||||
// okay = false;
|
||||
// }
|
||||
@ -592,8 +593,7 @@ ServerConfig::CheckResourceConfig() {
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return (okay ? SERVER_SUCCESS : SERVER_INVALID_ARGUMENT);
|
||||
// return SERVER_SUCCESS;
|
||||
// return (okay ? Status::OK() : Status(SERVER_INVALID_ARGUMENT, "Resource config is illegal"));
|
||||
//}
|
||||
|
||||
void
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "utils/Error.h"
|
||||
#include "utils/Status.h"
|
||||
#include "config/ConfigNode.h"
|
||||
|
||||
#include "yaml-cpp/yaml.h"
|
||||
@ -78,20 +78,20 @@ class ServerConfig {
|
||||
public:
|
||||
static ServerConfig &GetInstance();
|
||||
|
||||
ErrorCode LoadConfigFile(const std::string& config_filename);
|
||||
ErrorCode ValidateConfig();
|
||||
Status LoadConfigFile(const std::string& config_filename);
|
||||
Status ValidateConfig();
|
||||
void PrintAll() const;
|
||||
|
||||
ConfigNode GetConfig(const std::string& name) const;
|
||||
ConfigNode& GetConfig(const std::string& name);
|
||||
|
||||
private:
|
||||
ErrorCode CheckServerConfig();
|
||||
ErrorCode CheckDBConfig();
|
||||
ErrorCode CheckMetricConfig();
|
||||
ErrorCode CheckCacheConfig();
|
||||
ErrorCode CheckEngineConfig();
|
||||
ErrorCode CheckResourceConfig();
|
||||
Status CheckServerConfig();
|
||||
Status CheckDBConfig();
|
||||
Status CheckMetricConfig();
|
||||
Status CheckCacheConfig();
|
||||
Status CheckEngineConfig();
|
||||
Status CheckResourceConfig();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -58,7 +58,7 @@ class NoReusePortOption : public ::grpc::ServerBuilderOption {
|
||||
};
|
||||
|
||||
|
||||
void
|
||||
Status
|
||||
GrpcMilvusServer::StartService() {
|
||||
if (server != nullptr) {
|
||||
std::cout << "stop service!\n";
|
||||
@ -92,13 +92,16 @@ GrpcMilvusServer::StartService() {
|
||||
server = builder.BuildAndStart();
|
||||
server->Wait();
|
||||
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
void
|
||||
Status
|
||||
GrpcMilvusServer::StopService() {
|
||||
if (server != nullptr) {
|
||||
server->Shutdown();
|
||||
}
|
||||
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -17,6 +17,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "utils/Status.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
@ -27,10 +29,10 @@ namespace grpc {
|
||||
|
||||
class GrpcMilvusServer {
|
||||
public:
|
||||
static void
|
||||
static Status
|
||||
StartService();
|
||||
|
||||
static void
|
||||
static Status
|
||||
StopService();
|
||||
};
|
||||
|
||||
|
||||
@ -75,8 +75,7 @@ namespace {
|
||||
GrpcBaseTask::GrpcBaseTask(const std::string &task_group, bool async)
|
||||
: task_group_(task_group),
|
||||
async_(async),
|
||||
done_(false),
|
||||
error_code_(SERVER_SUCCESS) {
|
||||
done_(false) {
|
||||
|
||||
}
|
||||
|
||||
@ -84,10 +83,10 @@ GrpcBaseTask::~GrpcBaseTask() {
|
||||
WaitToFinish();
|
||||
}
|
||||
|
||||
ErrorCode GrpcBaseTask::Execute() {
|
||||
error_code_ = OnExecute();
|
||||
Status GrpcBaseTask::Execute() {
|
||||
status_ = OnExecute();
|
||||
Done();
|
||||
return error_code_;
|
||||
return status_;
|
||||
}
|
||||
|
||||
void GrpcBaseTask::Done() {
|
||||
@ -95,19 +94,17 @@ void GrpcBaseTask::Done() {
|
||||
finish_cond_.notify_all();
|
||||
}
|
||||
|
||||
ErrorCode GrpcBaseTask::SetError(ErrorCode error_code, const std::string &error_msg) {
|
||||
error_code_ = error_code;
|
||||
error_msg_ = error_msg;
|
||||
|
||||
SERVER_LOG_ERROR << error_msg_;
|
||||
return error_code_;
|
||||
Status GrpcBaseTask::SetStatus(ErrorCode error_code, const std::string &error_msg) {
|
||||
status_ = Status(error_code, error_msg);
|
||||
SERVER_LOG_ERROR << error_msg;
|
||||
return status_;
|
||||
}
|
||||
|
||||
ErrorCode GrpcBaseTask::WaitToFinish() {
|
||||
Status GrpcBaseTask::WaitToFinish() {
|
||||
std::unique_lock<std::mutex> lock(finish_mtx_);
|
||||
finish_cond_.wait(lock, [this] { return done_; });
|
||||
|
||||
return error_code_;
|
||||
return status_;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -130,10 +127,10 @@ void GrpcRequestScheduler::ExecTask(BaseTaskPtr &task_ptr, ::milvus::grpc::Statu
|
||||
|
||||
if (!task_ptr->IsAsync()) {
|
||||
task_ptr->WaitToFinish();
|
||||
ErrorCode err = task_ptr->ErrorID();
|
||||
if (err != SERVER_SUCCESS) {
|
||||
grpc_status->set_reason(task_ptr->ErrorMsg());
|
||||
grpc_status->set_error_code(ErrorMap(err));
|
||||
const Status& status = task_ptr->status();
|
||||
if (!status.ok()) {
|
||||
grpc_status->set_reason(status.message());
|
||||
grpc_status->set_error_code(ErrorMap(status.code()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -171,19 +168,19 @@ void GrpcRequestScheduler::Stop() {
|
||||
SERVER_LOG_INFO << "Scheduler stopped";
|
||||
}
|
||||
|
||||
ErrorCode GrpcRequestScheduler::ExecuteTask(const BaseTaskPtr &task_ptr) {
|
||||
Status GrpcRequestScheduler::ExecuteTask(const BaseTaskPtr &task_ptr) {
|
||||
if (task_ptr == nullptr) {
|
||||
return SERVER_NULL_POINTER;
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
ErrorCode err = PutTaskToQueue(task_ptr);
|
||||
if (err != SERVER_SUCCESS) {
|
||||
SERVER_LOG_ERROR << "Put task to queue failed with code: " << err;
|
||||
return err;
|
||||
auto status = PutTaskToQueue(task_ptr);
|
||||
if (!status.ok()) {
|
||||
SERVER_LOG_ERROR << "Put task to queue failed with code: " << status.ToString();
|
||||
return status;
|
||||
}
|
||||
|
||||
if (task_ptr->IsAsync()) {
|
||||
return SERVER_SUCCESS;//async execution, caller need to call WaitToFinish at somewhere
|
||||
return Status::OK(); //async execution, caller need to call WaitToFinish at somewhere
|
||||
}
|
||||
|
||||
return task_ptr->WaitToFinish();//sync execution
|
||||
@ -203,9 +200,9 @@ void GrpcRequestScheduler::TakeTaskToExecute(TaskQueuePtr task_queue) {
|
||||
}
|
||||
|
||||
try {
|
||||
ErrorCode err = task->Execute();
|
||||
if (err != SERVER_SUCCESS) {
|
||||
SERVER_LOG_ERROR << "Task failed with code: " << err;
|
||||
auto status = task->Execute();
|
||||
if (!status.ok()) {
|
||||
SERVER_LOG_ERROR << "Task failed with code: " << status.ToString();
|
||||
}
|
||||
} catch (std::exception &ex) {
|
||||
SERVER_LOG_ERROR << "Task failed to execute: " << ex.what();
|
||||
@ -213,7 +210,7 @@ void GrpcRequestScheduler::TakeTaskToExecute(TaskQueuePtr task_queue) {
|
||||
}
|
||||
}
|
||||
|
||||
ErrorCode GrpcRequestScheduler::PutTaskToQueue(const BaseTaskPtr &task_ptr) {
|
||||
Status GrpcRequestScheduler::PutTaskToQueue(const BaseTaskPtr &task_ptr) {
|
||||
std::lock_guard<std::mutex> lock(queue_mtx_);
|
||||
|
||||
std::string group_name = task_ptr->TaskGroup();
|
||||
@ -230,7 +227,7 @@ ErrorCode GrpcRequestScheduler::PutTaskToQueue(const BaseTaskPtr &task_ptr) {
|
||||
SERVER_LOG_INFO << "Create new thread for task group: " << group_name;
|
||||
}
|
||||
|
||||
return SERVER_SUCCESS;
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "utils/Status.h"
|
||||
#include "utils/BlockingQueue.h"
|
||||
#include "status.grpc.pb.h"
|
||||
#include "status.pb.h"
|
||||
@ -37,24 +38,22 @@ protected:
|
||||
virtual ~GrpcBaseTask();
|
||||
|
||||
public:
|
||||
ErrorCode Execute();
|
||||
Status Execute();
|
||||
|
||||
void Done();
|
||||
|
||||
ErrorCode WaitToFinish();
|
||||
Status WaitToFinish();
|
||||
|
||||
std::string TaskGroup() const { return task_group_; }
|
||||
|
||||
ErrorCode ErrorID() const { return error_code_; }
|
||||
|
||||
std::string ErrorMsg() const { return error_msg_; }
|
||||
const Status& status() const { return status_; }
|
||||
|
||||
bool IsAsync() const { return async_; }
|
||||
|
||||
protected:
|
||||
virtual ErrorCode OnExecute() = 0;
|
||||
virtual Status OnExecute() = 0;
|
||||
|
||||
ErrorCode SetError(ErrorCode error_code, const std::string &msg);
|
||||
Status SetStatus(ErrorCode error_code, const std::string &msg);
|
||||
|
||||
protected:
|
||||
mutable std::mutex finish_mtx_;
|
||||
@ -63,8 +62,7 @@ protected:
|
||||
std::string task_group_;
|
||||
bool async_;
|
||||
bool done_;
|
||||
ErrorCode error_code_;
|
||||
std::string error_msg_;
|
||||
Status status_;
|
||||
};
|
||||
|
||||
using BaseTaskPtr = std::shared_ptr<GrpcBaseTask>;
|
||||
@ -83,7 +81,7 @@ public:
|
||||
|
||||
void Stop();
|
||||
|
||||
ErrorCode ExecuteTask(const BaseTaskPtr &task_ptr);
|
||||
Status ExecuteTask(const BaseTaskPtr &task_ptr);
|
||||
|
||||
static void ExecTask(BaseTaskPtr &task_ptr, ::milvus::grpc::Status *grpc_status);
|
||||
|
||||
@ -94,7 +92,7 @@ protected:
|
||||
|
||||
void TakeTaskToExecute(TaskQueuePtr task_queue);
|
||||
|
||||
ErrorCode PutTaskToQueue(const BaseTaskPtr &task_ptr);
|
||||
Status PutTaskToQueue(const BaseTaskPtr &task_ptr);
|
||||
|
||||
private:
|
||||
mutable std::mutex queue_mtx_;
|
||||
|
||||
@ -77,33 +77,26 @@ namespace {
|
||||
|
||||
constexpr long DAY_SECONDS = 24 * 60 * 60;
|
||||
|
||||
void
|
||||
Status
|
||||
ConvertTimeRangeToDBDates(const std::vector<::milvus::grpc::Range> &range_array,
|
||||
std::vector<DB_DATE> &dates,
|
||||
ErrorCode &error_code,
|
||||
std::string &error_msg) {
|
||||
std::vector<DB_DATE> &dates) {
|
||||
dates.clear();
|
||||
for (auto &range : range_array) {
|
||||
time_t tt_start, tt_end;
|
||||
tm tm_start, tm_end;
|
||||
if (!CommonUtil::TimeStrToTime(range.start_value(), tt_start, tm_start)) {
|
||||
error_code = SERVER_INVALID_TIME_RANGE;
|
||||
error_msg = "Invalid time range: " + range.start_value();
|
||||
return;
|
||||
return Status(SERVER_INVALID_TIME_RANGE, "Invalid time range: " + range.start_value());
|
||||
}
|
||||
|
||||
if (!CommonUtil::TimeStrToTime(range.end_value(), tt_end, tm_end)) {
|
||||
error_code = SERVER_INVALID_TIME_RANGE;
|
||||
error_msg = "Invalid time range: " + range.start_value();
|
||||
return;
|
||||
return Status(SERVER_INVALID_TIME_RANGE, "Invalid time range: " + range.start_value());
|
||||
}
|
||||
|
||||
long days = (tt_end > tt_start) ? (tt_end - tt_start) / DAY_SECONDS : (tt_start - tt_end) /
|
||||
DAY_SECONDS;
|
||||
if (days == 0) {
|
||||
error_code = SERVER_INVALID_TIME_RANGE;
|
||||
error_msg = "Invalid time range: " + range.start_value() + " to " + range.end_value();
|
||||
return;
|
||||
return Status(SERVER_INVALID_TIME_RANGE,
|
||||
"Invalid time range: " + range.start_value() + " to " + range.end_value());
|
||||
}
|
||||
|
||||
//range: [start_day, end_day)
|
||||
@ -117,6 +110,8 @@ namespace {
|
||||
dates.push_back(date);
|
||||
}
|
||||
}
|
||||
|
||||
return Status::OK();
|
||||
}
|
||||
}
|
||||
|
||||
@ -136,30 +131,30 @@ CreateTableTask::Create(const ::milvus::grpc::TableSchema *schema) {
|
||||
return std::shared_ptr<GrpcBaseTask>(new CreateTableTask(schema));
|
||||
}
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
CreateTableTask::OnExecute() {
|
||||
TimeRecorder rc("CreateTableTask");
|
||||
|
||||
try {
|
||||
//step 1: check arguments
|
||||
ErrorCode res = ValidationUtil::ValidateTableName(schema_->table_name().table_name());
|
||||
if (res != SERVER_SUCCESS) {
|
||||
return SetError(res, "Invalid table name: " + schema_->table_name().table_name());
|
||||
auto status = ValidationUtil::ValidateTableName(schema_->table_name().table_name());
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
res = ValidationUtil::ValidateTableDimension(schema_->dimension());
|
||||
if (res != SERVER_SUCCESS) {
|
||||
return SetError(res, "Invalid table dimension: " + std::to_string(schema_->dimension()));
|
||||
status = ValidationUtil::ValidateTableDimension(schema_->dimension());
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
res = ValidationUtil::ValidateTableIndexFileSize(schema_->index_file_size());
|
||||
if(res != SERVER_SUCCESS) {
|
||||
return SetError(res, "Invalid index file size: " + std::to_string(schema_->index_file_size()));
|
||||
status = ValidationUtil::ValidateTableIndexFileSize(schema_->index_file_size());
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
res = ValidationUtil::ValidateTableIndexMetricType(schema_->metric_type());
|
||||
if(res != SERVER_SUCCESS) {
|
||||
return SetError(res, "Invalid index metric type: " + std::to_string(schema_->metric_type()));
|
||||
status = ValidationUtil::ValidateTableIndexMetricType(schema_->metric_type());
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
//step 2: construct table schema
|
||||
@ -170,22 +165,22 @@ CreateTableTask::OnExecute() {
|
||||
table_info.metric_type_ = schema_->metric_type();
|
||||
|
||||
//step 3: create table
|
||||
auto stat = DBWrapper::DB()->CreateTable(table_info);
|
||||
if (!stat.ok()) {
|
||||
status = DBWrapper::DB()->CreateTable(table_info);
|
||||
if (!status.ok()) {
|
||||
//table could exist
|
||||
if(stat.code() == DB_ALREADY_EXIST) {
|
||||
return SetError(SERVER_INVALID_TABLE_NAME, stat.ToString());
|
||||
if(status.code() == DB_ALREADY_EXIST) {
|
||||
return Status(SERVER_INVALID_TABLE_NAME, status.message());
|
||||
}
|
||||
return SetError(DB_META_TRANSACTION_FAILED, stat.ToString());
|
||||
return status;
|
||||
}
|
||||
|
||||
} catch (std::exception &ex) {
|
||||
return SetError(SERVER_UNEXPECTED_ERROR, ex.what());
|
||||
return Status(SERVER_UNEXPECTED_ERROR, ex.what());
|
||||
}
|
||||
|
||||
rc.ElapseFromBegin("totally cost");
|
||||
|
||||
return SERVER_SUCCESS;
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -200,23 +195,23 @@ DescribeTableTask::Create(const std::string &table_name, ::milvus::grpc::TableSc
|
||||
return std::shared_ptr<GrpcBaseTask>(new DescribeTableTask(table_name, schema));
|
||||
}
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
DescribeTableTask::OnExecute() {
|
||||
TimeRecorder rc("DescribeTableTask");
|
||||
|
||||
try {
|
||||
//step 1: check arguments
|
||||
ErrorCode res = ValidationUtil::ValidateTableName(table_name_);
|
||||
if (res != SERVER_SUCCESS) {
|
||||
return SetError(res, "Invalid table name: " + table_name_);
|
||||
auto status = ValidationUtil::ValidateTableName(table_name_);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
//step 2: get table info
|
||||
engine::meta::TableSchema table_info;
|
||||
table_info.table_id_ = table_name_;
|
||||
auto stat = DBWrapper::DB()->DescribeTable(table_info);
|
||||
if (!stat.ok()) {
|
||||
return SetError(DB_META_TRANSACTION_FAILED, stat.ToString());
|
||||
status = DBWrapper::DB()->DescribeTable(table_info);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
schema_->mutable_table_name()->set_table_name(table_info.table_id_);
|
||||
@ -225,12 +220,12 @@ DescribeTableTask::OnExecute() {
|
||||
schema_->set_metric_type(table_info.metric_type_);
|
||||
|
||||
} catch (std::exception &ex) {
|
||||
return SetError(SERVER_UNEXPECTED_ERROR, ex.what());
|
||||
return Status(SERVER_UNEXPECTED_ERROR, ex.what());
|
||||
}
|
||||
|
||||
rc.ElapseFromBegin("totally cost");
|
||||
|
||||
return SERVER_SUCCESS;
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -248,54 +243,54 @@ CreateIndexTask::Create(const ::milvus::grpc::IndexParam *index_param) {
|
||||
return std::shared_ptr<GrpcBaseTask>(new CreateIndexTask(index_param));
|
||||
}
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
CreateIndexTask::OnExecute() {
|
||||
try {
|
||||
TimeRecorder rc("CreateIndexTask");
|
||||
|
||||
//step 1: check arguments
|
||||
std::string table_name_ = index_param_->table_name().table_name();
|
||||
ErrorCode res = ValidationUtil::ValidateTableName(table_name_);
|
||||
if (res != SERVER_SUCCESS) {
|
||||
return SetError(res, "Invalid table name: " + table_name_);
|
||||
auto status = ValidationUtil::ValidateTableName(table_name_);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
bool has_table = false;
|
||||
auto stat = DBWrapper::DB()->HasTable(table_name_, has_table);
|
||||
if (!stat.ok()) {
|
||||
return SetError(DB_META_TRANSACTION_FAILED, stat.ToString());
|
||||
status = DBWrapper::DB()->HasTable(table_name_, has_table);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
if (!has_table) {
|
||||
return SetError(SERVER_TABLE_NOT_EXIST, "Table " + table_name_ + " not exists");
|
||||
return Status(SERVER_TABLE_NOT_EXIST, "Table " + table_name_ + " not exists");
|
||||
}
|
||||
|
||||
auto &grpc_index = index_param_->index();
|
||||
res = ValidationUtil::ValidateTableIndexType(grpc_index.index_type());
|
||||
if(res != SERVER_SUCCESS) {
|
||||
return SetError(res, "Invalid index type: " + std::to_string(grpc_index.index_type()));
|
||||
status = ValidationUtil::ValidateTableIndexType(grpc_index.index_type());
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
res = ValidationUtil::ValidateTableIndexNlist(grpc_index.nlist());
|
||||
if(res != SERVER_SUCCESS) {
|
||||
return SetError(res, "Invalid index nlist: " + std::to_string(grpc_index.nlist()));
|
||||
status = ValidationUtil::ValidateTableIndexNlist(grpc_index.nlist());
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
//step 2: check table existence
|
||||
engine::TableIndex index;
|
||||
index.engine_type_ = grpc_index.index_type();
|
||||
index.nlist_ = grpc_index.nlist();
|
||||
stat = DBWrapper::DB()->CreateIndex(table_name_, index);
|
||||
if (!stat.ok()) {
|
||||
return SetError(SERVER_BUILD_INDEX_ERROR, stat.ToString());
|
||||
status = DBWrapper::DB()->CreateIndex(table_name_, index);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
rc.ElapseFromBegin("totally cost");
|
||||
} catch (std::exception &ex) {
|
||||
return SetError(SERVER_UNEXPECTED_ERROR, ex.what());
|
||||
return Status(SERVER_UNEXPECTED_ERROR, ex.what());
|
||||
}
|
||||
|
||||
return SERVER_SUCCESS;
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -311,29 +306,29 @@ HasTableTask::Create(const std::string &table_name, bool &has_table) {
|
||||
return std::shared_ptr<GrpcBaseTask>(new HasTableTask(table_name, has_table));
|
||||
}
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
HasTableTask::OnExecute() {
|
||||
try {
|
||||
TimeRecorder rc("HasTableTask");
|
||||
|
||||
//step 1: check arguments
|
||||
ErrorCode res = ValidationUtil::ValidateTableName(table_name_);
|
||||
if (res != SERVER_SUCCESS) {
|
||||
return SetError(res, "Invalid table name: " + table_name_);
|
||||
auto status = ValidationUtil::ValidateTableName(table_name_);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
//step 2: check table existence
|
||||
auto stat = DBWrapper::DB()->HasTable(table_name_, has_table_);
|
||||
if (!stat.ok()) {
|
||||
return SetError(DB_META_TRANSACTION_FAILED, stat.ToString());
|
||||
status = DBWrapper::DB()->HasTable(table_name_, has_table_);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
rc.ElapseFromBegin("totally cost");
|
||||
} catch (std::exception &ex) {
|
||||
return SetError(SERVER_UNEXPECTED_ERROR, ex.what());
|
||||
return Status(SERVER_UNEXPECTED_ERROR, ex.what());
|
||||
}
|
||||
|
||||
return SERVER_SUCCESS;
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -348,26 +343,26 @@ DropTableTask::Create(const std::string &table_name) {
|
||||
return std::shared_ptr<GrpcBaseTask>(new DropTableTask(table_name));
|
||||
}
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
DropTableTask::OnExecute() {
|
||||
try {
|
||||
TimeRecorder rc("DropTableTask");
|
||||
|
||||
//step 1: check arguments
|
||||
ErrorCode res = ValidationUtil::ValidateTableName(table_name_);
|
||||
if (res != SERVER_SUCCESS) {
|
||||
return SetError(res, "Invalid table name: " + table_name_);
|
||||
auto status = ValidationUtil::ValidateTableName(table_name_);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
//step 2: check table existence
|
||||
engine::meta::TableSchema table_info;
|
||||
table_info.table_id_ = table_name_;
|
||||
auto stat = DBWrapper::DB()->DescribeTable(table_info);
|
||||
if (!stat.ok()) {
|
||||
if (stat.code() == DB_NOT_FOUND) {
|
||||
return SetError(SERVER_TABLE_NOT_EXIST, "Table " + table_name_ + " not exists");
|
||||
status = DBWrapper::DB()->DescribeTable(table_info);
|
||||
if (!status.ok()) {
|
||||
if (status.code() == DB_NOT_FOUND) {
|
||||
return Status(SERVER_TABLE_NOT_EXIST, "Table " + table_name_ + " not exists");
|
||||
} else {
|
||||
return SetError(DB_META_TRANSACTION_FAILED, stat.ToString());
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
@ -375,17 +370,17 @@ DropTableTask::OnExecute() {
|
||||
|
||||
//step 3: Drop table
|
||||
std::vector<DB_DATE> dates;
|
||||
stat = DBWrapper::DB()->DeleteTable(table_name_, dates);
|
||||
if (!stat.ok()) {
|
||||
return SetError(DB_META_TRANSACTION_FAILED, stat.ToString());
|
||||
status = DBWrapper::DB()->DeleteTable(table_name_, dates);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
rc.ElapseFromBegin("total cost");
|
||||
} catch (std::exception &ex) {
|
||||
return SetError(SERVER_UNEXPECTED_ERROR, ex.what());
|
||||
return Status(SERVER_UNEXPECTED_ERROR, ex.what());
|
||||
}
|
||||
|
||||
return SERVER_SUCCESS;
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -400,22 +395,22 @@ ShowTablesTask::Create(::grpc::ServerWriter<::milvus::grpc::TableName> *writer)
|
||||
return std::shared_ptr<GrpcBaseTask>(new ShowTablesTask(writer));
|
||||
}
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
ShowTablesTask::OnExecute() {
|
||||
std::vector<engine::meta::TableSchema> schema_array;
|
||||
auto stat = DBWrapper::DB()->AllTables(schema_array);
|
||||
if (!stat.ok()) {
|
||||
return SetError(DB_META_TRANSACTION_FAILED, stat.ToString());
|
||||
auto statuts = DBWrapper::DB()->AllTables(schema_array);
|
||||
if (!statuts.ok()) {
|
||||
return statuts;
|
||||
}
|
||||
|
||||
for (auto &schema : schema_array) {
|
||||
::milvus::grpc::TableName tableName;
|
||||
tableName.set_table_name(schema.table_id_);
|
||||
if (!writer_->Write(tableName)) {
|
||||
return SetError(SERVER_WRITE_ERROR, "Write table name failed!");
|
||||
return Status(SERVER_WRITE_ERROR, "Write table name failed!");
|
||||
}
|
||||
}
|
||||
return SERVER_SUCCESS;
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -436,23 +431,23 @@ InsertTask::Create(const ::milvus::grpc::InsertParam *insert_param,
|
||||
return std::shared_ptr<GrpcBaseTask>(new InsertTask(insert_param, record_ids));
|
||||
}
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
InsertTask::OnExecute() {
|
||||
try {
|
||||
TimeRecorder rc("InsertVectorTask");
|
||||
|
||||
//step 1: check arguments
|
||||
ErrorCode res = ValidationUtil::ValidateTableName(insert_param_->table_name());
|
||||
if (res != SERVER_SUCCESS) {
|
||||
return SetError(res, "Invalid table name: " + insert_param_->table_name());
|
||||
auto status = ValidationUtil::ValidateTableName(insert_param_->table_name());
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
if (insert_param_->row_record_array().empty()) {
|
||||
return SetError(SERVER_INVALID_ROWRECORD_ARRAY, "Row record array is empty");
|
||||
return Status(SERVER_INVALID_ROWRECORD_ARRAY, "Row record array is empty");
|
||||
}
|
||||
|
||||
if (!record_ids_->vector_id_array().empty()) {
|
||||
if (record_ids_->vector_id_array().size() != insert_param_->row_record_array_size()) {
|
||||
return SetError(SERVER_ILLEGAL_VECTOR_ID,
|
||||
return Status(SERVER_ILLEGAL_VECTOR_ID,
|
||||
"Size of vector ids is not equal to row record array size");
|
||||
}
|
||||
}
|
||||
@ -460,13 +455,13 @@ InsertTask::OnExecute() {
|
||||
//step 2: check table existence
|
||||
engine::meta::TableSchema table_info;
|
||||
table_info.table_id_ = insert_param_->table_name();
|
||||
auto stat = DBWrapper::DB()->DescribeTable(table_info);
|
||||
if (!stat.ok()) {
|
||||
if (stat.code() == DB_NOT_FOUND) {
|
||||
return SetError(SERVER_TABLE_NOT_EXIST,
|
||||
status = DBWrapper::DB()->DescribeTable(table_info);
|
||||
if (!status.ok()) {
|
||||
if (status.code() == DB_NOT_FOUND) {
|
||||
return Status(SERVER_TABLE_NOT_EXIST,
|
||||
"Table " + insert_param_->table_name() + " not exists");
|
||||
} else {
|
||||
return SetError(DB_META_TRANSACTION_FAILED, stat.ToString());
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
@ -475,12 +470,12 @@ InsertTask::OnExecute() {
|
||||
bool user_provide_ids = !insert_param_->row_id_array().empty();
|
||||
//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_ILLEGAL_VECTOR_ID, "Table vector ids are user defined, please provide id for this batch");
|
||||
return Status(SERVER_ILLEGAL_VECTOR_ID, "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((table_info.flag_ & engine::meta::FLAG_MASK_NO_USERID) && user_provide_ids) {
|
||||
return SetError(SERVER_ILLEGAL_VECTOR_ID, "Table vector ids are auto generated, no need to provide id for this batch");
|
||||
return Status(SERVER_ILLEGAL_VECTOR_ID, "Table vector ids are auto generated, no need to provide id for this batch");
|
||||
}
|
||||
|
||||
rc.RecordSection("check validation");
|
||||
@ -496,7 +491,7 @@ InsertTask::OnExecute() {
|
||||
// TODO: change to one dimension array in protobuf or use multiple-thread to copy the data
|
||||
for (size_t i = 0; i < insert_param_->row_record_array_size(); i++) {
|
||||
if (insert_param_->row_record_array(i).vector_data().empty()) {
|
||||
return SetError(SERVER_INVALID_ROWRECORD_ARRAY, "Row record array data is empty");
|
||||
return Status(SERVER_INVALID_ROWRECORD_ARRAY, "Row record array data is empty");
|
||||
}
|
||||
uint64_t vec_dim = insert_param_->row_record_array(i).vector_data().size();
|
||||
if (vec_dim != table_info.dimension_) {
|
||||
@ -504,7 +499,7 @@ InsertTask::OnExecute() {
|
||||
std::string error_msg = "Invalid row record dimension: " + std::to_string(vec_dim)
|
||||
+ " vs. table dimension:" +
|
||||
std::to_string(table_info.dimension_);
|
||||
return SetError(error_code, error_msg);
|
||||
return Status(error_code, error_msg);
|
||||
}
|
||||
memcpy(&vec_f[i * table_info.dimension_],
|
||||
insert_param_->row_record_array(i).vector_data().data(),
|
||||
@ -522,10 +517,10 @@ InsertTask::OnExecute() {
|
||||
memcpy(target_data, src_data, (size_t)(sizeof(int64_t)*insert_param_->row_id_array_size()));
|
||||
}
|
||||
|
||||
stat = DBWrapper::DB()->InsertVectors(insert_param_->table_name(), vec_count, vec_f.data(), vec_ids);
|
||||
status = DBWrapper::DB()->InsertVectors(insert_param_->table_name(), vec_count, vec_f.data(), vec_ids);
|
||||
rc.ElapseFromBegin("add vectors to engine");
|
||||
if (!stat.ok()) {
|
||||
return SetError(SERVER_CACHE_ERROR, "Cache error: " + stat.ToString());
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
for (int64_t id : vec_ids) {
|
||||
record_ids_->add_vector_id_array(id);
|
||||
@ -535,13 +530,13 @@ InsertTask::OnExecute() {
|
||||
if (ids_size != vec_count) {
|
||||
std::string msg = "Add " + std::to_string(vec_count) + " vectors but only return "
|
||||
+ std::to_string(ids_size) + " id";
|
||||
return SetError(SERVER_ILLEGAL_VECTOR_ID, msg);
|
||||
return Status(SERVER_ILLEGAL_VECTOR_ID, msg);
|
||||
}
|
||||
|
||||
//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_);
|
||||
status = DBWrapper::DB()->UpdateTableFlag(insert_param_->table_name(), table_info.flag_);
|
||||
|
||||
#ifdef MILVUS_ENABLE_PROFILING
|
||||
ProfilerStop();
|
||||
@ -551,10 +546,10 @@ InsertTask::OnExecute() {
|
||||
rc.ElapseFromBegin("total cost");
|
||||
|
||||
} catch (std::exception &ex) {
|
||||
return SetError(SERVER_UNEXPECTED_ERROR, ex.what());
|
||||
return Status(SERVER_UNEXPECTED_ERROR, ex.what());
|
||||
}
|
||||
|
||||
return SERVER_SUCCESS;
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -580,7 +575,7 @@ SearchTask::Create(const ::milvus::grpc::SearchParam *search_vector_infos,
|
||||
response));
|
||||
}
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
SearchTask::OnExecute() {
|
||||
try {
|
||||
int64_t top_k = search_param_->topk();
|
||||
@ -591,53 +586,51 @@ SearchTask::OnExecute() {
|
||||
|
||||
//step 1: check table name
|
||||
std::string table_name_ = search_param_->table_name();
|
||||
ErrorCode res = ValidationUtil::ValidateTableName(table_name_);
|
||||
if (res != SERVER_SUCCESS) {
|
||||
return SetError(res, "Invalid table name: " + table_name_);
|
||||
auto status = ValidationUtil::ValidateTableName(table_name_);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
//step 2: check table existence
|
||||
engine::meta::TableSchema table_info;
|
||||
table_info.table_id_ = table_name_;
|
||||
auto stat = DBWrapper::DB()->DescribeTable(table_info);
|
||||
if (!stat.ok()) {
|
||||
if (stat.code() == DB_NOT_FOUND) {
|
||||
return SetError(SERVER_TABLE_NOT_EXIST, "Table " + table_name_ + " not exists");
|
||||
status = DBWrapper::DB()->DescribeTable(table_info);
|
||||
if (!status.ok()) {
|
||||
if (status.code() == DB_NOT_FOUND) {
|
||||
return Status(SERVER_TABLE_NOT_EXIST, "Table " + table_name_ + " not exists");
|
||||
} else {
|
||||
return SetError(DB_META_TRANSACTION_FAILED, stat.ToString());
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
//step 3: check search parameter
|
||||
res = ValidationUtil::ValidateSearchTopk(top_k, table_info);
|
||||
if (res != SERVER_SUCCESS) {
|
||||
return SetError(res, "Invalid topk: " + std::to_string(top_k));
|
||||
status = ValidationUtil::ValidateSearchTopk(top_k, table_info);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
res = ValidationUtil::ValidateSearchNprobe(nprobe, table_info);
|
||||
if (res != SERVER_SUCCESS) {
|
||||
return SetError(res, "Invalid nprobe: " + std::to_string(nprobe));
|
||||
status = ValidationUtil::ValidateSearchNprobe(nprobe, table_info);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
if (search_param_->query_record_array().empty()) {
|
||||
return SetError(SERVER_INVALID_ROWRECORD_ARRAY, "Row record array is empty");
|
||||
return Status(SERVER_INVALID_ROWRECORD_ARRAY, "Row record array is empty");
|
||||
}
|
||||
|
||||
//step 4: check date range, and convert to db dates
|
||||
std::vector<DB_DATE> dates;
|
||||
ErrorCode error_code = SERVER_SUCCESS;
|
||||
std::string error_msg;
|
||||
|
||||
std::vector<::milvus::grpc::Range> range_array;
|
||||
for (size_t i = 0; i < search_param_->query_range_array_size(); i++) {
|
||||
range_array.emplace_back(search_param_->query_range_array(i));
|
||||
}
|
||||
ConvertTimeRangeToDBDates(range_array, dates, error_code, error_msg);
|
||||
if (error_code != SERVER_SUCCESS) {
|
||||
return SetError(error_code, error_msg);
|
||||
|
||||
status = ConvertTimeRangeToDBDates(range_array, dates);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
double span_check = rc.RecordSection("check validation");
|
||||
rc.RecordSection("check validation");
|
||||
|
||||
|
||||
//step 5: prepare float data
|
||||
@ -645,14 +638,14 @@ SearchTask::OnExecute() {
|
||||
std::vector<float> vec_f(record_array_size * table_info.dimension_, 0);
|
||||
for (size_t i = 0; i < record_array_size; i++) {
|
||||
if (search_param_->query_record_array(i).vector_data().empty()) {
|
||||
return SetError(SERVER_INVALID_ROWRECORD_ARRAY, "Row record array data is empty");
|
||||
return Status(SERVER_INVALID_ROWRECORD_ARRAY, "Row record array data is empty");
|
||||
}
|
||||
uint64_t query_vec_dim = search_param_->query_record_array(i).vector_data().size();
|
||||
if (query_vec_dim != table_info.dimension_) {
|
||||
ErrorCode error_code = SERVER_INVALID_VECTOR_DIMENSION;
|
||||
std::string error_msg = "Invalid row record dimension: " + std::to_string(query_vec_dim)
|
||||
+ " vs. table dimension:" + std::to_string(table_info.dimension_);
|
||||
return SetError(error_code, error_msg);
|
||||
return Status(error_code, error_msg);
|
||||
}
|
||||
|
||||
memcpy(&vec_f[i * table_info.dimension_],
|
||||
@ -671,11 +664,11 @@ SearchTask::OnExecute() {
|
||||
#endif
|
||||
|
||||
if (file_id_array_.empty()) {
|
||||
stat = DBWrapper::DB()->Query(table_name_, (size_t) top_k, record_count, nprobe, vec_f.data(),
|
||||
dates, results);
|
||||
status = DBWrapper::DB()->Query(table_name_, (size_t) top_k, record_count, nprobe,
|
||||
vec_f.data(), dates, results);
|
||||
} else {
|
||||
stat = DBWrapper::DB()->Query(table_name_, file_id_array_, (size_t) top_k,
|
||||
record_count, nprobe, vec_f.data(), dates, results);
|
||||
status = DBWrapper::DB()->Query(table_name_, file_id_array_, (size_t) top_k,
|
||||
record_count, nprobe, vec_f.data(), dates, results);
|
||||
}
|
||||
|
||||
#ifdef MILVUS_ENABLE_PROFILING
|
||||
@ -683,18 +676,18 @@ SearchTask::OnExecute() {
|
||||
#endif
|
||||
|
||||
rc.RecordSection("search vectors from engine");
|
||||
if (!stat.ok()) {
|
||||
return SetError(stat.code(), stat.ToString());
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
if (results.empty()) {
|
||||
return SERVER_SUCCESS; //empty table
|
||||
return Status::OK(); //empty table
|
||||
}
|
||||
|
||||
if (results.size() != record_count) {
|
||||
std::string msg = "Search " + std::to_string(record_count) + " vectors but only return "
|
||||
+ std::to_string(results.size()) + " results";
|
||||
return SetError(SERVER_ILLEGAL_SEARCH_RESULT, msg);
|
||||
return Status(SERVER_ILLEGAL_SEARCH_RESULT, msg);
|
||||
}
|
||||
|
||||
//step 7: construct result array
|
||||
@ -713,10 +706,10 @@ SearchTask::OnExecute() {
|
||||
|
||||
|
||||
} catch (std::exception &ex) {
|
||||
return SetError(SERVER_UNEXPECTED_ERROR, ex.what());
|
||||
return Status(SERVER_UNEXPECTED_ERROR, ex.what());
|
||||
}
|
||||
|
||||
return SERVER_SUCCESS;
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -732,23 +725,22 @@ CountTableTask::Create(const std::string &table_name, int64_t &row_count) {
|
||||
return std::shared_ptr<GrpcBaseTask>(new CountTableTask(table_name, row_count));
|
||||
}
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
CountTableTask::OnExecute() {
|
||||
try {
|
||||
TimeRecorder rc("GetTableRowCountTask");
|
||||
|
||||
//step 1: check arguments
|
||||
ErrorCode res = SERVER_SUCCESS;
|
||||
res = ValidationUtil::ValidateTableName(table_name_);
|
||||
if (res != SERVER_SUCCESS) {
|
||||
return SetError(res, "Invalid table name: " + table_name_);
|
||||
auto status = ValidationUtil::ValidateTableName(table_name_);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
//step 2: get row count
|
||||
uint64_t row_count = 0;
|
||||
auto stat = DBWrapper::DB()->GetTableRowCount(table_name_, row_count);
|
||||
if (!stat.ok()) {
|
||||
return SetError(DB_META_TRANSACTION_FAILED, stat.ToString());
|
||||
status = DBWrapper::DB()->GetTableRowCount(table_name_, row_count);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
row_count_ = (int64_t) row_count;
|
||||
@ -756,10 +748,10 @@ CountTableTask::OnExecute() {
|
||||
rc.ElapseFromBegin("total cost");
|
||||
|
||||
} catch (std::exception &ex) {
|
||||
return SetError(SERVER_UNEXPECTED_ERROR, ex.what());
|
||||
return Status(SERVER_UNEXPECTED_ERROR, ex.what());
|
||||
}
|
||||
|
||||
return SERVER_SUCCESS;
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -775,7 +767,7 @@ CmdTask::Create(const std::string &cmd, std::string &result) {
|
||||
return std::shared_ptr<GrpcBaseTask>(new CmdTask(cmd, result));
|
||||
}
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
CmdTask::OnExecute() {
|
||||
if (cmd_ == "version") {
|
||||
result_ = MILVUS_VERSION;
|
||||
@ -786,7 +778,7 @@ CmdTask::OnExecute() {
|
||||
result_ = "OK";
|
||||
}
|
||||
|
||||
return SERVER_SUCCESS;
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -804,27 +796,27 @@ DeleteByRangeTask::Create(const ::milvus::grpc::DeleteByRangeParam *delete_by_ra
|
||||
return std::shared_ptr<GrpcBaseTask>(new DeleteByRangeTask(delete_by_range_param));
|
||||
}
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
DeleteByRangeTask::OnExecute() {
|
||||
try {
|
||||
TimeRecorder rc("DeleteByRangeTask");
|
||||
|
||||
//step 1: check arguments
|
||||
std::string table_name = delete_by_range_param_->table_name();
|
||||
ErrorCode res = ValidationUtil::ValidateTableName(table_name);
|
||||
if (res != SERVER_SUCCESS) {
|
||||
return SetError(res, "Invalid table name: " + table_name);
|
||||
auto status = ValidationUtil::ValidateTableName(table_name);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
//step 2: check table existence
|
||||
engine::meta::TableSchema table_info;
|
||||
table_info.table_id_ = table_name;
|
||||
auto stat = DBWrapper::DB()->DescribeTable(table_info);
|
||||
if (!stat.ok()) {
|
||||
if (stat.code(), DB_NOT_FOUND) {
|
||||
return SetError(SERVER_TABLE_NOT_EXIST, "Table " + table_name + " not exists");
|
||||
status = DBWrapper::DB()->DescribeTable(table_info);
|
||||
if (!status.ok()) {
|
||||
if (status.code(), DB_NOT_FOUND) {
|
||||
return Status(SERVER_TABLE_NOT_EXIST, "Table " + table_name + " not exists");
|
||||
} else {
|
||||
return SetError(DB_META_TRANSACTION_FAILED, stat.ToString());
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
@ -837,25 +829,25 @@ DeleteByRangeTask::OnExecute() {
|
||||
|
||||
std::vector<::milvus::grpc::Range> range_array;
|
||||
range_array.emplace_back(delete_by_range_param_->range());
|
||||
ConvertTimeRangeToDBDates(range_array, dates, error_code, error_msg);
|
||||
if (error_code != SERVER_SUCCESS) {
|
||||
return SetError(error_code, error_msg);
|
||||
status = ConvertTimeRangeToDBDates(range_array, dates);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
#ifdef MILVUS_ENABLE_PROFILING
|
||||
std::string fname = "/tmp/search_nq_" + this->delete_by_range_param_->table_name() + ".profiling";
|
||||
ProfilerStart(fname.c_str());
|
||||
#endif
|
||||
stat = DBWrapper::DB()->DeleteTable(table_name, dates);
|
||||
if (!stat.ok()) {
|
||||
return SetError(DB_META_TRANSACTION_FAILED, stat.ToString());
|
||||
status = DBWrapper::DB()->DeleteTable(table_name, dates);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
} catch (std::exception &ex) {
|
||||
return SetError(SERVER_UNEXPECTED_ERROR, ex.what());
|
||||
return Status(SERVER_UNEXPECTED_ERROR, ex.what());
|
||||
}
|
||||
|
||||
return SERVER_SUCCESS;
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -870,29 +862,29 @@ PreloadTableTask::Create(const std::string &table_name){
|
||||
return std::shared_ptr<GrpcBaseTask>(new PreloadTableTask(table_name));
|
||||
}
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
PreloadTableTask::OnExecute() {
|
||||
try {
|
||||
TimeRecorder rc("PreloadTableTask");
|
||||
|
||||
//step 1: check arguments
|
||||
ErrorCode res = ValidationUtil::ValidateTableName(table_name_);
|
||||
if (res != SERVER_SUCCESS) {
|
||||
return SetError(res, "Invalid table name: " + table_name_);
|
||||
auto status = ValidationUtil::ValidateTableName(table_name_);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
//step 2: check table existence
|
||||
auto stat = DBWrapper::DB()->PreloadTable(table_name_);
|
||||
if (!stat.ok()) {
|
||||
return SetError(DB_META_TRANSACTION_FAILED, stat.ToString());
|
||||
status = DBWrapper::DB()->PreloadTable(table_name_);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
rc.ElapseFromBegin("totally cost");
|
||||
} catch (std::exception &ex) {
|
||||
return SetError(SERVER_UNEXPECTED_ERROR, ex.what());
|
||||
return Status(SERVER_UNEXPECTED_ERROR, ex.what());
|
||||
}
|
||||
|
||||
return SERVER_SUCCESS;
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -910,22 +902,22 @@ DescribeIndexTask::Create(const std::string &table_name,
|
||||
return std::shared_ptr<GrpcBaseTask>(new DescribeIndexTask(table_name, index_param));
|
||||
}
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
DescribeIndexTask::OnExecute() {
|
||||
try {
|
||||
TimeRecorder rc("DescribeIndexTask");
|
||||
|
||||
//step 1: check arguments
|
||||
ErrorCode res = ValidationUtil::ValidateTableName(table_name_);
|
||||
if (res != SERVER_SUCCESS) {
|
||||
return SetError(res, "Invalid table name: " + table_name_);
|
||||
auto status = ValidationUtil::ValidateTableName(table_name_);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
//step 2: check table existence
|
||||
engine::TableIndex index;
|
||||
auto stat = DBWrapper::DB()->DescribeIndex(table_name_, index);
|
||||
if (!stat.ok()) {
|
||||
return SetError(DB_META_TRANSACTION_FAILED, stat.ToString());
|
||||
status = DBWrapper::DB()->DescribeIndex(table_name_, index);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
index_param_->mutable_table_name()->set_table_name(table_name_);
|
||||
@ -934,10 +926,10 @@ DescribeIndexTask::OnExecute() {
|
||||
|
||||
rc.ElapseFromBegin("totally cost");
|
||||
} catch (std::exception &ex) {
|
||||
return SetError(SERVER_UNEXPECTED_ERROR, ex.what());
|
||||
return Status(SERVER_UNEXPECTED_ERROR, ex.what());
|
||||
}
|
||||
|
||||
return SERVER_SUCCESS;
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -952,39 +944,39 @@ DropIndexTask::Create(const std::string &table_name){
|
||||
return std::shared_ptr<GrpcBaseTask>(new DropIndexTask(table_name));
|
||||
}
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
DropIndexTask::OnExecute() {
|
||||
try {
|
||||
TimeRecorder rc("DropIndexTask");
|
||||
|
||||
//step 1: check arguments
|
||||
ErrorCode res = ValidationUtil::ValidateTableName(table_name_);
|
||||
if (res != SERVER_SUCCESS) {
|
||||
return SetError(res, "Invalid table name: " + table_name_);
|
||||
auto status = ValidationUtil::ValidateTableName(table_name_);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
bool has_table = false;
|
||||
auto stat = DBWrapper::DB()->HasTable(table_name_, has_table);
|
||||
if (!stat.ok()) {
|
||||
return SetError(DB_META_TRANSACTION_FAILED, stat.ToString());
|
||||
status = DBWrapper::DB()->HasTable(table_name_, has_table);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
if (!has_table) {
|
||||
return SetError(SERVER_TABLE_NOT_EXIST, "Table " + table_name_ + " not exists");
|
||||
return Status(SERVER_TABLE_NOT_EXIST, "Table " + table_name_ + " not exists");
|
||||
}
|
||||
|
||||
//step 2: check table existence
|
||||
stat = DBWrapper::DB()->DropIndex(table_name_);
|
||||
if (!stat.ok()) {
|
||||
return SetError(DB_META_TRANSACTION_FAILED, stat.ToString());
|
||||
status = DBWrapper::DB()->DropIndex(table_name_);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
rc.ElapseFromBegin("totally cost");
|
||||
} catch (std::exception &ex) {
|
||||
return SetError(SERVER_UNEXPECTED_ERROR, ex.what());
|
||||
return Status(SERVER_UNEXPECTED_ERROR, ex.what());
|
||||
}
|
||||
|
||||
return SERVER_SUCCESS;
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
|
||||
#pragma once
|
||||
#include "GrpcRequestScheduler.h"
|
||||
#include "utils/Error.h"
|
||||
#include "utils/Status.h"
|
||||
#include "db/Types.h"
|
||||
|
||||
#include "milvus.grpc.pb.h"
|
||||
@ -41,7 +41,7 @@ protected:
|
||||
explicit
|
||||
CreateTableTask(const ::milvus::grpc::TableSchema *request);
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
OnExecute() override;
|
||||
|
||||
private:
|
||||
@ -57,7 +57,7 @@ public:
|
||||
protected:
|
||||
HasTableTask(const std::string &request, bool &has_table);
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
OnExecute() override;
|
||||
|
||||
|
||||
@ -75,7 +75,7 @@ public:
|
||||
protected:
|
||||
DescribeTableTask(const std::string &table_name, ::milvus::grpc::TableSchema *schema);
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
OnExecute() override;
|
||||
|
||||
|
||||
@ -94,7 +94,7 @@ protected:
|
||||
explicit
|
||||
DropTableTask(const std::string &table_name);
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
OnExecute() override;
|
||||
|
||||
|
||||
@ -112,7 +112,7 @@ protected:
|
||||
explicit
|
||||
CreateIndexTask(const ::milvus::grpc::IndexParam *index_Param);
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
OnExecute() override;
|
||||
|
||||
|
||||
@ -130,7 +130,7 @@ protected:
|
||||
explicit
|
||||
ShowTablesTask(::grpc::ServerWriter<::milvus::grpc::TableName> *writer);
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
OnExecute() override;
|
||||
|
||||
private:
|
||||
@ -148,7 +148,7 @@ protected:
|
||||
InsertTask(const ::milvus::grpc::InsertParam *insert_Param,
|
||||
::milvus::grpc::VectorIds *record_ids_);
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
OnExecute() override;
|
||||
|
||||
private:
|
||||
@ -169,7 +169,7 @@ protected:
|
||||
const std::vector<std::string> &file_id_array,
|
||||
::milvus::grpc::TopKQueryResultList *response);
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
OnExecute() override;
|
||||
|
||||
private:
|
||||
@ -187,7 +187,7 @@ public:
|
||||
protected:
|
||||
CountTableTask(const std::string &table_name, int64_t &row_count);
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
OnExecute() override;
|
||||
|
||||
private:
|
||||
@ -204,7 +204,7 @@ public:
|
||||
protected:
|
||||
CmdTask(const std::string &cmd, std::string &result);
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
OnExecute() override;
|
||||
|
||||
private:
|
||||
@ -221,7 +221,7 @@ public:
|
||||
protected:
|
||||
DeleteByRangeTask(const ::milvus::grpc::DeleteByRangeParam *delete_by_range_param);
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
OnExecute() override;
|
||||
|
||||
private:
|
||||
@ -237,7 +237,7 @@ public:
|
||||
protected:
|
||||
PreloadTableTask(const std::string &table_name);
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
OnExecute() override;
|
||||
|
||||
private:
|
||||
@ -255,7 +255,7 @@ protected:
|
||||
DescribeIndexTask(const std::string &table_name,
|
||||
::milvus::grpc::IndexParam *index_param);
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
OnExecute() override;
|
||||
|
||||
private:
|
||||
@ -272,7 +272,7 @@ public:
|
||||
protected:
|
||||
DropIndexTask(const std::string &table_name);
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
OnExecute() override;
|
||||
|
||||
private:
|
||||
|
||||
@ -73,35 +73,35 @@ bool CommonUtil::IsDirectoryExist(const std::string &path) {
|
||||
return true;
|
||||
}
|
||||
|
||||
ErrorCode CommonUtil::CreateDirectory(const std::string &path) {
|
||||
Status CommonUtil::CreateDirectory(const std::string &path) {
|
||||
if(path.empty()) {
|
||||
return SERVER_SUCCESS;
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
struct stat directory_stat;
|
||||
int status = stat(path.c_str(), &directory_stat);
|
||||
if (status == 0) {
|
||||
return SERVER_SUCCESS;//already exist
|
||||
return Status::OK();//already exist
|
||||
}
|
||||
|
||||
fs::path fs_path(path);
|
||||
fs::path parent_path = fs_path.parent_path();
|
||||
ErrorCode err = CreateDirectory(parent_path.string());
|
||||
if(err != SERVER_SUCCESS){
|
||||
return err;
|
||||
Status err_status = CreateDirectory(parent_path.string());
|
||||
if(!err_status.ok()){
|
||||
return err_status;
|
||||
}
|
||||
|
||||
status = stat(path.c_str(), &directory_stat);
|
||||
if (status == 0) {
|
||||
return SERVER_SUCCESS;//already exist
|
||||
return Status::OK();//already exist
|
||||
}
|
||||
|
||||
int makeOK = mkdir(path.c_str(), S_IRWXU|S_IRGRP|S_IROTH);
|
||||
if (makeOK != 0) {
|
||||
return SERVER_UNEXPECTED_ERROR;
|
||||
return Status(SERVER_UNEXPECTED_ERROR, "failed to create directory: " + path);
|
||||
}
|
||||
|
||||
return SERVER_SUCCESS;
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
namespace {
|
||||
@ -134,18 +134,19 @@ namespace {
|
||||
}
|
||||
}
|
||||
|
||||
ErrorCode CommonUtil::DeleteDirectory(const std::string &path) {
|
||||
Status CommonUtil::DeleteDirectory(const std::string &path) {
|
||||
if(path.empty()) {
|
||||
return SERVER_SUCCESS;
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
struct stat directory_stat;
|
||||
int statOK = stat(path.c_str(), &directory_stat);
|
||||
if (statOK != 0)
|
||||
return SERVER_SUCCESS;
|
||||
if (statOK != 0) {
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
RemoveDirectory(path);
|
||||
return SERVER_SUCCESS;
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
bool CommonUtil::IsFileExist(const std::string &path) {
|
||||
|
||||
@ -17,10 +17,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "utils/Status.h"
|
||||
|
||||
#include <string>
|
||||
#include <time.h>
|
||||
|
||||
#include "Error.h"
|
||||
|
||||
namespace zilliz {
|
||||
namespace milvus {
|
||||
@ -34,8 +35,8 @@ class CommonUtil {
|
||||
static bool IsFileExist(const std::string &path);
|
||||
static uint64_t GetFileSize(const std::string &path);
|
||||
static bool IsDirectoryExist(const std::string &path);
|
||||
static ErrorCode CreateDirectory(const std::string &path);
|
||||
static ErrorCode DeleteDirectory(const std::string &path);
|
||||
static Status CreateDirectory(const std::string &path);
|
||||
static Status DeleteDirectory(const std::string &path);
|
||||
|
||||
static std::string GetExePath();
|
||||
|
||||
|
||||
@ -21,9 +21,9 @@
|
||||
namespace zilliz {
|
||||
namespace milvus {
|
||||
|
||||
constexpr int CODE_WIDTH = sizeof(ErrorCode);
|
||||
constexpr int CODE_WIDTH = sizeof(StatusCode);
|
||||
|
||||
Status::Status(ErrorCode code, const std::string& msg) {
|
||||
Status::Status(StatusCode code, const std::string& msg) {
|
||||
//4 bytes store code
|
||||
//4 bytes store message length
|
||||
//the left bytes store message string
|
||||
@ -50,7 +50,8 @@ Status::Status(const Status &s)
|
||||
CopyFrom(s);
|
||||
}
|
||||
|
||||
Status &Status::operator=(const Status &s) {
|
||||
Status&
|
||||
Status::operator=(const Status &s) {
|
||||
CopyFrom(s);
|
||||
return *this;
|
||||
}
|
||||
@ -60,12 +61,14 @@ Status::Status(Status &&s)
|
||||
MoveFrom(s);
|
||||
}
|
||||
|
||||
Status &Status::operator=(Status &&s) {
|
||||
Status&
|
||||
Status::operator=(Status &&s) {
|
||||
MoveFrom(s);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Status::CopyFrom(const Status &s) {
|
||||
void
|
||||
Status::CopyFrom(const Status &s) {
|
||||
delete state_;
|
||||
state_ = nullptr;
|
||||
if(s.state_ == nullptr) {
|
||||
@ -73,19 +76,37 @@ void Status::CopyFrom(const Status &s) {
|
||||
}
|
||||
|
||||
uint32_t length = 0;
|
||||
std::memcpy(&length, s.state_ + CODE_WIDTH, sizeof(length));
|
||||
memcpy(&length, s.state_ + CODE_WIDTH, sizeof(length));
|
||||
int buff_len = length + sizeof(length) + CODE_WIDTH;
|
||||
state_ = new char[buff_len];
|
||||
memcpy((void*)state_, (void*)s.state_, buff_len);
|
||||
}
|
||||
|
||||
void Status::MoveFrom(Status &s) {
|
||||
void
|
||||
Status::MoveFrom(Status &s) {
|
||||
delete state_;
|
||||
state_ = s.state_;
|
||||
s.state_ = nullptr;
|
||||
}
|
||||
|
||||
std::string Status::ToString() const {
|
||||
std::string
|
||||
Status::message() const {
|
||||
if (state_ == nullptr) {
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string msg;
|
||||
uint32_t length = 0;
|
||||
memcpy(&length, state_ + CODE_WIDTH, sizeof(length));
|
||||
if(length > 0) {
|
||||
msg.append(state_ + sizeof(length) + CODE_WIDTH, length);
|
||||
}
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
std::string
|
||||
Status::ToString() const {
|
||||
if (state_ == nullptr) {
|
||||
return "OK";
|
||||
}
|
||||
@ -115,12 +136,7 @@ std::string Status::ToString() const {
|
||||
break;
|
||||
}
|
||||
|
||||
uint32_t length = 0;
|
||||
memcpy(&length, state_ + CODE_WIDTH, sizeof(length));
|
||||
if(length > 0) {
|
||||
result.append(state_ + sizeof(length) + CODE_WIDTH, length);
|
||||
}
|
||||
|
||||
result += message();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@ -25,9 +25,11 @@
|
||||
namespace zilliz {
|
||||
namespace milvus {
|
||||
|
||||
using StatusCode = ErrorCode;
|
||||
|
||||
class Status {
|
||||
public:
|
||||
Status(ErrorCode code, const std::string &msg);
|
||||
Status(StatusCode code, const std::string &msg);
|
||||
Status();
|
||||
~Status();
|
||||
|
||||
@ -47,14 +49,17 @@ class Status {
|
||||
bool
|
||||
ok() const { return state_ == nullptr || code() == 0; }
|
||||
|
||||
StatusCode
|
||||
code() const {
|
||||
return (state_ == nullptr) ? 0 : *(StatusCode*)(state_);
|
||||
}
|
||||
|
||||
std::string
|
||||
message() const;
|
||||
|
||||
std::string
|
||||
ToString() const;
|
||||
|
||||
ErrorCode
|
||||
code() const {
|
||||
return (state_ == nullptr) ? 0 : *(ErrorCode*)(state_);
|
||||
}
|
||||
|
||||
private:
|
||||
inline void
|
||||
CopyFrom(const Status &s);
|
||||
|
||||
@ -36,11 +36,11 @@ void StringHelpFunctions::TrimStringQuote(std::string &string, const std::string
|
||||
}
|
||||
}
|
||||
|
||||
ErrorCode StringHelpFunctions::SplitStringByDelimeter(const std::string &str,
|
||||
const std::string &delimeter,
|
||||
std::vector<std::string> &result) {
|
||||
Status StringHelpFunctions::SplitStringByDelimeter(const std::string &str,
|
||||
const std::string &delimeter,
|
||||
std::vector<std::string> &result) {
|
||||
if(str.empty()) {
|
||||
return SERVER_SUCCESS;
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
size_t last = 0;
|
||||
@ -55,13 +55,13 @@ ErrorCode StringHelpFunctions::SplitStringByDelimeter(const std::string &str,
|
||||
result.emplace_back(temp);
|
||||
}
|
||||
|
||||
return SERVER_SUCCESS;
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
ErrorCode StringHelpFunctions::SplitStringByQuote(const std::string &str,
|
||||
const std::string &delimeter,
|
||||
const std::string "e,
|
||||
std::vector<std::string> &result) {
|
||||
Status StringHelpFunctions::SplitStringByQuote(const std::string &str,
|
||||
const std::string &delimeter,
|
||||
const std::string "e,
|
||||
std::vector<std::string> &result) {
|
||||
if (quote.empty()) {
|
||||
return SplitStringByDelimeter(str, delimeter, result);
|
||||
}
|
||||
@ -88,7 +88,7 @@ ErrorCode StringHelpFunctions::SplitStringByDelimeter(const std::string &str,
|
||||
std::string postfix = process_str.substr(last);
|
||||
index = postfix.find_first_of(quote, 0);
|
||||
if (index == std::string::npos) {
|
||||
return SERVER_UNEXPECTED_ERROR;
|
||||
return Status(SERVER_UNEXPECTED_ERROR, "");
|
||||
}
|
||||
std::string quoted_text = postfix.substr(0, index);
|
||||
append_prefix += quoted_text;
|
||||
@ -105,7 +105,7 @@ ErrorCode StringHelpFunctions::SplitStringByDelimeter(const std::string &str,
|
||||
result.emplace_back(append_prefix);
|
||||
|
||||
if (last == postfix.length()) {
|
||||
return SERVER_SUCCESS;
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
process_str = postfix.substr(index + 1);
|
||||
@ -117,7 +117,7 @@ ErrorCode StringHelpFunctions::SplitStringByDelimeter(const std::string &str,
|
||||
return SplitStringByDelimeter(process_str, delimeter, result);
|
||||
}
|
||||
|
||||
return SERVER_SUCCESS;
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "./Error.h"
|
||||
#include "utils/Status.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
@ -41,9 +41,9 @@ public:
|
||||
// ,b, | b |
|
||||
// ,, | |
|
||||
// a a
|
||||
static ErrorCode SplitStringByDelimeter(const std::string &str,
|
||||
const std::string &delimeter,
|
||||
std::vector<std::string> &result);
|
||||
static Status SplitStringByDelimeter(const std::string &str,
|
||||
const std::string &delimeter,
|
||||
std::vector<std::string> &result);
|
||||
|
||||
//assume the table has two columns, quote='\"', delimeter=','
|
||||
// a,b a | b
|
||||
@ -52,10 +52,10 @@ public:
|
||||
// "aa,bb" aa,bb
|
||||
// 55,1122\"aa,bb\",yyy,\"kkk\" 55 | 1122aa,bb | yyy | kkk
|
||||
// "55,1122"aa,bb",yyy,"kkk" illegal
|
||||
static ErrorCode SplitStringByQuote(const std::string &str,
|
||||
const std::string &delimeter,
|
||||
const std::string "e,
|
||||
std::vector<std::string> &result);
|
||||
static Status SplitStringByQuote(const std::string &str,
|
||||
const std::string &delimeter,
|
||||
const std::string "e,
|
||||
std::vector<std::string> &result);
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -21,9 +21,7 @@
|
||||
#include "Log.h"
|
||||
|
||||
#include <cuda_runtime.h>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <regex>
|
||||
#include <algorithm>
|
||||
|
||||
@ -36,135 +34,156 @@ constexpr size_t TABLE_NAME_SIZE_LIMIT = 255;
|
||||
constexpr int64_t TABLE_DIMENSION_LIMIT = 16384;
|
||||
constexpr int32_t INDEX_FILE_SIZE_LIMIT = 4096; //index trigger size max = 4096 MB
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
ValidationUtil::ValidateTableName(const std::string &table_name) {
|
||||
|
||||
// Table name shouldn't be empty.
|
||||
if (table_name.empty()) {
|
||||
SERVER_LOG_ERROR << "Empty table name";
|
||||
return SERVER_INVALID_TABLE_NAME;
|
||||
std::string msg = "Empty table name";
|
||||
SERVER_LOG_ERROR << msg;
|
||||
return Status(SERVER_INVALID_TABLE_NAME, msg);
|
||||
}
|
||||
|
||||
// Table name size shouldn't exceed 16384.
|
||||
if (table_name.size() > TABLE_NAME_SIZE_LIMIT) {
|
||||
SERVER_LOG_ERROR << "Table name size exceed the limitation";
|
||||
return SERVER_INVALID_TABLE_NAME;
|
||||
std::string msg = "Table name size exceed the limitation";
|
||||
SERVER_LOG_ERROR << msg;
|
||||
return Status(SERVER_INVALID_TABLE_NAME, msg);
|
||||
}
|
||||
|
||||
// Table name first character should be underscore or character.
|
||||
char first_char = table_name[0];
|
||||
if (first_char != '_' && std::isalpha(first_char) == 0) {
|
||||
SERVER_LOG_ERROR << "Table name first character isn't underscore or character: " << first_char;
|
||||
return SERVER_INVALID_TABLE_NAME;
|
||||
std::string msg = "Table name first character isn't underscore or character";
|
||||
SERVER_LOG_ERROR << msg;
|
||||
return Status(SERVER_INVALID_TABLE_NAME, msg);
|
||||
}
|
||||
|
||||
int64_t table_name_size = table_name.size();
|
||||
for (int64_t i = 1; i < table_name_size; ++i) {
|
||||
char name_char = table_name[i];
|
||||
if (name_char != '_' && std::isalnum(name_char) == 0) {
|
||||
SERVER_LOG_ERROR << "Table name character isn't underscore or alphanumber: " << name_char;
|
||||
return SERVER_INVALID_TABLE_NAME;
|
||||
std::string msg = "Table name character isn't underscore or alphanumber";
|
||||
SERVER_LOG_ERROR << msg;
|
||||
return Status(SERVER_INVALID_TABLE_NAME, msg);
|
||||
}
|
||||
}
|
||||
|
||||
return SERVER_SUCCESS;
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
ValidationUtil::ValidateTableDimension(int64_t dimension) {
|
||||
if (dimension <= 0 || dimension > TABLE_DIMENSION_LIMIT) {
|
||||
SERVER_LOG_ERROR << "Table dimension excceed the limitation: " << TABLE_DIMENSION_LIMIT;
|
||||
return SERVER_INVALID_VECTOR_DIMENSION;
|
||||
std::string msg = "Table dimension excceed the limitation: " + std::to_string(TABLE_DIMENSION_LIMIT);
|
||||
SERVER_LOG_ERROR << msg;
|
||||
return Status(SERVER_INVALID_VECTOR_DIMENSION, msg);
|
||||
}
|
||||
else {
|
||||
return SERVER_SUCCESS;
|
||||
return Status::OK();
|
||||
}
|
||||
}
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
ValidationUtil::ValidateTableIndexType(int32_t index_type) {
|
||||
int engine_type = (int) engine::EngineType(index_type);
|
||||
if (engine_type <= 0 || engine_type > (int) engine::EngineType::MAX_VALUE) {
|
||||
return SERVER_INVALID_INDEX_TYPE;
|
||||
std::string msg = "Invalid index type: " + std::to_string(index_type);
|
||||
SERVER_LOG_ERROR << msg;
|
||||
return Status(SERVER_INVALID_INDEX_TYPE, msg);
|
||||
}
|
||||
|
||||
return SERVER_SUCCESS;
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
ValidationUtil::ValidateTableIndexNlist(int32_t nlist) {
|
||||
if (nlist <= 0) {
|
||||
return SERVER_INVALID_INDEX_NLIST;
|
||||
std::string msg = "Invalid nlist value: " + std::to_string(nlist);
|
||||
SERVER_LOG_ERROR << msg;
|
||||
return Status(SERVER_INVALID_INDEX_NLIST, msg);
|
||||
}
|
||||
|
||||
return SERVER_SUCCESS;
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
ValidationUtil::ValidateTableIndexFileSize(int64_t index_file_size) {
|
||||
if (index_file_size <= 0 || index_file_size > INDEX_FILE_SIZE_LIMIT) {
|
||||
return SERVER_INVALID_INDEX_FILE_SIZE;
|
||||
std::string msg = "Invalid index file size: " + std::to_string(index_file_size);
|
||||
SERVER_LOG_ERROR << msg;
|
||||
return Status(SERVER_INVALID_INDEX_FILE_SIZE, msg);
|
||||
}
|
||||
|
||||
return SERVER_SUCCESS;
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
ValidationUtil::ValidateTableIndexMetricType(int32_t metric_type) {
|
||||
if (metric_type != (int32_t) engine::MetricType::L2 && metric_type != (int32_t) engine::MetricType::IP) {
|
||||
return SERVER_INVALID_INDEX_METRIC_TYPE;
|
||||
std::string msg = "Invalid metric type: " + std::to_string(metric_type);
|
||||
SERVER_LOG_ERROR << msg;
|
||||
return Status(SERVER_INVALID_INDEX_METRIC_TYPE, msg);
|
||||
}
|
||||
return SERVER_SUCCESS;
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
ValidationUtil::ValidateSearchTopk(int64_t top_k, const engine::meta::TableSchema &table_schema) {
|
||||
if (top_k <= 0 || top_k > 2048) {
|
||||
return SERVER_INVALID_TOPK;
|
||||
std::string msg = "Invalid top k value: " + std::to_string(top_k);
|
||||
SERVER_LOG_ERROR << msg;
|
||||
return Status(SERVER_INVALID_TOPK, msg);
|
||||
}
|
||||
|
||||
return SERVER_SUCCESS;
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
ValidationUtil::ValidateSearchNprobe(int64_t nprobe, const engine::meta::TableSchema &table_schema) {
|
||||
if (nprobe <= 0 || nprobe > table_schema.nlist_) {
|
||||
return SERVER_INVALID_NPROBE;
|
||||
std::string msg = "Invalid nprobe value: " + std::to_string(nprobe);
|
||||
SERVER_LOG_ERROR << msg;
|
||||
return Status(SERVER_INVALID_NPROBE, msg);
|
||||
}
|
||||
|
||||
return SERVER_SUCCESS;
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
ValidationUtil::ValidateGpuIndex(uint32_t gpu_index) {
|
||||
int num_devices = 0;
|
||||
auto cuda_err = cudaGetDeviceCount(&num_devices);
|
||||
if (cuda_err) {
|
||||
SERVER_LOG_ERROR << "Failed to count video card: " << std::to_string(cuda_err);
|
||||
return SERVER_UNEXPECTED_ERROR;
|
||||
std::string msg = "Failed to get gpu card number, cuda error:" + std::to_string(cuda_err);
|
||||
SERVER_LOG_ERROR << msg;
|
||||
return Status(SERVER_UNEXPECTED_ERROR, msg);
|
||||
}
|
||||
|
||||
if (gpu_index >= num_devices) {
|
||||
return SERVER_INVALID_ARGUMENT;
|
||||
std::string msg = "Invalid gpu index: " + std::to_string(gpu_index);
|
||||
SERVER_LOG_ERROR << msg;
|
||||
return Status(SERVER_INVALID_ARGUMENT, msg);
|
||||
}
|
||||
|
||||
return SERVER_SUCCESS;
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
ValidationUtil::GetGpuMemory(uint32_t gpu_index, size_t &memory) {
|
||||
cudaDeviceProp deviceProp;
|
||||
auto cuda_err = cudaGetDeviceProperties(&deviceProp, gpu_index);
|
||||
if (cuda_err) {
|
||||
SERVER_LOG_ERROR << "Failed to get video card properties: " << std::to_string(cuda_err);
|
||||
return SERVER_UNEXPECTED_ERROR;
|
||||
std::string msg = "Failed to get gpu properties, cuda error:" + std::to_string(cuda_err);
|
||||
SERVER_LOG_ERROR << msg;
|
||||
return Status(SERVER_UNEXPECTED_ERROR, msg);
|
||||
}
|
||||
|
||||
memory = deviceProp.totalGlobalMem;
|
||||
return SERVER_SUCCESS;
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
ValidationUtil::ValidateIpAddress(const std::string &ip_address) {
|
||||
|
||||
struct in_addr address;
|
||||
@ -172,50 +191,56 @@ ValidationUtil::ValidateIpAddress(const std::string &ip_address) {
|
||||
int result = inet_pton(AF_INET, ip_address.c_str(), &address);
|
||||
|
||||
switch (result) {
|
||||
case 1:return SERVER_SUCCESS;
|
||||
case 0:SERVER_LOG_ERROR << "Invalid IP address: " << ip_address;
|
||||
return SERVER_INVALID_ARGUMENT;
|
||||
default:SERVER_LOG_ERROR << "inet_pton conversion error";
|
||||
return SERVER_UNEXPECTED_ERROR;
|
||||
case 1:return Status::OK();
|
||||
case 0: {
|
||||
std::string msg = "Invalid IP address: " + ip_address;
|
||||
SERVER_LOG_ERROR << msg;
|
||||
return Status(SERVER_INVALID_ARGUMENT, msg);
|
||||
}
|
||||
default: {
|
||||
std::string msg = "IP address conversion error: " + ip_address;
|
||||
SERVER_LOG_ERROR << msg;
|
||||
return Status(SERVER_UNEXPECTED_ERROR, msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
ValidationUtil::ValidateStringIsNumber(const std::string &string) {
|
||||
if (!string.empty() && std::all_of(string.begin(), string.end(), ::isdigit)) {
|
||||
return SERVER_SUCCESS;
|
||||
return Status::OK();
|
||||
}
|
||||
else {
|
||||
return SERVER_INVALID_ARGUMENT;
|
||||
return Status(SERVER_INVALID_ARGUMENT, "Not a number");
|
||||
}
|
||||
}
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
ValidationUtil::ValidateStringIsBool(std::string &str) {
|
||||
std::transform(str.begin(), str.end(), str.begin(), ::tolower);
|
||||
if (str == "true" || str == "on" || str == "yes" || str == "1" ||
|
||||
str == "false" || str == "off" || str == "no" || str == "0" ||
|
||||
str.empty()) {
|
||||
return SERVER_SUCCESS;
|
||||
return Status::OK();
|
||||
}
|
||||
else {
|
||||
return SERVER_INVALID_ARGUMENT;
|
||||
return Status(SERVER_INVALID_ARGUMENT, "Not a boolean: " + str);
|
||||
}
|
||||
}
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
ValidationUtil::ValidateStringIsDouble(const std::string &str, double &val) {
|
||||
char *end = nullptr;
|
||||
val = std::strtod(str.c_str(), &end);
|
||||
if (end != str.c_str() && *end == '\0' && val != HUGE_VAL) {
|
||||
return SERVER_SUCCESS;
|
||||
return Status::OK();
|
||||
}
|
||||
else {
|
||||
return SERVER_INVALID_ARGUMENT;
|
||||
return Status(SERVER_INVALID_ARGUMENT, "Not a double value: " + str);
|
||||
}
|
||||
}
|
||||
|
||||
ErrorCode
|
||||
Status
|
||||
ValidationUtil::ValidateDbURI(const std::string &uri) {
|
||||
std::string dialectRegex = "(.*)";
|
||||
std::string usernameRegex = "(.*)";
|
||||
@ -256,7 +281,8 @@ ValidationUtil::ValidateDbURI(const std::string &uri) {
|
||||
|
||||
std::string port = pieces_match[5].str();
|
||||
if (!port.empty()) {
|
||||
if (ValidateStringIsNumber(port) != SERVER_SUCCESS) {
|
||||
auto status = ValidateStringIsNumber(port);
|
||||
if (!status.ok()) {
|
||||
SERVER_LOG_ERROR << "Invalid port in uri = " << port;
|
||||
okay = false;
|
||||
}
|
||||
@ -267,7 +293,7 @@ ValidationUtil::ValidateDbURI(const std::string &uri) {
|
||||
okay = false;
|
||||
}
|
||||
|
||||
return (okay ? SERVER_SUCCESS : SERVER_INVALID_ARGUMENT);
|
||||
return (okay ? Status::OK() : Status(SERVER_INVALID_ARGUMENT, "Invalid db backend uri"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "db/meta/MetaTypes.h"
|
||||
#include "Error.h"
|
||||
#include "utils/Status.h"
|
||||
|
||||
namespace zilliz {
|
||||
namespace milvus {
|
||||
@ -27,49 +27,49 @@ namespace server {
|
||||
|
||||
class ValidationUtil {
|
||||
public:
|
||||
static ErrorCode
|
||||
static Status
|
||||
ValidateTableName(const std::string &table_name);
|
||||
|
||||
static ErrorCode
|
||||
static Status
|
||||
ValidateTableDimension(int64_t dimension);
|
||||
|
||||
static ErrorCode
|
||||
static Status
|
||||
ValidateTableIndexType(int32_t index_type);
|
||||
|
||||
static ErrorCode
|
||||
static Status
|
||||
ValidateTableIndexNlist(int32_t nlist);
|
||||
|
||||
static ErrorCode
|
||||
static Status
|
||||
ValidateTableIndexFileSize(int64_t index_file_size);
|
||||
|
||||
static ErrorCode
|
||||
static Status
|
||||
ValidateTableIndexMetricType(int32_t metric_type);
|
||||
|
||||
static ErrorCode
|
||||
static Status
|
||||
ValidateSearchTopk(int64_t top_k, const engine::meta::TableSchema& table_schema);
|
||||
|
||||
static ErrorCode
|
||||
static Status
|
||||
ValidateSearchNprobe(int64_t nprobe, const engine::meta::TableSchema& table_schema);
|
||||
|
||||
static ErrorCode
|
||||
static Status
|
||||
ValidateGpuIndex(uint32_t gpu_index);
|
||||
|
||||
static ErrorCode
|
||||
static Status
|
||||
GetGpuMemory(uint32_t gpu_index, size_t &memory);
|
||||
|
||||
static ErrorCode
|
||||
static Status
|
||||
ValidateIpAddress(const std::string &ip_address);
|
||||
|
||||
static ErrorCode
|
||||
static Status
|
||||
ValidateStringIsNumber(const std::string &str);
|
||||
|
||||
static ErrorCode
|
||||
static Status
|
||||
ValidateStringIsBool(std::string &str);
|
||||
|
||||
static ErrorCode
|
||||
static Status
|
||||
ValidateStringIsDouble(const std::string &str, double &val);
|
||||
|
||||
static ErrorCode
|
||||
static Status
|
||||
ValidateDbURI(const std::string &uri);
|
||||
};
|
||||
|
||||
|
||||
@ -107,11 +107,11 @@ TEST(ConfigTest, CONFIG_TEST) {
|
||||
|
||||
TEST(ConfigTest, SERVER_CONFIG_TEST) {
|
||||
server::ServerConfig& config = server::ServerConfig::GetInstance();
|
||||
ErrorCode err = config.LoadConfigFile(CONFIG_FILE_PATH);
|
||||
ASSERT_EQ(err, SERVER_SUCCESS);
|
||||
auto status = config.LoadConfigFile(CONFIG_FILE_PATH);
|
||||
ASSERT_TRUE(status.ok());
|
||||
|
||||
err = server::ServerConfig::GetInstance().ValidateConfig();
|
||||
ASSERT_EQ(err, SERVER_SUCCESS);
|
||||
status = server::ServerConfig::GetInstance().ValidateConfig();
|
||||
ASSERT_TRUE(status.ok());
|
||||
|
||||
const server::ServerConfig& config_const = config;
|
||||
server::ConfigNode node1 = config_const.GetConfig("server_config");
|
||||
@ -137,23 +137,23 @@ TEST(ConfigTest, SERVER_CONFIG_TEST) {
|
||||
server::ConfigNode& db_config = config.GetConfig("db_config");
|
||||
server::ConfigNode& cache_config = config.GetConfig(server::CONFIG_CACHE);
|
||||
cache_config.SetValue(server::CACHE_FREE_PERCENT, "2.0");
|
||||
err = config.ValidateConfig();
|
||||
ASSERT_NE(err, SERVER_SUCCESS);
|
||||
status = config.ValidateConfig();
|
||||
ASSERT_FALSE(status.ok());
|
||||
|
||||
size_t cache_cap = 16;
|
||||
size_t insert_buffer_size = (total_mem - cache_cap*GB + 1*GB)/GB;
|
||||
db_config.SetValue(server::CONFIG_DB_INSERT_BUFFER_SIZE, std::to_string(insert_buffer_size));
|
||||
cache_config.SetValue(server::CONFIG_CPU_CACHE_CAPACITY, std::to_string(cache_cap));
|
||||
err = config.ValidateConfig();
|
||||
ASSERT_NE(err, SERVER_SUCCESS);
|
||||
status = config.ValidateConfig();
|
||||
ASSERT_FALSE(status.ok());
|
||||
|
||||
cache_cap = total_mem/GB + 2;
|
||||
cache_config.SetValue(server::CONFIG_CPU_CACHE_CAPACITY, std::to_string(cache_cap));
|
||||
err = config.ValidateConfig();
|
||||
ASSERT_NE(err, SERVER_SUCCESS);
|
||||
status = config.ValidateConfig();
|
||||
ASSERT_FALSE(status.ok());
|
||||
|
||||
insert_buffer_size = total_mem/GB + 2;
|
||||
db_config.SetValue(server::CONFIG_DB_INSERT_BUFFER_SIZE, std::to_string(insert_buffer_size));
|
||||
err = config.ValidateConfig();
|
||||
ASSERT_NE(err, SERVER_SUCCESS);
|
||||
status = config.ValidateConfig();
|
||||
ASSERT_FALSE(status.ok());
|
||||
}
|
||||
@ -431,9 +431,9 @@ TEST_F(RpcHandlerTest, DeleteByRangeTest) {
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
class DummyTask : public GrpcBaseTask {
|
||||
public:
|
||||
ErrorCode
|
||||
Status
|
||||
OnExecute() override {
|
||||
return 0;
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
static BaseTaskPtr
|
||||
@ -441,11 +441,6 @@ class DummyTask : public GrpcBaseTask {
|
||||
return std::shared_ptr<GrpcBaseTask>(new DummyTask(dummy));
|
||||
}
|
||||
|
||||
ErrorCode
|
||||
DummySetError(ErrorCode error_code, const std::string &msg) {
|
||||
return SetError(error_code, msg);
|
||||
}
|
||||
|
||||
public:
|
||||
explicit DummyTask(std::string &dummy) : GrpcBaseTask(dummy) {
|
||||
|
||||
@ -464,11 +459,8 @@ class RpcSchedulerTest : public testing::Test {
|
||||
};
|
||||
|
||||
TEST_F(RpcSchedulerTest, BaseTaskTest){
|
||||
ErrorCode error_code = task_ptr->Execute();
|
||||
ASSERT_EQ(error_code, 0);
|
||||
|
||||
error_code = task_ptr->DummySetError(0, "test error");
|
||||
ASSERT_EQ(error_code, 0);
|
||||
auto status = task_ptr->Execute();
|
||||
ASSERT_TRUE(status.ok());
|
||||
|
||||
GrpcRequestScheduler::GetInstance().Start();
|
||||
::milvus::grpc::Status grpc_status;
|
||||
|
||||
@ -64,19 +64,19 @@ TEST(UtilTest, COMMON_TEST) {
|
||||
std::string path1 = "/tmp/milvus_test/";
|
||||
std::string path2 = path1 + "common_test_12345/";
|
||||
std::string path3 = path2 + "abcdef";
|
||||
ErrorCode err = server::CommonUtil::CreateDirectory(path3);
|
||||
ASSERT_EQ(err, SERVER_SUCCESS);
|
||||
Status status = server::CommonUtil::CreateDirectory(path3);
|
||||
ASSERT_TRUE(status.ok());
|
||||
//test again
|
||||
err = server::CommonUtil::CreateDirectory(path3);
|
||||
ASSERT_EQ(err, SERVER_SUCCESS);
|
||||
status = server::CommonUtil::CreateDirectory(path3);
|
||||
ASSERT_TRUE(status.ok());
|
||||
|
||||
ASSERT_TRUE(server::CommonUtil::IsDirectoryExist(path3));
|
||||
|
||||
err = server::CommonUtil::DeleteDirectory(path1);
|
||||
ASSERT_EQ(err, SERVER_SUCCESS);
|
||||
status = server::CommonUtil::DeleteDirectory(path1);
|
||||
ASSERT_TRUE(status.ok());
|
||||
//test again
|
||||
err = server::CommonUtil::DeleteDirectory(path1);
|
||||
ASSERT_EQ(err, SERVER_SUCCESS);
|
||||
status = server::CommonUtil::DeleteDirectory(path1);
|
||||
ASSERT_TRUE(status.ok());
|
||||
|
||||
ASSERT_FALSE(server::CommonUtil::IsDirectoryExist(path1));
|
||||
ASSERT_FALSE(server::CommonUtil::IsFileExist(path1));
|
||||
@ -114,24 +114,24 @@ TEST(UtilTest, STRINGFUNCTIONS_TEST) {
|
||||
|
||||
str = "a,b,c";
|
||||
std::vector<std::string> result;
|
||||
ErrorCode err = server::StringHelpFunctions::SplitStringByDelimeter(str , ",", result);
|
||||
ASSERT_EQ(err, SERVER_SUCCESS);
|
||||
auto status = server::StringHelpFunctions::SplitStringByDelimeter(str , ",", result);
|
||||
ASSERT_TRUE(status.ok());
|
||||
ASSERT_EQ(result.size(), 3UL);
|
||||
|
||||
result.clear();
|
||||
err = server::StringHelpFunctions::SplitStringByQuote(str , ",", "\"", result);
|
||||
ASSERT_EQ(err, SERVER_SUCCESS);
|
||||
status = server::StringHelpFunctions::SplitStringByQuote(str , ",", "\"", result);
|
||||
ASSERT_TRUE(status.ok());
|
||||
ASSERT_EQ(result.size(), 3UL);
|
||||
|
||||
result.clear();
|
||||
err = server::StringHelpFunctions::SplitStringByQuote(str , ",", "", result);
|
||||
ASSERT_EQ(err, SERVER_SUCCESS);
|
||||
status = server::StringHelpFunctions::SplitStringByQuote(str , ",", "", result);
|
||||
ASSERT_TRUE(status.ok());
|
||||
ASSERT_EQ(result.size(), 3UL);
|
||||
|
||||
str = "55,\"aa,gg,yy\",b";
|
||||
result.clear();
|
||||
err = server::StringHelpFunctions::SplitStringByQuote(str , ",", "\"", result);
|
||||
ASSERT_EQ(err, SERVER_SUCCESS);
|
||||
status = server::StringHelpFunctions::SplitStringByQuote(str , ",", "\"", result);
|
||||
ASSERT_TRUE(status.ok());
|
||||
ASSERT_EQ(result.size(), 3UL);
|
||||
|
||||
|
||||
@ -227,117 +227,117 @@ TEST(UtilTest, STATUS_TEST) {
|
||||
|
||||
TEST(ValidationUtilTest, VALIDATE_TABLENAME_TEST) {
|
||||
std::string table_name = "Normal123_";
|
||||
ErrorCode res = server::ValidationUtil::ValidateTableName(table_name);
|
||||
ASSERT_EQ(res, SERVER_SUCCESS);
|
||||
auto status = server::ValidationUtil::ValidateTableName(table_name);
|
||||
ASSERT_TRUE(status.ok());
|
||||
|
||||
table_name = "12sds";
|
||||
res = server::ValidationUtil::ValidateTableName(table_name);
|
||||
ASSERT_EQ(res, SERVER_INVALID_TABLE_NAME);
|
||||
status = server::ValidationUtil::ValidateTableName(table_name);
|
||||
ASSERT_EQ(status.code(), SERVER_INVALID_TABLE_NAME);
|
||||
|
||||
table_name = "";
|
||||
res = server::ValidationUtil::ValidateTableName(table_name);
|
||||
ASSERT_EQ(res, SERVER_INVALID_TABLE_NAME);
|
||||
status = server::ValidationUtil::ValidateTableName(table_name);
|
||||
ASSERT_EQ(status.code(), SERVER_INVALID_TABLE_NAME);
|
||||
|
||||
table_name = "_asdasd";
|
||||
res = server::ValidationUtil::ValidateTableName(table_name);
|
||||
ASSERT_EQ(res, SERVER_SUCCESS);
|
||||
status = server::ValidationUtil::ValidateTableName(table_name);
|
||||
ASSERT_EQ(status.code(), SERVER_SUCCESS);
|
||||
|
||||
table_name = "!@#!@";
|
||||
res = server::ValidationUtil::ValidateTableName(table_name);
|
||||
ASSERT_EQ(res, SERVER_INVALID_TABLE_NAME);
|
||||
status = server::ValidationUtil::ValidateTableName(table_name);
|
||||
ASSERT_EQ(status.code(), SERVER_INVALID_TABLE_NAME);
|
||||
|
||||
table_name = "_!@#!@";
|
||||
res = server::ValidationUtil::ValidateTableName(table_name);
|
||||
ASSERT_EQ(res, SERVER_INVALID_TABLE_NAME);
|
||||
status = server::ValidationUtil::ValidateTableName(table_name);
|
||||
ASSERT_EQ(status.code(), SERVER_INVALID_TABLE_NAME);
|
||||
|
||||
table_name = "中文";
|
||||
res = server::ValidationUtil::ValidateTableName(table_name);
|
||||
ASSERT_EQ(res, SERVER_INVALID_TABLE_NAME);
|
||||
status = server::ValidationUtil::ValidateTableName(table_name);
|
||||
ASSERT_EQ(status.code(), SERVER_INVALID_TABLE_NAME);
|
||||
|
||||
table_name = std::string(10000, 'a');
|
||||
res = server::ValidationUtil::ValidateTableName(table_name);
|
||||
ASSERT_EQ(res, SERVER_INVALID_TABLE_NAME);
|
||||
status = server::ValidationUtil::ValidateTableName(table_name);
|
||||
ASSERT_EQ(status.code(), SERVER_INVALID_TABLE_NAME);
|
||||
}
|
||||
|
||||
TEST(ValidationUtilTest, VALIDATE_DIMENSION_TEST) {
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateTableDimension(-1), SERVER_INVALID_VECTOR_DIMENSION);
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateTableDimension(0), SERVER_INVALID_VECTOR_DIMENSION);
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateTableDimension(16385), SERVER_INVALID_VECTOR_DIMENSION);
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateTableDimension(16384), SERVER_SUCCESS);
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateTableDimension(1), SERVER_SUCCESS);
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateTableDimension(-1).code(), SERVER_INVALID_VECTOR_DIMENSION);
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateTableDimension(0).code(), SERVER_INVALID_VECTOR_DIMENSION);
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateTableDimension(16385).code(), SERVER_INVALID_VECTOR_DIMENSION);
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateTableDimension(16384).code(), SERVER_SUCCESS);
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateTableDimension(1).code(), SERVER_SUCCESS);
|
||||
}
|
||||
|
||||
TEST(ValidationUtilTest, VALIDATE_INDEX_TEST) {
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateTableIndexType((int)engine::EngineType::INVALID), SERVER_INVALID_INDEX_TYPE);
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateTableIndexType((int)engine::EngineType::INVALID).code(), SERVER_INVALID_INDEX_TYPE);
|
||||
for(int i = 1; i <= (int)engine::EngineType::MAX_VALUE; i++) {
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateTableIndexType(i), SERVER_SUCCESS);
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateTableIndexType(i).code(), SERVER_SUCCESS);
|
||||
}
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateTableIndexType((int)engine::EngineType::MAX_VALUE + 1), SERVER_INVALID_INDEX_TYPE);
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateTableIndexType((int)engine::EngineType::MAX_VALUE + 1).code(), SERVER_INVALID_INDEX_TYPE);
|
||||
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateTableIndexNlist(0), SERVER_INVALID_INDEX_NLIST);
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateTableIndexNlist(100), SERVER_SUCCESS);
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateTableIndexNlist(0).code(), SERVER_INVALID_INDEX_NLIST);
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateTableIndexNlist(100).code(), SERVER_SUCCESS);
|
||||
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateTableIndexFileSize(0), SERVER_INVALID_INDEX_FILE_SIZE);
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateTableIndexFileSize(100), SERVER_SUCCESS);
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateTableIndexFileSize(0).code(), SERVER_INVALID_INDEX_FILE_SIZE);
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateTableIndexFileSize(100).code(), SERVER_SUCCESS);
|
||||
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateTableIndexMetricType(0), SERVER_INVALID_INDEX_METRIC_TYPE);
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateTableIndexMetricType(1), SERVER_SUCCESS);
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateTableIndexMetricType(2), SERVER_SUCCESS);
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateTableIndexMetricType(0).code(), SERVER_INVALID_INDEX_METRIC_TYPE);
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateTableIndexMetricType(1).code(), SERVER_SUCCESS);
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateTableIndexMetricType(2).code(), SERVER_SUCCESS);
|
||||
}
|
||||
|
||||
TEST(ValidationUtilTest, VALIDATE_TOPK_TEST) {
|
||||
engine::meta::TableSchema schema;
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateSearchTopk(10, schema), SERVER_SUCCESS);
|
||||
ASSERT_NE(server::ValidationUtil::ValidateSearchTopk(65536, schema), SERVER_SUCCESS);
|
||||
ASSERT_NE(server::ValidationUtil::ValidateSearchTopk(0, schema), SERVER_SUCCESS);
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateSearchTopk(10, schema).code(), SERVER_SUCCESS);
|
||||
ASSERT_NE(server::ValidationUtil::ValidateSearchTopk(65536, schema).code(), SERVER_SUCCESS);
|
||||
ASSERT_NE(server::ValidationUtil::ValidateSearchTopk(0, schema).code(), SERVER_SUCCESS);
|
||||
}
|
||||
|
||||
TEST(ValidationUtilTest, VALIDATE_NPROBE_TEST) {
|
||||
engine::meta::TableSchema schema;
|
||||
schema.nlist_ = 100;
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateSearchNprobe(10, schema), SERVER_SUCCESS);
|
||||
ASSERT_NE(server::ValidationUtil::ValidateSearchNprobe(0, schema), SERVER_SUCCESS);
|
||||
ASSERT_NE(server::ValidationUtil::ValidateSearchNprobe(101, schema), SERVER_SUCCESS);
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateSearchNprobe(10, schema).code(), SERVER_SUCCESS);
|
||||
ASSERT_NE(server::ValidationUtil::ValidateSearchNprobe(0, schema).code(), SERVER_SUCCESS);
|
||||
ASSERT_NE(server::ValidationUtil::ValidateSearchNprobe(101, schema).code(), SERVER_SUCCESS);
|
||||
}
|
||||
|
||||
TEST(ValidationUtilTest, VALIDATE_GPU_TEST) {
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateGpuIndex(0), SERVER_SUCCESS);
|
||||
ASSERT_NE(server::ValidationUtil::ValidateGpuIndex(100), SERVER_SUCCESS);
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateGpuIndex(0).code(), SERVER_SUCCESS);
|
||||
ASSERT_NE(server::ValidationUtil::ValidateGpuIndex(100).code(), SERVER_SUCCESS);
|
||||
|
||||
size_t memory = 0;
|
||||
ASSERT_EQ(server::ValidationUtil::GetGpuMemory(0, memory), SERVER_SUCCESS);
|
||||
ASSERT_NE(server::ValidationUtil::GetGpuMemory(100, memory), SERVER_SUCCESS);
|
||||
ASSERT_EQ(server::ValidationUtil::GetGpuMemory(0, memory).code(), SERVER_SUCCESS);
|
||||
ASSERT_NE(server::ValidationUtil::GetGpuMemory(100, memory).code(), SERVER_SUCCESS);
|
||||
}
|
||||
|
||||
TEST(ValidationUtilTest, VALIDATE_IPADDRESS_TEST) {
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateIpAddress("127.0.0.1"), SERVER_SUCCESS);
|
||||
ASSERT_NE(server::ValidationUtil::ValidateIpAddress("not ip"), SERVER_SUCCESS);
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateIpAddress("127.0.0.1").code(), SERVER_SUCCESS);
|
||||
ASSERT_NE(server::ValidationUtil::ValidateIpAddress("not ip").code(), SERVER_SUCCESS);
|
||||
}
|
||||
|
||||
TEST(ValidationUtilTest, VALIDATE_NUMBER_TEST) {
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateStringIsNumber("1234"), SERVER_SUCCESS);
|
||||
ASSERT_NE(server::ValidationUtil::ValidateStringIsNumber("not number"), SERVER_SUCCESS);
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateStringIsNumber("1234").code(), SERVER_SUCCESS);
|
||||
ASSERT_NE(server::ValidationUtil::ValidateStringIsNumber("not number").code(), SERVER_SUCCESS);
|
||||
}
|
||||
|
||||
TEST(ValidationUtilTest, VALIDATE_BOOL_TEST) {
|
||||
std::string str = "true";
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateStringIsBool(str), SERVER_SUCCESS);
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateStringIsBool(str).code(), SERVER_SUCCESS);
|
||||
str = "not bool";
|
||||
ASSERT_NE(server::ValidationUtil::ValidateStringIsBool(str), SERVER_SUCCESS);
|
||||
ASSERT_NE(server::ValidationUtil::ValidateStringIsBool(str).code(), SERVER_SUCCESS);
|
||||
}
|
||||
|
||||
TEST(ValidationUtilTest, VALIDATE_DOUBLE_TEST) {
|
||||
double ret = 0.0;
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateStringIsDouble("2.5", ret), SERVER_SUCCESS);
|
||||
ASSERT_NE(server::ValidationUtil::ValidateStringIsDouble("not double", ret), SERVER_SUCCESS);
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateStringIsDouble("2.5", ret).code(), SERVER_SUCCESS);
|
||||
ASSERT_NE(server::ValidationUtil::ValidateStringIsDouble("not double", ret).code(), SERVER_SUCCESS);
|
||||
}
|
||||
|
||||
TEST(ValidationUtilTest, VALIDATE_DBURI_TEST) {
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateDbURI("sqlite://:@:/"), SERVER_SUCCESS);
|
||||
ASSERT_NE(server::ValidationUtil::ValidateDbURI("xxx://:@:/"), SERVER_SUCCESS);
|
||||
ASSERT_NE(server::ValidationUtil::ValidateDbURI("not uri"), SERVER_SUCCESS);
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateDbURI("mysql://root:123456@127.0.0.1:3303/milvus"), SERVER_SUCCESS);
|
||||
ASSERT_NE(server::ValidationUtil::ValidateDbURI("mysql://root:123456@127.0.0.1:port/milvus"), SERVER_SUCCESS);
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateDbURI("sqlite://:@:/").code(), SERVER_SUCCESS);
|
||||
ASSERT_NE(server::ValidationUtil::ValidateDbURI("xxx://:@:/").code(), SERVER_SUCCESS);
|
||||
ASSERT_NE(server::ValidationUtil::ValidateDbURI("not uri").code(), SERVER_SUCCESS);
|
||||
ASSERT_EQ(server::ValidationUtil::ValidateDbURI("mysql://root:123456@127.0.0.1:3303/milvus").code(), SERVER_SUCCESS);
|
||||
ASSERT_NE(server::ValidationUtil::ValidateDbURI("mysql://root:123456@127.0.0.1:port/milvus").code(), SERVER_SUCCESS);
|
||||
}
|
||||
|
||||
TEST(UtilTest, ROLLOUTHANDLER_TEST){
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user