先决条件 – 两相锁定协议和两相锁定的类别
1. 保守的 2-PL :
- 它也称为静态 2-PL。
- 该协议要求事务在事务开始执行之前通过预先声明其读集和写集来锁定它访问的所有项目。
- 如果需要的任何预先声明的项目无法锁定,则事务不会锁定任何项目,而是等待所有项目都可用于锁定。
2. 严谨的2-PL:
- 这要求除了锁是 2-Phase 之外,事务持有的所有 Exclusive(X) 和 Shared(S) 锁都被释放,直到事务提交之后。
- 严格比严格 2-PL 更具限制性。
- Rigorous 2-PL 的实现很容易。
Conservative 和 Rigorous 2-PL 的区别:
S.No. | Conservative 2-PL | Rigorous 2-PL |
---|---|---|
1. | A transaction has to acquire locks on all the data items it requires before the transaction begins it execution. | A transaction can acquire locks on data items whenever it requires (only in growing phase) during its execution. |
2. | It does not have a growing phase. | It has a growing phase. |
3. | It has a shrinking phase. | It does not have a shrinking phase. |
4. | It ensures that the schedule generated would be Serializable and Deadlock-Free. | It ensures that the schedule generated would be Serializable, Recoverable and Cascadeless. |
5. | It does not ensures Recoverable and Cascadeless schedule. | It does not ensures Deadlock-Free schedule. |
6. | It does not ensure Strict Schedule. | It ensures that the schedule generated would be Strict. |
7. | It is not used in practise as its difficult to implement. | It is easy to implement but a lighter version of it (i.e Strict 2-PL) is used in practise. |
8. | In Conservative 2-PL, a transaction can read a value of uncommitted transaction. | In Rigorous 2-PL, a transaction only reads value of committed transaction. |