Documente Academic
Documente Profesional
Documente Cultură
Serializability
1
Why Have Concurrent Processes?
Transactions
2
Concurrency in a DBMS
Users submit transactions, and can think of each transaction as
executing by itself. (Give users such illusion.)
– Concurrency is achieved by the DBMS, which interleaves
actions (reads/writes of DB objects) of various transactions.
– Each transaction must leave the database in a consistent
state if the DB is consistent when the transaction begins.
DBMS will enforce some Integrity Constraints (IC), depending on
the ICs declared in CREATE TABLE statements.
Beyond this, the DBMS does not really understand the semantics of
the data. (e.g., it does not understand how the interest on a bank
account is computed).
Issues: Effect of interleaving transactions, and crashes.
Database Systems Implementation, Bongki Moon 5
3
Passing the ACID Test
4
Example: Balance Transfer
Consider two transactions:
T1: A=A+100, B=B-100
T2: Read(A), Read(B), Print(A+B)
5
Schedule
A schedule is a list of actions (read, write, abort,
commit) of a set of transactions.
– Show how operations are interleaved.
T1 T2
oldest action
R(A)
W(A)
R(A)
R(B)
R(B)
W(B) newest action
Examples of Schedules
Consider the following two schedules.
Are they correct? In other words, is the result produced by each of the
schedules can be obtained by either of the serial schedules T1-then-T3
and T3-then-T1?
How do you know a schedule is correct?
• For a set of N transactions, there are N! serial schedules. You can’t
try all of them!!
Database Systems Implementation, Bongki Moon 12
6
transfer add 6%
$100 from interest to
Conflicting Operations A to B
T1
A&B
T3
R(A)
Two operations by different W(A)
transactions conflict when they R(A)
access the same item, and at W(A)
least one of them is WRITE. Database is
inconsistent! R(B)
W1(A)-R3(A), W1(A)-W3(A),
W(B)
R3(B)-W1(B), W3(B)-R1(B), etc.
Commit
R(B)
W(B)
Commit
Database Systems Implementation, Bongki Moon 13
Anomalies by Conflicts
7
Serializable (SR) Schedules
Two schedules are equivalent if
(1) defined over the same set of Xacts and operations,
(2) same intra-xact order of operations, and
(3) same inter-xact order of conflicting operations.
Equivalent schedules:
S1: R1(A)→W1(A) →R1(B) →W1(B) →C1→R2(A) →R2(B) →C2
S2: R1(A) →W1(A) →R2(A) →R1(B) →W1(B) →C1→R2(B) →C2
8
Problems with Aborted Transactions
T1 T2
R(A)
Cascading Aborts W(A)
R(A)
W(A)
WR conflicts & Aborts?
Abort of T1 requires abort of T2!
To avoid cascading aborts, a Xact must abort
read data only from committed Xacts.
A schedule is ACA (avoids cascading abort) if
whenever Tj reads x from Ti (i.e., Wi[x] < Rj[x]),
then it must be that ci < Rj[x].
– No Dirty Reads are allowed.
9
T1 T2
R(A)
Recoverable Schedules W(A)
R(A)
Abort of T1 requires abort of T2!
W(A)
– But T2 has already committed!
commit
To be recoverable, a Xact commits only
after all the Xacts it depends on commit. abort
A schedule is RC (recoverable) if whenever Tj reads
from Ti (i.e., Wi[x] < Rj[x]), it must be that ci < cj.
– Unlike ACA, Dirty Reads are allowed.
Real systems typically ensure that only
recoverable schedules arise (through locking).
Strict Schedules
10
Relationships between Schedules
Summary
11