Jinze Liu - PowerPoint PPT Presentation

About This Presentation
Title:

Jinze Liu

Description:

Transaction Processing - University of Kentucky ... Jinze Liu – PowerPoint PPT presentation

Number of Views:119
Avg rating:3.0/5.0
Slides: 24
Provided by: JunY166
Category:
Tags: jinze | liu | locking | phase

less

Transcript and Presenter's Notes

Title: Jinze Liu


1
CS505 Intermediate Topics in Database Systems
  • Jinze Liu

2
Review
  • ACID
  • Atomicity TXs are either completely done or not
    done at all
  • Consistency TXs should leave the database in a
    consistent state
  • Isolation TXs must behave as if they are
    executed in isolation
  • Durability Effects of committed TXs are
    resilient against failures
  • SQL transactions
  • -- Begins implicitly
  • SELECT
  • UPDATE
  • ROLLBACK COMMIT

3
Concurrency control
  • Goal ensure the I (isolation) in ACID

4
Good versus bad schedules
Good!
Good! (But why?)
Bad!
Read 400
Read 400
Write400 100
Write400 50
5
Serial schedule
  • Execute transactions in order, with no
    interleaving of operations
  • T1.r(A), T1.w(A), T1.r(B), T1.w(B), T2.r(A),
    T2.w(A), T2.r(C), T2.w(C)
  • T2.r(A), T2.w(A), T2.r(C), T2.w(C), T1.r(A),
    T1.w(A), T1.r(B), T1.w(B)
  • Isolation achieved by definition!
  • Problem no concurrency at all
  • Question how to reorder operations to allow more
    concurrency

6
Conflicting operations
  • Two operations on the same data item conflict if
    at least one of the operations is a write
  • r(X) and w(X) conflict
  • w(X) and r(X) conflict
  • w(X) and w(X) conflict
  • r(X) and r(X) do not
  • r/w(X) and r/w(Y) do not
  • Order of conflicting operations matters
  • E.g., if T1.r(A) precedes T2.w(A), then
    conceptually, T1 should precede T2

7
Precedence graph
  • A node for each transaction
  • A directed edge from Ti to Tj if an operation of
    Ti precedes and conflicts with an operation of Tj
    in the schedule

Goodno cycle
Badcycle
8
Conflict-serializable schedule
  • A schedule is conflict-serializable iff its
    precedence graph has no cycles
  • A conflict-serializable schedule is equivalent to
    some serial schedule (and therefore is good)
  • In that serial schedule, transactions are
    executed in the topological order of the
    precedence graph
  • You can get to that serial schedule by repeatedly
    swapping adjacent, non-conflicting operations
    from different transactions

9
Locking
  • Rules
  • If a transaction wants to read an object, it must
    first request a shared lock (S mode) on that
    object
  • If a transaction wants to modify an object, it
    must first request an exclusive lock (X mode) on
    that object
  • Allow one exclusive lock, or multiple shared
    locks

10
Basic locking is not enough
T1 T2r(A)w(A) r(A) w(A) r(B) w(B) r(
B)w(B)
11
Two-phase locking (2PL)
  • All lock requests precede all unlock requests
  • Phase 1 obtain locks, phase 2 release locks

2PL guarantees aconflict-serializableschedule
12
Problem of 2PL
  • T2 has read uncommitted data written by T1
  • If T1 aborts, then T2 must abort as well
  • Cascading aborts possible if other transactions
    have read data written by T2
  • Even worse, what if T2 commits before T1?
  • Schedule is not recoverable if the system crashes
    right after T2 commits

13
Strict 2PL
  • Only release locks at commit/abort time
  • A writer will block all other readers until the
    writer commits or aborts
  • Used in most commercial DBMS (except Oracle)

14
Definition
  • S1, S2 are conflict equivalent schedules
  • if S1 can be transformed into S2 by a series of
    swaps on non-conflicting actions.

15
Definition
  • A schedule is conflict serializable if it is
    conflict equivalent to some serial schedule.

16
Precedence graph P(S) (S is schedule)
  • Nodes transactions in S
  • Arcs Ti -gt Tj whenever
  • - pi(A), qj(A) are actions in S
  • - pi(A) ltS qj(A)
  • - at least one of pi, qj is a write

17
Exercise
  • What is P(S) forS w3(A) w2(C) r1(A) w1(B)
    r1(C) w2(A) r4(A) w4(D)
  • Is S serializable?

18
Another Exercise
  • What is P(S) forS w1(A) r2(A) r3(A) w4(A) ?

19
Lemma
  • S1, S2 conflict equivalent ? P(S1)P(S2)

20
  • Note P(S1)P(S2) ? S1, S2 conflict equivalent
  • Counter example
  • S1w1(A) r2(A) w2(B) r1(B)
  • S2r2(A) w1(A) r1(B) w2(B)

21
Theorem
  • P(S1) acyclic ?? S1 conflict serializable

(?) Assume S1 is conflict serializable ? ? Ss
Ss, S1 conflict equivalent ? P(Ss) P(S1) ?
P(S1) acyclic since P(Ss) is acyclic
22
Theorem
P(S1) acyclic ?? S1 conflict serializable
T1 T2 T3 T4
  • (?) Assume P(S1) is acyclic
  • Transform S1 as follows
  • (1) Take T1 to be transaction with no incident
    arcs
  • (2) Move all T1 actions to the front
  • S1 . qj(A).p1(A)..
  • (3) we now have S1 lt T1 actions gtlt... rest ...gt
  • (4) repeat above steps to serialize rest!

23
How to enforce serializable schedules?
  • Option 1 run system, recording P(S) at end
    of day, check for P(S) cycles and declare if
    execution was good
Write a Comment
User Comments (0)
About PowerShow.com