chp13 1
chp13 1
13.1 Introduction
13.2 Transactions
13.3 Nested transactions
13.4 Locks
13.5 Optimistic concurrency control
13.6 Timestamp ordering
13.1 Introduction to transactions
y Recoverable objects
– can be recovered after their server crashes (recovery in Chapter 14)
– objects are stored in permanent storage
y Failure model
– transactions deal with crash failures of processes and omission
failures of communication
y Designed for an asynchronous system
– It is assumed that messages may be delayed
Banking example
Operations of the Account interface
deposit(amount)
deposit amount in the account Each Account is represented by a remote
withdraw(amount) object whose interface Account provides
withdraw amount from the account operations for making deposits and withdra-
getBalance() → amount wals and for setting and getting the balance.
return the balance of the account
setBalance(amount)
set the balance of the account to amount Figure 13.1
Each Branch of the bank is
Operations of the Branch interface represented by a remote object
create(name) → account whose interface Branch provides
create a new account with a given name operations for creating a new
lookUp(name) → account account, looking one up by
return a reference to the account with the given name name and enquiring about the
branchTotal() → amount total funds at the branch. It
return the total of all the balances at the branch stores a correspondence
between account names and
their remote object references
Atomic operations at server
Transaction T:
a.withdraw(100);
b.deposit(100);
c.withdraw(200); Figure 13.2
b.deposit(200);
2. Isolation:
– Each transaction must be performed without interference from other
transactions - there must be no observation by other transactions of a
transaction's intermediate effects
Isolation
Transaction T : Transaction U:
balance = b.getBalance(); balance = b.getBalance();
b.setBalance(balance*1.1); b.setBalance(balance*1.1);
a.withdraw(balance/10) c.withdraw(balance/10)
balance = b.getBalance(); $200
balance = b.getBalance(); $200
b.setBalance(balance*1.1); $220
b.setBalance(balance*1.1); $220
a.withdraw(balance/10)
Figure 13.5
$80
c.withdraw(balance/10) $280
a.withdraw(100); $100
total = a.getBalance() $100
Figure 13.6 total = total+b.getBalance() $300
total = total+c.getBalance()
b.deposit(100) $300
Transaction T: Transaction U:
balance = b.getBalance() balance = b.getBalance()
b.setBalance(balance*1.1) b.setBalance(balance*1.1)
a.withdraw(balance/10) c.withdraw(balance/10)
y if one of T and U runs before the other, they can’t get a lost update,
y the same is true if they are run in a serially equivalent ordering
A serially equivalent interleaving of V and W
(inconsistent retrievals cured) we could overlap the 1st line of W with the 2nd line of V
Transaction V: Transaction W:
a.withdraw(100);
aBranch.branchTotal()
b.deposit(100)
a.withdraw(100); $100
b.deposit(100) $300
total = a.getBalance() $100
total = total+b.getBalance() $400
Figure 13.8
total = total+c.getBalance()
...
y Conflicting operations
y a pair of operations conflicts if their combined effect depends
on the order in which they were executed
– e.g. read and write (whose effects are the result returned by read and the
value set by write)
Serial equivalence Which of their operations conflict?
defined in terms of conflicting operations
Transaction T: Transaction U:
x = read(i)
write(i, 10) Figure 13.10
y = read(j)
write(j, 30)
write(j, 20)
z = read (i)
For recoverability:
A commit is delayed until after the commitment of any other
transaction whose state has been observed
Figure 13.13
prov.commit