← 返回刚才阅读的位置

知识卡片

普通读书笔记卡 · 302.a

多次写入需要原子性

理解等级:中级

一次业务操作先更新用户最后访问时间,再插入访问日志,若第二步失败,数据库便只保留部分结果。把两次修改放在同一个数据库事务中,才能在失败时一起回滚。问题不取决于代码有多少行,而取决于必须共同成立的业务结果是否共享原子提交边界。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • 实现简单业务逻辑 · 查看原书依据

      If any issue occurs after the record in the Users table was updated (line 7) but before appending the log record on line 9 succeeds, the system will end up in an inconsistent state. The Users table will be updated but no corresponding record will be written to the VisitsLog table. The issue can be

    参考来源

    - 位置:《Learning Domain-Driven Design》第5章《实现简单业务逻辑》(来源项目:book-sources;源文件:extracted/Learning Domain-Driven Design/_epub-src/OEBPS/ch05.html) - 结论依据:原文对该概念的定义、应用条件及相邻概念的比较支撑本卡解释。 - 原始内容:If any issue occurs after the record in the Users table was updated (line 7) but before appending the log record on line 9 succeeds, the system will end up in an inconsistent state. The Users table will be updated but no corresponding record will be written to the VisitsLog table. The issue can be