使用乐观锁定策略时,它可以解决像下面并发问题:乐观锁定绝对安全吗?
| the first transaction started | | | | select a row | | | the second transaction started | update the row with version checking | | | select the same row | commit txn | | | update the row with version checking | | | | rolls back because version is dirty
但是,如果在极少数情况下,如果在第二个事务更新是在第一笔交易,但之前的UDPATE后交易提交?
| the first transaction started | | | the second transaction started | select a row | | | select the same row | update the row with version checking | | | update the row with version checking | commit txn | | | rolls back because version is dirty // will it? | | | |
我做了一个实验,在第二个事务更新无法读取“脏”的版本,因为第一个事务还没有被提交。第二笔交易在这种情况下会失败吗?
@亚当阿罗德谢谢你告诉我这句格言。我谷歌因为我不是一个本地的英语演讲者:)但乐观锁定策略会在我提到的情况下工作吗? – Hippoom
如果真的乐观,你怎么使用交易功能?更新将自动失败,无需任何回滚。 – tia
@tia也许在这个例子中,无论有无事务都可以。但有时我需要将其他更改(例如可能插入某个子表的某些子元素)回滚到数据库 – Hippoom