Top Banner
CS5204 – Operating Systems 1 Distributed Transactions
24

Distributed Transactions

Mar 19, 2016

Download

Documents

leal

Distributed Transactions. data manager. transactions. DM. TM. network. TM. T. T. …. …. TM. T. T. T. T. …. DM. transaction manager. DM. physical database. Distributed DBMS Model. T 1 : T 2 : T 3 :. concurrent execution. DB. log :. Serialization. Serialization. T 1 : - PowerPoint PPT Presentation
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: Distributed Transactions

CS5204 – Operating Systems 1

Distributed Transactions

Page 2: Distributed Transactions

CS 5204 – Operating Systems 2

Transactions

Distributed DBMS Model

transaction manager

physical database

transactions

….T T

….

T

T

data manager…

.T

T

DM

DM

DM

network

TM

TM

TM

Page 3: Distributed Transactions

CS 5204 – Operating Systems 3

Transactions

Serialization

T1 :

T2 :

T3 :

concurrent execution

DBlog :

Page 4: Distributed Transactions

CS 5204 – Operating Systems 4

Transactions

Serialization T1 :

T2 :

T3 :

concurrent execution

DBlog :

OPERATIONS

READ(X): read any one copy of XR1 (X3)

WRITE (Z): write all copies of ZW3(Z2) and W3 (Z3)

Page 5: Distributed Transactions

CS 5204 – Operating Systems 5

Transactions

Serialization T1 :

T2 :

T3 :

concurrent execution

DBlog :DB is acceptable if it is guaranteed to have resulted from any one of:

T1 T2 T3

T2 T1 T3

T2 T3 T1

T1 T3 T2

T3 T1 T2

T3 T2 T1

Page 6: Distributed Transactions

CS 5204 – Operating Systems 6

Transactions

Serialization Consider two concurrent transactions executed at only one DM

LOG: R1(X) R2(Y) R1(Y) W1(Z) W1(X) W2(X) R2(Z)

Page 7: Distributed Transactions

CS 5204 – Operating Systems 7

Transactions

Serialization Consider two concurrent transactions executed at only one DM

LOG: R1(X) R2(Y) R1(Y) W1(Z) W1(X) W2(X) R2(Z)

R2(Y) W2(X) R2(Z) ; R1(X) R1(Y) W1(Z) W1(X)

Serial Order:

Page 8: Distributed Transactions

CS 5204 – Operating Systems 8

Transactions

Serialization Consider two concurrent transactions executed at only one DM

LOG: R1(X) R2(Y) R1(Y) W1(Z) W1(X) W2(X) R2(Z)

R2(Y) W2(X) R2(Z) ; R1(X) R1(Y) W1(Z) W1(X)

2

1Serial Order:

2

1

2

last write conflictread source conflict

Page 9: Distributed Transactions

CS 5204 – Operating Systems 9

Transactions

Serialization Consider two concurrent transactions executed at only one DM

LOG: R1(X) R2(Y) R1(Y) W1(Z) W1(X) W2(X) R2(Z)

R1(X) R1(Y) W1(Z) W1(X) ; R2(Y) W2(X) R2(Z)

Serial Order:

Page 10: Distributed Transactions

CS 5204 – Operating Systems 10

Transactions

Serialization Consider two concurrent transactions executed at only one DM

LOG: R1(X) R2(Y) R1(Y) W1(Z) W1(X) W2(X) R2(Z)

R1(X) R1(Y) W1(Z) W1(X) ; R2(Y) W2(X) R2(Z)

Serial Order:

Page 11: Distributed Transactions

CS 5204 – Operating Systems 11

Transactions

Distributed Transaction Processing

T1 : READ(X); WRITE(Y);

T2 : READ(Y); WRITE(Z);

T3 : READ(Z); WRITE(X);

X1

Y1

DM1

Y2

Z2

DM2

Z3

X3

DM3

Transactions:

Page 12: Distributed Transactions

CS 5204 – Operating Systems 12

Transactions

Distributed Transaction Processing

LOGS:

L1 : R2(Y1) R1(X1) W1(Y1) W3(X1)

L2 : R3(Z2) W2(Z2) W1(Y2)

L3 : W3(X3) W2(Z3)

T1 : READ(X); WRITE(Y);

T2 : READ(Y); WRITE(Z);

T3 : READ(Z); WRITE(X);

X1

Y1

DM1

Y2

Z2

DM2

Z3

X3

DM3

Transactions:

Page 13: Distributed Transactions

CS 5204 – Operating Systems 13

Transactions

Distributed Transaction Processing

Question: Are these logs equivalent to some serial execution of the transactions?

LOGS: L1 : R2(Y1) R1(X1) W1(Y1) W3(X1)

L2 : R3(Z2) W2(Z2) W1(Y2)

L3 : W3(X3) W2(Z3)

T1 : READ(X); WRITE(Y);

T2 : READ(Y); WRITE(Z);

T3 : READ(Z); WRITE(X);

X1

Y1

DM1

Y2

Z2

DM2

Z3

X3

