# DB2 - lesson 03 #### Paraboschi ##### 13 October 2015 ## Concurrency Control pt.II ### Conflict Graph It is used to test __conflict-serializability__ #### Structure: - One node for each transaction $T_i$ - One arc from $T_i$ to $T_j$ if it exists at least one conflict between an action of $T_i$ and an action of $T_j$ such as $a_i$ precedes $a_j$. A schedule is in __CSR__ iff its __conflict graph__ is __acyclic__. #### Properties: - if $S$'s graph is *acyclic*, then it has a - __topological sort__: An ordering of the nodes such that the graph only contains arcs (i,j) with iLocks on a transaction can be released only after commit/rollback This version of 2PL is used in commercial DBMSs #### Implementation of 2-Phase Locking Lock tables are in reality __main memory data structures__ - Resource state can be: - free - read-locked - write-locked - Every resource has also a __read counter__ - Some late '90 systems only supported exclusive locks (binary info, no counter) A transaction asking for a lock is either franted a lock or __queued and suspended__, the queue is FIFO, there is danger of: - __Deadlock__: endless wait - __Starvation__: individual transaction waiting forever Starvation can occur for write transactions waiting for resources which are higly used for reading (e.g. index roots)