Lock Conversions(锁的转换) TWo-phase locking with lock conversions First Phase x can acquire a lock-s on item x can acquire a lock-x on item x can convert a lock-s to a lock-x(upgrade) Second Phase 大 can release a lock-S 大 can release a lock-X x can convert a lock-X to a lock-s(downgrade) This protocol assures serializability. But still relies on the programmer to insert the various locking instructions Database System Concepts 3rd Edition 16.11 OSilberschatz, Korth and Sudarshan
Database System Concepts 3 16.11 ©Silberschatz, Korth and Sudarshan rd Edition Lock Conversions(锁的转换) Two-phase locking with lock conversions: – First Phase: can acquire a lock-S on item can acquire a lock-X on item can convert a lock-S to a lock-X (upgrade) – Second Phase: can release a lock-S can release a lock-X can convert a lock-X to a lock-S (downgrade) This protocol assures serializability. But still relies on the programmer to insert the various locking instructions
Lock Conversions(锁的转换) lock-S(a1 lock-S(a1) lock-S(a2) lock-s(a2 lock-S(a3) lock-S(a4) unlock(a1) unlock(a2) lock-S(an) upgrade(a1) 标 Database System Concepts 3rd Edition 16.12 OSilberschatz, Korth and Sudarshan
Database System Concepts 3 16.12 ©Silberschatz, Korth and Sudarshan rd Edition Lock Conversions(锁的转换)
Graph-Based Protocols(基于图的协议) Graph-based protocols are an alternative to two- phase locking Impose a partial ordering >on the set d=d, d2 3 of all data items ★fd→>d, then any transaction accessing both a and d must access d before accessing d x Implies that the set d may now be viewed as a directed acyclic graph, called a database graph The tree-protocol is a simple kind of graph protocol 标 Database System Concepts 3rd Edition 16.13 OSilberschatz, Korth and Sudarshan
Database System Concepts 3 16.13 ©Silberschatz, Korth and Sudarshan rd Edition Graph-Based Protocols(基于图的协议) Graph-based protocols are an alternative to twophase locking Impose a partial ordering → on the set D = {d1 , d2 ,..., dh } of all data items. If di → dj then any transaction accessing both di and dj must access di before accessing dj . Implies that the set D may now be viewed as a directed acyclic graph, called a database graph. The tree-protocol is a simple kind of graph protocol
Tree Protoco(树形协议) 加锁指令只有ockX 事务T的首次加锁可以对任何 数据项进行 此后,事努T对数据项Q加锁的前提是事 务T持有Q的双亲数据项上的锁 The first lock by t, may be on any data item. Subsequently, a data Q can be locked by T; only if the parent of Q is currently locked by T 对数据项解锁可以随时进行 Data items may be unlocked at any time A data item that has been locked and unlocked by T; cannot Le subsequently be relocked by L数据项被事务T加锁并解锁之后 ,就不能再对该数据项加锁 Database System Concepts 3rd Edition 16.1 shan
Database System Concepts 3 16.14 ©Silberschatz, Korth and Sudarshan rd Edition Tree Protocol(树形协议) The first lock by Ti may be on any data item. Subsequently, a data Q can be locked by Ti only if the parent of Q is currently locked by Ti . Data items may be unlocked at any time. A data item that has been locked and unlocked by Ti cannot subsequently be relocked by Ti 加锁指令只有lock-X 事务T的首次加锁可以对任何 数据项进行 此后,事务T对数据项Q加锁的前提是事 务T持有Q的双亲数据项上的锁 对数据项解锁可以随时进行 数据项被事务T加锁并解锁之后 ,就不能再对该数据项加锁
Tree Protocol T T T1 12 T lock-X(B) ock×(D lock-X(H) unlock(D) lock-X(E) (D) unlock (B unlock(E) lock-X(B) lock-X(E) unlock(H) lock-X(G unlock(D lock-X(D) lock-X(H) unlock (D) unlock(H) unlock(E unlock(B) unlock (G) Database System Concepts 3rd Edition 16.15 OSilberschatz, Korth and Sudarshan
Database System Concepts 3 16.15 ©Silberschatz, Korth and Sudarshan rd Edition Tree Protocol