Docsity

Locking Idea and Levels - Database Management - Lecture Slides, Slides of Introduction to Database Management Systems

Partial preview of the text

Download Locking Idea and Levels - Database Management - Lecture Slides and more Slides Introduction to Database Management Systems in PDF only on Docsity!

Database

Management

System

Lecture - 45

Locking Idea

Before performing an operation a transaction applies for a S/E lock on an object

If object free or lock compatible then lock granted otherwise transaction will wait

Deadlock

TIME TA TB t 1 XLock (X)^ ……… t 2 …….^ XLock (Y) t 3 Request Y^ …….. t 4 Wait^ Request X t 5 Wait^ Wait t 6 Wait^ Wait

Deadlock Handling

Deadlock prevention

Deadlock detection and resolution

Prevention is not always possible

Deadlock is detected by wait-for

graph

Two-Phase Locking

2PL ensures serializability but

generates deadlock

The locks are granted and

released in two phases, the

growing and shrinking phase

Two-Phase Locking

A transaction must acquire a lock

before doing any operation

Locks are only granted in growing

phase, once a transaction enters in shrinking phase no locks can acquire

Database

Area A (^) Area B Area C

File A1 (^) File A2 File A

Rec A11 (^) Rec A12 Rec A

At A111 (^) At A112 At A

Granularity of Locks

……. Docsity.com

Granularity of Locks

When a lock at lower level is applied,

compatibility is checked upward

How will a lock at higher level know

about a lock at lower level

Individual checking is not feasible

Intension Locks

While applying for a lock on a node, compatibility with the intension lock is also checked

Share intension lock (SIX)

Conflicts with locks conflicting with S or IX; only one SIX

Extended Comp Matrix

N
Y
N
N
N Y N N N

S IS X IX SIX

Y

Y

N

N

Y

Y

Y

N

N

N

N

N

Y

N

Y

N

IS

S

IX

X

SIX

Timestamping

No locks are used

Guarantees consistency and no deadlocks, however, certain transactions are cancelled

Based on the concept of timestamp

Timestamp

An identifier that determines the relative order of the transactions

Greater timestamp younger the transaction

The transactions’ operations are allowed in the timestamp order

Two Problems

When a transaction wants to read an item that has been updated by a younger transaction

A transaction wants to write an item that has been read or written by a younger transaction

Versions of Data Items

First problem is met by

maintaining multiple versions of

data items

Value read-timestamp write-timestamp 742 6 8