oracle 2PL,Rigorous vs Strict Model,有什么好处吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29722886/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
2PL, Rigorous vs Strict Model, Is there any benefit?
提问by Anjela Minoeu
In 2PL (two phase locking), what advantage(s) does the rigorous model have over the strict model?
在 2PL(两相锁定)中,严格模型比严格模型有什么优势?
I) There is no advantage over the strict model.
I) 与严格模型相比没有优势。
II) In contrast to the strict model, it guarantees that starvation cannot occur.
II) 与严格模型相反,它保证不会发生饥饿。
III) In contrast to the strict model, it guarantees that deadlock cannot occur.
III) 与严格模型相反,它保证不会发生死锁。
IV) In contrast to the strict model, there is no need to predict data needed in the future.
IV) 相对于严格模型,不需要预测未来需要的数据。
My note says all of the above are false. I am a bit confused. Can someone clarify for me why all of this is false?
我的笔记说以上所有都是错误的。我有点困惑。有人可以为我澄清为什么所有这些都是错误的吗?
回答by Tharif
What is Two-Phase Locking (2PL) Protocol ?
什么是两相锁定 (2PL) 协议?
A transaction is two-phase locked if:
before reading x, it sets a read lock on x
before writing x, it sets a write lock on x
it holds each lock until after it executes the corresponding operation
after its first unlock operation, it requests no new locks
Now, what is Strict phase locking ?
现在,什么是严格锁相?
Here a transaction must hold all its exclusive locks till it commits/aborts.
在这里,事务必须持有其所有的排他锁,直到它提交/中止。
But ,whats rigorous 2PL ?
但是,什么是严格的 2PL?
Rigorous two-phase locking is even stricter: here all locks are held till commit/abort. In this protocol transactions can be serialized in the order in which they commit.
严格的两阶段锁定甚至更严格:这里所有的锁都被持有,直到提交/中止。在这个协议中,事务可以按照它们提交的顺序进行序列化。
Much deeper :
更深:
Strict 2PL :
严格的 2PL :
Same as 2PL but Hold all exclusive locks until the transaction has already successfully committed or aborted. –It guarantees cascadeless recoverability
与 2PL 相同,但持有所有排他锁,直到事务已成功提交或中止。– 它保证了无级联的可恢复性
Rigorous 2PL :
严谨的2PL:
Same as Strict 2PL but Hold all locks until the transaction has already successfully committed or aborted. –It is used in dynamic environments where data access patterns are not known before hand.
与 Strict 2PL 相同,但保留所有锁,直到事务已成功提交或中止。– 它用于事先不知道数据访问模式的动态环境。
There is no deadlock. Also, a younger transaction requesting an item held by an older transaction is aborted and restart with the same timestamp, starvation is avoided.
没有死锁。此外,请求旧交易持有的项目的新交易被中止并以相同的时间戳重新启动,避免了饥饿。
I hope that above clear explanations with diagram must have made you clear about the concept and advantages of rigorous over the other.
希望上面的图解说明一定已经让你明白了严谨的概念和优势。
Thanks
谢谢
回答by Simo Kivist?
I - there is an advantage
我 - 有优势
Look at this lecture note from UCLA:
Rigorous two-phase locking has the advantages of strict 2PL. In addition it has the property that for two conflicting transactions, their commit order is their serializability order. In some systems users might expect this behavior.
严格的两阶段锁定具有严格的 2PL 的优点。此外,对于两个冲突的事务,它们的提交顺序是它们的可序列化顺序。在某些系统中,用户可能会期望这种行为。
These lecture noteshave an example (the model in the example is strict - not rigorous):
这些讲义有一个例子(例子中的模型是严格的——不严谨):
Consider two transactions conducted at the same site in which a long running transaction T1 which reads x is ordered before a short transaction T2 that writes x. T2 returns first, showing an update version of x long before T1 completes based on the old version.
考虑在同一站点执行的两个事务,其中读取 x 的长时间运行的事务 T1 在写入 x 的短事务 T2 之前排序。T2 首先返回,在 T1 完成之前基于旧版本显示 x 的更新版本。
II and III - does not affect deadlocks/starvation
II 和 III - 不影响死锁/饥饿
Rigorous 2PL means that all locks are releasedafter the transaction ends as opposed to strict where read-only locks may be released earlier. This doesn't affect deadlocks or starvation as those occur in the expandingphase (a transaction cannot acquire the needed lock). In a deadlock both processes are always in the expanding phase.
严格的 2PL 意味着在事务结束后释放所有锁,而不是严格的,只读锁可能会更早释放。这不会影响死锁或饥饿,因为它们发生在扩展阶段(事务无法获取所需的锁)。在死锁中,两个进程总是处于扩展阶段。
IV - both need to know the needed data for locking in the expanding phase - shrinking phase varies
IV - 两者都需要知道在扩展阶段锁定所需的数据 - 收缩阶段各不相同
Strict:I don't know the usual implementation details of strict 2PL but if a read lock is released before a transaction ends there has to be a knowledge (100% sure prediction if you like) that the lock is not needed later in the transaction.
Rigorous:All the read locks are released at the end of a transaction and the transaction never has to evaluate if it should release a read lock or keep it for later reads in the transaction.
严格:我不知道严格 2PL 的通常实现细节,但如果在事务结束之前释放读锁,则必须知道(如果您愿意,可以 100% 确定预测)在事务后期不需要该锁.
严谨:所有读锁在事务结束时被释放,事务永远不必评估它是否应该释放读锁或保留它以供以后在事务中读取。
Is rigorous or strict more used/preferred?
更常用/更喜欢严格还是严格?
Which of those two models to use would depend on the situation. Modern DBMS use more complex concurrency handling than simple rigorous or strict 2PL. Having said that judging by the Wikipedia article on two-phase lockingthe rigorous (SS2PL) model is more widely used:
使用这两种模型中的哪一种取决于具体情况。现代 DBMS 使用比简单的严格或严格的 2PL 更复杂的并发处理。话虽如此,从维基百科关于两阶段锁定的文章来看,严格(SS2PL)模型被更广泛地使用:
SS2PL [rigorous] has been the concurrency control protocol of choice for most database systems and utilized since their early days in the 1970s. [...]
2PL in its general form, as well as when combined with Strictness, i.e., Strict 2PL (S2PL), are not known to be utilized in practice. The popular SS2PL does not require marking "end of phase-1" as 2PL and S2PL do, and thus is simpler to implement. Also, unlike the general 2PL, SS2PL provides, as mentioned above, the useful Strictness and Commitment ordering properties. [...]
SS2PL Vs. S2PL: Both provide Serializability and Strictness. Since S2PL is a super class of SS2PL it may, in principle, provide more concurrency. However, no concurrency advantage is typically practically noticed (exactly same locking exists for both, with practically not much earlier lock release for S2PL), and the overhead of dealing with an end-of-phase-1 mechanism in S2PL, separate from transaction-end, is not justified. Also, while SS2PL provides Commitment ordering, S2PL does not. This explains the preference of SS2PL over S2PL. [...]
SS2PL [rigorous] 一直是大多数数据库系统的并发控制协议,从 1970 年代早期就开始使用。[...]
2PL 的一般形式,以及与 Strictness 结合使用时,即 Strict 2PL (S2PL),在实践中尚不清楚。流行的 SS2PL 不需要像 2PL 和 S2PL 那样标记“阶段 1 结束”,因此更易于实现。此外,与一般的 2PL 不同,SS2PL 提供了有用的 Strictness 和 Commitment 排序属性,如上所述。[...]
SS2PL 对比 S2PL:两者都提供可序列化性和严格性。由于 S2PL 是 SS2PL 的超类,因此原则上它可以提供更多的并发性。但是,实际上通常没有注意到并发优势(两者存在完全相同的锁定,S2PL 的锁定释放实际上并不多),并且在 S2PL 中处理阶段 1 结束机制的开销,与事务分离 -结束,是没有道理的。此外,虽然 SS2PL 提供承诺排序,但 S2PL 没有。这解释了 SS2PL 优于 S2PL 的原因。[...]
回答by user5332534
Transaction T2 in the above example does not follow 2PL and S2PL as a lock request (lock B) is done after the lock release unlock(A) - hence violating the protocol.
上例中的事务 T2 不遵循 2PL 和 S2PL,因为在锁定释放 unlock(A) 之后完成了锁定请求(锁定 B)——因此违反了协议。
回答by Alireza Kavianifar
Rigorous two phase locking is similar to strict two phase locking with two major differences:
严格的两相锁定类似于严格的两相锁定,但有两个主要区别:
- In strict two phase locking the shared locks are released in shrinking phase, but in rigorous two phase locking all the shared and exclusive locks are kept until the end of the transaction.
- In rigorous two phase locking we do not need to know the access pattern of locks on data items beforehand so it is more appropriate for dynamic environments while in strict two phase locking the access pattern of locks should be specified at the start of transaction.
- 在严格的两阶段锁定中,共享锁在收缩阶段释放,但在严格的两阶段锁定中,所有共享锁和排他锁都保留到事务结束。
- 在严格的两阶段锁定中,我们不需要事先知道数据项上锁的访问模式,因此更适合动态环境,而在严格的两阶段锁定中,应在事务开始时指定锁的访问模式。
So the fourth option is the correct one.
所以第四个选项是正确的。