concurrency control 18.1 serial and serializable schedule by: nitin mathur id: 110 cs: 257

14
CONCURRENCY CONTROL 18.1 Serial and Serializable Schedule By: Nitin Mathur Id: 110 CS: 257

Post on 21-Dec-2015

222 views

Category:

Documents


0 download

TRANSCRIPT

CONCURRENCY CONTROL18.1 Serial and Serializable Schedule

By: Nitin MathurId: 110

CS: 257

What Is Concurrency Control & Who controls it?

• A process of assuming that the transactions preserve the consistency when executing simultaneously is called Concurrency Control.

• This consistency is taken care by Scheduler.

Flow How Transaction is Executed

Disk Buffer

INPUT

OUTPUT

READ & WRITE

Transaction Manager

Scheduler

Buffer

Read & Writes

Read / Write Requests

Correctness Principle

• It’s a principle that states that a transaction starts in a correct database state and ends in a correct database state.

• Does the system really follow the correctness principal all the time?

Basic Example Schedule

T1

READ (A,t)t := t+100

WRITE (A,t)READ (B,t)t := t+100

WRITE (B,t)

T2

READ (A,s)s := s*2

WRITE (A,s)READ (B,s)

s := s*2WRITE (B,s)

A=B=50To be consistent the final state should be A=B

Serial Schedule T1 T2 A B

50 50READ (A,t) t := t+100WRITE (A,t) 150READ (B,t) t := t+100WRITE (B,t) 150

READ (A,s) s := s*2 WRITE (A,s) 300 READ (B,s) s := s*2 WRITE (B,s) 300

(T1,T2)

A := 2*(A+100)

Does the order really matter? T1 T2 A B

50 50 READ (A,s) s := s*2 WRITE (A,s) 100 READ (B,s) s := s*2 WRITE (B,s) 100

READ (A,t) t := t+100WRITE (A,t) 200READ (B,t) t := t+100WRITE (B,t) 200

(T2,T1)

The final state of a database is not independent of the order of transaction.

Serializable Schedule T1 T2 A B

50 50READ (A,t) t := t+100WRITE (A,t) 150

READ (A,s) s := s*2 WRITE (A,s) 300

READ (B,t) t := t+100WRITE (B,t) 150

READ (B,s) s := s*2 WRITE (B,s) 300

Serializable but not Serial Schedule

Non-Serializable Schedule T1 T2 A B

50 50READ (A,t) t := t+100WRITE (A,t) 150

READ (A,s) s := s*2 WRITE (A,s) 300 READ (B,s) s := s*2 WRITE (B,s)

100READ (B,t) t := t+100WRITE (B,t) 200

A := 2*(A+100)B := 2*B + 100

A Serializable Schedule with details T1 T2 A B

50 50READ (A,t) t := t+100WRITE (A,t) 150

READ (A,s) s := s*1 WRITE (A,s) 150 READ (B,s) s := s*1 WRITE (B,s) 50

READ (B,t) t := t+100WRITE (B,t) 150

A := 1*(A+100)B := 1*B + 100

Notations for Transaction

1. Action : An expression of the form ri(X) or wi(X) meaning that transaction Ti reads or writes, respectively, the database X.

2. Transaction : A transaction Ti is a sequence of actions with subscript.

3. Schedule : A schedule S of a transactions T is a sequence of actions, in which for each transaction Ti in T, the action of Ti appear in the definition of Ti itself.

Notational Example

T1

READ (A,t)t := t+100

WRITE (A,t)READ (B,t)t := t+100

WRITE (B,t)

T2

READ (A,s)s := s*2

WRITE (A,s)READ (B,s)

s := s*2WRITE (B,s)

Notation:T1 : r1(A); w1(A); r1(B); w1(B)T2 : r2(A); w2(A); r2(B); w2(B)

Thank you4

Constructive listening