This famous problem is known as a "lost update"
来源:互联网 发布:soma 知乎 编辑:程序博客网 时间:2024/05/22 01:34
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.
- This famous problem is known as a "lost update"
- todo list ~~ this is a greet problem
- This is an A+B Problem
- SDNU__1221.This is a water problem.
- This is an A+B Problem SDUT 2613
- SVN update problem: This client is too old to work with working copy
- Node.js Setup:This may indicate a problem with this package. The error code is 2503.
- Marshalling Error: XXXX is not known to this context
- This is the first problem
- SPOJ Problem Set (classical) 11582. A Famous Grid
- Variable is declared as a storage pointer. Use an explicit "storage" keyword to silence this warning
- This is a test
- this is a demo:)
- This is a test
- This is a test
- This is a test
- this is a test
- This is a test
- 新的 Windows 驱动框架 WDF (Windows Driver Foundation)
- 使用未公开关键字在 C# 中导入外部 printf 等参数数量可变函数
- 随手记
- 经典自我介绍
- english song
- This famous problem is known as a "lost update"
- 评出的最伟大的100首英文歌曲!!
- 不要密码的登陆
- 2004.07.07,Wed - 停电一天
- C#操作Excel常用语句
- 两阶段检查的代码片断
- 期末考试快完了!
- Duwamish 7 初探——数据流程
- Web开发技术史话