浙江大学数据库系统概念PPT第十六章.ppt
《浙江大学数据库系统概念PPT第十六章.ppt》由会员分享,可在线阅读,更多相关《浙江大学数据库系统概念PPT第十六章.ppt(27页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、Silberschatz,Korth and Sudarshan,Bo Zhou16.1Database System Concepts 3rd EditionChapter 16:Concurrency ControlnLock-Based ProtocolsnMultiple GranularitynDeadlock HandlingnInsert and Delete OperationsnConcurrency in Index StructuresSilberschatz,Korth and Sudarshan,Bo Zhou16.2Database System Concepts
2、3rd EditionLock-Based ProtocolsnA lock is a mechanism to control concurrent access to a data itemnData 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.S-lock is r
3、equested using lock-S instruction.nLock requests are made to concurrency-control manager.Transaction can proceed only after request is granted.Silberschatz,Korth and Sudarshan,Bo Zhou16.3Database System Concepts 3rd EditionLock-Based Protocols(Cont.)nLock-compatibility matrixnA transaction may be gr
4、anted a lock on an item if the requested lock is compatible with locks already held on the item by other transactionsnAny 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.nIf a lock cannot
5、 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.Silberschatz,Korth and Sudarshan,Bo Zhou16.4Database System Concepts 3rd EditionLock-Based Protocols(Cont.)nExample of a transaction performing lo
6、cking:T2:lock-S(A);read(A);unlock(A);lock-S(B);read(B);unlock(B);display(A+B)Locking as above is not sufficient to guarantee serializability if A and B get updated in-between the read of A and B,the displayed sum would be wrong.nA locking protocol is a set of rules followed by all transactions while
7、 requesting and releasing locks.Locking protocols restrict the set of possible schedules.Basically,how to generate a correct(serializable)schedule?Silberschatz,Korth and Sudarshan,Bo Zhou16.5Database System Concepts 3rd EditionPitfalls of Lock-Based ProtocolsnConsider the partial schedulenNeither T3
8、 nor T4 can make progress executing lock-S(B)causes T4 to wait for T3 to release its lock on B,while executing lock-X(A)causes T3 to wait for T4 to release its lock on A.nSuch a situation is called a deadlock.To handle a deadlock one of T3 or T4 must be rolled back and its locks released.Silberschat
9、z,Korth and Sudarshan,Bo Zhou16.6Database System Concepts 3rd EditionPitfalls of Lock-Based Protocols(Cont.)nThe potential for deadlock exists in most locking protocols.Deadlocks are a necessary evil.nStarvation is also possible if concurrency control manager is badly designed.For example:A transact
10、ion may be waiting for an X-lock on an item,while a sequence of other transactions request and are granted an S-lock on the same item.The same transaction is repeatedly rolled back due to deadlocks.nConcurrency control manager can be designed to prevent starvation.Silberschatz,Korth and Sudarshan,Bo
11、 Zhou16.7Database System Concepts 3rd EditionThe Two-Phase Locking ProtocolnTwo-Phase Locking is a protocol which ensures conflict-serializable schedules.Phase 1:Growing Phasetransaction may obtain locks transaction may not release locksPhase 2:Shrinking Phasetransaction may release lockstransaction
12、 may not obtain locksnThe protocol assures serializability.It can be proved that the transactions can be serialized in the order of their lock points (i.e.the point where a transaction acquired its final lock).Silberschatz,Korth and Sudarshan,Bo Zhou16.8Database System Concepts 3rd EditionThe Two-Ph
13、ase Locking Protocol(Cont.)nTwo-phase locking does not ensure freedom from deadlocksnCascading roll-back is possible under two-phase locking.To avoid this,follow a modified protocol called strict two-phase locking.Here a transaction must hold all its exclusive locks till it commits/aborts.nRigorous
14、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.Silberschatz,Korth and Sudarshan,Bo Zhou16.9Database System Concepts 3rd EditionThe Two-Phase Locking Protocol(Cont.)nThere may be conflict s
15、erializable schedules that cannot be obtained if two-phase locking is used.nTo obtain conflict serializable schedules though non-two-phase locking protocol,we need:Either to have additional information about the transactionsOr to impose some structure or ordering on the set of date items in the data
16、base.Silberschatz,Korth and Sudarshan,Bo Zhou16.10Database System Concepts 3rd EditionLock ConversionsnLock Conversions:Only acquire X lock when necessary.Provide a mechanism for upgrading a S lock to a X lock.nTwo-phase locking with lock conversions:First Phase:can acquire a lock-S on itemcan acqui
17、re a lock-X on itemcan convert a lock-S to a lock-X(upgrade)Second Phase:can release a lock-Scan release a lock-Xcan convert a lock-X to a lock-S (downgrade)nThis protocol assures serializability.But still relies on the programmer to insert the various locking instructions.Silberschatz,Korth and Sud
18、arshan,Bo Zhou16.11Database System Concepts 3rd EditionAutomatic Acquisition of LocksAutomatic Acquisition of Locks(Commercial DBMS Uses)(Commercial DBMS Uses)nA transaction Ti issues the standard read/write instruction,without explicit locking calls.nThe operation read(D)is processed as:if Ti has a
19、 lock on D then read(D)else begin if necessary wait until no other transaction has a lock-X on D grant Ti a lock-S on D;read(D)endSilberschatz,Korth and Sudarshan,Bo Zhou16.12Database System Concepts 3rd EditionAutomatic Acquisition of Locks(Cont.)nwrite(D)is processed as:if Ti has a lock-X on D the
20、n write(D)else begin if necessary wait until no other trans.has any lock on D,if Ti has a lock-S on D then upgrade lock on D to lock-X else grant Ti a lock-X on D write(D)end;nAll locks are released after commit or abortSilberschatz,Korth and Sudarshan,Bo Zhou16.13Database System Concepts 3rd Editio
21、nOther Concurrency Control ProtocolsnGraph-Based Locking Protocol Tree protocolMaintain partial ordering of all data items.Only X lockGuarantee conflict serializablenTimestamp-Based ProtocolnValidation-Based ProtocolSilberschatz,Korth and Sudarshan,Bo Zhou16.14Database System Concepts 3rd EditionMul
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 浙江大学 数据库 系统 概念 PPT 第十六
限制150内