Professional Documents
Culture Documents
Today's Lecture: Locking and Deadlock Distributed Transactions
Today's Lecture: Locking and Deadlock Distributed Transactions
Today's Lecture
Transaction basics
Distributed transactions
L-16 Transactions
1 2
Transactions Transactions –
The ACID Properties
A transaction is a sequence of server Are the four desirable properties for reliable handling of
concurrent transactions.
operations that is guaranteed by the server Atomicity
to be atomic in the presence of multiple The “All or Nothing” behavior.
C: stands for either
clients and server crashes. Concurrency: Transactions can be executed concurrently
Free from interference by operations being performed … or Consistency: Each transaction, if executed by
itself,
on behalf of other concurrent clients maintains the correctness of the database.
Either all of the operations must be completed Isolation (Serializability)
successfully or they must have no effect at all in the Concurrent transaction execution should be equivalent
presence of server crashes (in effect) to a serialized execution.
Durability
Once a transaction is done, it stays done.
3 4
commit transaction;
openTransaction() trans;
starts a new transaction and delivers a unique TID trans. This identifier will be
used in the other operations in the transaction.
closeTransaction(trans) (commit, abort);
ends a transaction: a commit return value indicates that the transaction has
committed; an abort return value indicates that it has aborted.
abortTransaction(trans);
aborts the transaction.
9 10
11 12
transactions
T2: R2(X) W2(X) W2(Y) commit2
13 14
T1: R1(X) R1(Y) W1(X) commit1 T1: R1(X) R1(Y) W1(X) commit1
T2: R2(X) W2(X) W2(Y) commit2 T2: R2(X) W2(X) W2(Y) commit2
DB: R1(X) R2(X) W2(X) R1(Y) W1(X) W2(Y) commit2 commit1 DB: R2(X) W2(X) R1(X) W1(X) W2(Y) R1(Y) commit2 commit1
15 16
:
T11 :
T12
prov. commit
:
T21
abort When a parent aborts, all of its sub-transactions are
openSubTransaction
aborted
prov. commit prov. commit prov. commit
:
T211 When a sub-transaction aborts, the parent can decide
whether to abort or not
prov.commit
If a top-level transaction commits, then all of the sub-
transactions that have provisionally committed can
provisional commit commit too, provided that non of their ancestors has
aborted.
19 20
Locking
Transaction basics Server attempts to gain an exclusive ‘lock’ that is
about to be used by one of its operations in a
transaction.
Locking and deadlock Can use different lock types (read/write for example)
Two-phase locking
Distributed transactions Optimistic concurrency control
Time-stamp based concurrency control
21 22
23 24
25 26
27 28
29 30
31 32
33 34
35 36
Motivation
Transaction basics Provide distributed atomic operations at multiple
servers that maintain shared data for clients
Provide recoverability from server crashes
Locking and deadlock Properties
Atomicity, Consistency, Isolation, Durability (ACID)
Distributed transactions Concepts: commit, abort, distributed
commit
37 38
39 40
41 42
43 44
ok to commit?
Coordinator Participant
45 46
49 50
53 54
State of Q Action by P
PRECOMMIT Transition to PRECOMMIT. If all participants Note: if any participant
in PRECOMMIT, can COMMIT the transaction is in state PRECOMMIT,
it is impossible for any
ABORT Transition to ABORT other participant to be in
INIT Both P (in READY) and Q transition to ABORT any state other than READY
or PRECOMMIT.
(Q sends VOTE_ABORT)
READY Contact more participants. If can contact a
a) Finite state machine for the coordinator in 3PC majority and they are in ‘Ready’, then ABORT
b) Finite state machine for a participant the transaction.
If the participants contacted in ‘PreCommit’ it
55 is safe to COMMIT the transaction 56