KatInterview

Name the Anomaly in an Interleaved Two-Transaction Schedule

SQL & DataAuto-graded · 17 test cases
EasyAuto-gradedSQL & Datatransactionsconcurrencyisolation-levels

Last updated

Identify which classic concurrency anomaly a fixed read/read/write/write schedule on one shared value produces, and return the matching option letter.

Interleaved Updates on a Shared Value

Two database transactions, T1 and T2, run at the same time against a single stored value A. Their steps happen in this exact order:

  1. T1 reads A and sees 100.
  2. T2 reads A and sees 100.
  3. T1 computes A + 10 and writes 110.
  4. T2 computes A - 10 from the value it read earlier (100) and writes 90.

Decide which of the following best describes the concurrency problem in this schedule:

  • A. A transaction gets different results when it reads the same item twice (a non-repeatable read).
  • B. The schedule has no concurrency problem.
  • C. A transaction reads data written by another transaction that has not yet committed (a dirty read).
  • D. One transaction's update is overwritten and therefore lost (a lost update).

Task

Implement a function that takes no arguments and returns the letter of the correct option as an uppercase one-character string ("A", "B", "C", or "D").

Constraints

  • The function takes no parameters.
  • The return value is a str containing exactly one of "A", "B", "C", "D".
  • The schedule is the fixed four-step one above. Each transaction reads A exactly once.
  • The option letters keep the meanings listed above.

Examples

Example 1

Input: identify_schedule_anomaly()

Output: 'D'

Hints

Hint 1

Write the schedule as a sequence like R1(A), R2(A), W1(A), W2(A) and ask which transaction's result is still visible at the end.

Hint 2

Compare the final value with the results of the two serial orders (T1 then T2, and T2 then T1). Do they match?

Hint 3

Check each wrong option against its definition. Does any transaction read the same item twice, or read something an uncommitted writer produced?