fix(cache): 修 read_failed_slot 的未初始化读,补解析失败告警

This commit is contained in:
admin committed 2026-10-30 23:45:17 +08:00
1 parent c43ad3749e
commit 1ab8a84901
2 files changed
+85 -19

No files matched your search

+19
View File
@@ -667,6 +667,25 @@ pub fn upstream_configured(r: *mut ngx_http_request_t, route: &str) -> bool {
unsafe { memo_for(r, route) }.is_some()
}
/// 取本请求 memo 里的**有效源个数**(log 阶段用)。
///
/// `pub(crate)`:Task 5 的 `handlers::cool_down_failed` 要用它做
/// 「顺位下标 → 源下标」的边界检查。走 memo ⇒ **不再查一次上游表**、
/// **不再 clone 整份源列表**(log 阶段多一次 shm 读 + 逐行解码 +
/// String 分配的纯浪费)。
///
/// ⚠️ memo 里的源列表**就是**本次请求选源时用的那一份 ⇒ 顺位下标
/// (`$cache_pick`)与它是**同一个下标空间** ⇒ 边界检查恒成立
/// (保留检查是为了「越界就跳过」这条防御语义不变)。
///
/// `r` 必须是 nginx 传入的有效请求指针。
pub(crate) fn memo_source_count(r: *mut ngx_http_request_t, route: &str) -> Option<usize> {
// SAFETY: r 有效;memo 的路由必须与本路由一致
let m = unsafe { memo_for(r, route) }?;
// SAFETY: 指针指向请求池里的 Memo,请求存活期间有效
Some(unsafe { (*m).sources.len() })
}
/// 读 `$cache_pick` 的字符串值(空串 = 还没有)。
///
/// ⚠️ **不能用 `ngx_http_get_variable(r, name, 0)`**。