DM3

Transactions:

Page 14: Distributed Transactions

CS 5204 – Operating Systems 14

Transactions

Serialization of Distributed Logs

Conflict: Pj(AX) and Qi(BY) conflict if

(1) P and Q are not both READ, and(2) A = B (same data item), and(3) i j (different transactions), and(4) X = Y (same data manager/log)

Page 15: Distributed Transactions

CS 5204 – Operating Systems 15

Transactions

Serialization of Distributed Logs

Conflict: Pj(AX) and Qi(BY) conflict if

(1) P and Q are not both READ, and(2) A = B, and(3) i j, and(4) X = Y

LOGS: L1 : R2(Y1) R1(X1) W1(Y1) W3(X1)

L2 : R3(Z2) W2(Z2) W1(Y2)

L3 : W3(X3) W2(Z3)

Page 16: Distributed Transactions

CS 5204 – Operating Systems 16

Transactions

Serialization of Distributed Logs Conflict: Pj(AX) and Qi(BY) conflict if

(1) P and Q are not both READ, and(2) A = B, and (3) i j, and(4) X = Y

LOGS:

L1 : R2(Y1) R1(X1) W1(Y1) W3(X1)

L2 : R3(Z2) W2(Z2) W1(Y2)

L3 : W3(X3) W2(Z3)

2

13

Page 17: Distributed Transactions

CS 5204 – Operating Systems 17

Transactions

Serialization of Distributed Logs Conflict: Pj(AX) and Qi(BY) conflict if

(1) P and Q are not both READ, and(2) A = B, and(3) i j, and(4) X = Y

LOGS:

L1 : R2(Y1) R1(X1) W1(Y1) W3(X1)

L2 : R3(Z2) W2(Z2) W1(Y2)

L3 : W3(X3) W2(Z3)

2

13

=> T1 T3

=> T2 T1

=> T3 T2

123

Contradictory No total order Not serializable

Page 18: Distributed Transactions

CS 5204 – Operating Systems 18

Transactions

Serialization of Distributed Logs

LOGS:

L1 : R2(Y1) R1(X1) W1(Y1) W3(X1)

L2 : R3(Z2) W2(Z2) W1(Y2)

L3 : W3(X3) W2(Z3)

2

13

=> T1 T3

=> T2 T1

=> T3 T2

123

Contradictory No total order Not serializable

Theorem: Distributed logs are serializable if there exists a total ordering of the transactions such that for conflicting operations Pj and Qi a log shows Pj Qi only if Tj Ti

Page 19: Distributed Transactions

CS 5204 – Operating Systems 19

Transactions

Locking • transactions must use Two Phase Locking (2PL)

Ti

timeno locks released no new locks requested

locking phase release phase

• only the following lock requests are granted

current lock statelock request not locked READ locked WRITE locked

READ OK OK DENYWRITE OK DENY DENY

Page 20: Distributed Transactions

CS 5204 – Operating Systems 20

Transactions

Locking Ti

concurrency controller

Ri(X)

Wi(Y)

lock(X)

release(X,Y)lock(Y)

• request lock before accessing a data item• release all locks at the end of transaction

This guarantees serializability [ESWAREN]

Page 21: Distributed Transactions

CS 5204 – Operating Systems 21

Transactions

Effects of LockingL1 : R2(Y1)

L2 : R3(Z2)

L3 : W3(X3)

Suppose the transactions have executed to this point:

Only T3 is able to execute; it will complete its write and release its locks, leading to …

Lock for Lock state Waiting for lockX write-locked by T3 T1

Y read-locked by T2

Z read-locked by T3 T2

The locks are then:

Page 22: Distributed Transactions

CS 5204 – Operating Systems 22

Transactions

Effects of LockingL1 : R2(Y1), W3(X1)

L2 : R3(Z2)

L3 : W3(X3)

…these logs, and…

Both T1 and T2 can acquire the locks needed to execute their next actions, resulting in…

Lock for Lock state Waiting for lockX unlocked T1

Y read-locked by T2

Z unlocked T2

…this lock state:

Page 23: Distributed Transactions

CS 5204 – Operating Systems 23

Transactions

Effects of LockingL1 : R2(Y1), W3(X1), R1(X1)

L2 : R3(Z2), W2(Z2)

L3 : W3(X3), W2(Z3)

…these logs, and…

Transaction T2 completes, releases its lock - resulting in…

Lock for Lock state Waiting for lockX read-locked by T1

Y read-locked by T2 T1

Z write-locked by T2

…this lock state:

Page 24: Distributed Transactions

CS 5204 – Operating Systems 24

Transactions

Effects of Locking

L1 : R2(Y1), W3(X1), R1(X1), W1(Y1)

L2 : R3(Z2), W2(Z2), W1(Y2)

L3 : W3(X3), W2(Z3)

At this point, T1 can acquire the write-lock on Y, perform its write operations and complete, leading to the final serializable logs:

Lock for Lock state Waiting for lockX read-locked by T1

Y unlocked T1

Z unlocked

…this lock state: