Skip to content

Commit 9d0ef1d

Browse files
authored
[optimizer] bound KVCM replay state with 24h TTL
1 parent 4ca143e commit 9d0ef1d

4 files changed

Lines changed: 6 additions & 0 deletions

File tree

kv_cache_manager/optimizer/docs/online_event_subscription_code_review.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ KVCM capacity_bytes -> 一个 capacity_gb 容量点
298298
eviction_policy -> lru
299299
enable_prefix_hash -> true
300300
theoretical max -> true
301+
ttl_seconds -> 24 hours
301302
```
302303

303304
### Instance 映射
@@ -333,6 +334,7 @@ OnlineOptimizerManager::RegisterInstance
333334
- KVCM 自动接入暂不推断 linear state;多 group 的语义不明确时标记为 unsupported 并跳过。
334335
- Subscriber 收到已知 unsupported Instance 的事件时直接丢弃,不触发配置刷新。
335336
- KVCM Group quota 被每个 Instance 分别作为完整容量模拟,不是共享 quota。
337+
- KVCM 自动创建的 Group 固定使用 24 小时 TTL,限制 LiteHit 保留的历史工作集。
336338
- Group 已存在时不检查 capacity、prefix hash、theoretical flag。
337339
- Instance 已存在时不检查 block size 和 specs。
338340

kv_cache_manager/optimizer/service/optimizer_service_impl.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace kv_cache_manager {
2020
namespace {
2121

2222
constexpr long double kBytesPerGb = 1024.0L * 1024.0L * 1024.0L;
23+
constexpr int64_t kKvcmAutoGroupTtlSeconds = 24 * 60 * 60;
2324

2425
void SetPbResponseHeader(proto::optimizer::CommonResponseHeader *header, ErrorCode ec) {
2526
auto *status = header->mutable_status();
@@ -330,6 +331,7 @@ ErrorCode OptimizerServiceImpl::ApplyKvcmConfiguration(const proto::optimizer::K
330331
group.set_eviction_policy("lru");
331332
group.set_enable_prefix_hash(true);
332333
group.set_enable_theoretical_max_cache(true);
334+
group.set_ttl_seconds(kKvcmAutoGroupTtlSeconds);
333335

334336
std::string invalid_fields;
335337
if (!group.ValidateRequiredFields(invalid_fields)) {

kv_cache_manager/optimizer/test/kvcm_event_subscriber_test.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ TEST_F(KvcmEventSubscriberTest, DiscoversLeaderAndRegistersConfigurationBeforeCo
266266
EXPECT_DOUBLE_EQ(2.0, group->capacity_gb()[0]);
267267
EXPECT_TRUE(group->enable_prefix_hash());
268268
EXPECT_TRUE(group->enable_theoretical_max_cache());
269+
EXPECT_EQ(24 * 60 * 60, group->ttl_seconds());
269270

270271
leader.event_service_.Publish(MakeEvent("known", "normal", 1));
271272
auto short_prompt = MakeEvent("known", "short", 2);

kv_cache_manager/optimizer/test/optimizer_service_impl_test.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ TEST_F(OptimizerServiceImplTest, ApplyKvcmConfigurationCreatesEnabledGroupAndIns
433433
EXPECT_DOUBLE_EQ(2.0, stored_group->capacity_gb().front());
434434
EXPECT_TRUE(stored_group->enable_prefix_hash());
435435
EXPECT_TRUE(stored_group->enable_theoretical_max_cache());
436+
EXPECT_EQ(24 * 60 * 60, stored_group->ttl_seconds());
436437

437438
ASSERT_EQ(EC_OK, manager_->GetInstanceState("kvcm-instance", [](const InstanceState &state) {
438439
EXPECT_EQ("kvcm-group", state.instance_info->instance_group_name());

0 commit comments

Comments
 (0)