Skip to content

Commit c07d48e

Browse files
authored
[manager] exclude EventReport from cache reclamation (#286)
1 parent 36c4875 commit c07d48e

2 files changed

Lines changed: 103 additions & 2 deletions

File tree

kv_cache_manager/manager/cache_reclaimer.cc

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,10 @@ CacheReclaimer::GetWaterLevelExceed(const RequestContext *request_context,
779779
// skip vcns_hf3fs, because it is treated as hf3fs
780780
continue;
781781
}
782+
if (IsEventReportStorageType(type)) {
783+
// EventReport metadata is not reclaimed by CacheReclaimer.
784+
continue;
785+
}
782786

783787
const std::size_t type_idx = ToIndex(ToBaseType(type));
784788
const std::uint64_t type_credit = type_idx < credited_bytes.size() ? credited_bytes[type_idx] : 0;
@@ -1418,7 +1422,8 @@ bool CacheReclaimer::FilterLocID(RequestContext *request_context,
14181422
const bool covered = std::any_of(loc_map.begin(), loc_map.end(), [&is_pending_location, &loc_on_cold_storage, block_key, &source_spec](const auto &entry) {
14191423
const auto &loc_ptr = entry.second;
14201424
if (!loc_ptr || loc_ptr->status() != CacheLocationStatus::CLS_SERVING ||
1421-
is_pending_location(block_key, loc_ptr->id()) || !loc_on_cold_storage(*loc_ptr)) {
1425+
IsEventReportStorageType(loc_ptr->type()) || is_pending_location(block_key, loc_ptr->id()) ||
1426+
!loc_on_cold_storage(*loc_ptr)) {
14221427
return false;
14231428
}
14241429
return std::any_of(loc_ptr->location_specs().begin(),
@@ -1454,6 +1459,9 @@ bool CacheReclaimer::FilterLocID(RequestContext *request_context,
14541459
continue;
14551460
}
14561461
const auto &loc = *loc_ptr;
1462+
if (IsEventReportStorageType(loc.type())) {
1463+
continue;
1464+
}
14571465
if (is_pending_location(block_key, loc.id())) {
14581466
continue;
14591467
}
@@ -1482,6 +1490,12 @@ bool CacheReclaimer::FilterLocID(RequestContext *request_context,
14821490
}
14831491
++valid_location_count;
14841492
const auto &loc = *loc_ptr;
1493+
if (IsEventReportStorageType(loc.type())) {
1494+
// Generic reclamation must not remove metadata owned by a
1495+
// ReportEvent reporter. Dedicated lifecycle/snapshot cleanup
1496+
// uses metadata-only conditional deletion instead.
1497+
continue;
1498+
}
14851499
if (is_pending_location(block_key, loc.id())) {
14861500
METRICS_(cache_reclaimer, duplicate_pending_location_filtered_count) += 1;
14871501
continue;
@@ -1987,7 +2001,7 @@ std::shared_ptr<CacheReclaimer::GroupUsageData> CacheReclaimer::GetGroupUsageDat
19872001

19882002
for (std::size_t idx = 1; idx < static_cast<std::size_t>(DataStorageType::COUNT); ++idx) {
19892003
const auto type = static_cast<DataStorageType>(idx);
1990-
if (type == DataStorageType::DATA_STORAGE_TYPE_VCNS_HF3FS) {
2004+
if (type == DataStorageType::DATA_STORAGE_TYPE_VCNS_HF3FS || IsEventReportStorageType(type)) {
19912005
continue;
19922006
}
19932007
data->AddGroupUsageByType(type, meta_indexer->GetStorageUsageByType(type));

kv_cache_manager/manager/test/cache_reclaimer_test.cc

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1699,6 +1699,34 @@ TEST_F(CacheReclaimerTest, TestTriggerReclaiming17) {
16991699
}
17001700
}
17011701

1702+
TEST_F(CacheReclaimerTest, TestEventReportUsageDoesNotTriggerStorageTypeWaterLevel) {
1703+
dummy_meta_indexer->SetStorageUsageByType(DataStorageType::DATA_STORAGE_TYPE_EVENT_REPORT_L1P5, 90);
1704+
dummy_meta_indexer->SetStorageUsageByType(DataStorageType::DATA_STORAGE_TYPE_EVENT_REPORT_L2, 90);
1705+
1706+
const auto instance_group = InstanceGroupFactory();
1707+
instance_group->quota_.set_capacity(100);
1708+
instance_group->quota_.set_quota_config({
1709+
QuotaConfig(100, DataStorageType::DATA_STORAGE_TYPE_EVENT_REPORT_L1P5),
1710+
QuotaConfig(100, DataStorageType::DATA_STORAGE_TYPE_EVENT_REPORT_L2),
1711+
});
1712+
instance_group->cache_config_->reclaim_strategy_->trigger_strategy_.set_used_percentage(0.8);
1713+
key_count = 0;
1714+
max_key_count = 100;
1715+
1716+
cache_reclaimer_->job_state_flag_ = true;
1717+
const auto water_level = cache_reclaimer_->GetWaterLevelExceed(
1718+
request_context_.get(),
1719+
instance_group->name(),
1720+
instance_group->quota(),
1721+
instance_group->cache_config()->reclaim_strategy(),
1722+
instance_infos);
1723+
ASSERT_NE(nullptr, water_level);
1724+
EXPECT_TRUE(water_level->GetGeneralWaterLevelExceed());
1725+
EXPECT_FALSE(
1726+
water_level->GetWaterLevelExceedByType(DataStorageType::DATA_STORAGE_TYPE_EVENT_REPORT_L1P5));
1727+
EXPECT_FALSE(water_level->GetWaterLevelExceedByType(DataStorageType::DATA_STORAGE_TYPE_EVENT_REPORT_L2));
1728+
}
1729+
17021730
TEST_F(CacheReclaimerTest, TestInsufficientSampledKeys) {
17031731
sample_reclaim_keys = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
17041732
get_out_properties = {
@@ -3162,6 +3190,65 @@ TEST_F(CacheReclaimerTest, TestFilterLocationCreditsNormalizeTypeAndPredictKeysC
31623190
EXPECT_EQ(1, predicted_keys);
31633191
}
31643192

3193+
TEST_F(CacheReclaimerTest, TestFilterLocationExcludesEventReportStorage) {
3194+
const auto instance = InstanceInfoFactory();
3195+
batch_get_loc_out_maps = {
3196+
CacheLocationMap{
3197+
{"event_l1p5",
3198+
MakeCacheLocation("event_l1p5",
3199+
CacheLocationStatus::CLS_SERVING,
3200+
DataStorageType::DATA_STORAGE_TYPE_EVENT_REPORT_L1P5,
3201+
"nfs://reporter/l1p5?size=10")},
3202+
{"event_l2",
3203+
MakeCacheLocation("event_l2",
3204+
CacheLocationStatus::CLS_SERVING,
3205+
DataStorageType::DATA_STORAGE_TYPE_EVENT_REPORT_L2,
3206+
"nfs://reporter/l2?size=20")},
3207+
},
3208+
CacheLocationMap{
3209+
{"event_l2",
3210+
MakeCacheLocation("event_l2",
3211+
CacheLocationStatus::CLS_SERVING,
3212+
DataStorageType::DATA_STORAGE_TYPE_EVENT_REPORT_L2,
3213+
"nfs://reporter/l2?size=20")},
3214+
{"nfs",
3215+
MakeCacheLocation("nfs",
3216+
CacheLocationStatus::CLS_SERVING,
3217+
DataStorageType::DATA_STORAGE_TYPE_NFS,
3218+
"nfs://store/nfs?size=30")},
3219+
},
3220+
};
3221+
3222+
CacheReclaimer::WaterLevelExceed water_level;
3223+
water_level.SetGeneralWaterLevelExceed(true);
3224+
std::vector<std::vector<std::string>> location_ids;
3225+
CacheReclaimer::BytesByStorageType bytes_by_type{};
3226+
CacheReclaimer::CountsByStorageType counts_by_type{};
3227+
std::uint64_t predicted_keys = 0;
3228+
CacheReclaimer::AgeStats create_age_stats;
3229+
ASSERT_TRUE(cache_reclaimer_->FilterLocID(request_context_.get(),
3230+
instance,
3231+
{10, 11},
3232+
water_level,
3233+
location_ids,
3234+
bytes_by_type,
3235+
counts_by_type,
3236+
predicted_keys,
3237+
create_age_stats));
3238+
3239+
ASSERT_EQ(2, location_ids.size());
3240+
EXPECT_TRUE(location_ids[0].empty());
3241+
ASSERT_EQ(1, location_ids[1].size());
3242+
EXPECT_EQ("nfs", location_ids[1][0]);
3243+
EXPECT_EQ(0, bytes_by_type[ToIndex(DataStorageType::DATA_STORAGE_TYPE_EVENT_REPORT_L1P5)]);
3244+
EXPECT_EQ(0, bytes_by_type[ToIndex(DataStorageType::DATA_STORAGE_TYPE_EVENT_REPORT_L2)]);
3245+
EXPECT_EQ(0, counts_by_type[ToIndex(DataStorageType::DATA_STORAGE_TYPE_EVENT_REPORT_L1P5)]);
3246+
EXPECT_EQ(0, counts_by_type[ToIndex(DataStorageType::DATA_STORAGE_TYPE_EVENT_REPORT_L2)]);
3247+
EXPECT_EQ(30, bytes_by_type[ToIndex(DataStorageType::DATA_STORAGE_TYPE_NFS)]);
3248+
EXPECT_EQ(1, counts_by_type[ToIndex(DataStorageType::DATA_STORAGE_TYPE_NFS)]);
3249+
EXPECT_EQ(0, predicted_keys);
3250+
}
3251+
31653252
TEST_F(CacheReclaimerTest, TestCreditDeadlineDisablesCreditButKeepsPendingAndHardQuota) {
31663253
CacheReclaimerAsyncDeleteConfig config;
31673254
config.inflight_delete_timeout_ms = 1;

0 commit comments

Comments
 (0)