Yug*_*hou 5 optimistic-locking
当使用乐观锁定策略时,它可以解决如下的并发问题:
| 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? | | | |
我做了一个实验,第二个事务中的更新无法读取'脏'版本,因为第一个事务尚未提交.在这种情况下,第二笔交易会失败吗?
您在问题中没有说明您实际使用的数据库系统,所以我不知道您系统的详细信息。
但无论如何,在乐观锁定系统下,进程在执行更新语句时不能只检查行版本,因为这正是您担心的问题。
对于完全可序列化、隔离的事务,每个进程必须在提交时自动检查其检查和修改的所有行的行版本。因此,在第二种情况下,右侧进程在尝试提交之前不会检测到冲突(您没有为右侧进程包含此步骤)。当它尝试提交时,它会检测到冲突并回滚。
| 归档时间: |
|
| 查看次数: |
538 次 |
| 最近记录: |