- ClaimPendingLuckyGiftOutbox 把 status IN ('pending','retryable') 拆成单
status 查询并加 FOR UPDATE SKIP LOCKED:IN 跨 status 会 filesort 全部匹配行
并逐行加锁,积压时两实例互相阻塞(参照 chatapp3-golang 523cfe9 的修法);
ORDER BY 对齐 idx_lucky_gift_outbox_claim_retry/claim_lock 列序,索引序扫描
LIMIT 提前终止,只锁认领行。pending 留 10% 批次额度给 retryable 防饿死。
- 新增 delivered 行保留期清理 worker(默认开启,保留 30 天、5 分钟一轮、
单批 500):线上已积累 15.4 万只增不减的 delivered 行。清理按 app_code
迭代走 idx_lucky_gift_outbox_retention,只删 delivered 终态。
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
24 lines
622 B
Go
24 lines
622 B
Go
package luckygift
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestNormalizeOutboxRetentionOptionsFillsSafeDefaults(t *testing.T) {
|
|
got := normalizeOutboxRetentionOptions(OutboxRetentionOptions{})
|
|
want := defaultOutboxRetentionOptions()
|
|
if got != want {
|
|
t.Fatalf("normalizeOutboxRetentionOptions(zero) = %+v, want %+v", got, want)
|
|
}
|
|
|
|
custom := OutboxRetentionOptions{
|
|
ScanInterval: time.Minute,
|
|
MaxAge: 7 * 24 * time.Hour,
|
|
BatchSize: 100,
|
|
}
|
|
if got := normalizeOutboxRetentionOptions(custom); got != custom {
|
|
t.Fatalf("normalizeOutboxRetentionOptions(custom) = %+v, want unchanged %+v", got, custom)
|
|
}
|
|
}
|