Top Banner
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.

Dec 21, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CONCURRENCY CONTROL 18.1 Serial and Serializable Schedule By: Nitin Mathur Id: 110 CS: 257.

CONCURRENCY CONTROL18.1 Serial and Serializable Schedule

By: Nitin MathurId: 110

CS: 257

Page 2: CONCURRENCY CONTROL 18.1 Serial and Serializable Schedule By: Nitin Mathur Id: 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.

Page 3: CONCURRENCY CONTROL 18.1 Serial and Serializable Schedule By: Nitin Mathur Id: 110 CS: 257.

Flow How Transaction is Executed

Disk Buffer

INPUT

OUTPUT

READ & WRITE

Page 4: CONCURRENCY CONTROL 18.1 Serial and Serializable Schedule By: Nitin Mathur Id: 110 CS: 257.

Transaction Manager

Scheduler

Buffer

Read & Writes

Read / Write Requests

Page 5: CONCURRENCY CONTROL 18.1 Serial and Serializable Schedule By: Nitin Mathur Id: 110 CS: 257.

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?

Page 6: CONCURRENCY CONTROL 18.1 Serial and Serializable Schedule By: Nitin Mathur Id: 110 CS: 257.

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

Page 7: CONCURRENCY CONTROL 18.1 Serial and Serializable Schedule By: Nitin Mathur Id: 110 CS: 257.

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)

Page 8: CONCURRENCY CONTROL 18.1 Serial and Serializable Schedule By: Nitin Mathur Id: 110 CS: 257.

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.

Page 9: CONCURRENCY CONTROL 18.1 Serial and Serializable Schedule By: Nitin Mathur Id: 110 CS: 257.

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

Page 10: CONCURRENCY CONTROL 18.1 Serial and Serializable Schedule By: Nitin Mathur Id: 110 CS: 257.

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

Page 11: CONCURRENCY CONTROL 18.1 Serial and Serializable Schedule By: Nitin Mathur Id: 110 CS: 257.

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

Page 12: CONCURRENCY CONTROL 18.1 Serial and Serializable Schedule By: Nitin Mathur Id: 110 CS: 257.

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.

Page 13: CONCURRENCY CONTROL 18.1 Serial and Serializable Schedule By: Nitin Mathur Id: 110 CS: 257.

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)

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

Thank you4

Constructive listening