mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-07 05:39:32 +02:00
fix: use READ COMMITTED transactions on MySQL and MariaDB (#39506)
MariaDB 11.6.2+ defaults `innodb_snapshot_isolation` to `ON`, which fails REPEATABLE READ transactions with error 1020 when a row they write changed after their first read. Gitea's background work like push processing writes the same rows, so merges, issue closes and workflow runs fail sporadically. - Use READ COMMITTED on MySQL and MariaDB, like PostgreSQL and MSSQL - Update xorm to v1.4.3 Replaces: https://github.com/go-gitea/gitea/pull/39494 Fixes: https://github.com/go-gitea/gitea/issues/39492 --------- Signed-off-by: silverwind <me@silverwind.io>
This commit is contained in:
1 parent
fc81f2832a
commit
2f01ec38bd
3 files changed
+9
-3
No files matched your search
@@ -5,6 +5,7 @@ package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
|
||||
"gitea.dev/modules/log"
|
||||
@@ -59,6 +60,11 @@ func InitEngine(ctx context.Context) error {
|
||||
xe.SetMaxIdleConns(setting.Database.MaxIdleConns)
|
||||
xe.SetConnMaxLifetime(setting.Database.ConnMaxLifetime)
|
||||
|
||||
if setting.Database.Type.IsMySQL() {
|
||||
// like PostgreSQL and MSSQL, avoids MariaDB snapshot isolation errors
|
||||
xe.SetDefaultTxOptions(&sql.TxOptions{Isolation: sql.LevelReadCommitted})
|
||||
}
|
||||
|
||||
if setting.Database.SlowQueryThreshold > 0 {
|
||||
xe.AddHook(&EngineHook{
|
||||
Threshold: setting.Database.SlowQueryThreshold,
|
||||
|
||||
Reference in new issue
Block a user