perf: sync protocol and core hardening updates

This commit is contained in:
A 2026-07-11 19:48:26 +08:00
parent 152fed3b87
commit 4390ebf5a9
283 changed files with 29231 additions and 2295 deletions

View file

@ -2,11 +2,20 @@ package store
import (
"context"
"errors"
"time"
"telesrv/internal/domain"
)
// ErrDispatchLeaseLost means a completion belongs to an older claim attempt.
// Callers must not overwrite/delete the row now owned by a newer worker.
var ErrDispatchLeaseLost = errors.New("dispatch outbox lease lost")
// DispatchOutboxLogicalShards 是稳定的 user→lane 哈希空间。运行时 worker 数
// 只能改变 shard 的归属,不能改变这个值;PG 表达式索引也固定使用 256。
const DispatchOutboxLogicalShards = 256
// DispatchOutboxItem 是待投递给在线 session 的 update 任务。
type DispatchOutboxItem struct {
ID int64
@ -21,7 +30,7 @@ type DispatchOutboxItem struct {
// DispatchOutboxStore 持久化 transactional outbox。
type DispatchOutboxStore interface {
ClaimPending(ctx context.Context, limit int) ([]DispatchOutboxItem, error)
MarkDelivered(ctx context.Context, targetUserID, id int64) error
MarkFailed(ctx context.Context, targetUserID, id int64, lastError string) error
MarkDelivered(ctx context.Context, item DispatchOutboxItem) error
MarkFailed(ctx context.Context, item DispatchOutboxItem, lastError string) error
DeleteFailed(ctx context.Context, olderThan time.Duration, limit int) (int, error)
}