1 / 11

Concurrency Control

Concurrency Control. Complete Schedule. T 1. R 1 (X). W 1 (X). C 1. T 2. R 2 (X). W 2 (X). C 2. Example 1. T 1 : {R 1 (x), x = x+1, W 1 (x), C 1 } T 2 : {R 2 (x), x = x+1, W 2 (x), C 2 } Conflicting operations between T 1 and T 2 :

Télécharger la présentation

Concurrency Control

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Concurrency Control

  2. Complete Schedule T1 R1(X) W1(X) C1 T2 R2(X) W2(X) C2 Example 1 T1: {R1(x), x = x+1, W1(x), C1} T2: {R2(x), x = x+1, W2(x), C2} Conflicting operations between T1 and T2: { (R1(x), W2(x)) , (R2(x), W1(x)) , (W2(x),W1(x)) } We need to order these conflicting operations, e.g., R1(x)  W2(x) R2(x)  W1(x) W2(x)  W1(x)

  3. Another Way of Representing Schedules T1 R1(X) W1(X) C1 T2 R2(X) W2(X) C2 Note the explicit ordering of R1(X) and R2(X)

  4. T2 R2(x)  W2(y)  W2(x)  C2 T3 R3(y)  W3(x)  W3(y)  W3(z)  C3 T1 R1(x)  W1(x)  C1 Example 2 T1 = R1(x)  W1(x)  C1 T2 = R2(x)  W2(y)  W2(x)  C2 T3 = R3(y)  W3(x)  W3(y)  W3(z)  C3

  5. T2 R2(x)  W2(y)  W2(x)  C2 T3 R3(y)  W3(x)  W3(y)  W3(z)  C3 T1 R1(x)  W1(x)  C1 Example 2 in Table Form

  6. Precedence Graph • A set of transactions may have many possible schedules, which ones are correct? • Answer: use precedence graph • Precedence graph is a directed graph: • nodes/vertices as transactions • edges denoting precedence relationship between conflicting operations of different transactions. • For a pair of conflicting operations Oij Tiand Okl  Tk, • if Oij Okl then have an edge from Ti to Tk, else • if Okl Oij then have an edge from Tk to Ti • If there are more than one edge between two nodes, retain only one of the edges

  7. R1(X) W1(X) C1 T1 T2 R2(X) W2(X) C2 Precedence Graph of Example 1 Since there are two transactions, we have two nodes T1 and T2 R1(X)  W2(X)  edge T1 T2; R2(X)  W1(X)  edge T2 T1, T1 T2 W2(X)  W1(X)  edge T2 T1 A cycle in Precedence Graph implies potential for database inconsistency

  8. R2(x)  W2(y)  W2(x)  C2 T2 T3 R3(y)  W3(x)  W3(y)  W3(z)  C3 T1 R1(x)  W1(x)  C1 Precedence Graph of Example 2 T1 = R1(x)  W1(x)  C1 T2 = R2(x)  W2(y)  W2(x)  C2 T3 = R3(y)  W3(x)  W3(y)  W3(z)  C3 T1 T3 T2 T1  T3 because W1(x)  W3(x); T3  T2 because W3(x)  R2(x); T1  T2 because W1(x)  W2(x) No cycle in precedence graph so no database inconsistency.

  9. R2(x)  W2(y)  W2(x)  C2 T1  T3  T2 R3(y)  W3(x)  W3(y)  W3(z)  C3 R1(x)  W1(x)  C1 Using Another Schedule for Example 2 T1 = R1(x)  W1(x)  C1 T2 = R2(x)  W2(y)  W2(x)  C2 T3 = R3(y)  W3(x)  W3(y)  W3(z)  C3 PG has a cycle; the database may not be consistent

  10. T1 T2 T3 Another Example on Serializability Schedule is NOT serializable

  11. R2(x)  W2(y) Schedule = R3(y)  W3(x)  W3(y) R1(x)  W1(x)  C1 Run-time Construction of Precedence Graph T1 = R1(x)  W1(x)  C1 T2 = R2(x)  W2(y)  W2(x)  C2 T3 = R3(y)  W3(x)  W3(y)  W3(z)  C3 • The scheduler keeps building the Precedence Graph as the operations of active transactions are scheduled so that the PG is acyclic. • The scheduler delays scheduling those operation that can cause a cycle in PG

More Related