• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Problem solutions
 

Problem solutions

on

  • 883 views

TO Algorithm soution

TO Algorithm soution

Statistics

Views

Total Views
883
Views on SlideShare
883
Embed Views
0

Actions

Likes
0
Downloads
18
Comments
0

0 Embeds 0

No embeds

Accessibility

Upload Details

Uploaded via as Microsoft Word

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Problem solutions Problem solutions Document Transcript

    • Basic TO algorithm :Case 1 : If Tj requests read operation on data item x, If TS(Tj) < WTS(x) then Reject the operation and abort Tj; Restart Tj with new timestamp; Else Execute read operation; Set RTS(x) = max {RTS(x), TS(Tj)};Case 2 : If Tj requests write operation on data item x, If TS(Tj) < RTS(x) and TS(Tj) < WTS(x) then Reject the operation and abort Tj; Restart Tj with new timestamp; Else Execute write operation; Set WTS(x) = TS(Tj);RTS(x) is read timestamp of x – sometimes called RTM(x)WTS(x) is write timestamp of x – sometimes called WTM(x)PROBLEM :Consider a data item X. Let RTM(X) = 25 and WTM(X) = 20. Let the pair (<Ri(X),TS>, Wi(X), TS)denote a read / write request of transaction Ti on the item X with timestamp TS. Indicate thebehavior of the basic timestamp method with the following sequence of requests.<R1(X), 19>, <R2(X), 22>, <W3(X), 21>,<W4(X), 23>, <R5(X), 28>, <W6(X), 27>ANSWER :a) <R1(X), 19> - it means that T1 transaction wants to perform read(X) operation and TS(T1)=19. From basic TO algorithm, As, TS(T1) < WTM(X), reject the operation and abort T1 and restart T1 with new timestamp.b) <R2(X), 22> - it means that T2 transaction wants to perform read(X) operation and TS(T1)=22. From basic TO algorithm, As, TS(T2) > WTM(X), perform the operation and set RTM(X), RTM(X) = max{RTM(X), TS(T2)} = max{25, 22} = 25c) <W3(X), 21> - it means that T3 transaction wants to perform write(X) operation and TS(T1)=21. From basic TO algorithm, As, TS(T3) < RTM(X) but TS(T3) > WTM(X), perform the operation and set WTM(X), WTM(X) = TS(T3) = 21
    • d) <W4(X), 23> - it means that T4 transaction wants to perform write(X) operation and TS(T1)=23. From basic TO algorithm, As, TS(T4) < RTM(X) but TS(T4) > WTM(X) (i.e. new WTM value 21), perform the operationand set WTM(X), WTM(X) = TS(T4) = 23e) <R5(X), 28> - it means that T5 transaction wants to perform read(X) operation and TS(T1)=28. From basic TO algorithm, As, TS(T5) > WTM(X) (i.e. new WTM value 23), perform the operation and set RTM(X), RTM(X) = max{RTM(X), TS(T5)} = max{25, 28} = 28f) <W6(X), 27> - it means that T6 transaction wants to perform write(X) operation and TS(T1)=27. From basic TO algorithm, As, TS(T6) < RTM(X)(i.e. new RTM value 28) but TS(T6) > WTM(X) (i.e. new WTM value 23),perform the operation and set WTM(X), WTM(X) = TS(T6) = 27Distributed Deadlock Detection Algorithm : This algorithm works by successive iterations. At each iteration each site receives potential deadlock information which was produced by other sites during the previous iteration, then it performs deadlock detection and finally it sends potential deadlock information to other sites. Therefore, the communication between local deadlock detectors occurs between different iterations of the algorithm. It may happen that two sites may send the same global deadlock information to each other. This would cause that the same deadlock be discovered twice, which is not necessary. To avoid this unnecessary transmission, the algorithm uses the following rule : The potential deadlock cycle is transmitted only if the transaction identifier of the transaction for which EX waits is greater than the transaction identifier of the transaction waiting for EX. For example, consider following DWFG, Site 1 T1 T2 Site 2 T1 T2
    • The local deadlock detectors at each site builds the LWFG as follows, At site 1 T1 T2 EX At site 2 T1 T2 EX NOTE : In LWFG, all output and input ports are collected into a single node, called external (EX). From above LWFFGs , we obtain that only site 2 transmits the potential deadlock cycle because atsite 2 EX is waiting for T2 and T1 is waiting for EX in the potential cycle (from the above rule). At each iteration of the algorithm, the local deadlock detectors at each site perform the following actions : 1) Build the LWFG using local information. The LWFG includes the node EX. 2) For each message which has been received, perform the following modifications of the LWFG : a) For each transaction in the message, add it to the LWFG if it does not already exist. b) For each transaction in the message, starting with EX, create an edge to the next transaction in the message. This step has included all potential deadlock information received from other sites into the local LWFG. 3) Find cycles not involving EX in the LWFG. Each such cycle indicated the existence of a deadlock. Deadlock resolution is invoked to eliminate these deadlocks. 4) Find cycles involving EX. These cycles are potential deadlock cycles. The rule described above is used to determine whether a potential deadlock cycle must be transmitted to a different site. If the transmission is required, the message is prepared and transmitted. The transmission of potential deadlock cycles terminates the current iteration of the deadlock detection process.
    • PROBLEM 1:Consider the following DWFT given below, Site1 T2 T2 T3 Site2 T1 T1 T3 Site3Detect the deadlock using the distributed deadlock diagram.ANSWER :Iteration 1:First draw LWFG for each site. T1 T2 EX At site 1 T2 T3 EX At site 2 EX T1 T3 At site 3At site3, there is no potential deadlock cycle exists. But site1 and site2 LWFG contain potentialdeadlock cycle.The rule for transmitting the potential deadlock cycle is as follows : The potential deadlock cycle is transmitted only if the transaction identifier of the transaction for which EX waits is greater than the transaction identifier of the transaction waiting for EX.From the above rule, none of the site sends the information to the remaining sites. Therefore theiteration terminates without sending any information.
    • PROBLEM 2 : Consider following DWFG, Site 1 T1 T2 Site 2 T1 T2 Detect the deadlock using the distributed deadlock diagram. ANSWER : Iteration 1 : First draw LWFG for each site. T1 T2 EX T1 T2 EX Site1 Site2 Both site1 and site2 LWFGs contain potential deadlock cycle. The rule for transmitting the potential deadlock cycle is as follows : The potential deadlock cycle is transmitted only if the transaction identifier of the transaction for which EX waits is greater than the transaction identifier of the transaction waiting for EX. From the above rule, only site 2 transmits the potential deadlock cycle because at site 2 EX is waiting for T2 and T1 is waiting for EX in the potential cycle. Cycle involves EX. Therefore site1 receives message from site1 as (EX, T2, T1). Iteration 2 : At site 1, after receiving the message from site2, the local deadlock detector modifies the LWFG as follows : a) No need to add any transaction the LWFG as each transaction in the message is already exists in LWFG. b) For each transaction in the message i.e. T1 and T2, starting with EX, create an edge to the next transaction in the message. T1 T2 EXc) There is a cycle not involving EX in the above LWFG (i.e. T1-T2-T1). Thus there is a deadlock detected at site1. Deadlock resolution is invoked at site1 by selecting a victim and an abort message for that victim is send to all sites where the victim was active (i.e. to site2). ******************