Professional Documents
Culture Documents
1
Example
Transaction T:
a.Withdraw(100)
b.deposit(100)
c.withdraw(200)
b.deposit(200)
2
Transaction in Distributed System
A transaction is an execution of a
sequence of client requests transforming
the server data from one consistent state
to another.
3
Transaction Properties
ACID
Atomicity
Consistency
Isolation
Durability
4
The Transaction Model (1)
Updating a master tape is fault tolerant.
5
The Transaction Model (2)
Examples of primitives for transactions.
Primitive Description
6
The Transaction Model (3)
BEGIN_TRANSACTION BEGIN_TRANSACTION
reserve Lhr -> Kar; reserve Lhr -> Kar;
reserve Kar -> Isb; reserve Kar -> Isb;
reserve Isb -> Muree; reserve Isb -> Muree full =>
END_TRANSACTION ABORT_TRANSACTION
(a) (b)
7
Types of Transactions
Flat Transaction
Type of simple transaction that satisfy ACID
properties.
Nested Transaction
Transaction constructed from number of sub-
transactions operates on multiple data on multiple
machines.
Distributed Transaction
Number of flat sub-transactions that operates on
data that are distributed across multiple machines
8
Distributed Transactions
a) A nested transaction
b) A distributed transaction
9
Implementation
Private Workspace
10
Private Workspace
11
Writeahead Log
12
Writeahead Log
x = 0; Log Log Log
y = 0;
BEGIN_TRANSACTION;
x = x + 1; [x = 0 / 1] [x = 0 / 1] [x = 0 / 1]
y=y+2 [y = 0/2] [y = 0/2]
x = y * y; [x = 1/4]
END_TRANSACTION;
(a) (b) (c) (d)
a) A transaction
b) – d) The log before each statement is executed
13
Writeahead Log
if transaction Commits a commit record is
written to the log.
14
Concurrency Control (1)
15
Concurrency Control (2)
General organization
of managers for
handling distributed
transactions.
16
Problems with Concurrency Control
Lost update Problem
A=100
B=200
C=300
Begin Transaction T
Bal=b.getbalance(); $200 Begin Transaction U
b.Setbalance(bal*1.1) $220 bal=b.getbalance(); $200
a.withdrawl(bal/10); $80 b.setbalance(bal*1.1); $220
c.withdraw(bal/10); $280
17
Inconsistent retrieval problem
Transaction V Transaction W
a.withdraw(100) $100
total=a.getbalance(); $100
total=total+b.getbalance(); $300
total=total+c.getbalance();
b.deposit(100) $300
18
Serializability
Transaction T Transaction U
Bal=b.getbalance(); $200
b.Setbalance(bal*1.1); $220
bal=b.getbalance(); $220
b.setbalance(bal*1.1); $242
a,.withdraw(bal/10); $80
c.withdraw(bal/10); $(278)
19
Serializability
BEGIN_TRANSACTION BEGIN_TRANSACTION BEGIN_TRANSACTION
x = 0; x = 0; x = 0;
x = x + 1; x = x + 2; x = x + 3;
END_TRANSACTION END_TRANSACTION END_TRANSACTION
Schedule 1 x = 0; x = x + 1; x = 0; x = x + 2; x = 0; x = x + 3 Legal
Schedule 2 x = 0; x = 0; x = x + 1; x = x + 2; x = 0; x = x + 3; Legal
Schedule 3 x = 0; x = 0; x = x + 1; x = 0; x = x + 2; x = x + 3; Illegal
(d)
Dirty Reads
Recoverability of Transactions
Cascading Aborts
Premature Writes
21
Solutions
Locking
22
Two-Phase Locking (1)
Two-phase locking.
23
Strict-Two-Phase Locking (2)
Strict two-phase locking.
24
Pessimistic Timestamp
Ordering
Concurrency control using timestamps.
25
Operation Conflicts for Time Stamp
Ordering
Rule Tc Ti
1. Write Read Tc must not write an object that has been read by
any Ti where Ti<Tc. It requires Tc>= max read
timestamp of the object.
2. Write Write Tc must not write an object that has been written by
any Ti where Ti > Tc. It requires Tc > write stamp of
the committed object
3. Read Write Tc must not read an object that has been written by
any Ti where Ti> Tc. It requires Tc > write
timestamp of committed object.
26
Rule: How to decide Write Operation
27
Rule: How to decide Read operation
If (Tc > write timestamp on committed version of D) {
let D be the version with maximum
timestamp <= Tc
If (D is committed )
Read
Else
Wait until that D version commits or
abort then apply read rule again. }
Else
Abort Transaction
28
Time Stamps in Transactions T and U
Pessimistic time stamp ordering
Tc Ti A B C
RTS WTS RTS WTS RTS WTS
Open Transaction {} S {} S {} S
Bal=b.getbalance() {T}
open Transaction
b.setbalance(bal*1.1) ST
Bal=b.getbalance()
wait for T
a.withdraw(bal/10) ST
Commit T T
Bal=b.getbalance() {U}
b.setbalance(bal*1.1) TU
c.withdraw(bal/10) SU
commit U U
29
Optimistic Timestamp Ordering
transactions execute
If there is a problem
30
Work Flow
Keeps track of which data items have
been read and written
At the point of committing it checks all
other transactions to see if any of its items
have been changed since it has started
If so Abort
If not Committed
31
Advantages
Deadlock free
Allow maximum parallelism
Disadvantages
If it fails the transaction has to run again
Failures can occur under heavy load
conditions
32