database-concurrency control-notes

1. Two-phase Locking

  • T want to R/W on X-->Get the lock on X first!
  • issue lock and unlock requests in 2 phases

a. Growing Phase: only lock; no unlock

b. Shrinking Phase: only unlock; no lock

  • once Ti releases a lock, it can never request lock.
  • 2PL allows only conflict-serializable schedules;
  • Not all conflict-serializable schedules are allowed by 2PL

e.g.: 

(1)

transactions with lock-unlock sequence conforming 2PL protocol

T1: Slock(A),Xlock(B),SLock(C)       Unlock(B),Unlock(C),Unlock(A)    Commit

T2: Slock(A),  Xlock(B)Wait.................Xlock(B)          Unlock(A),Unlock(B)         Commit

 

transactions violating 2PL protocol:

T1: Slock(A),Slock(B),Unlock(A)         Xlock(A) Unlcok(A) Unlock(B)

T2: Xlock(C),Xlock(D),Unlock(D),Slock(B),Unlock(C),Xlock(D),Unlock(D),Unlock(B)

(2)

A schedule generated by 2PL:

T1:R(A),R(B),R(C)              W(C),

T2:              R(A),R(B),                  W(A)

 

The corresponding lock-unlock sequence

T1:Slock(A),Slock(B),Slock(C)                  Xlock(C),Unlock(A) 

T2:                          Slock(A),Slock(B)                                  Xlock(A),   Unlock(A),Unlock(B),

 

Question: Is it allowed?

Can T2 Xlock on A before it releases the slock on A locked by itself???

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值