Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7564558

Browse files
committedJan 13, 2024
refactory: improvments of typo and some hotfix
Signed-off-by: Ji Bin <matrixji@live.com>
1 parent 0141b50 commit 7564558

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+204
-210
lines changed
 

‎src/impl/MilvusClientImpl.cpp

+18-17
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ MilvusClientImpl::LoadCollection(const std::string& collection_name, int replica
141141
};
142142

143143
auto wait_for_status = [this, &collection_name, &progress_monitor](const proto::common::Status&) {
144-
return waitForStatus(
144+
return WaitForStatus(
145145
[&collection_name, this](Progress& progress) -> Status {
146146
CollectionsInfo collections_info;
147147
auto collection_names = std::vector<std::string>{collection_name};
@@ -259,7 +259,7 @@ MilvusClientImpl::ShowCollections(const std::vector<std::string>& collection_nam
259259
};
260260

261261
auto post = [&collections_info](const proto::milvus::ShowCollectionsResponse& response) {
262-
for (size_t i = 0; i < response.collection_ids_size(); i++) {
262+
for (int i = 0; i < response.collection_ids_size(); i++) {
263263
auto inmemory_percentage = 0;
264264
if (response.inmemory_percentages_size() > i) {
265265
inmemory_percentage = response.inmemory_percentages(i);
@@ -331,7 +331,7 @@ MilvusClientImpl::LoadPartitions(const std::string& collection_name, const std::
331331
};
332332

333333
auto wait_for_status = [this, &collection_name, &partition_names, &progress_monitor](const proto::common::Status&) {
334-
return waitForStatus(
334+
return WaitForStatus(
335335
[&collection_name, &partition_names, this](Progress& progress) -> Status {
336336
PartitionsInfo partitions_info;
337337
auto status = ShowPartitions(collection_name, partition_names, partitions_info);
@@ -422,7 +422,7 @@ MilvusClientImpl::ShowPartitions(const std::string& collection_name, const std::
422422
if (count > 0) {
423423
partitions_info.reserve(count);
424424
}
425-
for (size_t i = 0; i < count; ++i) {
425+
for (int i = 0; i < count; ++i) {
426426
partitions_info.emplace_back(response.partition_names(i), response.partitionids(i),
427427
response.created_timestamps(i), response.inmemory_percentages(i));
428428
}
@@ -499,7 +499,7 @@ MilvusClientImpl::CreateIndex(const std::string& collection_name, const IndexDes
499499
};
500500

501501
auto wait_for_status = [&collection_name, &index_desc, &progress_monitor, this](const proto::common::Status&) {
502-
return waitForStatus(
502+
return WaitForStatus(
503503
[&collection_name, &index_desc, this](Progress& progress) -> Status {
504504
IndexState index_state;
505505
auto status = GetIndexState(collection_name, index_desc.FieldName(), index_state);
@@ -539,13 +539,13 @@ MilvusClientImpl::DescribeIndex(const std::string& collection_name, const std::s
539539

540540
auto post = [&index_desc](const proto::milvus::DescribeIndexResponse& response) {
541541
auto count = response.index_descriptions_size();
542-
for (size_t i = 0; i < count; ++i) {
542+
for (int i = 0; i < count; ++i) {
543543
auto& field_name = response.index_descriptions(i).field_name();
544544
auto& index_name = response.index_descriptions(i).index_name();
545545
index_desc.SetFieldName(field_name);
546546
index_desc.SetIndexName(index_name);
547547
auto index_params_size = response.index_descriptions(i).params_size();
548-
for (size_t j = 0; j < index_params_size; ++j) {
548+
for (int j = 0; j < index_params_size; ++j) {
549549
const auto& key = response.index_descriptions(i).params(j).key();
550550
const auto& value = response.index_descriptions(i).params(j).value();
551551
if (key == milvus::KeyIndexType()) {
@@ -759,19 +759,20 @@ MilvusClientImpl::Search(const SearchArguments& arguments, SearchResults& result
759759
const auto& scores = result_data.scores();
760760
const auto& fields_data = result_data.fields_data();
761761
auto num_of_queries = result_data.num_queries();
762-
std::vector<int64_t> topks(num_of_queries, result_data.top_k());
762+
std::vector<int> topks{};
763+
topks.reserve(result_data.topks_size());
763764
for (int i = 0; i < result_data.topks_size(); ++i) {
764-
topks[i] = result_data.topks(i);
765+
topks.emplace_back(result_data.topks(i));
765766
}
766767
std::vector<SingleResult> single_results;
767768
single_results.reserve(num_of_queries);
768-
size_t offset{0};
769-
for (int64_t i = 0; i < num_of_queries; ++i) {
769+
int offset{0};
770+
for (int i = 0; i < num_of_queries; ++i) {
770771
std::vector<float> item_scores;
771772
std::vector<FieldDataPtr> item_field_data;
772773
auto item_topk = topks[i];
773774
item_scores.reserve(item_topk);
774-
for (int64_t j = 0; j < item_topk; ++j) {
775+
for (int j = 0; j < item_topk; ++j) {
775776
item_scores.emplace_back(scores.at(offset + j));
776777
}
777778
item_field_data.reserve(fields_data.size());
@@ -842,7 +843,7 @@ MilvusClientImpl::CalcDistance(const CalcDistanceArguments& arguments, DistanceA
842843
}
843844

844845
// suppose vectors is not empty, already checked by Validate()
845-
data_array->set_dim(vectors[0].size());
846+
data_array->set_dim(static_cast<int>(vectors[0].size()));
846847
} else {
847848
auto data_ptr = std::static_pointer_cast<BinaryVecFieldData>(arg_vectors);
848849
auto& str = *data_array->mutable_binary_vector();
@@ -853,7 +854,7 @@ MilvusClientImpl::CalcDistance(const CalcDistanceArguments& arguments, DistanceA
853854
for (auto& vector : vectors) {
854855
str.append(vector);
855856
}
856-
data_array->set_dim(dimensions);
857+
data_array->set_dim(static_cast<int>(dimensions));
857858
}
858859

859860
} else if (arg_vectors->Type() == DataType::INT64) {
@@ -960,7 +961,7 @@ MilvusClientImpl::Flush(const std::vector<std::string>& collection_names, const
960961
return Status::OK();
961962
}
962963

963-
return waitForStatus(
964+
return WaitForStatus(
964965
[&segment_count, &flush_segments, &finished_count, this](Progress& p) -> Status {
965966
p.total_ = segment_count;
966967

@@ -1117,7 +1118,7 @@ MilvusClientImpl::ManualCompaction(const std::string& collection_name, uint64_t
11171118
return status;
11181119
}
11191120

1120-
auto pre = [&collection_name, &travel_timestamp, &collection_desc]() {
1121+
auto pre = [&travel_timestamp, &collection_desc]() {
11211122
proto::milvus::ManualCompactionRequest rpc_request;
11221123
rpc_request.set_collectionid(collection_desc.ID());
11231124
rpc_request.set_timetravel(travel_timestamp);
@@ -1223,7 +1224,7 @@ MilvusClientImpl::ListCredUsers(std::vector<std::string>& users) {
12231224
}
12241225

12251226
Status
1226-
MilvusClientImpl::waitForStatus(std::function<Status(Progress&)> query_function,
1227+
MilvusClientImpl::WaitForStatus(const std::function<Status(Progress&)>& query_function,
12271228
const ProgressMonitor& progress_monitor) {
12281229
// no need to check
12291230
if (progress_monitor.CheckTimeout() == 0) {

‎src/impl/MilvusClientImpl.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -186,16 +186,16 @@ class MilvusClientImpl : public MilvusClient {
186186
* @param [in] progress_monitor timeout setting for waiting progress
187187
* @return Status, the final status
188188
*/
189-
Status
190-
waitForStatus(std::function<Status(Progress&)> query_function, const ProgressMonitor& progress_monitor);
189+
static Status
190+
WaitForStatus(const std::function<Status(Progress&)>& query_function, const ProgressMonitor& progress_monitor);
191191

192192
/**
193193
* @brief template for public api call
194194
* validate -> pre -> rpc -> wait_for_status -> post
195195
*/
196196
template <typename Request, typename Response>
197197
Status
198-
apiHandler(std::function<Status(void)> validate, std::function<Request(void)> pre,
198+
apiHandler(const std::function<Status(void)>& validate, std::function<Request(void)> pre,
199199
Status (MilvusConnection::*rpc)(const Request&, Response&, const GrpcOpts&),
200200
std::function<Status(const Response&)> wait_for_status, std::function<void(const Response&)> post,
201201
const GrpcOpts& options = GrpcOpts{}) {
@@ -215,7 +215,7 @@ class MilvusClientImpl : public MilvusClient {
215215
auto status = std::bind(rpc, connection_.get(), std::placeholders::_1, std::placeholders::_2,
216216
std::placeholders::_3)(rpc_request, rpc_response, options);
217217
if (!status.IsOk()) {
218-
// resp's status already checked in connection class
218+
// response's status already checked in connection class
219219
return status;
220220
}
221221

0 commit comments

Comments
 (0)
Please sign in to comment.