CS542 - PowerPoint PPT Presentation

About This Presentation
Title:

CS542

Description:

* Two More Topics Strict 2P Locking : ... locks held by Ti Time Growing Shrinking Phase Phase 2 Phase Locking Protocol * Example: Ti To ... – PowerPoint PPT presentation

Number of Views:46
Avg rating:3.0/5.0
Slides: 29
Provided by: Siro151
Learn more at: http://web.cs.wpi.edu
Category:

less

Transcript and Presenter's Notes

Title: CS542


1
CS542
  • Concurrency Control
  • Aborts and Deadlocks

Professor Elke A. Rundensteiner
2
Two More Topics
  • Strict 2P Locking
  • Aborts can cause Cascading Aborts
  • Recoverable Schedules
  • Handling Deadlocks
  • Optimistic
  • Pessimistic

3
2 Phase Locking Protocol
  • locks
  • held by
  • Ti
  • Time
  • Growing Shrinking
  • Phase Phase

4
Concurrency control recovery
  • Example Ti To
  • Wi(A)
  • rj(A)
  • Commit To
  • Abort Ti






  • reads A even though Ti written A has not
    committed.
  • Rollback ? Cascading rollback? (But committed!)

5
  • Note
  • Schedule is conflict serializable
  • But Schedule is not recoverable

6
  • Need to make final decision for each
    transaction
  • commit decision - system guarantees transaction
    will or has completed, no matter what ( takes
    effect )
  • abort decision - system guarantees transaction
    will or has been rolled back
  • (has no effect)

7
To model this, two new actions
  • Ci - transaction Ti commits
  • Ai - transaction Ti aborts

8
Back to example Tj Ti Wj(A) ri(A
) Ci ? can we commit here?

...
...
...
...
9
Back to example Tj Ti Wj(A) ri(A
) Ci ? No, cannot commit Dont
commit if you use (read) a variable written by
any other Tj that did not yet commit.
...
...
...
...
10
Definition
  • Ti reads from Tj in S (Tj ?S Ti) if
  • wj(A) ltS ri(A)
  • aj ltS ri(A) (lt does not precede)
  • (3) If wj(A) ltS wk(A) ltS ri(A) then
  • ak ltS ri(A)

11
Definition
  • Schedule S is recoverable if
  • whenever Tj ?S Ti and j ? i and Ci ? S
  • then Cj ltS Ci
  • Idea Transactions only commit after all
    transactions they read from have been committed
    first.
  • (allows dirty reads for maximal concurrency)

12
Back to example Tj Ti Wj(A) ri(A
) Cj Ci ? Yes.
...
...
...
...
13
  • Note in transactions, reads and writes
    precede commit or abort
  • ? If Ci ? Ti, then ri(A) lt Ci
  • wi(A) lt Ci
  • ? If Ai ? Ti, then ri(A) lt Ai
  • wi(A) lt Ai

14
How to achieve recoverable schedules?
15
Strict 2PL With 2PL, hold locks until commit
  • Ti Tj
  • Wi(A)
  • Ci
  • ui(A)
  • rj(A)

...
...
...
...
...
...
...
16
  • S is recoverable if each transaction commits only
    after all transactions from which it read have
    committed.
  • S avoids cascading rollback if each transaction
    may read only those values written by committed
    transactions.
  • S is strict if each transaction may read and
    write only items previously written by committed
    transactions.

17
Recoverable
Avoids cascading rollback
Strict
SERIAL
Avoid Cascading Aborts
Conflict Serializable
18
Now what to do about deadlocks? (which
can arise for our 2PL and even
strict-2P protocol).
19
Schedule with Deadlock
  • T1 T2
  • l1(A) Read(A) l2(B)Read(B)
  • A A100Write(A) B Bx2Write(B)
  • l1(B) l2(A)

delayed
delayed
20
Deadlocks
  • Detection
  • Wait-for graph
  • Prevention
  • Resource ordering
  • Timeout
  • Wait-die
  • Wound-wait

21
Deadlock Detection
  • Build Wait-For graph
  • Use lock table structures
  • Build incrementally or periodically
  • When cycle found, rollback victim

T5
T2
T1
T7
T4
T6
T3
22
Deadlock Prevention Resource Ordering
  • Order all elements A1, A2, , An
  • A transaction T can lock Ai after Aj only if i gt
    j

Problem Ordered lock requests not realistic in
most cases
23
Timeout
  • If transaction waits more than L sec., roll
    it back!
  • Simple scheme
  • Hard to select L

24
Wait-die
  • Transactions are given a timestamp when they
    arrive . ts(Ti)
  • Ti can only wait for Tj if ts(Ti)lt ts(Tj)
    ...else die

25
Example
  • T1
  • (ts 10)
  • T2
  • (ts 20)
  • T3
  • (ts 25)

wait
wait
26
Wound-wait
  • Transactions given a timestamp when they arrive
    ts(Ti)
  • Ti wounds Tj if ts(Ti)lt ts(Tj)
  • else Ti waits
  • Wound Tj rolls back and gives lock to Ti

27
Example
  • T1
  • (ts 10)
  • T2
  • (ts 20)
  • T3
  • (ts 15)

Not wait (instead wound T2)
wait
28
Summary
  • Cascading rollbacks and
  • Recoverable schedules
  • Deadlocks
  • Prevention
  • Detection
Write a Comment
User Comments (0)
About PowerShow.com