加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

并发 – 聚合是否应该涉及数据库中的读锁?

发布时间:2020-12-14 04:59:34 所属栏目:百科 来源:网络整理
导读:我读了Eric Evan的关于DDD的书,聚合章节. 在处理Order / OrderLine示例时,声明: When both users have saved their changes,an Order will be stored in the database that violates the invariant of the domain model. An important business rule has be
我读了Eric Evan的关于DDD的书,聚合章节.

在处理Order / OrderLine示例时,声明:

When both users have saved their changes,an Order will be stored in the
database that violates the invariant of the domain model. An important
business rule has been broken. And nobody even knows. Clearly,locking
a single line-item isn’t an adequate safeguard. If,instead,we locked
an entire Order at a time
,the problem would have been prevented.

我很清楚Aggregate的本质是用单个包装的数据库事务来保护不变量.

但是,是否应该在数据库端使用读锁定指定每个聚合,以防止潜在的并发问题(竞争条件),同时由多个用户同时修改此聚合?

制作聚合的真正含义是为数据库端的读锁收集一些元素吗?

对此的任何澄清都会让我感到高兴.

解决方法

不,这两者是正交的:

聚合设计的目标是建立一致性边界并保护该边界内的不变量.锁定设计的目标是在应用程序中实现适当的并发级别.

这意味着使用相同的聚合设计,不同的锁定机制可能有意义(取决于应用程序的非功能性要求).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读