Skip to content

[manager] move EventReport cleanup into background GC - #281

Open
shaohuaxi wants to merge 1 commit into
mainfrom
rc/feat/event-report-gc-cleanup
Open

[manager] move EventReport cleanup into background GC#281
shaohuaxi wants to merge 1 commit into
mainfrom
rc/feat/event-report-gc-cleanup

Conversation

@shaohuaxi

@shaohuaxi shaohuaxi commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Background

EventReport currently schedules an instance-wide metadata scan after every successful Snapshot and HOST_DOWN/liveness cleanup. Repeated events can therefore multiply full scans and compete with deletion and migration work in the shared executor.

This PR builds on #244 and moves those cleanup paths into the resident background GC. EventReport events register or advance cleanup intents; GC merges compatible intents and reconciles them with bounded per-instance scans.

Changes

  • Add an EventReport intent lane for stale Snapshot generations, explicit HOST_DOWN, liveness cleanup, and post-recovery absent reporters.
  • Merge repeated intents by instance, storage type, and reporter/host, while scanning each instance keyspace once per pass.
  • Preserve Snapshot committed/in-flight generation, attempt epoch, reporter lifecycle generation, and backend incarnation fencing.
  • Perform metadata-only expected-value compare-delete; EventReport cleanup never issues a physical storage DELETE.
  • Add no-touch/no-backfill maintenance reads, cached-metadata recovery gating, exact hot/persistent accounting, and retry-safe usage/key-count settlement.
  • Bound metadata mutation impact to one key/shard at a time and expose scan, backlog, retry, action latency, and shard-lock wait/hold metrics.
  • Harden shutdown callbacks, intent cancellation, interrupted-pass completion, and recovery discovery behavior.
  • Document the architecture, failure semantics, observability, and rollout boundaries.

Correctness boundaries

  • Cleanup remains strictly instance-isolated.
  • Missing, malformed, unavailable, or changed metadata fails closed.
  • A re-registered reporter or a newer Snapshot/lifecycle invalidates older cleanup work.
  • Full expected Location values are checked again immediately before deletion.
  • Ordinary WRITING/SERVING GC and SchedulePlanExecutor physical deletion behavior are unchanged.

Dependency

This is the second layer of a stacked change and depends on #244.

Stack created with GitHub Stacks CLIGive Feedback 💬

@shaohuaxi shaohuaxi changed the title rc/feat/event report gc cleanup [manager] move EventReport cleanup into background GC Aug 10, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8770c29720

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread kv_cache_manager/meta/meta_storage_backend_manager.cc Outdated
Comment thread kv_cache_manager/manager/cache_garbage_collector.cc Outdated

@qoderai qoderai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Reviewed PR #281 (EventReport active cleanup integrated into background scan GC). The design document (docs/design/event_report_background_gc.md) is thorough and well-structured. The intent model, three-state lifecycle lease, per-instance cursor pass, fair scheduling, and maintenance metadata API contracts are clearly documented and faithfully implemented.

Key strengths

  • Intent merge/replace semantics correctly handle event storms (multiple Snapshots/HOST_DOWN collapse into per-Instance passes).
  • Maintenance no-touch reads (ApplyToEntryNoTouch, GetForOneKeyForMaintenance) prevent LRU/access-time pollution — the two-phase ScanLocationsForMaintenance refactor in meta_local_backend.cc is a clean fix for the prior shard-mutex-during-item-read concern.
  • Accounting safety: prior mutation flags are carried across Sync failures (meta_searcher.cc lines 2001-2007) to prevent double-counting, and CommitMaintenanceDeleteAccounting only runs after all hard errors converge.
  • Shutdown ordering (RequestStop → ClearCallbacks → Join → Reset) and fail-closed restart semantics (no persisted generation, intent/cursor discarded) are sound.
  • Test coverage is comprehensive across intent lifecycle, lease states, maintenance delete, metrics, and E2E.

