-
Notifications
You must be signed in to change notification settings - Fork 54
[manager/service/client] add cache meta detail API #225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,8 @@ | |
| #include <chrono> | ||
| #include <grpcpp/grpcpp.h> | ||
| #include <type_traits> | ||
| #include <unordered_map> | ||
| #include <utility> | ||
|
|
||
| #include "kv_cache_manager/client/src/internal/util/debug_string_util.h" | ||
| #include "kv_cache_manager/common/logger.h" | ||
|
|
@@ -63,6 +65,8 @@ | |
|
|
||
| namespace { | ||
|
|
||
| kv_cache_manager::ClientErrorCode ToClientError(kv_cache_manager::proto::meta::ErrorCode service_error); | ||
|
|
||
| kv_cache_manager::Locations GenLocations( | ||
| const google::protobuf::RepeatedPtrField<::kv_cache_manager::proto::meta::CacheLocation> &proto_locations) { | ||
| kv_cache_manager::Locations locations; | ||
|
|
@@ -78,6 +82,42 @@ kv_cache_manager::Locations GenLocations( | |
| return locations; | ||
| } | ||
|
|
||
| kv_cache_manager::CacheMetaDetails | ||
| GenCacheMetaDetails(const google::protobuf::RepeatedPtrField<::kv_cache_manager::proto::meta::CacheMetaDetailItem> | ||
| &proto_cache_meta_details) { | ||
| kv_cache_manager::CacheMetaDetails cache_meta_details; | ||
| cache_meta_details.reserve(proto_cache_meta_details.size()); | ||
| for (const auto &proto_item : proto_cache_meta_details) { | ||
| kv_cache_manager::CacheMetaDetailItem item; | ||
| if (proto_item.has_status() && proto_item.status().code() != kv_cache_manager::proto::meta::OK) { | ||
| item.error_code = ToClientError(proto_item.status().code()); | ||
| item.error_message = proto_item.status().message(); | ||
| } | ||
| item.request_index = proto_item.request_index(); | ||
| item.block_key = proto_item.block_key(); | ||
| item.prev_block_key = proto_item.prev_block_key(); | ||
| for (const auto &[property_name, property_value] : proto_item.properties()) { | ||
| item.properties[property_name] = property_value; | ||
| } | ||
| item.locations.reserve(proto_item.locations_size()); | ||
| for (const auto &proto_location : proto_item.locations()) { | ||
| kv_cache_manager::CacheMetaLocationDetail location; | ||
| location.location_id = proto_location.location_id(); | ||
| location.status = static_cast<kv_cache_manager::CacheMetaLocationStatus>(proto_location.status()); | ||
| location.storage_type = static_cast<kv_cache_manager::CacheMetaStorageType>(proto_location.type()); | ||
| location.spec_size = proto_location.spec_size(); | ||
| location.create_time = proto_location.create_time(); | ||
| location.location_specs.reserve(proto_location.location_specs_size()); | ||
| for (const auto &proto_spec : proto_location.location_specs()) { | ||
| location.location_specs.push_back({proto_spec.name(), proto_spec.uri()}); | ||
| } | ||
| item.locations.push_back(std::move(location)); | ||
| } | ||
| cache_meta_details.push_back(std::move(item)); | ||
| } | ||
| return cache_meta_details; | ||
| } | ||
|
|
||
| kv_cache_manager::ClientErrorCode | ||
| GenCacheLocation(const kv_cache_manager::Locations &locations, | ||
| google::protobuf::RepeatedPtrField<::kv_cache_manager::proto::meta::CacheLocation> *proto_locations) { | ||
|
|
@@ -322,6 +362,27 @@ std::pair<ClientErrorCode, Metas> GrpcStub::GetCacheMeta(const std::string &trac | |
| return {ER_OK, {locations, metas}}; | ||
| } | ||
|
|
||
| std::pair<ClientErrorCode, CacheMetaDetails> GrpcStub::GetCacheMetaDetail(const std::string &trace_id, | ||
| const std::string &instance_id, | ||
| const KeyVector &keys, | ||
| const TokenIdsVector &tokens, | ||
| const BlockMask &block_mask, | ||
| int32_t detail_level) { | ||
| auto stub = GET_AND_CHECK_STUB_WITH_TYPE(); | ||
| proto::meta::GetCacheMetaDetailRequest request; | ||
| SetKeysAndTokens(request, trace_id, instance_id, keys, tokens); | ||
| ProtoConvert::BlockMaskToProto(block_mask, request.mutable_block_mask()); | ||
| request.set_detail_level(detail_level); | ||
| grpc::ClientContext context; | ||
| proto::meta::GetCacheMetaDetailResponse response; | ||
| auto grpc_status = stub->GetCacheMetaDetail(&context, request, &response); | ||
| CHECK_GRPC_STATUS_WITH_TYPE(grpc_status); | ||
| CHECK_COMMON_HEADER_WITH_TYPE(response); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When every raw metadata lookup fails, the service deliberately returns a non-OK header together with populated per-key Useful? React with 👍 / 👎. |
||
| auto cache_meta_details = GenCacheMetaDetails(response.items()); | ||
| KVCM_LOG_DEBUG("get cache meta detail success, items: %lu", cache_meta_details.size()); | ||
| return {ER_OK, cache_meta_details}; | ||
| } | ||
|
|
||
| std::pair<ClientErrorCode, Locations> GrpcStub::GetCacheLocation(const std::string &trace_id, | ||
| const std::string &instance_id, | ||
| QueryType query_type, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The abstract method has a default
return {}body. Python'sabc.abstractmethoddoes not enforce the override if a default body is provided; subclasses that forget to implement this will silently get an empty dict back rather than a clearTypeError. This is the same pattern as the existing methods, so it's consistent, but worth noting that test coverage depends on callers going through the concreteGrpcInterfaceTest/HttpInterfaceTestimplementations. There are no test cases in this PR that actually exerciseget_cache_meta_detailend-to-end through the integration test runner (only stub plumbing is added) — adding at least one basic call-and-assert test would close this gap.🤖 Generated by Qoder