perf(worker): 隔离异步等待登记与执行锁

为异步等待队列登记增加独立的进程内和 PostgreSQL advisory lock 域,使严格队列上限校验不再等待 Worker 执行槽事务的跨城同步提交。任务级锁保持不变,调度期间 active 与 waiting 总量守恒。\n\n新增 PostgreSQL 集成测试,验证执行 scope 锁被占用时等待登记仍可独立完成。\n\n验证:go vet ./...;go test ./... -count=1;隔离 PostgreSQL 集成测试;迁移安全检查;gofmt;git diff --check。
This commit is contained in:
2026-07-31 09:29:01 +08:00
parent 11ec057e6a
commit 387bf5842d
3 changed files with 138 additions and 4 deletions
@@ -114,6 +114,14 @@ func admissionOperationLockKeys(input TaskAdmissionInput) []string {
return normalizedAdmissionLockKeys(keys)
}
func queuedAdmissionOperationLockKeys(input TaskAdmissionInput) []string {
keys := []string{"task-admission:" + input.TaskID}
for _, scope := range normalizedAdmissionScopes(input.Scopes) {
keys = append(keys, admissionQueueRegistrationLockKey(scope))
}
return normalizedAdmissionLockKeys(keys)
}
func tryAdmissionTransactionLock(ctx context.Context, tx pgx.Tx, key string) error {
// The process-local lock limits this wait to one PostgreSQL connection per
// API or Worker process. Let PostgreSQL queue those process representatives