1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//! `MySQL` deadlock detection utility.
//!
//! > "Always be prepared to re-issue a transaction if it fails due to deadlock.
//! > Deadlocks are not dangerous. Just try again."
//! > — [`MySQL` 8.0 Reference Manual, `InnoDB` Deadlocks](https://dev.mysql.com/doc/refman/8.0/en/innodb-deadlocks.html)
//!
//! `InnoDB` detects deadlocks instantly and rolls back one transaction (the victim).
//! SQLSTATE `40001` signals a serialization failure that is always safe to retry.
//! This module provides detection helpers for use by callers that manage their
//! own transaction lifecycle (e.g., the outbox sequencer).
use DbErr;
/// `MySQL` deadlock SQLSTATE code.
const DEADLOCK_SQLSTATE: &str = "40001";
/// Returns `true` if the error is a `MySQL`/`MariaDB` deadlock (SQLSTATE `40001`).
///
/// Always returns `false` for `Postgres` and `SQLite` errors — those engines
/// resolve lock conflicts differently (`SKIP LOCKED`, single-writer).
///
/// Detection is based on the error's string representation containing the
/// SQLSTATE code, which avoids a direct dependency on `sqlx` types.