Docsity

Locking Methods - Data Base Management System - Lecture Slides, Slides of Database Management Systems (DBMS)

Partial preview of the text

Download Locking Methods - Data Base Management System - Lecture Slides and more Slides Database Management Systems (DBMS) in PDF only on Docsity!

Locking Methods and Deadlock

Review:

♦ Properties of transactions: ACID

♦ Concurrency control is needed Example: the lost update problem

Locking Methods

Locking: A procedure used to control concurrent access to data. When one transaction is accessing the database, a lock may deny access to other transactions to prevent incorrect results.

Lock types:

♦ Shared lock (read lock) : If a transaction has a shared lock on a data item, it can read the item but not update it. ♦ Exclusive lock (write lock) : If a transaction has an exclusive lock on a data item, it can both read and update the item.

Two-phase locking(2PL)

♦ A transaction follows 2PL protocol if all locking operations precede first unlock operation in the transaction

♦ Two phases for transaction:

  • Growing phase - acquires all locks needed but cannot release any locks.
  • Shrinking phase - releases locks but cannot acquire any new locks.

Example: Preventing the lost update

problem using 2PL

Deadlock

An impasse that may result when two (or more) transactions are each waiting for locks to be released that are held by the other.

Deadlock example:

Wait-For Graph (WFG)

  • WFG is a directed graph G = ( N, E)
  • Create a node for each transaction
  • Create a directed edge T (^) i T (^) j
  • Deadlock exists if and only if the WFG contains a cycle.

Recovery from deadlock detection

  • Choice of deadlock victim
  • how long the transaction has been running
  • how many data items have been updated
  • how many data items need to be updated
  • How far to roll a transaction back

* it is possible to resolve the deadlock by

rolling back only part of the transaction.