fix: reduce persistence lag and retry audit deadlocks

This commit is contained in:
richjohnrambo
2026-09-27 16:33:05 +08:00
parent 704c65a7a4
commit d96f661f30
8 changed files with 185 additions and 18 deletions
+12 -1
View File
@@ -93,7 +93,18 @@ func (a *adapter) TenantLoginAuditClose(id t.TenantID, sessionID string, at time
if tenantAdp != a {
return tenantAdp.TenantLoginAuditClose(id, sessionID, at)
}
_, err = a.db.Exec("UPDATE im_user_login_logs SET logout_at=? WHERE tenant_id=? AND session_id=? AND logout_at IS NULL", at, int64(id), sessionID)
return retryMySQLDeadlock(func() error {
_, execErr := a.db.Exec("UPDATE im_user_login_logs SET logout_at=? WHERE tenant_id=? AND session_id=? AND logout_at IS NULL", at, int64(id), sessionID)
return execErr
}, time.Sleep)
}
func retryMySQLDeadlock(operation func() error, sleep func(time.Duration)) error {
err := operation()
for attempt := 1; isRetryableMySQLError(err) && attempt < 4; attempt++ {
sleep(time.Duration(attempt) * 25 * time.Millisecond)
err = operation()
}
return err
}