可序列化事务中的所有 40 类错误都正常吗? [英] Are all class 40 errors normal in serializable transactions?
问题描述
我的一些交易被声明为 SERIALIZABLE.有时我会返回 40 类错误,例如 40001 serialization_failure
和 40P01 deadlock_detected
(我还没有看到其他代码),特别是当我通过以下方式对系统进行压力测试时大量并发事务.
Some of my transactions are declared as SERIALIZABLE. Sometimes I get back class 40 errors such as 40001 serialization_failure
and 40P01 deadlock_detected
(I haven't seen other codes yet), particularly when I'm stress testing the system by doing lots of concurrent transactions.
如果我正确理解了手册,这是意料之中的.当这些错误发生时,我因此假设重试事务.我的疑问是在处理 SERIALIZABLE 事务时,所有 类 40 错误是否是正常的".换句话说,我是否可以假设任何 40 类错误都会导致我重试交易,还是这种假设仅适用于 40 类错误的一个子集?
If I understood the manual correctly, this is to be expected. When these errors happen, I'm therefore suppose to retry the transaction. My doubt is whether all of class 40 errors are "normal" when handling SERIALIZABLE transactions. In other words, can I just assume that any class 40 error should lead me to retry the transaction, or is this assumption correct only for a subset of class 40 errors?
推荐答案
Per 错误代码部分手册的 40xxxx
SQLSTATE
类别是事务回滚".
Per the error codes section of the manual the 40xxxx
SQLSTATE
category is "transaction rollback".
它包括错误代码:
40000
transaction_rollback40002
transaction_integrity_constraint_violation40001
serialization_failure40003
statement_completion_unknown40P01
检测到死锁
40000
transaction_rollback40002
transaction_integrity_constraint_violation40001
serialization_failure40003
statement_completion_unknown40P01
deadlock_detected
其中,我通常不希望 transaction_integrity_constraint_violation
触发重试,因为当 DEFERRED
外键检查导致事务在提交时中止时会引发重试被尝试.除非您的应用程序在并发和锁定设计方面存在问题,否则如果重试,这种情况不太可能消失.
Of these, I would not generally expect transaction_integrity_constraint_violation
to trigger a retry, since that'll be raised when a DEFERRED
foreign key check causes a transaction to abort when commit is attempted. This is unlikely to go away if retried unless your application has issues with concurrency and locking design.
我没有遇到statement_completion_unknown
;我建议查一下.
I haven't encountered statement_completion_unknown
; I'd suggest looking it up.
我个人只会重试 deadlock_detected
和 serialization_failure
.
Personally I would retry on deadlock_detected
and serialization_failure
only.
这篇关于可序列化事务中的所有 40 类错误都正常吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!