3

I have two transactions T and U which are executed simultaneously in a DB. How does one provide an example of the lost update problem?

We can assume that we have three accounts A,B,C and they each have £100,£200 and £300 respectively.

Erick Robertson
  • 32,125
  • 13
  • 69
  • 98
CGF
  • 313
  • 3
  • 5
  • 15
  • This was tagged as not-programming-related. It seems pretty programming related to me... – Zifre May 12 '09 at 22:09
  • Well it's way too generalized - bordering on not a real question - please provide some more specifics - thanks. – DJ. May 12 '09 at 23:03
  • it's a pretty specific problem with a general solution - although the question is obviously a homework or exam question – Jeffrey Kemp May 19 '09 at 03:26

3 Answers3

20

The "lost update" problem relates to concurrent reads and updates to data, in a system where readers do not block writers. It is not necessary for the transactions to be exactly simultaneous.

  1. Session #1 reads Account A, gets 100.
  2. Session #2 reads Account A, gets 100.
  3. Session #2 updates Account A to 150 (+50) and commits.
  4. Session #1 updates Account A to 120 (+20) and commits.

In this scenario, because Session #1 does not know that another session has already modified the account, the update by Session #2 is overwritten ("lost").

There are several ways to solve this, e.g. version numbers or before-and-after compares.

Jeffrey Kemp
  • 59,135
  • 14
  • 106
  • 158
  • By version numbers you mean using optimistic locking of hibernate – Anand May 07 '16 at 17:03
  • Hi Anand, yes, as far as I understand Hibernate's implementation of optimistic locking involves comparison of record version numbers. I'm not sure if that's the only method that Hibernate supports, however. – Jeffrey Kemp May 08 '16 at 12:13
1

This occurs when two transactions that access the same database items have their operations interleaved in a way that makes the value of some database item incorrect.

ibrahim
  • 11
  • 1
1

(3) Update Account A to 150 Where Account is 100 -> Account A is now 150

(4) Update Account A to 120 Where Account is 100 -> Update fail because account A is 150 and not 100

Steen A
  • 11
  • 1