Skip to content
Official PYQ · 2017

GATE CS 2017 Set 1 Q42 — Transactions and Concurrency Control

Explain with AI

In a database system, unique timestamps are assigned to each transaction using Lamport's logical clock. Let TS(T1)TS(T_{1}) and TS(T2)TS(T_{2}) be the timestamps of transactions T1T_{1} and T2T_{2} respectively. Besides, T1T_{1} holds a lock on the resource R,R, and T2T_{2} has requested a conflicting lock on the same resource R.R. The following algorithm is used to prevent deadlocks in the database system assuming that a killed transaction is restarted with the same timestamp.

                                      if TS(T2)<TS(T1)TS(T_{2})<TS(T_{1}) then

                                              T1T_{1} is killed

                                      else T2T_{2} waits.

Assume any transaction that is not killed terminates eventually. Which of the following is TRUE about the database system that uses the above algorithm to prevent deadlocks?

Choose one option
View worked solution

Answer: A

The given algorithm is the standard Wound-Wait scheme used for deadlock prevention in database systems.

1. Deadlock-Freedom

Let us analyze when a transaction is allowed to wait:

  • T2T_2 (the requesting transaction) is allowed to wait for T1T_1 (the holding transaction) only if TS(T2)>TS(T1)TS(T_2) > TS(T_1).
  • This means a transaction can only wait for another transaction that is older than itself (i.e., has a smaller timestamp).

Since the wait-for relation only goes from a younger transaction to an older transaction (Tyoung→ToldT_{\text{young}} \to T_{\text{old}}), a cycle in the wait-for graph is impossible because timestamps are unique and strictly ordered. Without a cycle, a deadlock cannot occur.

2. Starvation-Freedom

Let us analyze if a transaction can be rolled back indefinitely:

  • When a transaction is killed, it is restarted with its original timestamp.
  • As time progresses, the restarted transaction becomes older relative to newly entering transactions.
  • Eventually, it becomes the oldest active transaction in the system.
  • Once it is the oldest transaction, no other transaction can have a smaller timestamp. Thus, it will never be killed by any other transaction requesting a resource. Instead, it will either immediately acquire the resource (by killing the younger holder) or wait for it without being preempted.

Since every transaction eventually becomes the oldest and completes, the system is starvation-free.

Thus, the database system is both deadlock-free and starvation-free.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Transactions and Concurrency Control questions