Chap16 17 Transaction Con Currency
Chap16 17 Transaction Con Currency
Acknowledgement:
This slide is based upon the slides
by the authors and others
Goals (= Objectives) of CS566
• ESSENTIAL OBJECTIVES:
– (1)TO GAIN FACTUAL KNOWLEDGE
(terminology, classifications, methods, etc.)
and (2) TO LEARN FUNDAMENTAL
PRINCIPLES, GENERALIZATIONS, OR
THEORIES;
• IMPORTANT OBJECTIVE:
– TO DEVELOPING SPECIFIC SKILLS,
COMPETENCIES, AND POINT OF VIEW needed
by professionals in the closely related fields.
Concurrency Control & Recovery
• System checks ICs and if they fail, the transaction rolls back
(i.e., is aborted).
– DBMS enforces some ICs, depending on the ICs declared in CREATE
TABLE statements.
– Beyond this, DBMS does not understand the semantics of the data.
(e.g., it does not understand how the interest on a bank account is
computed).
Isolation (Concurrency)
• Multiple users can submit transactions.
• Each transaction executes as if it was running by
itself.
– Concurrency is achieved by DBMS, which interleaves
actions (reads/writes of DB objects) of various
transactions.
• We will formalize this notion shortly.
• Many techniques have been developed. Fall into two
basic categories:
– Pessimistic – don’t let problems arise in the first place
– Optimistic – assume conflicts are rare, deal with them
after they happen.
Durability - Recovering From a Crash
• System Crash - short-term memory lost (disk okay)
– This is the case we will handle.
• Disk Crash - “stable” data lost
– ouch --- need back ups; raid-techniques can help avoid this.
• There are 3 phases in Aries recovery (and most others):
– Analysis: Scan the log forward (from the most recent checkpoint) to
identify all Xacts that were active, and all dirty pages in the buffer pool at
the time of the crash.
– Redo: Redoes all updates to dirty pages in the buffer pool, as needed, to
ensure that all logged updates are in fact carried out.
– Undo: The writes of all Xacts that were active at the crash are undone (by
restoring the before value of the update, as found in the log), working
backwards in the log.
• At the end --- all committed updates and only those updates are
reflected in the database.
– Some care must be taken to handle the case of a crash occurring during the
recovery process!
Plan of attack (ACID properties)
R(A) W(A)
R(A) W(A)
• Serializable or not????
NOT!
Dependency Graph
T1:
T1: R(A),
R(A), W(A),
W(A), R(B),
R(B), W(B)
W(B)
T2:
T2: R(A),
R(A), W(A),
W(A), R(B),
R(B), W(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 vice-
versa.
Notes on Conflict Serializability
• Conflict Serializability doesn’t allow all schedules that
you would consider correct.
– This is because it is strictly syntactic - it doesn’t consider the
meanings of the operations or the data.
Unlock(A) <granted>
Read(A)
Unlock(A)
Lock_S(B) <granted>
Lock_X(B)
Read(B)
<granted> Unlock(B)
PRINT(A+B)
Read(B)
B := B +50
Write(B)
Unlock(B)
Lock_X(B) <granted>
Unlock(A) <granted>
Read(A)
Lock_S(B)
Read(B)
B := B +50
Write(B)
Unlock(B) <granted>
Unlock(A)
Read(B)
Unlock(B)
PRINT(A+B)
Lock_X(B) <granted>
Read(B)
B := B +50
Write(B)
Unlock(A)
Unlock(B) <granted>
Read(A)
Lock_S(B) <granted>
Read(B)
PRINT(A+B)
Unlock(A)
Unlock(B)
Lock_X(B) <granted>
Unlock(A) <granted>
Read(A)
Lock_S(B)
Read(B)
B := B +50
Write(B)
Unlock(B) <granted>
Unlock(A)
Read(B)
Unlock(B)
PRINT(A+B)
Read(A)
A: = A-50
Write(A)
Lock_X(B)
T1 T2
T4 T3
Multiple-Granularity Locks
• Hard to decide what granularity to lock (tuples
vs. pages vs. tables).
• Shouldn’t have to make same decision for all
transactions!
• Data “containers” are nested:
Database
Tables
contains
Pages
Tuples
Solution: New Lock Modes, Protocol
• Allow Xacts to lock at each level, but with a special protocol using Database
new “intention” locks:
• Still need S and X locks, but before locking an item, Xact must have
proper intension locks on all its ancestors in the granularity hierarchy. Tables
Pages
Tuples
SIX
IS IX S X
IS – Intent to get S lock(s) at IS -
finer granularity. IX - - -
IX – Intent to get X lock(s) SIX - - - -
at finer granularity. - - -
S
SIX mode: Like S & IX at
the same time. Why useful?
X - - - - -
Database
modified ROOT
objects new
Details on Opt. CC
Ti
Tj
R V W
R V W
Test 2
• For all i and j such that Ti < Tj, check that:
Ti
R V W
Tj
R V W
Ti
R V W
Tj
R V W