面试经验:丢失更新(第一类&第二类)

本文通过银行转账和取款的实例,详细解析了第一类和第二类丢失更新问题,展示了当两个事务交错执行时,如何可能导致数据不一致的情况。

第一类丢失更新 

    A事务撤销时,把已经提交的B事务的更新数据覆盖了。这种错误可能造成很严重的问题,通过下面的账户取款转账就可以看出来:

时间

取款事务A

转账事务B

T1

开始事务

 

T2

 

开始事务

T3

查询账户余额为1000元    

 

T4

 

查询账户余额为1000元

T5

 

汇入100元把余额改为1100元

T6

 

提交事务

T7

取出100元把余额改为900元

 

T8

撤销事务

 

T9

余额恢复为1000 元(丢失更新)

 

   

A事务在撤销时,“不小心”将B事务已经转入账户的金额给抹去了。 

    第二类丢失更新 

A事务覆盖B事务已经提交的数据,造成B事务所做操作丢失:   

时间

转账事务A

取款事务B

T1

 

开始事务

T2

开始事务

                         

T3

               

查询账户余额为1000元    

T4

查询账户余额为1000元

                         

T5

 

取出100元把余额改为900元

T6

 

提交事务           

T7

汇入100元

 

T8

提交事务

 

T9

把余额改为1100 元(丢失更新)

 

 

    上面的例子里由于支票转账事务覆盖了取款事务对存款余额所做的更新,导致银行最后损失了100元,相反如果转账事务先提交,那么用户账户将损失100元。

 

<html>没有匹配ostream(即 ostream)和function-overload-set类型的实参的可行 operator<<。<br/>考虑的候选项:<br/>ostream::__ostream_type &amp;operator<<(ostream::__ostream_type &amp;(*__pf)(ostream::__ostream_type &amp;)) (class basic_ostream<char, char_traits<char>> 中)<br/>1st实参 count 的转换格式错误: 无法将function-overload-set转换为形参类型 ostream::__ostream_type &amp;(*)(ostream::__ostream_type &amp;)<br/>ostream::__ostream_type &amp;operator<<(ostream::__ios_type &amp;(*__pf)(ostream::__ios_type &amp;)) (class basic_ostream<char, char_traits<char>> 中)<br/>1st实参 count 的转换格式错误: 无法将function-overload-set转换为形参类型 ostream::__ios_type &amp;(*)(ostream::__ios_type &amp;)<br/>ostream::__ostream_type &amp;operator<<(ios_base &amp;(*__pf)(ios_base &amp;)) (class basic_ostream<char, char_traits<char>> 中)<br/>1st实参 count 的转换格式错误: 无法将function-overload-set转换为形参类型 ios_base &amp;(*)(ios_base &amp;)<br/>ostream::__ostream_type &amp;operator<<(long __n) (class basic_ostream<char, char_traits<char>> 中)<br/>1st实参 count 的转换格式错误: 无法将function-overload-set转换为形参类型 long<br/>ostream::__ostream_type &amp;operator<<(unsigned long __n) (class basic_ostream<char, char_traits<char>> 中)<br/>1st实参 count 的转换格式错误: 无法将function-overload-set转换为形参类型 unsigned long<br/>ostream::__ostream_type &amp;operator<<(bool __n) (class basic_ostream<char, char_traits<char>> 中)<br/>1st实参 count 的转换格式错误: 无法将function-overload-set转换为形参类型 bool<br/>ostream::__ostream_type &amp;operator<<(short __n) (class basic_ostream<char, char_traits<char>> 中)<br/>1st实参 count 的转换格式错误: 无法将function-overload-set转换为形参类型 short<br/>ostream::__ostream_type &amp;operator<<(unsigned short __n) (class basic_ostream<char, char_traits<char>> 中)<br/>1st实参 count 的转换格式错误: 无法将function-overload-set转换为形参类型 unsigned short<br/>ostream::__ostream_type &amp;operator<<(int __n) (class basic_ostream<char, char_traits<char>> 中)<br/>1st实参
最新发布
07-17
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值