Professional Documents
Culture Documents
Concurrency Control: R&G - Chapter 17
Concurrency Control: R&G - Chapter 17
R&G - Chapter 17
Review
ACID transaction semantics.
Today: focus on Isolation
property
Serial schedules safe but slow
Try to find schedules equivalent to
serial
Conflicting Operations
Need a tool to decide if 2 schedules are
equivalent
Use notion of conflicting operations
Definition: Two operations conflict if:
They are by different transactions,
they are on the same object,
and at least one of them is a write.
Conflict Serializable
Schedules
Definition: Two schedules are conflict equivalent
iff:
They involve the same actions of the same transactions,
and
every pair of conflicting actions is ordered the same way
Conflict Serializability
Intuition
A schedule S is conflict serializable if:
You are able to transform S into a serial
schedule by swapping consecutive nonconflicting operations of different
transactions.
Example:
R(A) W(A)
R(B)W(B)
R(A)W(A)
R(B)W(B)
R(A) W(A) R(B)
W(B)
R(B)
W(B)R(B)
W(B)
R(A)W(A) R(A)R(A)R(B)
W(A)W(B)
Conflict Serializability
(Continued)
Heres another example:
R(A)
W(A)
R(A)W(A)
Serializable or not????
NOT!
Dependency Graph
Ti
Dependency graph:
One node per Xact
Edge from Ti to Tj if:
An operation Oi of Ti conflicts with an
operation Oj of Tj and
Oi appears earlier in the schedule than
Oj.
Tj
Example
A schedule that is not conflict
serializable:
T1:
T2:
R(A), W(A),
R(A), W(A), R(B), W(B)
A
T1
T2
Dependency graph
B
The cycle in the graph reveals the problem.
The output of T1 depends on T2, and viceversa.
An Aside: View
Serializability
Notes on Serializability
Definitions
Lock
Compatibility
X
Matrix
rules:
release phase
# locks held
time
Strict 2PL
R(B),
2PL) protocol:
acquisiti
on phase
# locks held
release all
locks at end
of xact
time
Next ...
A few examples
Lock_S(A)
A: = A-50
Write(A)
Unlock(A)
Read(A)
Unlock(A)
Lock_S(B)
Lock_X(B)
Read(B)
Unlock(B)
PRINT(A+B)
Read(B)
B := B +50
Write(B)
Unlock(B)
Lock_S(A)
A: = A-50
Write(A)
Lock_X(B)
Unlock(A)
Read(A)
Lock_S(B)
Read(B)
B := B +50
Write(B)
Unlock(B)
Unlock(A)
Read(B)
Unlock(B)
PRINT(A+B)
Lock_S(A)
A: = A-50
Write(A)
Lock_X(B)
Read(B)
B := B +50
Write(B)
Unlock(A)
Unlock(B)
Read(A)
Lock_S(B)
Read(B)
PRINT(A+B)
Unlock(A)
Unlock(B)
View Serializable
Conflict Serializable
Avoid
Cascading
Abort
Serial
View Serializable
Conflict Serializable
Avoid
Cascading
Abort
Serial
Lock Management
Lock and unlock requests handled by
Lock Manager
LM keeps an entry for each currently
held lock.
Entry contains:
Lock upgrade:
xact with shared lock can request to upgrade
to exclusive
Example
Lock_X(A)
Lock_S(B)
Read(B)
Lock_S(A)
Read(A)
A: = A-50
Write(A)
Lock_X(B)
Deadlocks
Deadlock: Cycle of transactions waiting
for locks to be released by each other.
Two ways of dealing with deadlocks:
prevention
detection
Deadlock Detection
Create and maintain a waits-for
graph
Periodically check for cycles in
graph
Deadlock Detection
(Continued)
Example:
T1:
T2:
T3:
T4:
S(A), S(D),
X(B)
S(D), S(C),
X(B)
S(B)
X(C)
X(A)
T1
T2
T4
T3
Deadlock Prevention
Assign priorities based on timestamps.
Say Ti wants a lock that Tj holds
Two policies are possible:
Wait-Die: If Ti has higher priority, Ti waits for
Tj;
otherwise Ti aborts
Wound-wait: If Ti has higher priority, Tj aborts;
otherwise Ti waits
Summary
Correctness criterion for isolation is
serializability.
In practice, we use conflict serializability,
which is somewhat
more restrictive but easy to enforce.