Skip to content

feat: v1.5 TTL 惰性淘汰(LIMITATIONS #11 闭环)+ 文档口径收尾 - #11

Merged
H2Rhan merged 1 commit into
masterfrom
feat/lazy-ttl-eviction
Sep 9, 2026
Merged

H2Rhan merged 1 commit into
masterfrom
feat/lazy-ttl-eviction

Conversation

@H2Rhan

@H2Rhan H2Rhan commented Sep 9, 2026

Copy link
Copy Markdown
Owner

目的

闭环 LIMITATIONS #11:evict_expired 早已实现且有测试,但网关主进程没有任何触发器,会话表随运行时间无界增长。

方案:惰性淘汰(读写顺手触发,无后台线程)

  • SessionStore.maybe_evict():在 get_or_create(每个正常请求的必经路径)顺手触发淘汰
  • 60s 节流(_EVICT_INTERVAL):两次全表扫描至少间隔 60 秒,避免每请求一次扫描;_last_evict 竞写良性(最坏多扫一次),不加锁
  • 锁外调用:evict_expired 取的是同一把非可重入 threading.Lock,若在 get_or_create 临界区内调用必死锁——已在代码注释中写明

回归测试(2 项,测试 44 → 46 全过 + 11 项冒烟全过)

  • test_lazy_eviction_throttled:首次淘汰 1 个超时会话 → 窗口内新超时会话不扫(返回 0)→ 窗口过后恢复淘汰
  • test_get_or_create_triggers_lazy_eviction:任意流量触发,超时会话被 archive、活跃会话不受影响

文档同步

验证

python -m unittest tests.test_offline 46 项 OK;python tools/smoke_e2e.py 11/11 通过(Python 3.13)

- SessionStore.maybe_evict():读写路径惰性触发 TTL 淘汰,60s 节流;锁外调用规避非可重入锁死锁
- 回归测试 2 项(节流窗口 / 流量驱动),46 项单测 + 11 项冒烟全过
- LIMITATIONS #11 标记已修复留档;#12 补标已闭环(PR #8 落地,标记滞后)
- README/REVIEW/CHANGELOG 口径同步(单测 46 项、3 项限制已闭环)
@H2Rhan
H2Rhan merged commit 3a7883c into master Sep 9, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant