Docsity

Serializability Theorem - E-Commerce - Lecture Slides, Slides of Fundamentals of E-Commerce

Toggle sidebar
bg1
The Serializability Theorem
A history is SR if and only if SG(H) is acyclic.
Proof: (if) SG(H) is acyclic. So let Hs be a serial history
consistent with SG(H). Each pair of conflicting ops
in H induces an edge in SG(H). Since conflicting ops
in Hs and H are in the same order, Hs≡H, so H is SR.
(only if) H is SR. Let Hs be a serial history equivalent
to H. We claim that if Ti → Tk in SG(H), then Ti
precedes Tk in Hs (else Hs H). If SG(H) had a cycle,
T1→T2→…→Tn→T1, then T1 precedes T1 in Hs, a
contradiction. So SG(H) is acyclic.
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Serializability Theorem - E-Commerce - Lecture Slides and more Slides Fundamentals of E-Commerce in PDF only on Docsity!

The Serializability Theorem

A history is SR if and only if SG(H) is acyclic.Proof: (if) SG(H) is acyclic. So let H

be a serial historys

consistent with SG(H). Each pair of conflicting opsin H induces an edge in SG(H). Since conflicting opsin Hs

and H are in the same order, H

≡H, so H is SR.s

(only if) H is SR. Let H

be a serial history equivalents

to H. We claim that if T

→^ Ti

in SG(H), then Tk

i

precedes T

in Hk

(else Hs

^ H). If SG(H) had a cycle,s

T→T^1

→T→n

T, then T^1

precedes T 1

in H 1 , as

contradiction. So SG(H) is acyclic.

How to Use

the Serializability Theorem

-^ Characterize the set of histories that aconcurrency control algorithm allows •^ Prove that any such history must have anacyclic serialization graph. •^ Therefore, the algorithm guarantees SRexecutions. •^ We’ll use this soon to prove that lockingproduces serializable executions.

Recoverability

-^ If T

reads from Tk

and Ti

aborts, then Ti

must abortk

-^ Example - w

[x] r 12 [x] a^1

implies T

must abort 2

-^ But what if T

already committed? We’d be stuck.k

-^ Example - w

[x] r 12 [x] c^2

a^1

-^ Tcan’t abort after it commits^2 • Executions must be

recoverable

A transaction T’s commit operation must follow thecommit of every transaction from which T read.^ –^ Recoverable - w

[x] r 12 [x] c^1

c^2

-^ Not recoverable - w

[x] r 12 [x] c^2

a^1

-^ Recoverability requires synchronizing operations.

Avoiding Cascading Aborts

-^ Cascading aborts are worth avoiding to^ –^ avoid complex bookkeeping, and^ –^ avoid an uncontrolled number of forced aborts •^ To avoid cascading aborts, a data manager shouldensure transactions only read committed data •^ Example^ –^ avoids cascading aborts: w

[x] c 11

r[x] 2

-^ allows cascading aborts: w

[x] r 12 [x] a^1

-^ A system that avoids cascading aborts alsoguarantees recoverability.

Strictness (cont’d)

-^ More precisely, a system is

strict

if it only executes

r[x] or wi

[x] if all previous transactions that wrote xi committed or aborted. • Examples (“…” marks a non-strict prefix)^ –^ strict:

w

[x] c 11

w[x] a 2

2

-^ not strict: w

[x] w 1

[x] … c 2

a 1 2

-^ strict:

w

[x] w 1

[y] c 11

r[x] w 2

[y] a 22

-^ not strict: w

[x] w 1

[y] r 12 [x] … c

w[y] a 1 2

2

-^ To see why strictness matters in the above histories,consider what happens if T

aborts 1

-^ “Strict” implies “avoids cascading aborts.”

3.4 Two-Phase Locking

-^ Basic locking - Each transaction sets a

lock^

on each data

item before accessing the data^ –^ the lock is a reservation^ –^ there are read locks and write locks^ –^ if one transaction has a write lock on x, then no othertransaction can have any lock on x • Example^ –^ rl[x], rui

[x], wli

[x], wui

[x] denote lock/unlock operationsi

-^ wl[x] w^1

[x] rl 12 [x] r[x] is impossible^2

-^ wl[x] w^1

[x] wu 1

[x]^ rl 12 [x] r[x] is OK^2

Two-Phase Locking (2PL) Protocol • A transaction is

two-phase locked

if:

-^ before reading x, it sets a read lock on x –^ before writing x, it sets a write lock on x –^ it holds each lock until after it executes thecorresponding operation –^ after its first unlock operation, it requests no new locks • Each transaction sets locks during a

growing phase

and releases them during a

shrinking phase

-^ Example - on the previous page T

is two-phase 2

locked, but not T

since ru 1

[x] < wl 1

[y] 1

-^ use “<” for “precedes”

2PL Theorem:

If all transactions in an execution are

two-phase locked, then the execution is SR. Proof:^

Define T

⇒^ Ti

if eitherk

-^ Tread x and Ti^

later wrote x, ork

-^ Twrote x and Ti^

later read or wrote xk

-^ If T

⇒^ Ti

, then Tk

released a lock before Ti

k

obtained some lock. • If T⇒i^

T⇒k^

T, then Tm

released a lock before Ti

m

obtained some lock (because T

is two-phase).k

-^ If T

⇒...i ⇒^ Ti

, then T

released a lock before Ti

i

obtained some lock, breaking the 2-phase rule. • So there cannot be a cycle. By the SerializabilityTheorem, the execution is SR.