提交 d1251fb0 编写于 作者: S starlord

format code by clang-tidy


Former-commit-id: 437b1fff79da965b8aafce026c8be4f9d582c909
上级 e8ae6127
......@@ -18,8 +18,10 @@
Checks: 'clang-diagnostic-*,clang-analyzer-*,-clang-analyzer-alpha*,google-*,modernize-*,readability-*'
# produce HeaderFilterRegex from cpp/build-support/lint_exclusions.txt with:
# echo -n '^('; sed -e 's/*/\.*/g' cpp/build-support/lint_exclusions.txt | tr '\n' '|'; echo ')$'
HeaderFilterRegex: '^(.*cmake-build-debug.*|.*cmake-build-release.*|.*cmake_build.*|.*src/thirdparty.*|.*src/core/thirdparty.*|.*src/grpc.*|)$'
HeaderFilterRegex: '^(.*cmake-build-debug.*|.*cmake-build-release.*|.*cmake_build.*|.*src/core/thirdparty.*|.*thirdparty.*|.*easylogging++.*|.*SqliteMetaImpl.cpp|.*src/grpc.*|.*src/core.*|.*src/wrapper.*)$'
AnalyzeTemporaryDtors: true
ChainedConditionalReturn: 1
ChainedConditionalAssignment: 1
CheckOptions:
- key: google-readability-braces-around-statements.ShortStatementLines
value: '1'
......
......@@ -111,14 +111,14 @@ if [[ ${RUN_CPPLINT} == "ON" ]]; then
exit 1
fi
echo "clang-format check passed!"
#
# # clang-tidy check
# make check-clang-tidy
# if [ $? -ne 0 ]; then
# echo "ERROR! clang-tidy check failed"
# exit 1
# fi
# echo "clang-tidy check passed!"
# clang-tidy check
make check-clang-tidy
if [ $? -ne 0 ]; then
echo "ERROR! clang-tidy check failed"
exit 1
fi
echo "clang-tidy check passed!"
else
# compile and build
make -j 4 || exit 1
......
......@@ -32,7 +32,7 @@ class CpuCacheMgr : public CacheMgr<DataObjPtr> {
CpuCacheMgr();
public:
// TODO: use smart pointer instead
// TODO(myh): use smart pointer instead
static CpuCacheMgr*
GetInstance();
......
......@@ -44,7 +44,7 @@ DatasetPtr
generate_queries(int64_t n, int64_t d, int64_t k, int64_t base) {
size_t size = sizeof(float) * n * d;
auto v = (float *) malloc(size);
// TODO: check malloc
// TODO(lxj): check malloc
for (auto i = 0; i < n; ++i) {
for (auto j = 0; j < d; ++j) {
v[i * d + j] = float(base + i);
......
......@@ -694,4 +694,4 @@ TEST_F(GPURESTEST, TrainAndSearch) {
// TODO(linxj): Add exception test
// TODO(lxj): Add exception test
......@@ -85,7 +85,7 @@ void PrintResult(const DatasetPtr &result,
std::cout << "dist\n" << ss_dist.str() << std::endl;
}
// TODO(linxj): add test about count() and dimension()
// TODO(lxj): add test about count() and dimension()
TEST_F(KDTTest, kdt_basic) {
assert(!xb.empty());
......
......@@ -179,13 +179,13 @@ FileMetadataSet::SaveMetadata(const std::string& p_metaFile, const std::string&
ErrorCode
FileMetadataSet::SaveMetadataToMemory(void **pGraphMemFile, int64_t &len) {
// TODO: serialize file to mem?
// TODO(lxj): serialize file to mem?
return ErrorCode::Fail;
}
ErrorCode
FileMetadataSet::LoadMetadataFromMemory(void *pGraphMemFile) {
// TODO: not support yet
// TODO(lxj): not support yet
return ErrorCode::Fail;
}
......
......@@ -242,7 +242,7 @@ DBImpl::GetTableRowCount(const std::string& table_id, uint64_t& row_count) {
}
Status
DBImpl::InsertVectors(const std::string& table_id_, uint64_t n, const float* vectors, IDNumbers& vector_ids_) {
DBImpl::InsertVectors(const std::string& table_id, uint64_t n, const float* vectors, IDNumbers& vector_ids) {
// ENGINE_LOG_DEBUG << "Insert " << n << " vectors to cache";
if (shutting_down_.load(std::memory_order_acquire)) {
return Status(DB_ERROR, "Milsvus server is shutdown!");
......@@ -250,7 +250,7 @@ DBImpl::InsertVectors(const std::string& table_id_, uint64_t n, const float* vec
Status status;
zilliz::milvus::server::CollectInsertMetrics metrics(n, status);
status = mem_mgr_->InsertVectors(table_id_, n, vectors, vector_ids_);
status = mem_mgr_->InsertVectors(table_id, n, vectors, vector_ids);
// std::chrono::microseconds time_span =
// std::chrono::duration_cast<std::chrono::microseconds>(end_time - start_time);
// double average_time = double(time_span.count()) / n;
......@@ -295,15 +295,17 @@ DBImpl::CreateIndex(const std::string& table_id, const TableIndex& index) {
// for IDMAP type, only wait all NEW file converted to RAW file
// for other type, wait NEW/RAW/NEW_MERGE/NEW_INDEX/TO_INDEX files converted to INDEX files
std::vector<int> file_types;
if (index.engine_type_ == (int)EngineType::FAISS_IDMAP) {
if (index.engine_type_ == static_cast<int32_t>(EngineType::FAISS_IDMAP)) {
file_types = {
(int)meta::TableFileSchema::NEW, (int)meta::TableFileSchema::NEW_MERGE,
static_cast<int32_t>(meta::TableFileSchema::NEW), static_cast<int32_t>(meta::TableFileSchema::NEW_MERGE),
};
} else {
file_types = {
(int)meta::TableFileSchema::RAW, (int)meta::TableFileSchema::NEW,
(int)meta::TableFileSchema::NEW_MERGE, (int)meta::TableFileSchema::NEW_INDEX,
(int)meta::TableFileSchema::TO_INDEX,
static_cast<int32_t>(meta::TableFileSchema::RAW),
static_cast<int32_t>(meta::TableFileSchema::NEW),
static_cast<int32_t>(meta::TableFileSchema::NEW_MERGE),
static_cast<int32_t>(meta::TableFileSchema::NEW_INDEX),
static_cast<int32_t>(meta::TableFileSchema::TO_INDEX),
};
}
......
......@@ -228,7 +228,7 @@ ParseMetaUri(const std::string& uri, MetaUriInfo& info) {
info.port_ = pieces_match[5].str();
info.db_name_ = pieces_match[6].str();
// TODO: verify host, port...
// TODO(myh): verify host, port...
} else {
return Status(DB_INVALID_META_URI, "Invalid meta uri: " + uri);
}
......
......@@ -342,8 +342,9 @@ Status
ExecutionEngineImpl::Init() {
server::Config& config = server::Config::GetInstance();
Status s = config.GetDBConfigBuildIndexGPU(gpu_num_);
if (!s.ok())
if (!s.ok()) {
return s;
}
return Status::OK();
}
......
......@@ -68,7 +68,7 @@ MySQLConnectionPool::create() {
try {
// Create connection using the parameters we were passed upon
// creation.
mysqlpp::Connection* conn = new mysqlpp::Connection();
auto conn = new mysqlpp::Connection();
conn->set_option(new mysqlpp::ReconnectOption(true));
conn->connect(db_.empty() ? 0 : db_.c_str(), server_.empty() ? 0 : server_.c_str(),
user_.empty() ? 0 : user_.c_str(), password_.empty() ? 0 : password_.c_str(), port_);
......
......@@ -50,11 +50,11 @@ HandleException(const std::string& desc, const char* what = nullptr) {
if (what == nullptr) {
ENGINE_LOG_ERROR << desc;
return Status(DB_META_TRANSACTION_FAILED, desc);
} else {
std::string msg = desc + ":" + what;
ENGINE_LOG_ERROR << msg;
return Status(DB_META_TRANSACTION_FAILED, msg);
}
std::string msg = desc + ":" + what;
ENGINE_LOG_ERROR << msg;
return Status(DB_META_TRANSACTION_FAILED, msg);
}
class MetaField {
......@@ -324,7 +324,7 @@ MySQLMetaImpl::Initialize() {
return Status::OK();
}
// PXU TODO: Temp solution. Will fix later
// TODO(myh): Delete single vecotor by id
Status
MySQLMetaImpl::DropPartitionsByDates(const std::string& table_id, const DatesT& dates) {
if (dates.empty()) {
......@@ -1379,7 +1379,7 @@ MySQLMetaImpl::GetTableFiles(const std::string& table_id, const std::vector<size
}
}
// PXU TODO: Support Swap
// TODO(myh): Support swap to cloud storage
Status
MySQLMetaImpl::Archive() {
auto& criterias = options_.archive_conf_.GetCriterias();
......@@ -1984,9 +1984,8 @@ MySQLMetaImpl::DropAll() {
if (dropTableQuery.exec()) {
return Status::OK();
} else {
return HandleException("QUERY ERROR WHEN DROPPING ALL", dropTableQuery.error());
}
return HandleException("QUERY ERROR WHEN DROPPING ALL", dropTableQuery.error());
} catch (std::exception& e) {
return HandleException("GENERAL ERROR WHEN DROPPING ALL", e.what());
}
......
......@@ -155,7 +155,7 @@ SqliteMetaImpl::Initialize() {
return Status::OK();
}
// PXU TODO: Temp solution. Will fix later
// TODO(myh): Delete single vecotor by id
Status
SqliteMetaImpl::DropPartitionsByDates(const std::string &table_id,
const DatesT &dates) {
......@@ -885,7 +885,7 @@ SqliteMetaImpl::GetTableFiles(const std::string &table_id,
}
}
// PXU TODO: Support Swap
// TODO(myh): Support swap to cloud storage
Status
SqliteMetaImpl::Archive() {
auto &criterias = options_.archive_conf_.GetCriterias();
......
......@@ -31,8 +31,9 @@ namespace server {
void
SystemInfo::Init() {
if (initialized_)
if (initialized_) {
return;
}
initialized_ = true;
......@@ -45,9 +46,10 @@ SystemInfo::Init() {
last_user_cpu_ = time_sample.tms_utime;
file = fopen("/proc/cpuinfo", "r");
num_processors_ = 0;
while (fgets(line, 128, file) != NULL) {
if (strncmp(line, "processor", 9) == 0)
while (fgets(line, 128, file) != nullptr) {
if (strncmp(line, "processor", 9) == 0) {
num_processors_++;
}
if (strncmp(line, "physical", 8) == 0) {
num_physical_processors_ = ParseLine(line);
}
......@@ -80,7 +82,9 @@ SystemInfo::ParseLine(char* line) {
// This assumes that a digit will be found and the line ends in " Kb".
int i = strlen(line);
const char* p = line;
while (*p < '0' || *p > '9') p++;
while (*p < '0' || *p > '9') {
p++;
}
line[i - 3] = '\0';
i = atoi(p);
return static_cast<uint64_t>(i);
......@@ -105,7 +109,7 @@ SystemInfo::GetProcessUsedMemory() {
constexpr uint64_t KB_SIZE = 1024;
char line[line_length];
while (fgets(line, line_length, file) != NULL) {
while (fgets(line, line_length, file) != nullptr) {
if (strncmp(line, "VmRSS:", 6) == 0) {
result = ParseLine(line);
break;
......@@ -118,9 +122,12 @@ SystemInfo::GetProcessUsedMemory() {
double
SystemInfo::MemoryPercent() {
if (!initialized_)
if (!initialized_) {
Init();
return (double)(GetProcessUsedMemory() * 100) / (double)total_ram_;
}
double mem_used = static_cast<double>(GetProcessUsedMemory() * 100);
return mem_used / static_cast<double>(total_ram_);
}
std::vector<double>
......@@ -174,8 +181,9 @@ SystemInfo::getTotalCpuTime(std::vector<uint64_t>& work_time_array) {
double
SystemInfo::CPUPercent() {
if (!initialized_)
if (!initialized_) {
Init();
}
struct tms time_sample;
clock_t now;
double percent;
......@@ -233,7 +241,7 @@ SystemInfo::CPUTemperature() {
for (int i = 0; i <= num_physical_processors_; ++i) {
std::string path = "/sys/class/thermal/thermal_zone" + std::to_string(i) + "/temp";
FILE* file = fopen(path.data(), "r");
if (file == NULL) {
if (file == nullptr) {
perror("Could not open thermal file");
return result;
}
......@@ -269,7 +277,7 @@ SystemInfo::Octets() {
std::ifstream file(filename);
std::string lastline = "";
std::string line = "";
while (file) {
while (true) {
getline(file, line);
if (file.fail()) {
break;
......
......@@ -75,7 +75,7 @@ ResourceMgr::Connect(const std::string& name1, const std::string& name2, Connect
auto res2 = GetResource(name2);
if (res1 && res2) {
res1->AddNeighbour(std::static_pointer_cast<Node>(res2), connection);
// TODO: enable when task balance supported
// TODO(wxy): enable when task balance supported
// res2->AddNeighbour(std::static_pointer_cast<Node>(res1), connection);
return true;
}
......
......@@ -65,7 +65,7 @@ class ResourceMgr {
return disk_resources_;
}
// TODO: why return shared pointer
// TODO(wxy): why return shared pointer
inline std::vector<ResourcePtr>
GetAllResources() {
return resources_;
......@@ -90,7 +90,7 @@ class ResourceMgr {
GetNumGpuResource() const;
public:
// TODO: add stats interface(low)
// TODO(wxy): add stats interface(low)
public:
/******** Utility Functions ********/
......
......@@ -147,7 +147,7 @@ load_advance_config() {
// }
// } catch (const char *msg) {
// SERVER_LOG_ERROR << msg;
// // TODO: throw exception instead
// // TODO(wxy): throw exception instead
// exit(-1);
//// throw std::exception();
// }
......
......@@ -93,7 +93,7 @@ Scheduler::Process(const EventPtr& event) {
process_event(event);
}
// TODO: refactor the function
// TODO(wxy): refactor the function
void
Scheduler::OnLoadCompleted(const EventPtr& event) {
auto load_completed_event = std::static_pointer_cast<LoadCompletedEvent>(event);
......
......@@ -32,7 +32,7 @@ namespace zilliz {
namespace milvus {
namespace scheduler {
// TODO: refactor, not friendly to unittest, logical in framework code
// TODO(wxy): refactor, not friendly to unittest, logical in framework code
class Scheduler {
public:
explicit Scheduler(ResourceMgrWPtr res_mgr);
......
......@@ -33,7 +33,7 @@ TaskCreator::Create(const JobPtr& job) {
return Create(std::static_pointer_cast<DeleteJob>(job));
}
default: {
// TODO: error
// TODO(wxy): error
return std::vector<TaskPtr>();
}
}
......
......@@ -126,7 +126,7 @@ class TaskTable {
Get(uint64_t index);
/*
* TODO(wxyu): BIG GC
* TODO(wxy): BIG GC
* Remove sequence task which is DONE or MOVED from front;
* Called by ?
*/
......@@ -174,7 +174,7 @@ class TaskTable {
public:
/******** Action ********/
// TODO: bool to Status
// TODO(wxy): bool to Status
/*
* Load a task;
* Set state loading;
......
......@@ -83,7 +83,7 @@ Action::PushTaskToNeighbourRandomly(const TaskPtr& task, const ResourcePtr& self
}
} else {
// TODO: process
// TODO(wxy): process
}
}
......
......@@ -41,7 +41,7 @@ struct Neighbour {
Connection connection;
};
// TODO(linxj): return type void -> Status
// TODO(lxj): return type void -> Status
class Node {
public:
Node();
......
......@@ -39,7 +39,7 @@ namespace zilliz {
namespace milvus {
namespace scheduler {
// TODO(wxyu): Storage, Route, Executor
// TODO(wxy): Storage, Route, Executor
enum class ResourceType {
DISK = 0,
CPU = 1,
......@@ -115,11 +115,11 @@ class Resource : public Node, public std::enable_shared_from_this<Resource> {
return enable_executor_;
}
// TODO: const
// TODO(wxy): const
uint64_t
NumOfTaskToExec();
// TODO: need double ?
// TODO(wxy): need double ?
inline uint64_t
TaskAvgCost() const {
return total_cost_ / total_task_;
......
......@@ -27,7 +27,7 @@ namespace zilliz {
namespace milvus {
namespace scheduler {
// TODO: rewrite
// TODO(wxy): rewrite
class XSearchTask : public Task {
public:
explicit XSearchTask(TableFileSchemaPtr file);
......
......@@ -30,10 +30,10 @@ main(int argc, char* argv[]) {
printf("Client start...\n");
std::string app_name = basename(argv[0]);
static struct option long_options[] = {{"server", optional_argument, 0, 's'},
{"port", optional_argument, 0, 'p'},
{"help", no_argument, 0, 'h'},
{NULL, 0, 0, 0}};
static struct option long_options[] = {{"server", optional_argument, nullptr, 's'},
{"port", optional_argument, nullptr, 'p'},
{"help", no_argument, nullptr, 'h'},
{nullptr, 0, nullptr, 0}};
int option_index = 0;
std::string address = "127.0.0.1", port = "19530";
......
......@@ -29,10 +29,7 @@ namespace milvus {
bool
UriCheck(const std::string& uri) {
size_t index = uri.find_first_of(':', 0);
if (index == std::string::npos) {
return false;
}
return true;
return (index != std::string::npos);
}
Status
......@@ -99,7 +96,7 @@ ClientProxy::CreateTable(const TableSchema& param) {
schema.set_table_name(param.table_name);
schema.set_dimension(param.dimension);
schema.set_index_file_size(param.index_file_size);
schema.set_metric_type((int32_t)param.metric_type);
schema.set_metric_type(static_cast<int32_t>(param.metric_type));
return client_ptr_->CreateTable(schema);
} catch (std::exception& ex) {
......@@ -130,7 +127,6 @@ ClientProxy::DropTable(const std::string& table_name) {
Status
ClientProxy::CreateIndex(const IndexParam& index_param) {
try {
// TODO: add index params
::milvus::grpc::IndexParam grpc_index_param;
grpc_index_param.set_table_name(index_param.table_name);
grpc_index_param.mutable_index()->set_index_type(static_cast<int32_t>(index_param.index_type));
......@@ -274,7 +270,7 @@ ClientProxy::DescribeTable(const std::string& table_name, TableSchema& table_sch
table_schema.table_name = grpc_schema.table_name();
table_schema.dimension = grpc_schema.dimension();
table_schema.index_file_size = grpc_schema.index_file_size();
table_schema.metric_type = (MetricType)grpc_schema.metric_type();
table_schema.metric_type = static_cast<MetricType>(grpc_schema.metric_type());
return status;
} catch (std::exception& ex) {
......@@ -384,7 +380,7 @@ ClientProxy::DescribeIndex(const std::string& table_name, IndexParam& index_para
grpc_table_name.set_table_name(table_name);
::milvus::grpc::IndexParam grpc_index_param;
Status status = client_ptr_->DescribeIndex(grpc_table_name, grpc_index_param);
index_param.index_type = (IndexType)(grpc_index_param.mutable_index()->index_type());
index_param.index_type = static_cast<IndexType>(grpc_index_param.mutable_index()->index_type());
index_param.nlist = grpc_index_param.mutable_index()->nlist();
return status;
......
......@@ -468,7 +468,7 @@ InsertTask::OnExecute() {
// step 4: prepare float data
std::vector<float> vec_f(insert_param_->row_record_array_size() * table_info.dimension_, 0);
// TODO: change to one dimension array in protobuf or use multiple-thread to copy the data
// TODO(yk): change to one dimension array 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 Status(SERVER_INVALID_ROWRECORD_ARRAY, "Row record array data is empty");
......
......@@ -291,7 +291,7 @@ TEST_F(DBTest, SEARCH_TEST) {
ASSERT_TRUE(stat.ok());
}
// TODO(linxj): add groundTruth assert
// TODO(lxj): add groundTruth assert
}
TEST_F(DBTest, PRELOADTABLE_TEST) {
......
......@@ -193,7 +193,7 @@ TEST(CacheTest, GPU_CACHE_TEST) {
ASSERT_EQ(gpu_mgr->ItemCount(), 0);
for (auto i = 0; i < 3; i++) {
// TODO: use gpu index to mock
// TODO(myh): use gpu index to mock
//each vector is 1k byte, total size less than 2G
ms::engine::VecIndexPtr mock_index = std::make_shared<MockVecIndex>(256, 2000000);
ms::cache::DataObjPtr data_obj = std::make_shared<ms::cache::DataObj>(mock_index);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册