知识卡片
库存先读后写存在竞态
两个购买流程先读到同一正库存,再分别据此扣减和收款;第一个把库存变为零后,第二个的旧读取条件已失效。若不保护这个读写依赖,业务就可能接受超出当前库存的购买。此问题发生在并发决策窗口,不能靠“每个API都成功”消除。对应收束方式见[[原子预留收束库存读写]]。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 保持状态一致 · 查看原书依据
Here, we read the item count, and the next operation depends on this. Consider that there are two transactions happening, and both have read the item count. If the first transaction checks the condition and updates the item count to zero, to enforce the isolation condition of transactions, the database must roll back the second transaction.
参考来源
- 位置:《Software Architecture and Decision-Making》第07章《保持状态一致》(来源项目:book-sources;源文件:extracted/Software Architecture and Decision-Making Leveraging Leadership, Technology, and Product Management to Build Great Products… (Srinath Perera)/_epub-src/ch07.xhtml)
- 结论依据:所引连续原文给出本卡机制或取舍;条件与示例结合本节已读上下文解释。
- 原始内容:Here, we read the item count, and the next operation depends on this. Consider that there are two transactions happening, and both have read the item count. If the first transaction checks the condition and updates the item count to zero, to enforce the isolation condition of transactions, the database must roll back the second transaction.