|
5 | 5 | #include <chrono> |
6 | 6 | #include <grpcpp/grpcpp.h> |
7 | 7 | #include <type_traits> |
| 8 | +#include <unordered_map> |
| 9 | +#include <utility> |
8 | 10 |
|
9 | 11 | #include "kv_cache_manager/client/src/internal/util/debug_string_util.h" |
10 | 12 | #include "kv_cache_manager/common/logger.h" |
@@ -78,6 +80,39 @@ kv_cache_manager::Locations GenLocations( |
78 | 80 | return locations; |
79 | 81 | } |
80 | 82 |
|
| 83 | +kv_cache_manager::CacheMetaDetails GenCacheMetaDetails( |
| 84 | + const google::protobuf::RepeatedPtrField<::kv_cache_manager::proto::meta::CacheMetaDetailItem> |
| 85 | + &proto_cache_meta_details) { |
| 86 | + kv_cache_manager::CacheMetaDetails cache_meta_details; |
| 87 | + cache_meta_details.reserve(proto_cache_meta_details.size()); |
| 88 | + for (const auto &proto_item : proto_cache_meta_details) { |
| 89 | + kv_cache_manager::CacheMetaDetailItem item; |
| 90 | + item.request_index = proto_item.request_index(); |
| 91 | + item.block_key = proto_item.block_key(); |
| 92 | + item.prev_block_key = proto_item.prev_block_key(); |
| 93 | + for (const auto &[property_name, property_value] : proto_item.properties()) { |
| 94 | + item.properties[property_name] = property_value; |
| 95 | + } |
| 96 | + item.locations.reserve(proto_item.locations_size()); |
| 97 | + for (const auto &proto_location : proto_item.locations()) { |
| 98 | + kv_cache_manager::CacheMetaLocationDetail location; |
| 99 | + location.location_id = proto_location.location_id(); |
| 100 | + location.status = |
| 101 | + static_cast<kv_cache_manager::CacheMetaLocationStatus>(proto_location.status()); |
| 102 | + location.storage_type = static_cast<int32_t>(proto_location.type()); |
| 103 | + location.spec_size = proto_location.spec_size(); |
| 104 | + location.create_time = proto_location.create_time(); |
| 105 | + location.location_specs.reserve(proto_location.location_specs_size()); |
| 106 | + for (const auto &proto_spec : proto_location.location_specs()) { |
| 107 | + location.location_specs.push_back({proto_spec.name(), proto_spec.uri()}); |
| 108 | + } |
| 109 | + item.locations.push_back(std::move(location)); |
| 110 | + } |
| 111 | + cache_meta_details.push_back(std::move(item)); |
| 112 | + } |
| 113 | + return cache_meta_details; |
| 114 | +} |
| 115 | + |
81 | 116 | kv_cache_manager::ClientErrorCode |
82 | 117 | GenCacheLocation(const kv_cache_manager::Locations &locations, |
83 | 118 | google::protobuf::RepeatedPtrField<::kv_cache_manager::proto::meta::CacheLocation> *proto_locations) { |
@@ -322,6 +357,27 @@ std::pair<ClientErrorCode, Metas> GrpcStub::GetCacheMeta(const std::string &trac |
322 | 357 | return {ER_OK, {locations, metas}}; |
323 | 358 | } |
324 | 359 |
|
| 360 | +std::pair<ClientErrorCode, CacheMetaDetails> GrpcStub::GetCacheMetaDetail(const std::string &trace_id, |
| 361 | + const std::string &instance_id, |
| 362 | + const KeyVector &keys, |
| 363 | + const TokenIdsVector &tokens, |
| 364 | + const BlockMask &block_mask, |
| 365 | + int32_t detail_level) { |
| 366 | + auto stub = GET_AND_CHECK_STUB_WITH_TYPE(); |
| 367 | + proto::meta::GetCacheMetaDetailRequest request; |
| 368 | + SetKeysAndTokens(request, trace_id, instance_id, keys, tokens); |
| 369 | + ProtoConvert::BlockMaskToProto(block_mask, request.mutable_block_mask()); |
| 370 | + request.set_detail_level(detail_level); |
| 371 | + grpc::ClientContext context; |
| 372 | + proto::meta::GetCacheMetaDetailResponse response; |
| 373 | + auto grpc_status = stub->GetCacheMetaDetail(&context, request, &response); |
| 374 | + CHECK_GRPC_STATUS_WITH_TYPE(grpc_status); |
| 375 | + CHECK_COMMON_HEADER_WITH_TYPE(response); |
| 376 | + auto cache_meta_details = GenCacheMetaDetails(response.items()); |
| 377 | + KVCM_LOG_DEBUG("get cache meta detail success, items: %lu", cache_meta_details.size()); |
| 378 | + return {ER_OK, cache_meta_details}; |
| 379 | +} |
| 380 | + |
325 | 381 | std::pair<ClientErrorCode, Locations> GrpcStub::GetCacheLocation(const std::string &trace_id, |
326 | 382 | const std::string &instance_id, |
327 | 383 | QueryType query_type, |
|
0 commit comments