More than Just Lines on a Map: Best Practices for U.S Bike Routes
Problem solutions
1. 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 the
behavior 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}
= 25
c) <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
2. 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 operation
and set WTM(X),
WTM(X) = TS(T4) = 23
e) <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}
= 28
f) <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) = 27
Distributed 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
3. 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 at
site 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.
4. PROBLEM 1:
Consider the following DWFT given below,
Site1 T2 T2 T3 Site2
T1 T1 T3 Site3
Detect 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 3
At site3, there is no potential deadlock cycle exists. But site1 and site2 LWFG 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, none of the site sends the information to the remaining sites. Therefore the
iteration terminates without sending any information.
5. 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 EX
c) 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).
******************