Docsity

Concurrency Control and Recovery: Transaction Management, Slides of Database Management Systems (DBMS)

Partial preview of the text

Download Concurrency Control and Recovery: Transaction Management and more Slides Database Management Systems (DBMS) in PDF only on Docsity!

More Transaction Management

Concurrency control and recovery Resolving deadlocks Logical logging

Concurrency control & recovery

Example: T j T i

wj (A) ri(A) Commit Ti

Abort Tj

2

 Cascading rollback (Bad!)

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

To model this, two new actions:

  • • CAi i - transaction T- transaction T i i commitsaborts
  • • Each transaction TEvery read and write of T i has exactly one, either C i precedes the Ci (or Ai or A i ) i

Definition

T i reads from T j in S (denoted T j ⇒S T i ) if

  1. there is a write wj (A) in S that is followed by a read ri (A) in S
  2. there is no abort of T j in S before the r i (A) in S
  3. if there is a write to A in S between w j (A) and r i (A) by another transaction T k, then T k aborts before the r i (A)

Definition

Schedule S is recoverable if whenever Ti reads from another transaction Tj, Ti does not commit until after Tj commits.

 With 2PL, hold write locks until transaction commits (strict 2PL)

T j T i

Wj (A)

Cj uj (A) ri(A)

10

  • 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.

Where are serializable schedules?

13

Avoids cascading rollback

RC

ACR

ST (^) SERIAL

SERIALIZABLE

Examples

  • Recoverable:
    • w 1 (A) w 1 (B) w 2 (A) r 2 (B) c 1 c 2
  • Avoids Cascading Rollback:
    • w 1 (A) w 1 (B) w 2 (A) c 1 r 2 (B) c 2
  • Strict:
    • w 1 (A) w 1 (B) c 1 w 2 (A) r 2 (B) c 2

Deadlocks

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

Deadlock Detection

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

17

T 1

T 3

T 2

T 6

T 5

T 4

T 7

Timeout

  • If transaction waits more than L sec., roll it back!
  • Simple scheme
  • Hard to select L

Wait-die

  • Each transaction Ti is given a timestamp when it starts, denoted ts(T i)
  • Suppose T i requests a lock currently held by Tj
  • if ts(T i)< ts(T j ) then Ti waits for T j (older waits for younger) else Ti dies (aborts) (younger dies)
  • If Ti dies then it later restarts with the same timestamp