在并发控制中丢失更新? [英] Lost update in Concurrency control?

查看:141
本文介绍了在并发控制中丢失更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个事务T和U在DB中同时执行。如何提供丢失更新问题的示例?

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?

我们可以假设我们有三个帐户A,B,C,他们每个有100英镑,200英镑£300。

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

推荐答案

丢失更新问题涉及并发读取和更新数据,在读者不阻止写入者的系统中。

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. 会话#1读取帐户A,获取100。

  2. 会话#2读取帐户A,获取100。

  3. 会话#2将帐户A更新为150(+50)并提交。

  4. 会话#1将帐户A更新为120(+20)并提交。

  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.

知道另一个会话已经修改了帐户,会话#2的更新被覆盖(丢失)。

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.

这篇关于在并发控制中丢失更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