如javascript - A lot of WriteConflict errors with MongoDB transactions - Stack Overflow中所示,假设一个事务所做的操作是“read-modify-write”,那么在多线程的环境下会出现 WriteConflict 。它介绍了两种解决方案,一种是排队系统,另一种是重新运行系统。个人觉得重新运行系统是不适合在竞争激烈的情况下使用的,那样只能让情况变得更糟。想问一下大家是怎么处理 MongoDB 的 WriteConflict 的?
![]() |
1
guyeu 14 天前
避免 WriteConflict ?
|
2
JasonLaw 14 天前 via iPhone
@guyeu #1 排队系统其实就是避免的一种方法,而重新运行系统更像是“在避免不了或者不避免的情况下,应该怎么做”。但是在竞争激烈的环境下,重新运行系统真的是种好的解决方案吗?
|
![]() |
3
Nillouise 13 天前
跟 arp 解决冲突思路那样,重新运行系统需要等待一个随机时间,怎么样?
|
![]() |
6
guyeu 13 天前
@JasonLaw #5 你的文章倒数第二段
> MongoDB does lock a document that is being modified by a transaction. However, other sessions that attempt to modify that document do not block. Rather, their transaction is aborted, and they are required to retry the transaction. This is potentially wasteful since other operations in the transaction will need to be re-executed, and also results in requests being serviced in a non-deterministic order. |