fix: reduce persistence lag and retry audit deadlocks
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user