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

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

format code by clang-tidy

See merge request megasearch/milvus!638

Former-commit-id: a735d07459f91f1337e641fd36153b7d599c7a4b
...@@ -23,3 +23,5 @@ AccessModifierOffset: -3 ...@@ -23,3 +23,5 @@ AccessModifierOffset: -3
AlwaysBreakAfterReturnType: All AlwaysBreakAfterReturnType: All
AllowShortBlocksOnASingleLine: false AllowShortBlocksOnASingleLine: false
AllowShortFunctionsOnASingleLine: false AllowShortFunctionsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AlignTrailingComments: true
...@@ -47,7 +47,7 @@ class YamlConfigMgr : public ConfigMgr { ...@@ -47,7 +47,7 @@ class YamlConfigMgr : public ConfigMgr {
SetConfigValue(const YAML::Node& node, const std::string& key, ConfigNode& config); SetConfigValue(const YAML::Node& node, const std::string& key, ConfigNode& config);
bool bool
SetChildConfig(const YAML::Node& node, const std::string& name, ConfigNode& config); SetChildConfig(const YAML::Node& node, const std::string& child_name, ConfigNode& config);
bool bool
SetSequence(const YAML::Node& node, const std::string& child_name, ConfigNode& config); SetSequence(const YAML::Node& node, const std::string& child_name, ConfigNode& config);
......
...@@ -46,12 +46,14 @@ struct Cfg { ...@@ -46,12 +46,14 @@ struct Cfg {
const int64_t &k, const int64_t &k,
const int64_t &gpu_id, const int64_t &gpu_id,
METRICTYPE type) METRICTYPE type)
: d(dim), k(k), gpu_id(gpu_id), metric_type(type) {} : metric_type(type), k(k), gpu_id(gpu_id), d(dim) {}
Cfg() = default; Cfg() = default;
virtual bool virtual bool
CheckValid(){}; CheckValid(){
return true;
};
}; };
using Config = std::shared_ptr<Cfg>; using Config = std::shared_ptr<Cfg>;
......
...@@ -127,10 +127,10 @@ class Dataset { ...@@ -127,10 +127,10 @@ class Dataset {
//} //}
private: private:
SchemaPtr array_schema_;
SchemaPtr tensor_schema_;
std::vector<ArrayPtr> array_; std::vector<ArrayPtr> array_;
SchemaPtr array_schema_;
std::vector<TensorPtr> tensor_; std::vector<TensorPtr> tensor_;
SchemaPtr tensor_schema_;
//Config meta_; //Config meta_;
}; };
......
...@@ -25,9 +25,14 @@ namespace zilliz { ...@@ -25,9 +25,14 @@ namespace zilliz {
namespace knowhere { namespace knowhere {
faiss::MetricType GetMetricType(METRICTYPE &type) { faiss::MetricType GetMetricType(METRICTYPE &type) {
if (type == METRICTYPE::L2) return faiss::METRIC_L2; if (type == METRICTYPE::L2) {
if (type == METRICTYPE::IP) return faiss::METRIC_INNER_PRODUCT; return faiss::METRIC_L2;
if (type == METRICTYPE::INVALID) KNOWHERE_THROW_MSG("Metric type is invalid"); }
if (type == METRICTYPE::IP) {
return faiss::METRIC_INNER_PRODUCT;
}
KNOWHERE_THROW_MSG("Metric type is invalid");
} }
......
...@@ -52,12 +52,15 @@ struct IVFCfg : public Cfg { ...@@ -52,12 +52,15 @@ struct IVFCfg : public Cfg {
const int64_t &nlist, const int64_t &nlist,
const int64_t &nprobe, const int64_t &nprobe,
METRICTYPE type) METRICTYPE type)
: nlist(nlist), nprobe(nprobe), Cfg(dim, k, gpu_id, type) {} : Cfg(dim, k, gpu_id, type), nlist(nlist), nprobe(nprobe) {
}
IVFCfg() = default; IVFCfg() = default;
bool bool
CheckValid() override {}; CheckValid() override {
return true;
};
}; };
using IVFConfig = std::shared_ptr<IVFCfg>; using IVFConfig = std::shared_ptr<IVFCfg>;
...@@ -72,12 +75,15 @@ struct IVFSQCfg : public IVFCfg { ...@@ -72,12 +75,15 @@ struct IVFSQCfg : public IVFCfg {
const int64_t &nprobe, const int64_t &nprobe,
const int64_t &nbits, const int64_t &nbits,
METRICTYPE type) METRICTYPE type)
: nbits(nbits), IVFCfg(dim, k, gpu_id, nlist, nprobe, type) {} : IVFCfg(dim, k, gpu_id, nlist, nprobe, type), nbits(nbits) {
}
IVFSQCfg() = default; IVFSQCfg() = default;
bool bool
CheckValid() override {}; CheckValid() override {
return true;
};
}; };
using IVFSQConfig = std::shared_ptr<IVFSQCfg>; using IVFSQConfig = std::shared_ptr<IVFSQCfg>;
...@@ -98,12 +104,15 @@ struct IVFPQCfg : public IVFCfg { ...@@ -98,12 +104,15 @@ struct IVFPQCfg : public IVFCfg {
const int64_t &nbits, const int64_t &nbits,
const int64_t &m, const int64_t &m,
METRICTYPE type) METRICTYPE type)
: nbits(nbits), m(m), IVFCfg(dim, k, gpu_id, nlist, nprobe, type) {} : IVFCfg(dim, k, gpu_id, nlist, nprobe, type), m(m), nbits(nbits) {
}
IVFPQCfg() = default; IVFPQCfg() = default;
bool bool
CheckValid() override {}; CheckValid() override {
return true;
};
}; };
using IVFPQConfig = std::shared_ptr<IVFPQCfg>; using IVFPQConfig = std::shared_ptr<IVFPQCfg>;
...@@ -123,13 +132,17 @@ struct NSGCfg : public IVFCfg { ...@@ -123,13 +132,17 @@ struct NSGCfg : public IVFCfg {
const int64_t &out_degree, const int64_t &out_degree,
const int64_t &candidate_size, const int64_t &candidate_size,
METRICTYPE type) METRICTYPE type)
: knng(knng), search_length(search_length), out_degree(out_degree), candidate_pool_size(candidate_size), : IVFCfg(dim, k, gpu_id, nlist, nprobe, type),
IVFCfg(dim, k, gpu_id, nlist, nprobe, type) {} knng(knng), search_length(search_length),
out_degree(out_degree), candidate_pool_size(candidate_size) {
}
NSGCfg() = default; NSGCfg() = default;
bool bool
CheckValid() override {}; CheckValid() override {
return true;
};
}; };
using NSGConfig = std::shared_ptr<NSGCfg>; using NSGConfig = std::shared_ptr<NSGCfg>;
......
...@@ -81,7 +81,7 @@ void NsgIndex::Build_with_ids(size_t nb, const float *data, const long *ids, con ...@@ -81,7 +81,7 @@ void NsgIndex::Build_with_ids(size_t nb, const float *data, const long *ids, con
//>> Debug code //>> Debug code
/// ///
int total_degree = 0; int total_degree = 0;
for (int i = 0; i < ntotal; ++i) { for (size_t i = 0; i < ntotal; ++i) {
total_degree += nsg[i].size(); total_degree += nsg[i].size();
} }
...@@ -172,7 +172,7 @@ void NsgIndex::GetNeighbors(const float *query, ...@@ -172,7 +172,7 @@ void NsgIndex::GetNeighbors(const float *query,
for (size_t i = 0; i < init_ids.size(); ++i) { for (size_t i = 0; i < init_ids.size(); ++i) {
node_t id = init_ids[i]; node_t id = init_ids[i];
if (id >= ntotal) { if (id >= static_cast<node_t>(ntotal)) {
KNOWHERE_THROW_MSG("Build Index Error, id > ntotal"); KNOWHERE_THROW_MSG("Build Index Error, id > ntotal");
continue; continue;
} }
...@@ -262,7 +262,7 @@ void NsgIndex::GetNeighbors(const float *query, std::vector<Neighbor> &resset, s ...@@ -262,7 +262,7 @@ void NsgIndex::GetNeighbors(const float *query, std::vector<Neighbor> &resset, s
for (size_t i = 0; i < init_ids.size(); ++i) { for (size_t i = 0; i < init_ids.size(); ++i) {
node_t id = init_ids[i]; node_t id = init_ids[i];
if (id >= ntotal) { if (id >= static_cast<node_t>(ntotal)) {
KNOWHERE_THROW_MSG("Build Index Error, id > ntotal"); KNOWHERE_THROW_MSG("Build Index Error, id > ntotal");
continue; continue;
} }
...@@ -350,7 +350,7 @@ void NsgIndex::GetNeighbors(const float *query, ...@@ -350,7 +350,7 @@ void NsgIndex::GetNeighbors(const float *query,
node_t id = init_ids[i]; node_t id = init_ids[i];
//assert(id < ntotal); //assert(id < ntotal);
if (id >= ntotal) { if (id >= static_cast<node_t>(ntotal)) {
KNOWHERE_THROW_MSG("Build Index Error, id > ntotal"); KNOWHERE_THROW_MSG("Build Index Error, id > ntotal");
continue; continue;
} }
...@@ -461,7 +461,7 @@ void NsgIndex::Link() { ...@@ -461,7 +461,7 @@ void NsgIndex::Link() {
//} //}
///// /////
for (int i = 0; i < ntotal; ++i) { for (size_t i = 0; i < ntotal; ++i) {
nsg[i].shrink_to_fit(); nsg[i].shrink_to_fit();
} }
} }
...@@ -483,7 +483,9 @@ void NsgIndex::SyncPrune(size_t n, ...@@ -483,7 +483,9 @@ void NsgIndex::SyncPrune(size_t n,
unsigned cursor = 0; unsigned cursor = 0;
std::sort(pool.begin(), pool.end()); std::sort(pool.begin(), pool.end());
std::vector<Neighbor> result; std::vector<Neighbor> result;
if (pool[cursor].id == n) cursor++; if (pool[cursor].id == static_cast<node_t>(n)) {
cursor++;
}
result.push_back(pool[cursor]); // init result with nearest neighbor result.push_back(pool[cursor]); // init result with nearest neighbor
SelectEdge(cursor, pool, result, true); SelectEdge(cursor, pool, result, true);
...@@ -518,7 +520,7 @@ void NsgIndex::InterInsert(unsigned n, std::vector<std::mutex> &mutex_vec, float ...@@ -518,7 +520,7 @@ void NsgIndex::InterInsert(unsigned n, std::vector<std::mutex> &mutex_vec, float
int duplicate = false; int duplicate = false;
{ {
LockGuard lk(mutex_vec[current_neighbor]); LockGuard lk(mutex_vec[current_neighbor]);
for (int j = 0; j < out_degree; ++j) { for (size_t j = 0; j < out_degree; ++j) {
if (nsn_dist_pool[j] == -1) break; if (nsn_dist_pool[j] == -1) break;
// 保证至少有一条边能连回来 // 保证至少有一条边能连回来
...@@ -551,14 +553,14 @@ void NsgIndex::InterInsert(unsigned n, std::vector<std::mutex> &mutex_vec, float ...@@ -551,14 +553,14 @@ void NsgIndex::InterInsert(unsigned n, std::vector<std::mutex> &mutex_vec, float
{ {
LockGuard lk(mutex_vec[current_neighbor]); LockGuard lk(mutex_vec[current_neighbor]);
for (int j = 0; j < result.size(); ++j) { for (size_t j = 0; j < result.size(); ++j) {
nsn_id_pool[j] = result[j].id; nsn_id_pool[j] = result[j].id;
nsn_dist_pool[j] = result[j].distance; nsn_dist_pool[j] = result[j].distance;
} }
} }
} else { } else {
LockGuard lk(mutex_vec[current_neighbor]); LockGuard lk(mutex_vec[current_neighbor]);
for (int j = 0; j < out_degree; ++j) { for (size_t j = 0; j < out_degree; ++j) {
if (nsn_dist_pool[j] == -1) { if (nsn_dist_pool[j] == -1) {
nsn_id_pool.push_back(current_as_neighbor.id); nsn_id_pool.push_back(current_as_neighbor.id);
nsn_dist_pool[j] = current_as_neighbor.distance; nsn_dist_pool[j] = current_as_neighbor.distance;
...@@ -605,9 +607,11 @@ void NsgIndex::CheckConnectivity() { ...@@ -605,9 +607,11 @@ void NsgIndex::CheckConnectivity() {
boost::dynamic_bitset<> has_linked{ntotal, 0}; boost::dynamic_bitset<> has_linked{ntotal, 0};
int64_t linked_count = 0; int64_t linked_count = 0;
while (linked_count < ntotal) { while (linked_count < static_cast<int64_t>(ntotal)) {
DFS(root, has_linked, linked_count); DFS(root, has_linked, linked_count);
if (linked_count >= ntotal) break; if (linked_count >= static_cast<int64_t>(ntotal)) {
break;
}
FindUnconnectedNode(has_linked, root); FindUnconnectedNode(has_linked, root);
} }
} }
...@@ -697,7 +701,7 @@ void NsgIndex::Search(const float *query, ...@@ -697,7 +701,7 @@ void NsgIndex::Search(const float *query,
} else{ } else{
//#pragma omp parallel for schedule(dynamic, 50) //#pragma omp parallel for schedule(dynamic, 50)
#pragma omp parallel for #pragma omp parallel for
for (int i = 0; i < nq; ++i) { for (unsigned int i = 0; i < nq; ++i) {
// TODO(linxj): when to use openmp // TODO(linxj): when to use openmp
auto single_query = query + i * dim; auto single_query = query + i * dim;
GetNeighbors(single_query, resset[i], nsg, &params); GetNeighbors(single_query, resset[i], nsg, &params);
...@@ -705,8 +709,8 @@ void NsgIndex::Search(const float *query, ...@@ -705,8 +709,8 @@ void NsgIndex::Search(const float *query,
} }
rc.ElapseFromBegin("cost"); rc.ElapseFromBegin("cost");
for (int i = 0; i < nq; ++i) { for (unsigned int i = 0; i < nq; ++i) {
for (int j = 0; j < k; ++j) { for (unsigned int j = 0; j < k; ++j) {
//ids[i * k + j] = resset[i][j].id; //ids[i * k + j] = resset[i][j].id;
// Fix(linxj): bug, reset[i][j] out of range // Fix(linxj): bug, reset[i][j] out of range
......
...@@ -29,7 +29,7 @@ namespace algo { ...@@ -29,7 +29,7 @@ namespace algo {
// TODO: impl search && insert && return insert pos. why not just find and swap? // TODO: impl search && insert && return insert pos. why not just find and swap?
int InsertIntoPool(Neighbor *addr, unsigned K, Neighbor nn) { int InsertIntoPool(Neighbor *addr, unsigned K, Neighbor nn) {
//>> Fix: Add assert //>> Fix: Add assert
for (int i = 0; i < K; ++i) { for (unsigned int i = 0; i < K; ++i) {
assert(addr[i].id != nn.id); assert(addr[i].id != nn.id);
} }
......
...@@ -38,8 +38,8 @@ void DataGen::Generate(const int &dim, const int &nb, const int &nq) { ...@@ -38,8 +38,8 @@ void DataGen::Generate(const int &dim, const int &nb, const int &nq) {
this->dim = dim; this->dim = dim;
GenAll(dim, nb, xb, ids, nq, xq); GenAll(dim, nb, xb, ids, nq, xq);
assert(xb.size() == dim * nb); assert(xb.size() == (size_t)dim * nb);
assert(xq.size() == dim * nq); assert(xq.size() == (size_t)dim * nq);
base_dataset = generate_dataset(nb, dim, xb.data(), ids.data()); base_dataset = generate_dataset(nb, dim, xb.data(), ids.data());
query_dataset = generate_query_dataset(nq, dim, xq.data()); query_dataset = generate_query_dataset(nq, dim, xq.data());
...@@ -47,7 +47,7 @@ void DataGen::Generate(const int &dim, const int &nb, const int &nq) { ...@@ -47,7 +47,7 @@ void DataGen::Generate(const int &dim, const int &nb, const int &nq) {
} }
zilliz::knowhere::DatasetPtr DataGen::GenQuery(const int &nq) { zilliz::knowhere::DatasetPtr DataGen::GenQuery(const int &nq) {
xq.resize(nq * dim); xq.resize(nq * dim);
for (size_t i = 0; i < nq * dim; ++i) { for (int i = 0; i < nq * dim; ++i) {
xq[i] = xb[i]; xq[i] = xb[i];
} }
return generate_query_dataset(nq, dim, xq.data()); return generate_query_dataset(nq, dim, xq.data());
...@@ -72,7 +72,7 @@ void GenAll(const int64_t &dim, ...@@ -72,7 +72,7 @@ void GenAll(const int64_t &dim,
const int64_t &nq, const int64_t &nq,
float *xq) { float *xq) {
GenBase(dim, nb, xb, ids); GenBase(dim, nb, xb, ids);
for (size_t i = 0; i < nq * dim; ++i) { for (int64_t i = 0; i < nq * dim; ++i) {
xq[i] = xb[i]; xq[i] = xb[i];
} }
} }
......
...@@ -638,7 +638,8 @@ DBImpl::MergeFiles(const std::string& table_id, const meta::DateT& date, const m ...@@ -638,7 +638,8 @@ DBImpl::MergeFiles(const std::string& table_id, const meta::DateT& date, const m
ENGINE_LOG_DEBUG << "Merging file " << file_schema.file_id_; ENGINE_LOG_DEBUG << "Merging file " << file_schema.file_id_;
index_size = index->Size(); index_size = index->Size();
if (index_size >= file_schema.index_file_size_) break; if (index_size >= file_schema.index_file_size_)
break;
} }
// step 3: serialize to disk // step 3: serialize to disk
......
...@@ -53,9 +53,9 @@ struct ArchiveConf { ...@@ -53,9 +53,9 @@ struct ArchiveConf {
private: private:
void void
ParseCritirias(const std::string& type); ParseCritirias(const std::string& criterias);
void void
ParseType(const std::string& criterias); ParseType(const std::string& type);
std::string type_; std::string type_;
CriteriaT criterias_; CriteriaT criterias_;
......
...@@ -143,7 +143,8 @@ GetTableFilePath(const DBMetaOptions& options, meta::TableFileSchema& table_file ...@@ -143,7 +143,8 @@ GetTableFilePath(const DBMetaOptions& options, meta::TableFileSchema& table_file
if (boost::filesystem::exists(file_path)) { if (boost::filesystem::exists(file_path)) {
table_file.location_ = file_path; table_file.location_ = file_path;
return Status::OK(); return Status::OK();
} else { }
for (auto& path : options.slave_paths_) { for (auto& path : options.slave_paths_) {
parent_path = ConstructParentFolder(path, table_file); parent_path = ConstructParentFolder(path, table_file);
file_path = parent_path + "/" + table_file.file_id_; file_path = parent_path + "/" + table_file.file_id_;
...@@ -152,7 +153,6 @@ GetTableFilePath(const DBMetaOptions& options, meta::TableFileSchema& table_file ...@@ -152,7 +153,6 @@ GetTableFilePath(const DBMetaOptions& options, meta::TableFileSchema& table_file
return Status::OK(); return Status::OK();
} }
} }
}
std::string msg = "Table file doesn't exist: " + file_path; std::string msg = "Table file doesn't exist: " + file_path;
ENGINE_LOG_ERROR << msg << " in path: " << options.path_ << " for table: " << table_file.table_id_; ENGINE_LOG_ERROR << msg << " in path: " << options.path_ << " for table: " << table_file.table_id_;
......
...@@ -342,7 +342,8 @@ Status ...@@ -342,7 +342,8 @@ Status
ExecutionEngineImpl::Init() { ExecutionEngineImpl::Init() {
server::Config& config = server::Config::GetInstance(); server::Config& config = server::Config::GetInstance();
Status s = config.GetDBConfigBuildIndexGPU(gpu_num_); Status s = config.GetDBConfigBuildIndexGPU(gpu_num_);
if (!s.ok()) return s; if (!s.ok())
return s;
return Status::OK(); return Status::OK();
} }
......
...@@ -39,12 +39,12 @@ main(int argc, char* argv[]) { ...@@ -39,12 +39,12 @@ main(int argc, char* argv[]) {
std::cout << std::endl << "Welcome to use Milvus by Zilliz!" << std::endl; std::cout << std::endl << "Welcome to use Milvus by Zilliz!" << std::endl;
std::cout << "Milvus " << BUILD_TYPE << " version: v" << MILVUS_VERSION << " built at " << BUILD_TIME << std::endl; std::cout << "Milvus " << BUILD_TYPE << " version: v" << MILVUS_VERSION << " built at " << BUILD_TIME << std::endl;
static struct option long_options[] = {{"conf_file", required_argument, 0, 'c'}, static struct option long_options[] = {{"conf_file", required_argument, nullptr, 'c'},
{"log_conf_file", required_argument, 0, 'l'}, {"log_conf_file", required_argument, nullptr, 'l'},
{"help", no_argument, 0, 'h'}, {"help", no_argument, nullptr, 'h'},
{"daemon", no_argument, 0, 'd'}, {"daemon", no_argument, nullptr, 'd'},
{"pid_file", required_argument, 0, 'p'}, {"pid_file", required_argument, nullptr, 'p'},
{NULL, 0, 0, 0}}; {nullptr, 0, nullptr, 0}};
int option_index = 0; int option_index = 0;
int64_t start_daemonized = 0; int64_t start_daemonized = 0;
......
...@@ -33,13 +33,20 @@ PrometheusMetrics::Init() { ...@@ -33,13 +33,20 @@ PrometheusMetrics::Init() {
try { try {
Config& config = Config::GetInstance(); Config& config = Config::GetInstance();
Status s = config.GetMetricConfigEnableMonitor(startup_); Status s = config.GetMetricConfigEnableMonitor(startup_);
if (!s.ok()) return s.code(); if (!s.ok()) {
if (!startup_) return SERVER_SUCCESS; return s.code();
}
if (!startup_) {
return SERVER_SUCCESS;
}
// Following should be read from config file. // Following should be read from config file.
std::string bind_address; std::string bind_address;
s = config.GetMetricConfigPrometheusPort(bind_address); s = config.GetMetricConfigPrometheusPort(bind_address);
if (!s.ok()) return s.code(); if (!s.ok()) {
return s.code();
}
const std::string uri = std::string("/tmp/metrics"); const std::string uri = std::string("/tmp/metrics");
const std::size_t num_threads = 2; const std::size_t num_threads = 2;
...@@ -58,21 +65,30 @@ PrometheusMetrics::Init() { ...@@ -58,21 +65,30 @@ PrometheusMetrics::Init() {
void void
PrometheusMetrics::CPUUsagePercentSet() { PrometheusMetrics::CPUUsagePercentSet() {
if (!startup_) return; if (!startup_) {
return;
}
double usage_percent = server::SystemInfo::GetInstance().CPUPercent(); double usage_percent = server::SystemInfo::GetInstance().CPUPercent();
CPU_usage_percent_.Set(usage_percent); CPU_usage_percent_.Set(usage_percent);
} }
void void
PrometheusMetrics::RAMUsagePercentSet() { PrometheusMetrics::RAMUsagePercentSet() {
if (!startup_) return; if (!startup_) {
return;
}
double usage_percent = server::SystemInfo::GetInstance().MemoryPercent(); double usage_percent = server::SystemInfo::GetInstance().MemoryPercent();
RAM_usage_percent_.Set(usage_percent); RAM_usage_percent_.Set(usage_percent);
} }
void void
PrometheusMetrics::GPUPercentGaugeSet() { PrometheusMetrics::GPUPercentGaugeSet() {
if (!startup_) return; if (!startup_) {
return;
}
int numDevice = server::SystemInfo::GetInstance().num_device(); int numDevice = server::SystemInfo::GetInstance().num_device();
std::vector<uint64_t> used_total = server::SystemInfo::GetInstance().GPUMemoryTotal(); std::vector<uint64_t> used_total = server::SystemInfo::GetInstance().GPUMemoryTotal();
std::vector<uint64_t> used_memory = server::SystemInfo::GetInstance().GPUMemoryUsed(); std::vector<uint64_t> used_memory = server::SystemInfo::GetInstance().GPUMemoryUsed();
...@@ -86,7 +102,10 @@ PrometheusMetrics::GPUPercentGaugeSet() { ...@@ -86,7 +102,10 @@ PrometheusMetrics::GPUPercentGaugeSet() {
void void
PrometheusMetrics::GPUMemoryUsageGaugeSet() { PrometheusMetrics::GPUMemoryUsageGaugeSet() {
if (!startup_) return; if (!startup_) {
return;
}
std::vector<uint64_t> values = server::SystemInfo::GetInstance().GPUMemoryUsed(); std::vector<uint64_t> values = server::SystemInfo::GetInstance().GPUMemoryUsed();
constexpr uint64_t MtoB = 1024 * 1024; constexpr uint64_t MtoB = 1024 * 1024;
int numDevice = server::SystemInfo::GetInstance().num_device(); int numDevice = server::SystemInfo::GetInstance().num_device();
...@@ -100,7 +119,9 @@ PrometheusMetrics::GPUMemoryUsageGaugeSet() { ...@@ -100,7 +119,9 @@ PrometheusMetrics::GPUMemoryUsageGaugeSet() {
void void
PrometheusMetrics::AddVectorsPerSecondGaugeSet(int num_vector, int dim, double time) { PrometheusMetrics::AddVectorsPerSecondGaugeSet(int num_vector, int dim, double time) {
// MB/s // MB/s
if (!startup_) return; if (!startup_) {
return;
}
int64_t MtoB = 1024 * 1024; int64_t MtoB = 1024 * 1024;
int64_t size = num_vector * dim * 4; int64_t size = num_vector * dim * 4;
...@@ -109,7 +130,10 @@ PrometheusMetrics::AddVectorsPerSecondGaugeSet(int num_vector, int dim, double t ...@@ -109,7 +130,10 @@ PrometheusMetrics::AddVectorsPerSecondGaugeSet(int num_vector, int dim, double t
void void
PrometheusMetrics::QueryIndexTypePerSecondSet(std::string type, double value) { PrometheusMetrics::QueryIndexTypePerSecondSet(std::string type, double value) {
if (!startup_) return; if (!startup_) {
return;
}
if (type == "IVF") { if (type == "IVF") {
query_index_IVF_type_per_second_gauge_.Set(value); query_index_IVF_type_per_second_gauge_.Set(value);
} else if (type == "IDMap") { } else if (type == "IDMap") {
...@@ -119,19 +143,27 @@ PrometheusMetrics::QueryIndexTypePerSecondSet(std::string type, double value) { ...@@ -119,19 +143,27 @@ PrometheusMetrics::QueryIndexTypePerSecondSet(std::string type, double value) {
void void
PrometheusMetrics::ConnectionGaugeIncrement() { PrometheusMetrics::ConnectionGaugeIncrement() {
if (!startup_) return; if (!startup_) {
return;
}
connection_gauge_.Increment(); connection_gauge_.Increment();
} }
void void
PrometheusMetrics::ConnectionGaugeDecrement() { PrometheusMetrics::ConnectionGaugeDecrement() {
if (!startup_) return; if (!startup_) {
return;
}
connection_gauge_.Decrement(); connection_gauge_.Decrement();
} }
void void
PrometheusMetrics::OctetsSet() { PrometheusMetrics::OctetsSet() {
if (!startup_) return; if (!startup_) {
return;
}
// get old stats and reset them // get old stats and reset them
uint64_t old_inoctets = SystemInfo::GetInstance().get_inoctets(); uint64_t old_inoctets = SystemInfo::GetInstance().get_inoctets();
...@@ -147,14 +179,19 @@ PrometheusMetrics::OctetsSet() { ...@@ -147,14 +179,19 @@ PrometheusMetrics::OctetsSet() {
auto now_time = std::chrono::system_clock::now(); auto now_time = std::chrono::system_clock::now();
auto total_microsecond = METRICS_MICROSECONDS(old_time, now_time); auto total_microsecond = METRICS_MICROSECONDS(old_time, now_time);
auto total_second = total_microsecond * micro_to_second; auto total_second = total_microsecond * micro_to_second;
if (total_second == 0) return; if (total_second == 0) {
return;
}
inoctets_gauge_.Set((in_and_out_octets.first - old_inoctets) / total_second); inoctets_gauge_.Set((in_and_out_octets.first - old_inoctets) / total_second);
outoctets_gauge_.Set((in_and_out_octets.second - old_outoctets) / total_second); outoctets_gauge_.Set((in_and_out_octets.second - old_outoctets) / total_second);
} }
void void
PrometheusMetrics::CPUCoreUsagePercentSet() { PrometheusMetrics::CPUCoreUsagePercentSet() {
if (!startup_) return; if (!startup_) {
return;
}
std::vector<double> cpu_core_percent = server::SystemInfo::GetInstance().CPUCorePercent(); std::vector<double> cpu_core_percent = server::SystemInfo::GetInstance().CPUCorePercent();
...@@ -166,7 +203,9 @@ PrometheusMetrics::CPUCoreUsagePercentSet() { ...@@ -166,7 +203,9 @@ PrometheusMetrics::CPUCoreUsagePercentSet() {
void void
PrometheusMetrics::GPUTemperature() { PrometheusMetrics::GPUTemperature() {
if (!startup_) return; if (!startup_) {
return;
}
std::vector<uint64_t> GPU_temperatures = server::SystemInfo::GetInstance().GPUTemperature(); std::vector<uint64_t> GPU_temperatures = server::SystemInfo::GetInstance().GPUTemperature();
...@@ -178,7 +217,9 @@ PrometheusMetrics::GPUTemperature() { ...@@ -178,7 +217,9 @@ PrometheusMetrics::GPUTemperature() {
void void
PrometheusMetrics::CPUTemperature() { PrometheusMetrics::CPUTemperature() {
if (!startup_) return; if (!startup_) {
return;
}
std::vector<float> CPU_temperatures = server::SystemInfo::GetInstance().CPUTemperature(); std::vector<float> CPU_temperatures = server::SystemInfo::GetInstance().CPUTemperature();
......
...@@ -31,7 +31,8 @@ namespace server { ...@@ -31,7 +31,8 @@ namespace server {
void void
SystemInfo::Init() { SystemInfo::Init() {
if (initialized_) return; if (initialized_)
return;
initialized_ = true; initialized_ = true;
...@@ -45,7 +46,8 @@ SystemInfo::Init() { ...@@ -45,7 +46,8 @@ SystemInfo::Init() {
file = fopen("/proc/cpuinfo", "r"); file = fopen("/proc/cpuinfo", "r");
num_processors_ = 0; num_processors_ = 0;
while (fgets(line, 128, file) != NULL) { while (fgets(line, 128, file) != NULL) {
if (strncmp(line, "processor", 9) == 0) num_processors_++; if (strncmp(line, "processor", 9) == 0)
num_processors_++;
if (strncmp(line, "physical", 8) == 0) { if (strncmp(line, "physical", 8) == 0) {
num_physical_processors_ = ParseLine(line); num_physical_processors_ = ParseLine(line);
} }
...@@ -116,7 +118,8 @@ SystemInfo::GetProcessUsedMemory() { ...@@ -116,7 +118,8 @@ SystemInfo::GetProcessUsedMemory() {
double double
SystemInfo::MemoryPercent() { SystemInfo::MemoryPercent() {
if (!initialized_) Init(); if (!initialized_)
Init();
return (double)(GetProcessUsedMemory() * 100) / (double)total_ram_; return (double)(GetProcessUsedMemory() * 100) / (double)total_ram_;
} }
...@@ -171,7 +174,8 @@ SystemInfo::getTotalCpuTime(std::vector<uint64_t>& work_time_array) { ...@@ -171,7 +174,8 @@ SystemInfo::getTotalCpuTime(std::vector<uint64_t>& work_time_array) {
double double
SystemInfo::CPUPercent() { SystemInfo::CPUPercent() {
if (!initialized_) Init(); if (!initialized_)
Init();
struct tms time_sample; struct tms time_sample;
clock_t now; clock_t now;
double percent; double percent;
...@@ -195,7 +199,8 @@ SystemInfo::CPUPercent() { ...@@ -195,7 +199,8 @@ SystemInfo::CPUPercent() {
std::vector<uint64_t> std::vector<uint64_t>
SystemInfo::GPUMemoryTotal() { SystemInfo::GPUMemoryTotal() {
// get GPU usage percent // get GPU usage percent
if (!initialized_) Init(); if (!initialized_)
Init();
std::vector<uint64_t> result; std::vector<uint64_t> result;
nvmlMemory_t nvmlMemory; nvmlMemory_t nvmlMemory;
for (int i = 0; i < num_device_; ++i) { for (int i = 0; i < num_device_; ++i) {
...@@ -209,7 +214,8 @@ SystemInfo::GPUMemoryTotal() { ...@@ -209,7 +214,8 @@ SystemInfo::GPUMemoryTotal() {
std::vector<uint64_t> std::vector<uint64_t>
SystemInfo::GPUTemperature() { SystemInfo::GPUTemperature() {
if (!initialized_) Init(); if (!initialized_)
Init();
std::vector<uint64_t> result; std::vector<uint64_t> result;
for (int i = 0; i < num_device_; i++) { for (int i = 0; i < num_device_; i++) {
nvmlDevice_t device; nvmlDevice_t device;
...@@ -241,7 +247,8 @@ SystemInfo::CPUTemperature() { ...@@ -241,7 +247,8 @@ SystemInfo::CPUTemperature() {
std::vector<uint64_t> std::vector<uint64_t>
SystemInfo::GPUMemoryUsed() { SystemInfo::GPUMemoryUsed() {
// get GPU memory used // get GPU memory used
if (!initialized_) Init(); if (!initialized_)
Init();
std::vector<uint64_t> result; std::vector<uint64_t> result;
nvmlMemory_t nvmlMemory; nvmlMemory_t nvmlMemory;
......
...@@ -48,7 +48,7 @@ class ResourceMgr { ...@@ -48,7 +48,7 @@ class ResourceMgr {
Add(ResourcePtr&& resource); Add(ResourcePtr&& resource);
bool bool
Connect(const std::string& res1, const std::string& res2, Connection& connection); Connect(const std::string& name1, const std::string& name2, Connection& connection);
void void
Clear(); Clear();
......
...@@ -30,7 +30,8 @@ get_neighbours(const ResourcePtr& self) { ...@@ -30,7 +30,8 @@ get_neighbours(const ResourcePtr& self) {
std::vector<ResourcePtr> neighbours; std::vector<ResourcePtr> neighbours;
for (auto& neighbour_node : self->GetNeighbours()) { for (auto& neighbour_node : self->GetNeighbours()) {
auto node = neighbour_node.neighbour_node.lock(); auto node = neighbour_node.neighbour_node.lock();
if (not node) continue; if (not node)
continue;
auto resource = std::static_pointer_cast<Resource>(node); auto resource = std::static_pointer_cast<Resource>(node);
// if (not resource->HasExecutor()) continue; // if (not resource->HasExecutor()) continue;
...@@ -45,7 +46,8 @@ get_neighbours_with_connetion(const ResourcePtr& self) { ...@@ -45,7 +46,8 @@ get_neighbours_with_connetion(const ResourcePtr& self) {
std::vector<std::pair<ResourcePtr, Connection>> neighbours; std::vector<std::pair<ResourcePtr, Connection>> neighbours;
for (auto& neighbour_node : self->GetNeighbours()) { for (auto& neighbour_node : self->GetNeighbours()) {
auto node = neighbour_node.neighbour_node.lock(); auto node = neighbour_node.neighbour_node.lock();
if (not node) continue; if (not node)
continue;
auto resource = std::static_pointer_cast<Resource>(node); auto resource = std::static_pointer_cast<Resource>(node);
// if (not resource->HasExecutor()) continue; // if (not resource->HasExecutor()) continue;
......
...@@ -92,7 +92,8 @@ uint64_t ...@@ -92,7 +92,8 @@ uint64_t
Resource::NumOfTaskToExec() { Resource::NumOfTaskToExec() {
uint64_t count = 0; uint64_t count = 0;
for (auto& task : task_table_) { for (auto& task : task_table_) {
if (task->state == TaskTableItemState::LOADED) ++count; if (task->state == TaskTableItemState::LOADED)
++count;
} }
return count; return count;
} }
...@@ -102,7 +103,8 @@ Resource::pick_task_load() { ...@@ -102,7 +103,8 @@ Resource::pick_task_load() {
auto indexes = task_table_.PickToLoad(10); auto indexes = task_table_.PickToLoad(10);
for (auto index : indexes) { for (auto index : indexes) {
// try to set one task loading, then return // try to set one task loading, then return
if (task_table_.Load(index)) return task_table_.Get(index); if (task_table_.Load(index))
return task_table_.Get(index);
// else try next // else try next
} }
return nullptr; return nullptr;
...@@ -113,7 +115,8 @@ Resource::pick_task_execute() { ...@@ -113,7 +115,8 @@ Resource::pick_task_execute() {
auto indexes = task_table_.PickToExecute(3); auto indexes = task_table_.PickToExecute(3);
for (auto index : indexes) { for (auto index : indexes) {
// try to set one task executing, then return // try to set one task executing, then return
if (task_table_.Execute(index)) return task_table_.Get(index); if (task_table_.Execute(index))
return task_table_.Get(index);
// else try next // else try next
} }
return nullptr; return nullptr;
......
...@@ -26,7 +26,7 @@ namespace scheduler { ...@@ -26,7 +26,7 @@ namespace scheduler {
class XDeleteTask : public Task { class XDeleteTask : public Task {
public: public:
explicit XDeleteTask(const scheduler::DeleteJobPtr& job); explicit XDeleteTask(const scheduler::DeleteJobPtr& delete_job);
void void
Load(LoadType type, uint8_t device_id) override; Load(LoadType type, uint8_t device_id) override;
......
...@@ -31,9 +31,8 @@ UriCheck(const std::string& uri) { ...@@ -31,9 +31,8 @@ UriCheck(const std::string& uri) {
size_t index = uri.find_first_of(':', 0); size_t index = uri.find_first_of(':', 0);
if (index == std::string::npos) { if (index == std::string::npos) {
return false; return false;
} else {
return true;
} }
return true;
} }
Status Status
...@@ -45,11 +44,11 @@ ClientProxy::Connect(const ConnectParam& param) { ...@@ -45,11 +44,11 @@ ClientProxy::Connect(const ConnectParam& param) {
connected_ = true; connected_ = true;
client_ptr_ = std::make_shared<GrpcClient>(channel_); client_ptr_ = std::make_shared<GrpcClient>(channel_);
return Status::OK(); return Status::OK();
} else { }
std::string reason = "connect failed!"; std::string reason = "connect failed!";
connected_ = false; connected_ = false;
return Status(StatusCode::NotConnected, reason); return Status(StatusCode::NotConnected, reason);
}
} }
Status Status
...@@ -134,7 +133,7 @@ ClientProxy::CreateIndex(const IndexParam& index_param) { ...@@ -134,7 +133,7 @@ ClientProxy::CreateIndex(const IndexParam& index_param) {
// TODO: add index params // TODO: add index params
::milvus::grpc::IndexParam grpc_index_param; ::milvus::grpc::IndexParam grpc_index_param;
grpc_index_param.set_table_name(index_param.table_name); grpc_index_param.set_table_name(index_param.table_name);
grpc_index_param.mutable_index()->set_index_type((int32_t)index_param.index_type); grpc_index_param.mutable_index()->set_index_type(static_cast<int32_t>(index_param.index_type));
grpc_index_param.mutable_index()->set_nlist(index_param.nlist); grpc_index_param.mutable_index()->set_nlist(index_param.nlist);
return client_ptr_->CreateIndex(grpc_index_param); return client_ptr_->CreateIndex(grpc_index_param);
} catch (std::exception& ex) { } catch (std::exception& ex) {
......
...@@ -85,7 +85,7 @@ class Status { ...@@ -85,7 +85,7 @@ class Status {
MoveFrom(Status& s); MoveFrom(Status& s);
private: private:
const char* state_ = nullptr; char* state_ = nullptr;
}; // Status }; // Status
} // namespace milvus } // namespace milvus
...@@ -28,7 +28,7 @@ Status::Status(StatusCode code, const std::string& msg) { ...@@ -28,7 +28,7 @@ Status::Status(StatusCode code, const std::string& msg) {
// 4 bytes store message length // 4 bytes store message length
// the left bytes store message string // the left bytes store message string
const uint32_t length = (uint32_t)msg.size(); const uint32_t length = (uint32_t)msg.size();
char* result = new char[length + sizeof(length) + CODE_WIDTH]; auto result = new char[length + sizeof(length) + CODE_WIDTH];
memcpy(result, &code, CODE_WIDTH); memcpy(result, &code, CODE_WIDTH);
memcpy(result + CODE_WIDTH, &length, sizeof(length)); memcpy(result + CODE_WIDTH, &length, sizeof(length));
memcpy(result + sizeof(length) + CODE_WIDTH, msg.data(), length); memcpy(result + sizeof(length) + CODE_WIDTH, msg.data(), length);
...@@ -75,7 +75,7 @@ Status::CopyFrom(const Status& s) { ...@@ -75,7 +75,7 @@ Status::CopyFrom(const Status& s) {
memcpy(&length, s.state_ + CODE_WIDTH, sizeof(length)); memcpy(&length, s.state_ + CODE_WIDTH, sizeof(length));
int buff_len = length + sizeof(length) + CODE_WIDTH; int buff_len = length + sizeof(length) + CODE_WIDTH;
state_ = new char[buff_len]; state_ = new char[buff_len];
memcpy((void*)state_, (void*)s.state_, buff_len); memcpy(state_, s.state_, buff_len);
} }
void void
......
此差异已折叠。
...@@ -30,9 +30,6 @@ namespace zilliz { ...@@ -30,9 +30,6 @@ namespace zilliz {
namespace milvus { namespace milvus {
namespace server { namespace server {
DBWrapper::DBWrapper() {
}
Status Status
DBWrapper::StartService() { DBWrapper::StartService() {
Config& config = Config::GetInstance(); Config& config = Config::GetInstance();
...@@ -41,27 +38,37 @@ DBWrapper::StartService() { ...@@ -41,27 +38,37 @@ DBWrapper::StartService() {
engine::DBOptions opt; engine::DBOptions opt;
s = config.GetDBConfigBackendUrl(opt.meta_.backend_uri_); s = config.GetDBConfigBackendUrl(opt.meta_.backend_uri_);
if (!s.ok()) return s; if (!s.ok()) {
return s;
}
std::string path; std::string path;
s = config.GetDBConfigPrimaryPath(path); s = config.GetDBConfigPrimaryPath(path);
if (!s.ok()) return s; if (!s.ok()) {
return s;
}
opt.meta_.path_ = path + "/db"; opt.meta_.path_ = path + "/db";
std::string db_slave_path; std::string db_slave_path;
s = config.GetDBConfigSecondaryPath(db_slave_path); s = config.GetDBConfigSecondaryPath(db_slave_path);
if (!s.ok()) return s; if (!s.ok()) {
return s;
}
StringHelpFunctions::SplitStringByDelimeter(db_slave_path, ";", opt.meta_.slave_paths_); StringHelpFunctions::SplitStringByDelimeter(db_slave_path, ";", opt.meta_.slave_paths_);
// cache config // cache config
s = config.GetCacheConfigCacheInsertData(opt.insert_cache_immediately_); s = config.GetCacheConfigCacheInsertData(opt.insert_cache_immediately_);
if (!s.ok()) return s; if (!s.ok()) {
return s;
}
std::string mode; std::string mode;
s = config.GetServerConfigDeployMode(mode); s = config.GetServerConfigDeployMode(mode);
if (!s.ok()) return s; if (!s.ok()) {
return s;
}
if (mode == "single") { if (mode == "single") {
opt.mode_ = engine::DBOptions::MODE::SINGLE; opt.mode_ = engine::DBOptions::MODE::SINGLE;
...@@ -78,14 +85,17 @@ DBWrapper::StartService() { ...@@ -78,14 +85,17 @@ DBWrapper::StartService() {
// engine config // engine config
int32_t omp_thread; int32_t omp_thread;
s = config.GetEngineConfigOmpThreadNum(omp_thread); s = config.GetEngineConfigOmpThreadNum(omp_thread);
if (!s.ok()) return s; if (!s.ok()) {
return s;
}
if (omp_thread > 0) { if (omp_thread > 0) {
omp_set_num_threads(omp_thread); omp_set_num_threads(omp_thread);
SERVER_LOG_DEBUG << "Specify openmp thread number: " << omp_thread; SERVER_LOG_DEBUG << "Specify openmp thread number: " << omp_thread;
} else { } else {
uint32_t sys_thread_cnt = 8; uint32_t sys_thread_cnt = 8;
if (CommonUtil::GetSystemAvailableThreads(sys_thread_cnt)) { if (CommonUtil::GetSystemAvailableThreads(sys_thread_cnt)) {
omp_thread = (int32_t)ceil(sys_thread_cnt * 0.5); omp_thread = static_cast<int32_t>(ceil(sys_thread_cnt * 0.5));
omp_set_num_threads(omp_thread); omp_set_num_threads(omp_thread);
} }
} }
...@@ -93,20 +103,29 @@ DBWrapper::StartService() { ...@@ -93,20 +103,29 @@ DBWrapper::StartService() {
// init faiss global variable // init faiss global variable
int32_t use_blas_threshold; int32_t use_blas_threshold;
s = config.GetEngineConfigUseBlasThreshold(use_blas_threshold); s = config.GetEngineConfigUseBlasThreshold(use_blas_threshold);
if (!s.ok()) return s; if (!s.ok()) {
return s;
}
faiss::distance_compute_blas_threshold = use_blas_threshold; faiss::distance_compute_blas_threshold = use_blas_threshold;
// set archive config // set archive config
engine::ArchiveConf::CriteriaT criterial; engine::ArchiveConf::CriteriaT criterial;
int32_t disk, days; int32_t disk, days;
s = config.GetDBConfigArchiveDiskThreshold(disk); s = config.GetDBConfigArchiveDiskThreshold(disk);
if (!s.ok()) return s; if (!s.ok()) {
return s;
}
if (disk > 0) { if (disk > 0) {
criterial[engine::ARCHIVE_CONF_DISK] = disk; criterial[engine::ARCHIVE_CONF_DISK] = disk;
} }
s = config.GetDBConfigArchiveDaysThreshold(days); s = config.GetDBConfigArchiveDaysThreshold(days);
if (!s.ok()) return s; if (!s.ok()) {
return s;
}
if (days > 0) { if (days > 0) {
criterial[engine::ARCHIVE_CONF_DAYS] = days; criterial[engine::ARCHIVE_CONF_DAYS] = days;
} }
......
...@@ -28,7 +28,7 @@ namespace server { ...@@ -28,7 +28,7 @@ namespace server {
class DBWrapper { class DBWrapper {
private: private:
DBWrapper(); DBWrapper() = default;
~DBWrapper() = default; ~DBWrapper() = default;
public: public:
......
...@@ -146,7 +146,7 @@ Server::Daemonize() { ...@@ -146,7 +146,7 @@ Server::Daemonize() {
void void
Server::Start() { Server::Start() {
if (daemonized_) { if (daemonized_ != 0) {
Daemonize(); Daemonize();
} }
......
...@@ -227,7 +227,7 @@ class GrpcRequestHandler final : public ::milvus::grpc::MilvusService::Service { ...@@ -227,7 +227,7 @@ class GrpcRequestHandler final : public ::milvus::grpc::MilvusService::Service {
*/ */
::grpc::Status ::grpc::Status
ShowTables(::grpc::ServerContext* context, const ::milvus::grpc::Command* request, ShowTables(::grpc::ServerContext* context, const ::milvus::grpc::Command* request,
::milvus::grpc::TableNameList* table_name_list) override; ::milvus::grpc::TableNameList* response) override;
/** /**
* @brief Give the server status * @brief Give the server status
......
...@@ -163,7 +163,8 @@ GrpcRequestScheduler::Stop() { ...@@ -163,7 +163,8 @@ GrpcRequestScheduler::Stop() {
} }
for (auto iter : execute_threads_) { for (auto iter : execute_threads_) {
if (iter == nullptr) continue; if (iter == nullptr)
continue;
iter->join(); iter->join();
} }
......
...@@ -69,7 +69,7 @@ class GrpcBaseTask { ...@@ -69,7 +69,7 @@ class GrpcBaseTask {
OnExecute() = 0; OnExecute() = 0;
Status Status
SetStatus(ErrorCode error_code, const std::string& msg); SetStatus(ErrorCode error_code, const std::string& error_msg);
protected: protected:
mutable std::mutex finish_mtx_; mutable std::mutex finish_mtx_;
......
...@@ -159,7 +159,7 @@ CreateTableTask::OnExecute() { ...@@ -159,7 +159,7 @@ CreateTableTask::OnExecute() {
// step 2: construct table schema // step 2: construct table schema
engine::meta::TableSchema table_info; engine::meta::TableSchema table_info;
table_info.table_id_ = schema_->table_name(); table_info.table_id_ = schema_->table_name();
table_info.dimension_ = (uint16_t)schema_->dimension(); table_info.dimension_ = static_cast<uint16_t>(schema_->dimension());
table_info.index_file_size_ = schema_->index_file_size(); table_info.index_file_size_ = schema_->index_file_size();
table_info.metric_type_ = schema_->metric_type(); table_info.metric_type_ = schema_->metric_type();
...@@ -446,13 +446,13 @@ InsertTask::OnExecute() { ...@@ -446,13 +446,13 @@ InsertTask::OnExecute() {
// all user provide id, or all internal id // all user provide id, or all internal id
bool user_provide_ids = !insert_param_->row_id_array().empty(); bool user_provide_ids = !insert_param_->row_id_array().empty();
// user already provided id before, all insert action require user id // user already provided id before, all insert action require user id
if ((table_info.flag_ & engine::meta::FLAG_MASK_HAS_USERID) && !user_provide_ids) { if ((table_info.flag_ & engine::meta::FLAG_MASK_HAS_USERID) != 0 && !user_provide_ids) {
return Status(SERVER_ILLEGAL_VECTOR_ID, return Status(SERVER_ILLEGAL_VECTOR_ID,
"Table vector ids are user defined, please provide id for this batch"); "Table vector ids are user defined, please provide id for this batch");
} }
// user didn't provided id before, no need to provide user id // 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) { if ((table_info.flag_ & engine::meta::FLAG_MASK_NO_USERID) != 0 && user_provide_ids) {
return Status(SERVER_ILLEGAL_VECTOR_ID, return Status(SERVER_ILLEGAL_VECTOR_ID,
"Table vector ids are auto generated, no need to provide id for this batch"); "Table vector ids are auto generated, no need to provide id for this batch");
} }
...@@ -487,12 +487,12 @@ InsertTask::OnExecute() { ...@@ -487,12 +487,12 @@ InsertTask::OnExecute() {
rc.ElapseFromBegin("prepare vectors data"); rc.ElapseFromBegin("prepare vectors data");
// step 5: insert vectors // step 5: insert vectors
auto vec_count = (uint64_t)insert_param_->row_record_array_size(); auto vec_count = static_cast<uint64_t>(insert_param_->row_record_array_size());
std::vector<int64_t> vec_ids(insert_param_->row_id_array_size(), 0); std::vector<int64_t> vec_ids(insert_param_->row_id_array_size(), 0);
if (!insert_param_->row_id_array().empty()) { if (!insert_param_->row_id_array().empty()) {
const int64_t* src_data = insert_param_->row_id_array().data(); const int64_t* src_data = insert_param_->row_id_array().data();
int64_t* target_data = vec_ids.data(); int64_t* target_data = vec_ids.data();
memcpy(target_data, src_data, (size_t)(sizeof(int64_t) * insert_param_->row_id_array_size())); memcpy(target_data, src_data, static_cast<size_t>(sizeof(int64_t) * insert_param_->row_id_array_size()));
} }
status = 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);
...@@ -710,7 +710,7 @@ CountTableTask::OnExecute() { ...@@ -710,7 +710,7 @@ CountTableTask::OnExecute() {
return status; return status;
} }
row_count_ = (int64_t)row_count; row_count_ = static_cast<int64_t>(row_count);
rc.ElapseFromBegin("total cost"); rc.ElapseFromBegin("total cost");
} catch (std::exception& ex) { } catch (std::exception& ex) {
......
...@@ -41,7 +41,7 @@ class CreateTableTask : public GrpcBaseTask { ...@@ -41,7 +41,7 @@ class CreateTableTask : public GrpcBaseTask {
Create(const ::milvus::grpc::TableSchema* schema); Create(const ::milvus::grpc::TableSchema* schema);
protected: protected:
explicit CreateTableTask(const ::milvus::grpc::TableSchema* request); explicit CreateTableTask(const ::milvus::grpc::TableSchema* schema);
Status Status
OnExecute() override; OnExecute() override;
...@@ -57,7 +57,7 @@ class HasTableTask : public GrpcBaseTask { ...@@ -57,7 +57,7 @@ class HasTableTask : public GrpcBaseTask {
Create(const std::string& table_name, bool& has_table); Create(const std::string& table_name, bool& has_table);
protected: protected:
HasTableTask(const std::string& request, bool& has_table); HasTableTask(const std::string& table_name, bool& has_table);
Status Status
OnExecute() override; OnExecute() override;
...@@ -104,10 +104,10 @@ class DropTableTask : public GrpcBaseTask { ...@@ -104,10 +104,10 @@ class DropTableTask : public GrpcBaseTask {
class CreateIndexTask : public GrpcBaseTask { class CreateIndexTask : public GrpcBaseTask {
public: public:
static BaseTaskPtr static BaseTaskPtr
Create(const ::milvus::grpc::IndexParam* index_Param); Create(const ::milvus::grpc::IndexParam* index_param);
protected: protected:
explicit CreateIndexTask(const ::milvus::grpc::IndexParam* index_Param); explicit CreateIndexTask(const ::milvus::grpc::IndexParam* index_param);
Status Status
OnExecute() override; OnExecute() override;
...@@ -136,10 +136,10 @@ class ShowTablesTask : public GrpcBaseTask { ...@@ -136,10 +136,10 @@ class ShowTablesTask : public GrpcBaseTask {
class InsertTask : public GrpcBaseTask { class InsertTask : public GrpcBaseTask {
public: public:
static BaseTaskPtr static BaseTaskPtr
Create(const ::milvus::grpc::InsertParam* insert_Param, ::milvus::grpc::VectorIds* record_ids_); Create(const ::milvus::grpc::InsertParam* insert_param, ::milvus::grpc::VectorIds* record_ids);
protected: protected:
InsertTask(const ::milvus::grpc::InsertParam* insert_Param, ::milvus::grpc::VectorIds* record_ids_); InsertTask(const ::milvus::grpc::InsertParam* insert_param, ::milvus::grpc::VectorIds* record_ids);
Status Status
OnExecute() override; OnExecute() override;
......
...@@ -59,7 +59,9 @@ CommonUtil::GetSystemAvailableThreads(uint32_t& thread_count) { ...@@ -59,7 +59,9 @@ CommonUtil::GetSystemAvailableThreads(uint32_t& thread_count) {
// threadCnt = std::thread::hardware_concurrency(); // threadCnt = std::thread::hardware_concurrency();
thread_count = sysconf(_SC_NPROCESSORS_CONF); thread_count = sysconf(_SC_NPROCESSORS_CONF);
thread_count *= THREAD_MULTIPLY_CPU; thread_count *= THREAD_MULTIPLY_CPU;
if (thread_count == 0) thread_count = 8; if (thread_count == 0) {
thread_count = 8;
}
return true; return true;
} }
...@@ -162,9 +164,9 @@ CommonUtil::GetFileSize(const std::string& path) { ...@@ -162,9 +164,9 @@ CommonUtil::GetFileSize(const std::string& path) {
struct stat file_info; struct stat file_info;
if (stat(path.c_str(), &file_info) < 0) { if (stat(path.c_str(), &file_info) < 0) {
return 0; return 0;
} else {
return (uint64_t)file_info.st_size;
} }
return static_cast<uint64_t>(file_info.st_size);
} }
std::string std::string
......
...@@ -29,7 +29,7 @@ Status::Status(StatusCode code, const std::string& msg) { ...@@ -29,7 +29,7 @@ Status::Status(StatusCode code, const std::string& msg) {
// 4 bytes store message length // 4 bytes store message length
// the left bytes store message string // the left bytes store message string
const uint32_t length = (uint32_t)msg.size(); const uint32_t length = (uint32_t)msg.size();
char* result = new char[length + sizeof(length) + CODE_WIDTH]; auto result = new char[length + sizeof(length) + CODE_WIDTH];
std::memcpy(result, &code, CODE_WIDTH); std::memcpy(result, &code, CODE_WIDTH);
std::memcpy(result + CODE_WIDTH, &length, sizeof(length)); std::memcpy(result + CODE_WIDTH, &length, sizeof(length));
memcpy(result + sizeof(length) + CODE_WIDTH, msg.data(), length); memcpy(result + sizeof(length) + CODE_WIDTH, msg.data(), length);
...@@ -76,7 +76,7 @@ Status::CopyFrom(const Status& s) { ...@@ -76,7 +76,7 @@ Status::CopyFrom(const Status& s) {
memcpy(&length, s.state_ + CODE_WIDTH, sizeof(length)); memcpy(&length, s.state_ + CODE_WIDTH, sizeof(length));
int buff_len = length + sizeof(length) + CODE_WIDTH; int buff_len = length + sizeof(length) + CODE_WIDTH;
state_ = new char[buff_len]; state_ = new char[buff_len];
memcpy((void*)state_, (void*)s.state_, buff_len); memcpy(state_, s.state_, buff_len);
} }
void void
......
...@@ -71,7 +71,7 @@ class Status { ...@@ -71,7 +71,7 @@ class Status {
MoveFrom(Status& s); MoveFrom(Status& s);
private: private:
const char* state_ = nullptr; char* state_ = nullptr;
}; // Status }; // Status
} // namespace milvus } // namespace milvus
......
...@@ -70,7 +70,8 @@ inline ThreadPool::ThreadPool(size_t threads, size_t queue_size) : max_queue_siz ...@@ -70,7 +70,8 @@ inline ThreadPool::ThreadPool(size_t threads, size_t queue_size) : max_queue_siz
{ {
std::unique_lock<std::mutex> lock(this->queue_mutex_); std::unique_lock<std::mutex> lock(this->queue_mutex_);
this->condition_.wait(lock, [this] { return this->stop || !this->tasks_.empty(); }); this->condition_.wait(lock, [this] { return this->stop || !this->tasks_.empty(); });
if (this->stop && this->tasks_.empty()) return; if (this->stop && this->tasks_.empty())
return;
task = std::move(this->tasks_.front()); task = std::move(this->tasks_.front());
this->tasks_.pop(); this->tasks_.pop();
} }
...@@ -95,7 +96,8 @@ ThreadPool::enqueue(F&& f, Args&&... args) -> std::future<typename std::result_o ...@@ -95,7 +96,8 @@ ThreadPool::enqueue(F&& f, Args&&... args) -> std::future<typename std::result_o
std::unique_lock<std::mutex> lock(queue_mutex_); std::unique_lock<std::mutex> lock(queue_mutex_);
this->condition_.wait(lock, [this] { return this->tasks_.size() < max_queue_size_; }); this->condition_.wait(lock, [this] { return this->tasks_.size() < max_queue_size_; });
// don't allow enqueueing after stopping the pool // don't allow enqueueing after stopping the pool
if (stop) throw std::runtime_error("enqueue on stopped ThreadPool"); if (stop)
throw std::runtime_error("enqueue on stopped ThreadPool");
tasks_.emplace([task]() { (*task)(); }); tasks_.emplace([task]() { (*task)(); });
} }
......
...@@ -39,7 +39,8 @@ TimeRecorder::GetTimeSpanStr(double span) { ...@@ -39,7 +39,8 @@ TimeRecorder::GetTimeSpanStr(double span) {
void void
TimeRecorder::PrintTimeRecord(const std::string& msg, double span) { TimeRecorder::PrintTimeRecord(const std::string& msg, double span) {
std::string str_log; std::string str_log;
if (!header_.empty()) str_log += header_ + ": "; if (!header_.empty())
str_log += header_ + ": ";
str_log += msg; str_log += msg;
str_log += " ("; str_log += " (";
str_log += TimeRecorder::GetTimeSpanStr(span); str_log += TimeRecorder::GetTimeSpanStr(span);
......
...@@ -83,8 +83,8 @@ ValidationUtil::ValidateTableDimension(int64_t dimension) { ...@@ -83,8 +83,8 @@ ValidationUtil::ValidateTableDimension(int64_t dimension) {
Status Status
ValidationUtil::ValidateTableIndexType(int32_t index_type) { ValidationUtil::ValidateTableIndexType(int32_t index_type) {
int engine_type = (int)engine::EngineType(index_type); int engine_type = static_cast<int>(engine::EngineType(index_type));
if (engine_type <= 0 || engine_type > (int)engine::EngineType::MAX_VALUE) { if (engine_type <= 0 || engine_type > static_cast<int>(engine::EngineType::MAX_VALUE)) {
std::string msg = "Invalid index type: " + std::to_string(index_type); std::string msg = "Invalid index type: " + std::to_string(index_type);
SERVER_LOG_ERROR << msg; SERVER_LOG_ERROR << msg;
return Status(SERVER_INVALID_INDEX_TYPE, msg); return Status(SERVER_INVALID_INDEX_TYPE, msg);
...@@ -117,7 +117,8 @@ ValidationUtil::ValidateTableIndexFileSize(int64_t index_file_size) { ...@@ -117,7 +117,8 @@ ValidationUtil::ValidateTableIndexFileSize(int64_t index_file_size) {
Status Status
ValidationUtil::ValidateTableIndexMetricType(int32_t metric_type) { ValidationUtil::ValidateTableIndexMetricType(int32_t metric_type) {
if (metric_type != (int32_t)engine::MetricType::L2 && metric_type != (int32_t)engine::MetricType::IP) { if (metric_type != static_cast<int32_t>(engine::MetricType::L2) &&
metric_type != static_cast<int32_t>(engine::MetricType::IP)) {
std::string msg = "Invalid metric type: " + std::to_string(metric_type); std::string msg = "Invalid metric type: " + std::to_string(metric_type);
SERVER_LOG_ERROR << msg; SERVER_LOG_ERROR << msg;
return Status(SERVER_INVALID_INDEX_METRIC_TYPE, msg); return Status(SERVER_INVALID_INDEX_METRIC_TYPE, msg);
...@@ -151,7 +152,7 @@ Status ...@@ -151,7 +152,7 @@ Status
ValidationUtil::ValidateGpuIndex(uint32_t gpu_index) { ValidationUtil::ValidateGpuIndex(uint32_t gpu_index) {
int num_devices = 0; int num_devices = 0;
auto cuda_err = cudaGetDeviceCount(&num_devices); auto cuda_err = cudaGetDeviceCount(&num_devices);
if (cuda_err) { if (cuda_err != cudaSuccess) {
std::string msg = "Failed to get gpu card number, cuda error:" + std::to_string(cuda_err); std::string msg = "Failed to get gpu card number, cuda error:" + std::to_string(cuda_err);
SERVER_LOG_ERROR << msg; SERVER_LOG_ERROR << msg;
return Status(SERVER_UNEXPECTED_ERROR, msg); return Status(SERVER_UNEXPECTED_ERROR, msg);
...@@ -222,9 +223,8 @@ ValidationUtil::ValidateStringIsBool(const std::string& str) { ...@@ -222,9 +223,8 @@ ValidationUtil::ValidateStringIsBool(const std::string& str) {
if (s == "true" || s == "on" || s == "yes" || s == "1" || s == "false" || s == "off" || s == "no" || s == "0" || if (s == "true" || s == "on" || s == "yes" || s == "1" || s == "false" || s == "off" || s == "no" || s == "0" ||
s.empty()) { s.empty()) {
return Status::OK(); return Status::OK();
} else {
return Status(SERVER_INVALID_ARGUMENT, "Invalid boolean: " + str);
} }
return Status(SERVER_INVALID_ARGUMENT, "Invalid boolean: " + str);
} }
Status Status
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册