← 返回刚才阅读的位置

知识卡片

结构图卡 · 1971.o.1.b.4.d.1.c.4.a.1.b

共享部件加锁造成循环等待

理解等级:高级

原书继续追问部件价格变化是否会影响采购单,于是试着同时锁采购单和共享部件。不同人操作不同采购单却使用同一部件,会因共享部件锁而互相阻塞;图6.9–6.10中一人持有长号锁、等待小提琴,另一人持有小提琴锁、等待长号,形成循环等待。根因是把跨采购单共享且高争用的部件纳入即时锁定范围。对应方案见[[行项保存成交价降低争用]]。

结构图:

flowchart LR
    George["George:持有长号部件锁"] -->|等待小提琴部件锁| Amanda["Amanda:持有小提琴部件锁"]
    Amanda -->|等待长号部件锁| George
这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • 原书第06章|Aggregates · 查看原书依据

      Consider that "part." If someone changed the price of a trombone while Amanda was adding to her order, wouldn't that violate the invariant too? Let's try locking the part in addition to the entire PO. Here's what happens when George, Amanda, and Sam are working on different POs: Figure 6.9. Over-cautious locking is interfering with people's work. The inconvenience is mounting, because there is a lot of contention for the instruments (the "parts"). And then: Figure 6.10. Deadlock Those three will be waiting a while. At this point we can begin to improve the model by incorporating the following knowledge of the business: Parts are used in many POs (high contention).

    参考来源

    - 位置:《Domain-Driven Design: Tackling Complexity in the Heart of Software》第44章《原书第06章|Aggregates》(源文件:_epub-src/0321125215_ch06lev1sec1.html;图6.9–6.10) - 结论依据:正文提出采购单与部件同时加锁并描述共享乐器争用;图6.9–6.10显示两个编辑者分别等待对方锁住的部件,标记为死锁。 - 原始内容:Consider that "part." If someone changed the price of a trombone while Amanda was adding to her order, wouldn't that violate the invariant too? Let's try locking the part in addition to the entire PO. Here's what happens when George, Amanda, and Sam are working on different POs: Figure 6.9. Over-cautious locking is interfering with people's work. The inconvenience is mounting, because there is a lot of contention for the instruments (the "parts"). And then: Figure 6.10. Deadlock Those three will be waiting a while. At this point we can begin to improve the model by incorporating the following knowledge of the business: Parts are used in many POs (high contention). (图注和后续列表按原 EPUB 抽取顺序转录;两人锁等待关系据图6.9–6.10绘制,Sam另在等待长号锁。)