Chapter 16: Concurrency Control Lock- Based Protocols(基于锁的协议) Timestamp- Based protocols(基于肘间戳的协议 Validation- Based Protocols(基于有效性检查的协议) Multiple Granularity(多粒度 Multiversion schemes(多版本机制 Deadlock Handling(死锁处理) Insert and Delete Operations(插入与删除处理) 标 Database System Concepts 3rd Edition 16.1 OSilberschatz, Korth and Sudarshan
Database System Concepts 3 16.1 ©Silberschatz, Korth and Sudarshan rd Edition Chapter 16: Concurrency Control Lock-Based Protocols(基于锁的协议) Timestamp-Based Protocols(基于时间戳的协议) Validation-Based Protocols(基于有效性检查的协议) Multiple Granularity(多粒度) Multiversion Schemes(多版本机制) Deadlock Handling(死锁处理) Insert and Delete Operations(插入与删除处理)
Lock-Based Protocols(基于锁的协议) A lock is a mechanism to control concurrent access to a data item Data items can be locked in two modes 1. exclusive排他锁(x) mode Data item can be both read as well as written. X-lock is requested using lock-X nstruction 2. shared共享锁(S)mode. Data item can only be read.S lock is requested using lock-s instruction. Lock requests are made to concurrency-control manager. Transaction can proceed only after request is granted. 标 Database System Concepts 3rd Edition 16.2 OSilberschatz, Korth and Sudarshan
Database System Concepts 3 16.2 ©Silberschatz, Korth and Sudarshan rd Edition Lock-Based Protocols(基于锁的协议) A lock is a mechanism to control concurrent access to a data item Data items can be locked in two modes : 1. exclusive排他锁(X) mode. Data item can be both read as well as written. X-lock is requested using lock-X instruction. 2. shared共享锁(S) mode. Data item can only be read. Slock is requested using lock-S instruction. Lock requests are made to concurrency-control manager. Transaction can proceed only after request is granted
Lock-Based Protocols(Cont) 6 ck-compati bility matrix(锁相容性矩阵) s true false X false false A transaction may be granted a lock on an item if the requested lock is compatible with locks already held on the item by other transactions Any number of transactions can hold shared locks on an item, but if any transaction holds an exclusive on the item no other transaction may hold any lock on the item If a lock cannot be granted, the requesting transaction is made to wait till all incompatible locks held by other transactions have been release ed. The lock is then granted d Database System Concepts 3rd Edition 16.3 OSilberschatz, Korth and Sudarshan
Database System Concepts 3 16.3 ©Silberschatz, Korth and Sudarshan rd Edition Lock-Based Protocols (Cont.) Lock-compatibility matrix(锁相容性矩阵) A transaction may be granted a lock on an item if the requested lock is compatible with locks already held on the item by other transactions Any number of transactions can hold shared locks on an item, but if any transaction holds an exclusive on the item no other transaction may hold any lock on the item. If a lock cannot be granted, the requesting transaction is made to wait till all incompatible locks held by other transactions have been released. The lock is then granted
Lock-Based Protocols(Cont) Example of a transaction performing locking: T1: lock-X(B) lock-S(A) read(B read(A) B:=B-50 unlock(A) write (B) lock-S(B) unlock(B) read(B) lock-X(A unlock( B); read(A) display(A+B) A:=A+50 write(A) unlock(B) Database System Concepts 3rd Edition 16.4 OSilberschatz, Korth and Sudarshan
Database System Concepts 3 16.4 ©Silberschatz, Korth and Sudarshan rd Edition Lock-Based Protocols (Cont.) Example of a transaction performing locking: T1: lock-X(B) T2 : lock-S(A) read (B) read (A) B:=B-50 unlock(A) write(B) lock-S(B) unlock(B) read (B) lock-X(A) unlock(B); read(A) display(A+B) A:=A+50 write(A) unlock(B)
Lock-Based Protocols(Cont. concurrency-control manager lock-X(B) grant-x(B,T1) read (B) B:=B-50 write(B) unlock(B) lock-S(A grant-S A,T2) read(A) unlock(A lock-S(B) grant-s(B, T2) read(B) unlock(B display(A+B) lock-X(A) grant-X(A, T1) read (A A:=A+50 write(A) unlock(B) Database System Concepts 3rd Edition 16.5 OSilberschatz, Korth and Sudarshan
Database System Concepts 3 16.5 ©Silberschatz, Korth and Sudarshan rd Edition Lock-Based Protocols (Cont.) T1 T2 concurrency-control manager lock-X(B) grant-X(B,T1) read (B) B:=B-50 write(B) unlock(B) lock-S(A) grant-S(A,T2) read (A) unlock(A) lock-S(B) grant-S(B,T2) read (B) unlock(B) display(A+B) lock-X(A) grant-X(A,T1) read(A) A:=A+50 write(A) unlock(B)