Skip to content

Commit 22974bc

Browse files
authored
Add BatchDescribeCollections/DescribeReplicas interfaces (milvus-io#473)
Signed-off-by: yhmo <yihua.mo@zilliz.com>
1 parent b20c729 commit 22974bc

19 files changed

Lines changed: 1063 additions & 18 deletions

scripts/build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ if [[ "${BUILD_FROM_CONAN}" == "ON" ]]; then
171171
-s:b build_type=${BUILD_TYPE} \
172172
-s:b compiler.cppstd=${BUILD_CPPSTD} \
173173
-o "&:with_tests=${CONAN_WITH_TESTS}" \
174+
-c tools.build:jobs=${JOBS} \
174175
--build=missing || exit 1
175176

176177
TOOLCHAIN_FILE="${PWD}/build/${BUILD_TYPE}/generators/conan_toolchain.cmake"

src/impl/MilvusClientV2Impl.cpp

Lines changed: 138 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,41 @@
3434
#include "utils/TypeUtils.h"
3535

3636
namespace milvus {
37+
namespace {
38+
39+
Status
40+
ConvertDescribeCollectionResponse(const proto::milvus::DescribeCollectionResponse& rpc_response,
41+
CollectionDesc& collection_desc) {
42+
const auto& status = rpc_response.status();
43+
auto legacy_code = status.error_code();
44+
if (status.code() != 0 || legacy_code != proto::common::ErrorCode::Success) {
45+
return {StatusCode::SERVER_FAILED, status.reason(), 0, status.code(), legacy_code};
46+
}
47+
48+
CollectionSchema schema;
49+
ConvertCollectionSchema(rpc_response.schema(), schema);
50+
schema.SetShardsNum(rpc_response.shards_num());
51+
52+
collection_desc.SetSchema(std::move(schema));
53+
collection_desc.SetID(rpc_response.collectionid());
54+
collection_desc.SetCreatedTime(rpc_response.created_timestamp());
55+
56+
std::vector<std::string> aliases;
57+
aliases.reserve(rpc_response.aliases_size());
58+
aliases.insert(aliases.end(), rpc_response.aliases().begin(), rpc_response.aliases().end());
59+
collection_desc.SetAlias(std::move(aliases));
60+
61+
std::unordered_map<std::string, std::string> properties;
62+
for (int i = 0; i < rpc_response.properties_size(); i++) {
63+
const auto& prop = rpc_response.properties(i);
64+
properties[prop.key()] = prop.value();
65+
}
66+
collection_desc.SetProperties(std::move(properties));
67+
68+
return Status::OK();
69+
}
70+
71+
} // namespace
3772

3873
std::shared_ptr<MilvusClientV2>
3974
MilvusClientV2::Create() {
@@ -339,26 +374,11 @@ MilvusClientV2Impl::DescribeCollection(const DescribeCollectionRequest& request,
339374
};
340375

341376
auto post = [&response](const proto::milvus::DescribeCollectionResponse& rpc_response) {
342-
CollectionSchema schema;
343-
ConvertCollectionSchema(rpc_response.schema(), schema);
344-
schema.SetShardsNum(rpc_response.shards_num());
345-
346377
CollectionDesc collection_desc;
347-
collection_desc.SetSchema(std::move(schema));
348-
collection_desc.SetID(rpc_response.collectionid());
349-
collection_desc.SetCreatedTime(rpc_response.created_timestamp());
350-
351-
std::vector<std::string> aliases;
352-
aliases.reserve(rpc_response.aliases_size());
353-
aliases.insert(aliases.end(), rpc_response.aliases().begin(), rpc_response.aliases().end());
354-
collection_desc.SetAlias(std::move(aliases));
355-
356-
std::unordered_map<std::string, std::string> properties;
357-
for (int i = 0; i < rpc_response.properties_size(); i++) {
358-
const auto& prop = rpc_response.properties(i);
359-
properties[prop.key()] = prop.value();
378+
auto status = ConvertDescribeCollectionResponse(rpc_response, collection_desc);
379+
if (!status.IsOk()) {
380+
return status;
360381
}
361-
collection_desc.SetProperties(std::move(properties));
362382

363383
response.SetDesc(std::move(collection_desc));
364384
return Status::OK();
@@ -368,6 +388,106 @@ MilvusClientV2Impl::DescribeCollection(const DescribeCollectionRequest& request,
368388
pre, &MilvusConnection::DescribeCollection, post);
369389
}
370390

391+
Status
392+
MilvusClientV2Impl::BatchDescribeCollections(const BatchDescribeCollectionsRequest& request,
393+
BatchDescribeCollectionsResponse& response) {
394+
auto pre = [&request](proto::milvus::BatchDescribeCollectionRequest& rpc_request) {
395+
rpc_request.set_db_name(request.DatabaseName());
396+
for (const auto& collection_name : request.CollectionNames()) {
397+
rpc_request.add_collection_name(collection_name);
398+
}
399+
for (auto collection_id : request.CollectionIDs()) {
400+
rpc_request.add_collectionid(collection_id);
401+
}
402+
return Status::OK();
403+
};
404+
405+
auto post = [&response](const proto::milvus::BatchDescribeCollectionResponse& rpc_response) {
406+
std::vector<CollectionDesc> descs;
407+
descs.reserve(rpc_response.responses_size());
408+
for (const auto& rpc_desc : rpc_response.responses()) {
409+
CollectionDesc desc;
410+
auto status = ConvertDescribeCollectionResponse(rpc_desc, desc);
411+
if (!status.IsOk()) {
412+
return status;
413+
}
414+
descs.emplace_back(std::move(desc));
415+
}
416+
417+
response.SetDescs(std::move(descs));
418+
return Status::OK();
419+
};
420+
421+
return connection_.Invoke<proto::milvus::BatchDescribeCollectionRequest,
422+
proto::milvus::BatchDescribeCollectionResponse>(
423+
pre, &MilvusConnection::BatchDescribeCollection, post);
424+
}
425+
426+
Status
427+
MilvusClientV2Impl::DescribeReplicas(const DescribeReplicasRequest& request, DescribeReplicasResponse& response) {
428+
if (request.CollectionName().empty()) {
429+
return {StatusCode::INVALID_ARGUMENT, "Collection name cannot be empty"};
430+
}
431+
432+
auto pre = [&request](proto::milvus::GetReplicasRequest& rpc_request) {
433+
rpc_request.set_db_name(request.DatabaseName());
434+
rpc_request.set_collection_name(request.CollectionName());
435+
rpc_request.set_with_shard_nodes(true);
436+
return Status::OK();
437+
};
438+
439+
auto post = [&response](const proto::milvus::GetReplicasResponse& rpc_response) {
440+
std::vector<ReplicaInfo> replicas;
441+
replicas.reserve(rpc_response.replicas_size());
442+
for (const auto& rpc_replica : rpc_response.replicas()) {
443+
ReplicaInfo replica;
444+
replica.SetReplicaID(rpc_replica.replicaid());
445+
replica.SetCollectionID(rpc_replica.collectionid());
446+
447+
std::vector<int64_t> partition_ids;
448+
partition_ids.reserve(rpc_replica.partition_ids_size());
449+
partition_ids.insert(partition_ids.end(), rpc_replica.partition_ids().begin(), rpc_replica.partition_ids().end());
450+
replica.SetPartitionIDs(std::move(partition_ids));
451+
452+
std::vector<int64_t> node_ids;
453+
node_ids.reserve(rpc_replica.node_ids_size());
454+
node_ids.insert(node_ids.end(), rpc_replica.node_ids().begin(), rpc_replica.node_ids().end());
455+
replica.SetNodeIDs(std::move(node_ids));
456+
457+
replica.SetResourceGroupName(rpc_replica.resource_group_name());
458+
459+
std::unordered_map<std::string, int32_t> num_outbound_node;
460+
num_outbound_node.insert(rpc_replica.num_outbound_node().begin(), rpc_replica.num_outbound_node().end());
461+
replica.SetNumOutboundNode(std::move(num_outbound_node));
462+
463+
std::vector<ShardReplica> shard_replicas;
464+
shard_replicas.reserve(rpc_replica.shard_replicas_size());
465+
for (const auto& rpc_shard : rpc_replica.shard_replicas()) {
466+
ShardReplica shard_replica;
467+
shard_replica.SetLeaderID(rpc_shard.leaderid());
468+
shard_replica.SetLeaderAddress(rpc_shard.leader_addr());
469+
shard_replica.SetChannelName(rpc_shard.dm_channel_name());
470+
471+
std::vector<int64_t> shard_node_ids;
472+
shard_node_ids.reserve(rpc_shard.node_ids_size());
473+
shard_node_ids.insert(shard_node_ids.end(), rpc_shard.node_ids().begin(), rpc_shard.node_ids().end());
474+
shard_replica.SetNodeIDs(std::move(shard_node_ids));
475+
476+
shard_replicas.emplace_back(std::move(shard_replica));
477+
}
478+
replica.SetShardReplicas(std::move(shard_replicas));
479+
480+
replicas.emplace_back(std::move(replica));
481+
}
482+
483+
response.SetReplicas(std::move(replicas));
484+
return Status::OK();
485+
};
486+
487+
return connection_.Invoke<proto::milvus::GetReplicasRequest, proto::milvus::GetReplicasResponse>(
488+
pre, &MilvusConnection::GetReplicas, post);
489+
}
490+
371491
Status
372492
MilvusClientV2Impl::RenameCollection(const RenameCollectionRequest& request) {
373493
auto pre = [&request](proto::milvus::RenameCollectionRequest& rpc_request) {

src/impl/MilvusClientV2Impl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ class MilvusClientV2Impl : public MilvusClientV2 {
7575
Status
7676
DescribeCollection(const DescribeCollectionRequest& request, DescribeCollectionResponse& response) final;
7777

78+
Status
79+
BatchDescribeCollections(const BatchDescribeCollectionsRequest& request, BatchDescribeCollectionsResponse& response) final;
80+
81+
Status
82+
DescribeReplicas(const DescribeReplicasRequest& request, DescribeReplicasResponse& response) final;
83+
7884
Status
7985
RenameCollection(const RenameCollectionRequest& request) final;
8086

src/impl/MilvusConnection.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,19 @@ MilvusConnection::DescribeCollection(const proto::milvus::DescribeCollectionRequ
277277
return grpcCall("DescribeCollection", &Stub::DescribeCollection, request, response, options);
278278
}
279279

280+
Status
281+
MilvusConnection::BatchDescribeCollection(const proto::milvus::BatchDescribeCollectionRequest& request,
282+
proto::milvus::BatchDescribeCollectionResponse& response,
283+
const GrpcContextOptions& options) {
284+
return grpcCall("BatchDescribeCollection", &Stub::BatchDescribeCollection, request, response, options);
285+
}
286+
287+
Status
288+
MilvusConnection::GetReplicas(const proto::milvus::GetReplicasRequest& request,
289+
proto::milvus::GetReplicasResponse& response, const GrpcContextOptions& options) {
290+
return grpcCall("GetReplicas", &Stub::GetReplicas, request, response, options);
291+
}
292+
280293
Status
281294
MilvusConnection::RenameCollection(const proto::milvus::RenameCollectionRequest& request,
282295
proto::common::Status& response, const GrpcContextOptions& options) {

src/impl/MilvusConnection.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,15 @@ class MilvusConnection {
121121
DescribeCollection(const proto::milvus::DescribeCollectionRequest& request,
122122
proto::milvus::DescribeCollectionResponse& response, const GrpcContextOptions& options);
123123

124+
Status
125+
BatchDescribeCollection(const proto::milvus::BatchDescribeCollectionRequest& request,
126+
proto::milvus::BatchDescribeCollectionResponse& response,
127+
const GrpcContextOptions& options);
128+
129+
Status
130+
GetReplicas(const proto::milvus::GetReplicasRequest& request, proto::milvus::GetReplicasResponse& response,
131+
const GrpcContextOptions& options);
132+
124133
Status
125134
RenameCollection(const proto::milvus::RenameCollectionRequest& request, proto::common::Status& response,
126135
const GrpcContextOptions& options);
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// Licensed to the LF AI & Data foundation under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
#include "milvus/request/collection/BatchDescribeCollectionsRequest.h"
18+
19+
#include <utility>
20+
21+
namespace milvus {
22+
23+
const std::string&
24+
BatchDescribeCollectionsRequest::DatabaseName() const {
25+
return db_name_;
26+
}
27+
28+
void
29+
BatchDescribeCollectionsRequest::SetDatabaseName(const std::string& db_name) {
30+
db_name_ = db_name;
31+
}
32+
33+
BatchDescribeCollectionsRequest&
34+
BatchDescribeCollectionsRequest::WithDatabaseName(const std::string& db_name) {
35+
SetDatabaseName(db_name);
36+
return *this;
37+
}
38+
39+
const std::vector<std::string>&
40+
BatchDescribeCollectionsRequest::CollectionNames() const {
41+
return collection_names_;
42+
}
43+
44+
void
45+
BatchDescribeCollectionsRequest::SetCollectionNames(std::vector<std::string>&& collection_names) {
46+
collection_names_ = std::move(collection_names);
47+
}
48+
49+
BatchDescribeCollectionsRequest&
50+
BatchDescribeCollectionsRequest::WithCollectionNames(std::vector<std::string>&& collection_names) {
51+
SetCollectionNames(std::move(collection_names));
52+
return *this;
53+
}
54+
55+
BatchDescribeCollectionsRequest&
56+
BatchDescribeCollectionsRequest::AddCollectionName(const std::string& collection_name) {
57+
collection_names_.push_back(collection_name);
58+
return *this;
59+
}
60+
61+
const std::vector<int64_t>&
62+
BatchDescribeCollectionsRequest::CollectionIDs() const {
63+
return collection_ids_;
64+
}
65+
66+
void
67+
BatchDescribeCollectionsRequest::SetCollectionIDs(std::vector<int64_t>&& collection_ids) {
68+
collection_ids_ = std::move(collection_ids);
69+
}
70+
71+
BatchDescribeCollectionsRequest&
72+
BatchDescribeCollectionsRequest::WithCollectionIDs(std::vector<int64_t>&& collection_ids) {
73+
SetCollectionIDs(std::move(collection_ids));
74+
return *this;
75+
}
76+
77+
BatchDescribeCollectionsRequest&
78+
BatchDescribeCollectionsRequest::AddCollectionID(int64_t collection_id) {
79+
collection_ids_.push_back(collection_id);
80+
return *this;
81+
}
82+
83+
} // namespace milvus
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Licensed to the LF AI & Data foundation under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
#include "milvus/response/collection/BatchDescribeCollectionsResponse.h"
18+
19+
#include <utility>
20+
21+
namespace milvus {
22+
23+
const std::vector<CollectionDesc>&
24+
BatchDescribeCollectionsResponse::Descs() const {
25+
return descs_;
26+
}
27+
28+
void
29+
BatchDescribeCollectionsResponse::SetDescs(std::vector<CollectionDesc>&& descs) {
30+
descs_ = std::move(descs);
31+
}
32+
33+
} // namespace milvus
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Licensed to the LF AI & Data foundation under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
#include "milvus/response/collection/DescribeReplicasResponse.h"
18+
19+
#include <utility>
20+
21+
namespace milvus {
22+
23+
const std::vector<ReplicaInfo>&
24+
DescribeReplicasResponse::Replicas() const {
25+
return replicas_;
26+
}
27+
28+
void
29+
DescribeReplicasResponse::SetReplicas(std::vector<ReplicaInfo>&& replicas) {
30+
replicas_ = std::move(replicas);
31+
}
32+
33+
} // namespace milvus

0 commit comments

Comments
 (0)