Repository navigation
fix: roll back partial KV allocation on page miss - #365
shipiyouniao wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes a failure mode in KVCacheManager._alloc() where a PageAllocator.alloc_page() RuntimeError could escape after partially allocating block IDs, leaking those IDs instead of returning an allocation miss (None).
Changes:
- Catch
RuntimeErrorfrompage_allocator.alloc_page()/page.init()and returnNone(allocation miss) instead of propagating the exception. - Attempt to roll back any partially allocated block IDs via
free()before returningNone, and log rollback failures without masking the miss. - Add regression tests covering partial allocation followed by a page-allocation failure.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
kvcached/kv_cache_manager.py |
Adds exception handling + rollback for partial allocations when physical page allocation fails. |
tests/test_kvcache_manager_alloc_miss.py |
Adds regression tests for allocation-miss rollback scenarios. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
6e32f61 to
2940cb1
Compare
cf0d799 to
11738b1
Compare
11738b1 to
830f20a
Compare
830f20a to
5e9b29b
Compare
|
Superseded by #430. Its rollback restores both page blocks and the reservation ledger, releases pages created by the failed allocation, and the latest commit narrows recovery to the intended alloc_page()/page.init() failure path. The remaining CI failure on #430 is only the new test-classification check for tests/test_alloc_rollback.py, not a behavioral regression. |
Summary
Fixes #364.
Fixes a lower-level allocation failure path in
KVCacheManager.alloc()wherePageAllocator.alloc_page()can raise after some block ids have already been reserved for the current allocation request.Root Cause
available_size()and physical page allocation are not atomic across multiple instances sharing the same physical pool. A caller may pass the capacity check, consume reserved blocks or blocks from an existing page, and then fail when requesting a new physical page.Before this change, that
RuntimeErrorescaped without rolling back the partially allocated block ids.What Changed
RuntimeErroraroundpage_allocator.alloc_page().Noneas an allocation miss instead of crashing the allocation path.None._free(..., release_empty_pages=False)rollback path so a partial-allocation rollback does not unmap/release physical pages that were not intentionally returned to the physical pool.free()behavior unchanged for real releases.Tests