Presentation is loading. Please wait.

Presentation is loading. Please wait.

Algorithm 2 Algorithm 2 Problem

Similar presentations


Presentation on theme: "Algorithm 2 Algorithm 2 Problem"— Presentation transcript:

1 Algorithm 2 Algorithm 2 Problem
Apply Algorithm 2 to the Schedule of Transactions on the next Slide In this Case, Wlock Implies Reading For this Problem: Draw the Precedence Graph Check to See if the Schedule is Serializable If So, Determine ALL Serial Schedules

2 Algorithm 2: Read/Write Lock Model
Input: Schedule S for Transactions T1, T2 , … Tk Output: Is S Serializable? If so, Serial Schedule Method: Create a Directed Precedence Graph G: Suppose in S, Ti :Rlock A. If Tj : Wlock A is the Next Transaction to Wlock A (if it exists) then place an Arc from Ti to Tj. Repeat for all Ti’s, all Rlocks before Wlock on A! Suppose in S, Ti :Wlock A. If Also exists Tm :Rlock A after Ti :Wlock A but before Tj : Wlock A, then Draw an Arc from Ti to Tm. Review the Resulting Precedence Graph If G has Cycles - Non-Serializable If G is Acyclic - Topological Sort for Serial Schedule

3 Apply Algorithm 2 to Following Schedule
T1 T2 T3 T4 (1) Rlock A (2) Rlock A (3) Wlock C (4) Unlock C (5) Rlock C (6) Wlock B (7) Unlock B (8) Rlock B (9) Unlock A (10) Unlock A (11) Wlock A (12) Rlock C (13) Wlock D (14) Unlock B (15) Unlock C (16) Rlock B (17) Unlock A (18) Wlock A (19) Unlock B (20) Wlock B (21) Unlock B (22) Unlock D (23) Unlock C (24) Unlock A

4 Algorithm 3 – Steps 1 to 4 Input: Schedule S for Transactions T1, T2 , … Tk Output: Is S Serializable? If so, Serial Schedule Method: Create a Directed Polygraph Graph P: Augment S with Dummy To (Write Every Item) an Dummy Tf (Read Every Item) Create Initial Polygraph P by Adding Nodes for To, Tf, and Each Ti Transaction , in S Place an Arc from Ti to Tj Whenever Tj Reads A in Augmented S (with Dummy States) that was Last Written by Ti. Write to Read for Each Item Repeat this Step for all Arcs. Don’t Forget to Consider Dummy States! Discover Useless Transactions - T is Useless if there is no Path from T to Tf This is the “Initialization” Phase of Algorithm 3

5 Algorithm 3 – Steps 5 to 7 Method: Reassess the Initial Polygraph P:
For Each Remaining Arc Ti W to Tj R(meaning that Tj Reads Item A Written by Ti ) Consider all T  To and T  Tf that also Writes A: I. If Ti = To and Tj = Tf then Add No Arcs II. If Ti = To and Tj  Tf then Add Arc from Tj to T III. If Ti  To and Tj = Tf then Add Arc from T to Ti IV. If Ti  To and Tj  Tf then Add Arc Pair from T to Ti and Tj to T Determine if P is Acyclic by “Choosing” One Transaction Arc for Each Pair - Make Choices Carefully If Acyclic - Serializable - Perform Topological Sort without To , Tf for Equivalent Serial Schedule. Else - Not Serializable

6 Algorithm 3 – Key Steps Method: Reassess the Initial Polygraph P:
Place an Arc from Ti to Tj Whenever Tj Reads A in Augmented S (with Dummy States) that was Last Written by Ti. Write to Read for Each Item Repeat this Step for all Arcs. Don’t Forget to Consider Dummy States! Discover Useless Transactions - T is Useless if there is no Path from T to Tf For Each Remaining Arc Ti W to Tj R(meaning that Tj Reads Item A Written by Ti ) Consider all T  To and T  Tf that also Writes A: I. If Ti = To and Tj = Tf then Add No Arcs II. If Ti = To and Tj  Tf then Add Arc from Tj to T III. If Ti  To and Tj = Tf then Add Arc from T to Ti IV. If Ti  To and Tj  Tf then Add Arc Pair from T to Ti and Tj to T Determine if P is Acyclic by “Choosing” One Transaction Arc for Each Pair - Make Choices Carefully

7 Apply Algorithm 3 to Following Schedule
T1 T2 T3 T4 (T0) Write A Write B (1) Wlock A (2) Rlock B (3) Unlock A (4) Rlock A (5) Unlock B (6) Wlock B (7) Rlock A (8) Unlock B (9) Wlock B (10) Unlock A (11) Unlock A (12) Wlock A (13) Unlock B (14) Rlock B (15) Unlock A (16) Unlock B (TF) Read A Read B

8 Algorithm 4 Algorithm 4 Problem
Apply Algorithm 4 to the Schedule of Transactions on the next Slide Assume the Following Transaction Times T1 = 175, T2 = 150, T3 = 200, T4 = 225 Determine the RT and WT for A, B, C, and D at each Step Indicate when a Transaction Aborts or has No Effect Remember, RT=WT=0 for A, B, C, and D Prior to the 1st Step in the Schedule

9 Algorithm 4: Optimistic CC
Let T be a Transaction with Timestamp t Attempting to Perform Operation X on a Data Item I with Readtime tR and Writetime tW If (X = Read and t  tW ) Perform Oper If t > tW then set tR = t for Data Item I (read after write) If (X = Write and t  tR and t  tW ) Perform Oper If t > tr then set tW = t for Data Item I (write after read) If (X = Write and tR  t < tW ) then Do Nothing since Later Write will Cancel out the Write of T If (X = Read and t < tW ) or (X = Write and t < tR ) then Abort the Operation 1st - T trying to Read Item Before it was Written 2nd - T trying to Write an Item Before it was Read

10 Algorithm 4 Problem T1=175 T2=150 T3=200 T4=225 A B C D (1) Read A
Initially RT/WT of A, B, C, and D are all Zero (0) T1=175 T2= T3= T4= A B C D (1) Read A (2) Read A (3) Write C (4) Read C (5) Write B (6) Read B (7) Write A (8) Read C (9) Write D (10) Read B (11) Write A (12) Write B

11 Query Optimization Problem
Consider the Three Relations: Branch (BranchName, BranchCity, Assets) Account(AccountNumber, BranchName, Balance) Depositor(CustomerName, AccountNumber) Optimize the following Relational Express by Drawing the Initial Expression Tree Optimizing (Rewriting) the Tree The Query Finds all Customers who have Accounts at the Storrs Branch with Balance > 1000 CustomerName(BranchName=‘Storrs’^ Balance > 1000 (Branch x Account x Depositor))

12 Create the Initial Query Tree
Depositor Branch Account CustomerName BranchName = Storrs ^ Balance > 1000 X


Download ppt "Algorithm 2 Algorithm 2 Problem"

Similar presentations


Ads by Google