Findings (3 inline comments)

  1. kBusy blocks entire batch (cache_garbage_collector.cc:1263): One busy reporter fails the whole action batch, preventing progress for unrelated reporters. Consider continue + out_revisit_required=true.
  2. kStale early return skips remaining targets (cache_garbage_collector.cc:1275): Inconsistent with BeginEventReportPass (line 973 uses continue). Remaining targets are deferred to a full pass rescan unnecessarily.
  3. String-based metric lookups on hot path (cache_garbage_collector.cc:1506): Event report metrics use GetCounter("cache_gc.event_report_*") per call, unlike the regular GC path which uses cached METRICS_ macros.

All findings are low-to-medium severity — the implementation is functionally correct and the issues are about efficiency and consistency.


🤖 Generated by Qoder

Comment thread kv_cache_manager/manager/cache_garbage_collector.cc
Comment thread kv_cache_manager/manager/cache_garbage_collector.cc
Comment thread kv_cache_manager/manager/cache_garbage_collector.cc
@github-actions github-actions Bot added the ai reviewed AI has reviewed this PR label Aug 10, 2026
Base automatically changed from rc/feat/cache-gc-v1 to main August 10, 2026 07:03
@shaohuaxi
shaohuaxi force-pushed the rc/feat/event-report-gc-cleanup branch 2 times, most recently from e2d6708 to 8f48e72 Compare August 10, 2026 07:09

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8f48e72957

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread kv_cache_manager/meta/meta_storage_backend_manager.cc
Comment thread kv_cache_manager/meta/meta_storage_backend_manager.cc Outdated
@shaohuaxi
shaohuaxi force-pushed the rc/feat/event-report-gc-cleanup branch 2 times, most recently from 5a0246e to 0939176 Compare August 14, 2026 06:22

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 09391763ac

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread kv_cache_manager/manager/cache_manager.cc Outdated
Comment thread kv_cache_manager/manager/cache_garbage_collector.cc
Comment thread kv_cache_manager/manager/cache_garbage_collector.cc
@shaohuaxi
shaohuaxi force-pushed the rc/feat/event-report-gc-cleanup branch 2 times, most recently from 9a20dbb to 67cfab2 Compare August 15, 2026 07:21

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 67cfab2844

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +1239 to +1240
out_results.clear();
prior_results = nullptr;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve settled layer flags across partial retries

When cached metadata is enabled and the persistent deletion succeeds but the hot-layer deletion returns a hard error, this settlement accounts the persistent mutation and then clears all record of it. The subsequent retry can successfully remove the same logical location from hot cache, causing CommitMaintenanceDeleteAccounting() to subtract its storage usage—and, for a whole-key deletion, its key count—a second time. Carry an already-accounted layer marker into the retry or defer accounting until both layers converge.

Useful? React with 👍 / 👎.

@shaohuaxi
shaohuaxi force-pushed the rc/feat/event-report-gc-cleanup branch from 67cfab2 to 879020a Compare August 15, 2026 09:46

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 879020af84

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +891 to +893
const bool persistent_safe = layer_has_no_unauthorized_locations(i, persistent_id_ecs, persistent_location_ids);
const bool hot_safe = !cache_backend_ || layer_has_no_unauthorized_locations(i, hot_id_ecs, hot_location_ids);
delete_whole_keys[i] = persistent_safe && hot_safe;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Retry when location-ID enumeration fails

When either layer's GetLocationIdsForMaintenance() returns a timeout or other error while the targeted GetLocationsForMaintenance() succeeds, these checks merely disable whole-key deletion; the target is still authorized and deleted through the location-only plan below. If it was the last location, this leaves an empty metadata key without any reclaimed_*_key flag, so MetaIndexer never decrements its key count, and later scans cannot rediscover a location to repair the accounting. Treat an ID-enumeration error as a hard per-key failure that retains the intent for retry.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai reviewed AI has reviewed this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant