This famous problem is known as a "lost update"

原创 2004年07月07日 20:50:00

Each of the instances of the component performs the following steps:
1. Read an integer X from a database.
2. Add 10 to X.
3. Write the new value of X to the database.

If each these three steps exceutes together in an atomic operation, everthing
is fine. Neither instance can interfere with the other instance's operations.
Remember, though, that the thread-scheduling algorithm being used in the
backgroud does not guarentee this. If two instances are executing these three
operations, the operations could be interleaves. The follwing order of operations
is possible:

1. Instance A reads integer X from database. The database now contains X = 0.
2. Instance B reads integer X from database. The database now contains X = 0.
3. Instance A adds 10 to its copy of X and persists it to the database. The
   database now contains X = 10.
4. Instance B adds 10 to its copy of X and persists it to the database. The
   database now contains X = 10;
  
What happened here? Due to the interleaving of database operations, instance
B is working with a stale copy of X: The copy before instance A performed a
write. Thus, instance A's operations have been lost! This famous problem is
known as a "lost update"
. It is very serious situation-instance B has been
working with stale data and has overwritten instance A's write. How can
transactions avoid this scenario?

The solution to this problem is to use "locking" on the database to prevent the
two components from reading data. By locking the data your transaction is using,
you guarantee that your transaction and only your transaction has access to
that data until you release that lock. This prevents interleaving of sensitive
data operations.

In our scenario, if our component acquired an exclusive lock before the trans-
action began and released that lock after the transaction, then no interleaving
would be possible.

1. Request a lock on X.
2. Read an integer X from a database.
3. Add 10 to X.
4. Write then new value of X to the database.
5. Release the lock on X.

If another component ran concurrently with ours, that component would have to
wait until we relinguished our lock, which would give that component our
fresh copy of X.

POJ 2182 Lost Cows(树状数组,暴力解法)

POJ 2182 Lost Cows(树状数组,暴力解法) 分析:        其实这道题目只要会手算用例就能暴力解决。        假设读入题目给的数组a[n],其中a[1]=0 这道题目只给出...
  • u013480600
  • u013480600
  • 2014年03月20日 02:00
  • 1659

The 3n + 1 problem(杭电1032)(暴力求解)

The 3n + 1 problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe...
  • hdd871532887
  • hdd871532887
  • 2014年11月24日 23:33
  • 1014

问题分析报告--Hive表列属性更新慢并偶尔更新失败

问题分析报告--Hive表列属性更新慢并偶尔更新失败 1、问题描述 1.1 基本信息[Basic Information] 集群规模:37+3台物理机,每台128G内存;CPU:2*16C...
  • boyu_tung
  • boyu_tung
  • 2016年11月06日 13:38
  • 819

valgrind报的几种内存泄露(转)

转自http://www.th7.cn/system/lin/201505/103949.shtmlvalgrind是linux下用于调试程序和查找内存泄露的常用工具。valgrind会报告5种内存泄...
  • qq_35039122
  • qq_35039122
  • 2016年09月07日 17:59
  • 376

android 查看内存使用情况

文章出处:http://blog.csdn.net/shift_wwx/article/details/42490863 查看内存使用情况,有好几种方法,但是查看出来的结果是不一样的。 cat ...
  • jingerppp
  • jingerppp
  • 2015年01月07日 13:15
  • 4471

Spark on Yarn+Hbase环境搭建指南(四)NTP服务设置

一、简介     NTP(Network Time Protocol)是运行在传输层的协议,使用123端口的UDP,它允许计算机在网络上同步时间。NTP同步方式分为:使用ntpdate命令直...
  • Seraphous
  • Seraphous
  • 2015年09月10日 19:40
  • 980

撰写related work 格式方面心得

1、作者名如果很长最好
  • fht1051066200
  • fht1051066200
  • 2014年07月29日 02:13
  • 4507

《Lost》大结局最权威最彻底解读

Lost大结局最权威最彻底解读:      似乎有一些人还在纠结于Lost最终告诉我们的话:释怀然后继续前进。   所谓“一些人”,不仅仅是那些铁杆捞饭——还有些不太关注的观众也在周日的晚上第一次收看...
  • u013634961
  • u013634961
  • 2014年09月11日 00:20
  • 2059

Android内存优化之OOM

Android的内存优化是性能优化中很重要的一部分,而避免OOM又是内存优化中比较核心的一点。这是一篇关于内存优化中如何避免OOM的总结性概要文章,内容大多都是和OOM有关的实践总结概要。理解错误或是...
  • lostinai
  • lostinai
  • 2015年12月18日 12:46
  • 610

搭建Hadoop-2.6.0集群

硬件配置 四台:IBM System x3650 M4(7915I51) 产品类别:机架式 产品结构:2U CPU型号:Xeon E5-2650 标配CPU数量:1颗 内存类型:ECC...
  • icebergwang
  • icebergwang
  • 2015年03月15日 11:31
  • 1481
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:This famous problem is known as a "lost update"
举报原因:
原因补充:

(最多只允许输入30个字)