未验证 提交 d4eadc0b 编写于 作者: C Cai Yudong 提交者: GitHub

fix clang tidy warnings (#3371)

* fix clang-tidy warnings
Signed-off-by: Nyudong.cai <yudong.cai@zilliz.com>

* fix clang-format
Signed-off-by: Nyudong.cai <yudong.cai@zilliz.com>
上级 0bc69c43
......@@ -92,7 +92,7 @@ GetSnapshotIndex(const std::string& collection_name, const std::string& field_na
auto field_elements = ss->GetFieldElementsByField(field_name);
if (IsVectorField(field)) {
for (auto& field_element : field_elements) {
if (field_element->GetFtype() == (int64_t)milvus::engine::FieldElementType::FET_INDEX) {
if (field_element->GetFtype() == static_cast<snapshot::FTYPE_TYPE>(engine::FieldElementType::FET_INDEX)) {
index_info.index_name_ = field_element->GetName();
index_info.index_type_ = field_element->GetTypeName();
auto json = field_element->GetParams();
......@@ -107,7 +107,7 @@ GetSnapshotIndex(const std::string& collection_name, const std::string& field_na
}
} else {
for (auto& field_element : field_elements) {
if (field_element->GetFtype() == (int64_t)milvus::engine::FieldElementType::FET_INDEX) {
if (field_element->GetFtype() == static_cast<snapshot::FTYPE_TYPE>(engine::FieldElementType::FET_INDEX)) {
index_info.index_name_ = field_element->GetName();
index_info.index_type_ = field_element->GetTypeName();
}
......
......@@ -99,8 +99,8 @@ ParseMetaUri(const std::string& uri, MetaUriInfo& info) {
std::string host_regex = "(.*)";
std::string port_regex = "(.*)";
std::string db_name_regex = "(.*)";
std::string uri_regex_str = dialect_regex + "\\:\\/\\/" + username_tegex + "\\:" + password_regex + "\\@" +
host_regex + "\\:" + port_regex + "\\/" + db_name_regex;
std::string uri_regex_str = dialect_regex + R"(\:\/\/)" + username_tegex + R"(\:)" + password_regex + R"(\@)" +
host_regex + R"(\:)" + port_regex + R"(\/)" + db_name_regex;
std::regex uri_regex(uri_regex_str);
std::smatch pieces_match;
......@@ -142,7 +142,7 @@ GetIDFromChunk(const engine::DataChunkPtr& chunk, engine::IDNumbers& ids) {
if (!pair->second->data_.empty()) {
ids.resize(pair->second->data_.size() / sizeof(engine::idx_t));
memcpy((void*)(ids.data()), pair->second->data_.data(), pair->second->data_.size());
memcpy(ids.data(), pair->second->data_.data(), pair->second->data_.size());
}
}
......
......@@ -80,7 +80,8 @@ ExecutionEngineImpl::CreateVecIndex(const std::string& index_name) {
knowhere::VecIndexPtr index = vec_index_factory.CreateVecIndex(index_name, mode);
if (index == nullptr) {
std::string err_msg = "Invalid index type: " + index_name + " mode: " + std::to_string((int)mode);
std::string err_msg =
"Invalid index type: " + index_name + " mode: " + std::to_string(static_cast<int32_t>(mode));
LOG_ENGINE_ERROR_ << err_msg;
}
return index;
......@@ -228,8 +229,8 @@ ExecutionEngineImpl::CopyToGpu(uint64_t device_id) {
void
MapAndCopyResult(const knowhere::DatasetPtr& dataset, const std::vector<idx_t>& uids, int64_t nq, int64_t k,
float* distances, int64_t* labels) {
int64_t* res_ids = dataset->Get<int64_t*>(knowhere::meta::IDS);
float* res_dist = dataset->Get<float*>(knowhere::meta::DISTANCE);
auto res_ids = dataset->Get<int64_t*>(knowhere::meta::IDS);
auto res_dist = dataset->Get<float*>(knowhere::meta::DISTANCE);
memcpy(distances, res_dist, sizeof(float) * nq * k);
......@@ -319,11 +320,11 @@ ExecutionEngineImpl::Search(ExecutionEngineContext& context) {
return Status(SERVER_INVALID_DSL_PARAMETER, "Field: " + name + " is not existed");
}
auto field = field_visitor->GetField();
if (field->GetFtype() == (int)engine::DataType::VECTOR_FLOAT ||
field->GetFtype() == (int)engine::DataType::VECTOR_BINARY) {
if (field->GetFtype() == static_cast<snapshot::FTYPE_TYPE>(engine::DataType::VECTOR_FLOAT) ||
field->GetFtype() == static_cast<snapshot::FTYPE_TYPE>(engine::DataType::VECTOR_BINARY)) {
STATUS_CHECK(segment_ptr->GetVectorIndex(name, vec_index));
} else {
attr_type.insert(std::make_pair(name, (engine::DataType)field->GetFtype()));
attr_type.insert(std::make_pair(name, static_cast<engine::DataType>(field->GetFtype())));
}
}
......
......@@ -76,7 +76,7 @@ MemManagerImpl::ValidateChunk(int64_t collection_id, const DataChunkPtr& chunk)
size_t data_size = iter->second->data_.size();
snapshot::FieldPtr field = ss->GetField(name);
DataType ftype = static_cast<DataType>(field->GetFtype());
auto ftype = static_cast<DataType>(field->GetFtype());
std::string err_msg = "Illegal data size for chunk field: ";
switch (ftype) {
case DataType::BOOL:
......
......@@ -124,7 +124,7 @@ MemSegment::GetSingleEntitySize(int64_t& single_size) {
std::vector<std::string> field_names = ss->GetFieldNames();
for (auto& name : field_names) {
snapshot::FieldPtr field = ss->GetField(name);
DataType ftype = static_cast<DataType>(field->GetFtype());
auto ftype = static_cast<DataType>(field->GetFtype());
switch (ftype) {
case DataType::BOOL:
single_size += sizeof(bool);
......
......@@ -34,7 +34,7 @@ MergeManagerImpl::CreateStrategy(MergeStrategyType type, MergeStrategyPtr& strat
case MergeStrategyType::LAYERED:
case MergeStrategyType::ADAPTIVE:
default: {
std::string msg = "Unsupported merge strategy type: " + std::to_string((int32_t)type);
std::string msg = "Unsupported merge strategy type: " + std::to_string(static_cast<int32_t>(type));
LOG_ENGINE_ERROR_ << msg;
return Status(DB_ERROR, msg);
}
......
......@@ -79,8 +79,8 @@ MySQLConnectionPool::create() {
auto conn = new mysqlpp::Connection();
conn->set_option(new mysqlpp::ReconnectOption(true));
conn->set_option(new mysqlpp::ConnectTimeoutOption(5));
conn->connect(db_name_.empty() ? 0 : db_name_.c_str(), server_.empty() ? 0 : server_.c_str(),
user_.empty() ? 0 : user_.c_str(), password_.empty() ? 0 : password_.c_str(), port_);
conn->connect(db_name_.empty() ? nullptr : db_name_.c_str(), server_.empty() ? nullptr : server_.c_str(),
user_.empty() ? nullptr : user_.c_str(), password_.empty() ? nullptr : password_.c_str(), port_);
return conn;
} catch (const mysqlpp::ConnectionFailed& er) {
LOG_ENGINE_ERROR_ << "Failed to connect to database server"
......
......@@ -77,7 +77,7 @@ class Operations : public std::enable_shared_from_this<Operations> {
context_.lsn = lsn;
}
virtual Status
Status
CheckStale(const CheckStaleFunc& checker = nullptr) const;
virtual Status
DoCheckStale(ScopedSnapshotT& latest_snapshot) const;
......
......@@ -75,12 +75,10 @@ PartitionOperation::PreCheck() {
Status
PartitionOperation::DoExecute(StorePtr store) {
auto status = CheckStale();
if (!status.ok())
return status;
STATUS_CHECK(CheckStale());
resource_ = std::make_shared<Partition>(context_.name, GetStartedSS()->GetCollection()->GetID());
AddStep(*resource_, nullptr, false);
return status;
return Status::OK();
}
PartitionCommitOperation::PartitionCommitOperation(const OperationContext& context, ScopedSnapshotT prev_ss)
......
......@@ -152,8 +152,9 @@ SnapshotHolder::Add(StorePtr store, ID_TYPE id) {
}
active_[id] = ss;
if (active_.size() <= num_versions_)
if (active_.size() <= num_versions_) {
return status;
}
auto oldest_it = active_.find(min_id_);
oldest_ss = oldest_it->second;
......
......@@ -32,9 +32,7 @@ Snapshots::DropCollection(ID_TYPE collection_id, const LSN_TYPE& lsn) {
Status
Snapshots::DropCollection(const std::string& name, const LSN_TYPE& lsn) {
ScopedSnapshotT ss;
auto status = GetSnapshot(ss, name);
if (!status.ok())
return status;
STATUS_CHECK(GetSnapshot(ss, name));
return DoDropCollection(ss, lsn);
}
......@@ -56,25 +54,15 @@ Snapshots::DoDropCollection(ScopedSnapshotT& ss, const LSN_TYPE& lsn) {
Status
Snapshots::DropPartition(const ID_TYPE& collection_id, const ID_TYPE& partition_id, const LSN_TYPE& lsn) {
ScopedSnapshotT ss;
auto status = GetSnapshot(ss, collection_id);
if (!status.ok()) {
return status;
}
STATUS_CHECK(GetSnapshot(ss, collection_id));
PartitionContext context;
context.id = partition_id;
context.lsn = lsn;
auto op = std::make_shared<DropPartitionOperation>(context, ss);
status = op->Push();
if (!status.ok()) {
return status;
}
status = op->GetSnapshot(ss);
if (!status.ok()) {
return status;
}
STATUS_CHECK(op->Push());
STATUS_CHECK(op->GetSnapshot(ss));
return op->GetStatus();
}
......@@ -82,31 +70,22 @@ Snapshots::DropPartition(const ID_TYPE& collection_id, const ID_TYPE& partition_
Status
Snapshots::LoadSnapshot(StorePtr store, ScopedSnapshotT& ss, ID_TYPE collection_id, ID_TYPE id, bool scoped) {
SnapshotHolderPtr holder;
auto status = LoadHolder(store, collection_id, holder);
if (!status.ok())
return status;
status = holder->Load(store, ss, id, scoped);
return status;
STATUS_CHECK(LoadHolder(store, collection_id, holder));
return holder->Load(store, ss, id, scoped);
}
Status
Snapshots::GetSnapshot(ScopedSnapshotT& ss, ID_TYPE collection_id, ID_TYPE id, bool scoped) const {
SnapshotHolderPtr holder;
auto status = GetHolder(collection_id, holder);
if (!status.ok())
return status;
status = holder->Get(ss, id, scoped);
return status;
STATUS_CHECK(GetHolder(collection_id, holder));
return holder->Get(ss, id, scoped);
}
Status
Snapshots::GetSnapshot(ScopedSnapshotT& ss, const std::string& name, ID_TYPE id, bool scoped) const {
SnapshotHolderPtr holder;
auto status = GetHolder(name, holder);
if (!status.ok())
return status;
status = holder->Get(ss, id, scoped);
return status;
STATUS_CHECK(GetHolder(name, holder));
return holder->Get(ss, id, scoped);
}
Status
......
......@@ -140,7 +140,7 @@ json
TaskTableItem::Dump() const {
json ret{
{"id", id},
{"task", (int64_t)task.get()},
{"task", reinterpret_cast<int64_t>(task.get())},
{"state", ToString(state)},
{"timestamp", timestamp.Dump()},
};
......@@ -162,18 +162,21 @@ TaskTable::PickToLoad(uint64_t limit) {
uint64_t available_begin = table_.front() + 1;
for (uint64_t i = 0, loaded_count = 0, pick_count = 0; i < table_.size() && pick_count < limit; ++i) {
auto index = available_begin + i;
if (not table_[index])
if (table_[index] == nullptr) {
break;
if (index % table_.capacity() == table_.rear())
}
if (index % table_.capacity() == table_.rear()) {
break;
}
if (not cross && table_[index]->IsFinish()) {
table_.set_front(index);
table_[index]->SetFinished(FinishedTask::Create());
} else if (table_[index]->state == TaskTableItemState::LOADED) {
cross = true;
++loaded_count;
if (loaded_count > 2)
if (loaded_count > 2) {
return std::vector<uint64_t>();
}
} else if (table_[index]->state == TaskTableItemState::START) {
auto task = table_[index]->task;
......
......@@ -24,8 +24,9 @@ get_neighbours(const ResourcePtr& self) {
std::vector<ResourcePtr> neighbours;
for (auto& neighbour_node : self->GetNeighbours()) {
auto node = neighbour_node.neighbour_node;
if (not node)
if (not node) {
continue;
}
auto resource = std::static_pointer_cast<Resource>(node);
// if (not resource->HasExecutor()) continue;
......
......@@ -29,7 +29,7 @@ WhichFieldsToBuild(const engine::snapshot::ScopedSnapshotT& snapshot, engine::sn
engine::TargetFields structured_fields;
for (auto& field_name : field_names) {
auto field = snapshot->GetField(field_name);
engine::DataType ftype = static_cast<engine::DataType>(field->GetFtype());
auto ftype = static_cast<engine::DataType>(field->GetFtype());
bool is_vector = (ftype == engine::DataType::VECTOR_FLOAT || ftype == engine::DataType::VECTOR_BINARY);
auto elements = snapshot->GetFieldElementsByField(field_name);
for (auto& element : elements) {
......
......@@ -56,7 +56,7 @@ Job::TaskDone(Task* task) {
LOG_SERVER_DEBUG_ << LogOut("scheduler job [%ld] task %s finish", id(), task_desc.c_str());
std::unique_lock<std::mutex> lock(mutex_);
for (JobTasks::iterator iter = tasks_.begin(); iter != tasks_.end(); ++iter) {
for (auto iter = tasks_.begin(); iter != tasks_.end(); ++iter) {
if (task == (*iter).get()) {
tasks_.erase(iter);
break;
......
......@@ -116,8 +116,9 @@ Resource::pick_task_load() {
auto indexes = task_table_.PickToLoad(10);
for (auto index : indexes) {
// try to set one task loading, then return
if (task_table_.Load(index))
if (task_table_.Load(index)) {
return task_table_.at(index);
}
// else try next
}
return nullptr;
......
......@@ -26,8 +26,9 @@ BuildIndexPass::Init() {
bool
BuildIndexPass::Run(const TaskPtr& task) {
if (task->Type() != TaskType::BuildIndexTask)
if (task->Type() != TaskType::BuildIndexTask) {
return false;
}
ResourcePtr res_ptr;
if (!gpu_enable_) {
......
......@@ -49,7 +49,7 @@ FaissFlatPass::Run(const TaskPtr& task) {
if (!gpu_enable_) {
LOG_SERVER_DEBUG_ << LogOut("FaissFlatPass: gpu disable, specify cpu to search!");
res_ptr = ResMgrInst::GetInstance()->GetResource("cpu");
} else if (search_task->nq() < (int64_t)threshold_) {
} else if (search_task->nq() < threshold_) {
LOG_SERVER_DEBUG_ << LogOut("FaissFlatPass: nq < gpu_search_threshold, specify cpu to search!");
res_ptr = ResMgrInst::GetInstance()->GetResource("cpu");
} else {
......
......@@ -50,7 +50,7 @@ FaissIVFFlatPass::Run(const TaskPtr& task) {
if (!gpu_enable_) {
LOG_SERVER_DEBUG_ << LogOut("FaissIVFFlatPass: gpu disable, specify cpu to search!");
res_ptr = ResMgrInst::GetInstance()->GetResource("cpu");
} else if (search_task->nq() < (uint64_t)threshold_) {
} else if (search_task->nq() < threshold_) {
LOG_SERVER_DEBUG_ << LogOut("FaissIVFFlatPass: nq < gpu_search_threshold, specify cpu to search!");
res_ptr = ResMgrInst::GetInstance()->GetResource("cpu");
} else {
......
......@@ -52,7 +52,7 @@ FaissIVFPQPass::Run(const TaskPtr& task) {
if (!gpu_enable_) {
LOG_SERVER_DEBUG_ << LogOut("FaissIVFPQPass: gpu disable, specify cpu to search!");
res_ptr = ResMgrInst::GetInstance()->GetResource("cpu");
} else if (search_task->nq() < (uint64_t)threshold_) {
} else if (search_task->nq() < threshold_) {
LOG_SERVER_DEBUG_ << LogOut("FaissIVFPQPass: nq < gpu_search_threshold, specify cpu to search!");
res_ptr = ResMgrInst::GetInstance()->GetResource("cpu");
} else {
......
......@@ -50,7 +50,7 @@ FaissIVFSQ8HPass::Run(const TaskPtr& task) {
LOG_SERVER_ERROR_ << LogOut("FaissIVFSQ8HPass: SQ8H index only works with gpu enabled!");
return false;
}
if (search_task->nq() < (uint64_t)threshold_) {
if (search_task->nq() < threshold_) {
LOG_SERVER_DEBUG_ << LogOut("FaissIVFSQ8HPass: nq < gpu_search_threshold, specify cpu to search!");
res_ptr = ResMgrInst::GetInstance()->GetResource("cpu");
} else {
......
......@@ -50,7 +50,7 @@ FaissIVFSQ8Pass::Run(const TaskPtr& task) {
if (!gpu_enable_) {
LOG_SERVER_DEBUG_ << LogOut("FaissIVFSQ8Pass: gpu disable, specify cpu to search!");
res_ptr = ResMgrInst::GetInstance()->GetResource("cpu");
} else if (search_task->nq() < (uint64_t)threshold_) {
} else if (search_task->nq() < threshold_) {
LOG_SERVER_DEBUG_ << LogOut("FaissIVFSQ8Pass: nq < gpu_search_threshold, specify cpu to search!");
res_ptr = ResMgrInst::GetInstance()->GetResource("cpu");
} else {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册