-
Notifications
You must be signed in to change notification settings - Fork 957
[TENT] Bind transport policies to intent type #2839
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,11 +17,10 @@ | |
| #include "tent/runtime/platform.h" | ||
| #include "tent/thirdparty/nlohmann/json.h" | ||
|
|
||
| #include <algorithm> | ||
| #include <glog/logging.h> | ||
|
|
||
| #include <algorithm> | ||
| #include <cctype> | ||
| #include <cstdint> | ||
| #include <glog/logging.h> | ||
|
|
||
| namespace mooncake { | ||
| namespace tent { | ||
|
|
@@ -63,6 +62,46 @@ static const std::string kMemoryTypeCuda = "cuda"; | |
| static const std::string kMemoryTypeNpu = "npu"; | ||
| static const std::string kMemoryTypeWildcard = "*"; | ||
|
|
||
| static const std::unordered_map<std::string, IntentType> kIntentTypeNameMap = { | ||
| {"intent_unspec", IntentType::INTENT_UNSPEC}, | ||
| {"unspec", IntentType::INTENT_UNSPEC}, | ||
| {"foreground_get", IntentType::FOREGROUND_GET}, | ||
| {"background_prefetch", IntentType::BACKGROUND_PREFETCH}, | ||
| {"migration", IntentType::MIGRATION}, | ||
| {"checkpoint", IntentType::CHECKPOINT}, | ||
| {"weight_loading", IntentType::WEIGHT_LOADING}, | ||
| {"staging_internal", IntentType::STAGING_INTERNAL}, | ||
| }; | ||
|
|
||
| static std::optional<IntentType> parseIntentType(const json& value) { | ||
| if (value.is_string()) { | ||
| auto name = value.get<std::string>(); | ||
| std::transform(name.begin(), name.end(), name.begin(), | ||
| [](unsigned char c) { return std::tolower(c); }); | ||
| auto it = kIntentTypeNameMap.find(name); | ||
| if (it != kIntentTypeNameMap.end()) return it->second; | ||
| return std::nullopt; | ||
| } | ||
|
|
||
| if (value.is_number_unsigned()) { | ||
| const auto raw = value.get<uint64_t>(); | ||
| if (raw <= static_cast<uint64_t>(IntentType::STAGING_INTERNAL)) { | ||
| return static_cast<IntentType>(raw); | ||
| } | ||
| return std::nullopt; | ||
| } | ||
|
|
||
| if (value.is_number_integer()) { | ||
| const auto raw = value.get<int64_t>(); | ||
| if (raw >= static_cast<int64_t>(IntentType::INTENT_UNSPEC) && | ||
| raw <= static_cast<int64_t>(IntentType::STAGING_INTERNAL)) { | ||
| return static_cast<IntentType>(raw); | ||
| } | ||
| } | ||
|
Comment on lines
+86
to
+100
Contributor
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. The parsing logic for unsigned and signed integers can be simplified and made more consistent by using an if (value.is_number_unsigned()) {
const auto raw = value.get<uint64_t>();
if (raw <= static_cast<uint64_t>(IntentType::STAGING_INTERNAL)) {
return static_cast<IntentType>(raw);
}
} else if (value.is_number_integer()) {
const auto raw = value.get<int64_t>();
if (raw >= static_cast<int64_t>(IntentType::INTENT_UNSPEC) &&
raw <= static_cast<int64_t>(IntentType::STAGING_INTERNAL)) {
return static_cast<IntentType>(raw);
}
} |
||
|
|
||
| return std::nullopt; | ||
| } | ||
|
|
||
| std::string TransportSelector::transportTypeName(TransportType type) { | ||
| auto it = kTransportTypeNames.find(type); | ||
| if (it != kTransportTypeNames.end()) { | ||
|
|
@@ -86,26 +125,34 @@ std::vector<SelectionPolicy> TransportSelector::getDefaultPolicies() { | |
| { | ||
| "file_storage", | ||
| SegmentType::File, | ||
| std::nullopt, // same_machine doesn't matter for file | ||
| std::nullopt, // local_memory_pattern | ||
| std::nullopt, // remote_memory_pattern | ||
| std::nullopt, // min_size | ||
| std::nullopt, // max_size | ||
| std::nullopt, // priority | ||
| {}, // devices (empty = all devices) | ||
| {GDS, IOURING} // File segment priority (original: GDS -> IOURING) | ||
| std::nullopt, // same_machine doesn't matter for file | ||
| std::nullopt, // local_memory_pattern | ||
| std::nullopt, // remote_memory_pattern | ||
| std::nullopt, // min_size | ||
| std::nullopt, // max_size | ||
| std::nullopt, // priority | ||
| {}, // devices (empty = all devices) | ||
| {GDS, IOURING}, // File priority (original: GDS -> IOURING) | ||
| std::nullopt, // service_level | ||
| std::nullopt, // traffic_class | ||
| std::nullopt, // qp_pool | ||
| std::nullopt // intent_type | ||
| }, | ||
| { | ||
| "memory_default", | ||
| SegmentType::Memory, | ||
| std::nullopt, // any machine | ||
| std::nullopt, // any local memory | ||
| std::nullopt, // any remote memory | ||
| std::nullopt, // any size | ||
| std::nullopt, // min_priority | ||
| std::nullopt, // min_size | ||
| std::nullopt, // max_size | ||
| std::nullopt, // priority | ||
| {}, // devices (empty = all devices) | ||
| {} // Empty priority = use buffer_transports order (original | ||
| // behavior) | ||
| {}, // Empty = use buffer_transports order | ||
| std::nullopt, // service_level | ||
| std::nullopt, // traffic_class | ||
| std::nullopt, // qp_pool | ||
| std::nullopt // intent_type | ||
| }, | ||
| }; | ||
| } | ||
|
|
@@ -196,6 +243,19 @@ void TransportSelector::loadPolicies() { | |
| policy.priority = std::nullopt; | ||
| } | ||
|
|
||
| // Parse the optional business-intent filter. An invalid value skips the | ||
| // entire policy instead of turning it into a catch-all rule, which | ||
| // would silently broaden its authorization scope. | ||
| if (policy_json.contains("intent_type")) { | ||
| auto intent = parseIntentType(policy_json["intent_type"]); | ||
| if (!intent.has_value()) { | ||
| LOG(WARNING) | ||
| << "Skip policy " << policy.name << ": invalid intent_type"; | ||
| continue; | ||
| } | ||
| policy.intent_type = *intent; | ||
| } | ||
|
|
||
| // Parse devices (optional) | ||
| if (policy_json.contains("devices")) { | ||
| for (const auto& device_name : policy_json["devices"]) { | ||
|
|
@@ -351,6 +411,13 @@ bool TransportSelector::matchesPolicy(const SelectionPolicy& policy, | |
| } | ||
| } | ||
|
|
||
| // Policies without an intent filter retain the historical catch-all | ||
| // behavior. Intent-specific policies require an exact match. | ||
| if (policy.intent_type.has_value() && | ||
| context.intent_type != policy.intent_type.value()) { | ||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
While
ctx.intent_typeis correctly populated here, there is a critical gap inmergeRequests(and its sorting comparator) whereintent_typeis completely ignored.If two requests with different
intent_typevalues are submitted in the same batch, they can be merged into a single request. When merged, the second request'sintent_typeis lost, and its transfer will be executed under the first request'sintent_typepolicy (including its QP pool, service level, traffic class, etc.).To fix this,
intent_type(and ideallypolicy_nameas well) must be added to the sorting comparator and thecan_mergelambda inmergeRequeststo prevent merging requests with different intents.