Docsity

Concurrency Control Two - Advanced Database System - Lecture Slides, Slides of Database Management Systems (DBMS)

Partial preview of the text

Download Concurrency Control Two - Advanced Database System - Lecture Slides and more Slides Database Management Systems (DBMS) in PDF only on Docsity!

1

Advanced Database Systems

Notes 12: Concurrency Control (II)

2

How to enforce serializable schedules?

Option 1: run system, recording P(S);

at end of day, check for P(S)

cycles and declare if execution

was good

4

A locking protocol

Two new actions:

lock (exclusive): li (A)

unlock: u i (A)

scheduler

T 1 T 2

lock

table

5

Rule #1: Well-formed transactions

Ti: … l i(A) … p i(A) … ui(A) ...

7

  • What schedules are legal?

What transactions are well-formed?

S1 = l 1 (A)l 1 (B)r 1 (A)w 1 (B)l 2 (B)u 1 (A)u 1 (B)
r 2 (B)w 2 (B)u 2 (B)l 3 (B)r 3 (B)u 3 (B)
S2 = l 1 (A)r 1 (A)w 1 (B)u 1 (A)u 1 (B)
l 2 (B)r 2 (B)w 2 (B)l 3 (B)r 3 (B)u 3 (B)
S3 = l 1 (A)r 1 (A)u 1 (A)l 1 (B)w 1 (B)u 1 (B)
l 2 (B)r 2 (B)w 2 (B)u 2 (B)l 3 (B)r 3 (B)u 3 (B)

Exercise:

8

  • What schedules are legal?

What transactions are well-formed?

S1 = l 1 (A)l 1 (B)r 1 (A)w 1 (B)l 2 (B)u 1 (A)u 1 (B)
r 2 (B)w 2 (B)u 2 (B)l 3 (B)r 3 (B)u 3 (B)
S2 = l 1 (A)r 1 (A)w 1 (B)u 1 (A)u 1 (B)
l 2 (B)r 2 (B)w 2 (B)l 3 (B)r 3 (B)u 3 (B)
S3 = l 1 (A)r 1 (A)u 1 (A)l 1 (B)w 1 (B)u 1 (B)
l 2 (B)r 2 (B)w 2 (B)u 2 (B)l 3 (B)r 3 (B)u 3 (B)

Exercise:

10

Schedule F

T1 T2 25 25

l 1 (A);Read(A) A A+100;Write(A);u 1 (A) 125 l 2 (A);Read(A) A Ax2;Write(A);u 2 (A) 250 l 2 (B);Read(B) B Bx2;Write(B);u 2 (B) 50 l 1 (B);Read(B) B B+100;Write(B);u 1 (B) 150 250 150

A B

11

Rule #3 Two phase locking (2PL)

for transactions

Ti = ……. l i(A) ………... ui(A) ……...

no unlocks no locks

13

Schedule G

T1 T

l 1 (A);Read(A) A A+100;Write(A) l 1 (B); u 1 (A) l 2 (A);Read(A) A Ax2;Write(A);l 2 (B) delayed

14

Schedule G

T1 T

l 1 (A);Read(A) A A+100;Write(A) l 1 (B); u 1 (A) l 2 (A);Read(A) A Ax2;Write(A);l 2 (B) Read(B);B B+ Write(B); u 1 (B) delayed

16

Schedule H (T 2 reversed)

T1 T

l 1 (A); Read(A) l 2 (B);Read(B) A A+100;Write(A) B Bx2;Write(B) l 1 (B) l 2 (A) delayed delayed

17

  • Assume deadlocked transactions are

rolled back

  • They have no effect
  • They do not appear in schedule

E.g., Schedule H =

This space intentionally left blank!

19

Conflict rules for li(A), ui(A):

  • l i(A), lj (A) conflict
  • l i(A), uj (A) conflict Note: no conflict < u i (A), u j (A)>, < l i (A), r j (A)>,...

20

Theorem Rules #1,2,3 ⇒ conflict

(2PL) serializable

schedule

To help in proof:

Definition Shrink(Ti) = SH(Ti) =

first unlock action of Ti