mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-21 09:06:46 +09:00
fix: use READ_COMMITTED_SNAPSHOT on MSSQL (#39512)
MSSQL's default READ COMMITTED makes reads wait on writers, so the runner pickup deadlocks with concurrent claims, flaking `TestCreateTaskForRunnerConcurrentClaim`. - Enable `READ_COMMITTED_SNAPSHOT` on MSSQL so it reads like PostgreSQL and MySQL - Read the pickup cursor before claiming, a lost claim could skip waiting jobs - Add tests that fail without consistent READ COMMITTED Performance: Writes on MSSQL now also store the previous row version in tempdb, the same versioning cost PostgreSQL and MySQL always pay, and Azure SQL enables it by default. Reads no longer block on writers, and a 32-runner pickup stress test ran 2.5x faster with it. --------- Signed-off-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: Giteabot <teabot@gitea.io>
This commit is contained in:
4 files changed
+68
-4
No files matched your search
@@ -298,6 +298,12 @@ func CreateTaskForRunner(ctx context.Context, runner *ActionRunner) (*ActionTask
|
||||
if err := e.Where(cond).Asc("updated", "id").Limit(pickTaskBatchSize).Find(&jobs); err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
// A short page means no waiting jobs remain beyond it.
|
||||
isLastPage := len(jobs) < pickTaskBatchSize
|
||||
if !isLastPage {
|
||||
last := jobs[len(jobs)-1] // read before a lost claim bumps Updated
|
||||
cursorUpdated, cursorID = last.Updated, last.ID
|
||||
}
|
||||
|
||||
for _, v := range jobs {
|
||||
if !runner.CanMatchLabels(v.RunsOn) {
|
||||
@@ -313,12 +319,9 @@ func CreateTaskForRunner(ctx context.Context, runner *ActionRunner) (*ActionTask
|
||||
// Another runner claimed this job concurrently; try the next one.
|
||||
}
|
||||
|
||||
// A short page means no waiting jobs remain beyond it.
|
||||
if len(jobs) < pickTaskBatchSize {
|
||||
if isLastPage {
|
||||
return nil, false, nil
|
||||
}
|
||||
last := jobs[len(jobs)-1]
|
||||
cursorUpdated, cursorID = last.Updated, last.ID
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user