本文介绍了乐观vs多版本并发控制 - 差异?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出,乐观并发控制(OCC)和多版本并发控制(MVCC)之间的区别是什么?



到目前为止,我知道两者都基于版本检查更新。



在OCC中,我阅读了关于读取访问没有获得锁的事务,只有在以后的更新时才会失败,如果在版本增加和版本检查失败之间,则失败。在这种情况下,事务将被回滚。



在MVCC中,它基本相同,或不是?在哪里有区别?

解决方案

我认为它们有时可以互换使用,如果事务只涉及一个对象,相同,但MVCC是乐观并发(或其版本)的扩展,当涉及多个对象时提供保证。
说你有两个对象,A和B,它们之间必须保持一定的不变性。它们是其和为常数的两个数。现在,事务T1从A中减去10并将其添加到B,同时,另一个事务T2正在读取这两个数字。即使你乐观地独立地更新A和B(CAS它们),T2可能得到两个数字的不一致的视图(例如,如果它在修改之前读取A,但在修改之后读取B)。 MVCC将确保T2通过可能返回其旧值而读取A和B的一致视图,即它必须保存旧版本。



总而言之,乐观锁定或乐观并发控制),是同步w / o锁的一般原则。 MVCC是一种乐观的技术,允许跨越多个对象的隔离事务。


I am trying to find out, what the difference between optimistic concurrency control (OCC) and multi version concurrency control (MVCC) is?

So far I know that both is based on version checking for updates.

In OCC, I read about transactions that acquire no locks for reading access, only for the later update which will fail if in between the version was incremented and version checking fails. In this case the transaction will be rolled back.

In MVCC, it is basically the same, or not? Where is the difference?

解决方案

I think they are sometimes used interchangeably, and if the transaction only involves one object then they are essentially the same, but MVCC is an extension of optimistic concurrency (or a version of it) that provides guarantees when more than one object is involved.Say that you have two objects, A and B, which must maintain some invariant between them, e.g. they are two numbers whose sum is constant. Now, a transaction T1 subtracts 10 from A and adds it to B, while, concurrently, another transaction T2 is reading the two numbers.Even if you optimistically update A and B independently (CAS them), T2 could get an inconsistent view of the two numbers (say, if it reads A before it's modified but reads B after it's been modified). MVCC would ensure T2 reads a consistent view of A and B by possibly returning their old values, i.e., it must save the old versions.

To sum up, optimistic locking (or optimistic concurrency control), is a general principle for synchronization w/o locks. MVCC is an optimistic technique which allows isolated transactions which span multiple objects.

这篇关于乐观vs多版本并发控制 - 差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 02:26