









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










Computing & Information Sciences CIS 560: Database System Concepts Monday, 20 Nov 2006 Kansas State University
Monday, 20 November 2006
William H. Hsu Department of Computing and Information Sciences, KSU
KSOL course page: http://snipurl.com/va Course web site: http://www.kddresearch.org/Courses/Fall-2006/CIS Instructor home page: http://www.cis.ksu.edu/~bhsu
Reading for Next Class: First half of Chapter 16, Silberschatz et al. , 5th^ edition
Computing & Information Sciences CIS 560: Database System Concepts Monday, 20 Nov 2006 Kansas State University
z Lock-Based Protocols z Timestamp-Based Protocols z Validation-Based Protocols z Multiple Granularity z Multiversion Schemes z Deadlock Handling z Insert and Delete Operations z Concurrency in Index Structures
Computing & Information Sciences CIS 560: Database System Concepts Monday, 20 Nov 2006 Kansas State University
z A lock is a mechanism to control concurrent access to a data item z 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. S-lock is requested using lock-S instruction. z Lock requests are made to concurrency-control manager. Transaction can proceed only after request is granted.
Computing & Information Sciences CIS 560: Database System Concepts Monday, 20 Nov 2006 Kansas State University
z Lock-compatibility matrix
z 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 z 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. z 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.
Computing & Information Sciences CIS 560: Database System Concepts Monday, 20 Nov 2006 Kansas State University
z The potential for deadlock exists in most locking protocols. Deadlocks are a necessary evil. z Starvation is also possible if concurrency control manager is badly designed. For example: A transaction 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. z Concurrency control manager can be designed to prevent starvation.
Computing & Information Sciences CIS 560: Database System Concepts Monday, 20 Nov 2006 Kansas State University
z This is a protocol which ensures conflict-serializable schedules. z Phase 1: Growing Phase transaction may obtain locks transaction may not release locks z Phase 2: Shrinking Phase transaction may release locks transaction may not obtain locks z The 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).
Computing & Information Sciences CIS 560: Database System Concepts Monday, 20 Nov 2006 Kansas State University
z Two-phase locking does not ensure freedom from deadlocks z Cascading 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. z Rigorous 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.
Computing & Information Sciences CIS 560: Database System Concepts Monday, 20 Nov 2006 Kansas State University
z There can be conflict serializable schedules that cannot be obtained if two-phase locking is used. z However, in the absence of extra information (e.g., ordering of access to data), two-phase locking is needed for conflict serializability in the following sense: Given a transaction T i that does not follow two-phase locking, we can find a transaction Tj that uses two-phase locking, and a schedule for Ti and Tj that is not conflict serializable.
Computing & Information Sciences CIS 560: Database System Concepts Monday, 20 Nov 2006 Kansas State University
z write (D) is processed as: if Ti has a lock-X on D then 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 ; z All locks are released after commit or abort
Computing & Information Sciences CIS 560: Database System Concepts Monday, 20 Nov 2006 Kansas State University
z A lock manager can be implemented as a separate process to which transactions send lock and unlock requests z The lock manager replies to a lock request by sending a lock grant messages (or a message asking the transaction to roll back, in case of a deadlock) z The requesting transaction waits until its request is answered z The lock manager maintains a data-structure called a lock table to record granted locks and pending requests z The lock table is usually implemented as an in-memory hash table indexed on the name of the data item being locked
Computing & Information Sciences CIS 560: Database System Concepts Monday, 20 Nov 2006 Kansas State University
z Black rectangles indicate granted locks, white ones indicate waiting requests z Lock table also records the type of lock granted or requested z New request is added to the end of the queue of requests for the data item, and granted if it is compatible with all earlier locks z Unlock requests result in the request being deleted, and later requests are checked to see if they can now be granted z If transaction aborts, all waiting or granted requests of the transaction are deleted lock manager may keep a list of locks held by each transaction, to implement this efficiently
Computing & Information Sciences CIS 560: Database System Concepts Monday, 20 Nov 2006 Kansas State University
z Graph-based protocols are an alternative to two-phase locking z Impose a partial ordering → on the set D = { d 1 , d 2 ,..., 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. z The tree-protocol is a simple kind of graph protocol.
Computing & Information Sciences CIS 560: Database System Concepts Monday, 20 Nov 2006 Kansas State University
z Each transaction is issued a timestamp when it enters the system. If an old transaction Ti has time-stamp TS( Ti ), a new transaction Tj is assigned time-stamp TS( Tj ) such that TS( Ti ) <TS( Tj ). z The protocol manages concurrent execution such that the time- stamps determine the serializability order. z In order to assure such behavior, the protocol maintains for each data Q two timestamp values: W-timestamp ( Q ) is the largest time-stamp of any transaction that executed write ( Q ) successfully. R-timestamp ( Q ) is the largest time-stamp of any transaction that executed read ( Q ) successfully.
Computing & Information Sciences CIS 560: Database System Concepts Monday, 20 Nov 2006 Kansas State University
z The timestamp ordering protocol ensures that any conflicting read and write operations are executed in timestamp order. z Suppose a transaction T (^) i issues a read ( Q )
Computing & Information Sciences CIS 560: Database System Concepts Monday, 20 Nov 2006 Kansas State University
z Suppose that transaction Ti issues write ( Q ).
Computing & Information Sciences CIS 560: Database System Concepts Monday, 20 Nov 2006 Kansas State University
A partial schedule for several data items for transactions with timestamps 1, 2, 3, 4, 5
read( Y )
read( X ) read( Y ) write( Y ) write( Z ) read( Z ) read( X ) abort read( X ) write( Z ) abort write( Y ) write( Z )
Computing & Information Sciences CIS 560: Database System Concepts Monday, 20 Nov 2006 Kansas State University
z Modified version of the timestamp-ordering protocol in which obsolete write operations may be ignored under certain circumstances. z When Ti attempts to write data item Q , if TS( Ti ) < W- timestamp( Q ), then Ti is attempting to write an obsolete value of { Q }. Rather than rolling back T (^) i as the timestamp ordering protocol would have done, this { write } operation can be ignored. z Otherwise this protocol is the same as the timestamp ordering protocol. z Thomas' Write Rule allows greater potential concurrency. Allows some view-serializable schedules that are not conflict- serializable.
Computing & Information Sciences CIS 560: Database System Concepts Monday, 20 Nov 2006 Kansas State University
z Execution of transaction Ti is done in three phases.
1. Read and execution phase : Transaction Ti writes only to temporary local variables 2. Validation phase : Transaction Ti performs a ``validation test'' to determine if local variables can be written without violating serializability. 3. Write phase : If Ti is validated, the updates are applied to the database; otherwise, T (^) i is rolled back. z The three phases of concurrently executing transactions can be interleaved, but each transaction must go through the three phases in that order. Assume for simplicity that the validation and write phase occur together, atomically and serially Ö I.e., only one transaction executes validation/write at a time. z Also called as optimistic concurrency control since transaction executes fully in the hope that all will go well during validation
Computing & Information Sciences CIS 560: Database System Concepts Monday, 20 Nov 2006 Kansas State University
z Each transaction Ti has 3 timestamps Start(T (^) i) : the time when T (^) i started its execution Validation(T (^) i): the time when T (^) i entered its validation phase Finish(T (^) i) : the time when T (^) i finished its write phase z Serializability order is determined by timestamp given at validation time, to increase concurrency. Thus TS(T (^) i) is given the value of Validation(T (^) i). z This protocol is useful and gives greater degree of concurrency if probability of conflicts is low. because the serializability order is not pre-decided, and relatively few transactions will have to be rolled back.
Computing & Information Sciences CIS 560: Database System Concepts Monday, 20 Nov 2006 Kansas State University
z If for all Ti with TS ( Ti ) < TS ( Tj ) either one of the following condition holds: finish ( T (^) i ) < start ( T (^) j ) start ( T (^) j ) < finish ( T (^) i ) < validation ( T (^) j ) and the set of data items written by T (^) i does not intersect with the set of data items read by T (^) j. then validation succeeds and Tj can be committed. Otherwise, validation fails and Tj is aborted. z Justification : Either the first condition is satisfied, and there is no overlapped execution, or the second condition is satisfied and the writes of T (^) j do not affect reads of T (^) i since they occur after T (^) i has finished its reads. the writes of T (^) i do not affect reads of T (^) j since T (^) j does not read any item written by T (^) i.