某连锁酒店提供网上预订房间业务,流程如下:
(1)客户查询指定日期内所有类别的空余房间数,系统显示空房表(日期,房间类别,数量)中的信息;
(2)客户输入预订的起始日期和结束日期、房间类别和数量,并提交;
(3)系统将用户提交的信息写入预订表(身份证号,起始日期,结束日期,房间类别,数量),并修改空房表的相关数据。
针对上述业务流程,回答下列问題。
【问题1】(3分)
如果两个用户同时查询相同日期和房间类别的空房数量,得到的空房数量为1,并且这两个用户又同时要求预订,可能会产生什么结果,请用100字以内文字简要叙述。
【问题2】(8分)
引入如下伪指令:将预订过程作为一个事务,将查询和修改空房表的操作分别记为R(A)和W(A,x),插入预订表的操作记为W(B,a),其中x代表空余房间数,a代表预订房间数。则事务的伪指令序列为:x = R(A),W(A,x-a),W(B,a)。
在并发操作的情况下,若客户1、客户2同时预订相同类别的房间时,可能出现的执行序列为:x1=R(A), x2 = R(A), W(A, x1-a1), W(B1,a1), W(A, x2-a2), W(B2,a2)。
(1)此时会出现什么问题,请用100字以内文字简要叙述。
(2)为了解决上述问题,引入共享锁指令SLock(X)和独占锁指令XLock(X)对数据 X进行加锁,解锁指令Unlock(X)对数据X进行解锁,请补充上述执行序列,使其满足 2PL协议,使其不产生死锁且持有锁的时间最短。
【问题3】(4分)
下面是实现预订业务的程序,请补全空玦处的代码。其中主变量:Cid,:Bdate, :Edate,
:Rtype, :Num 分别代表身份证号,起始日期,结束日期,房间类别和订房数量。
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
UPDATE 空房表
SET数量=数量 - :Num
WHERE__(a)__;
if error then { ROLLBACK; return -1;}
INSERT INTO 预订表 VALUES (:Cid, :Bdate,:Edate,:Rtype,:Num);
if error then { ROLLBACK; return -2 ; }
__(b)__; .
正确答案及解析
正确答案
解析
【问题1】(3分)
同时预订时,可能会产生一个客户订不到或者把同一房订给两个客户
【问题2】(8分)
出现问题:丢失修改,客户1预订a1数量房间后,对空房数量的修改被T2的修改覆盖,造成数据不一致。(4分)
XLOCK(A),x1=R(A),W(A,x1-a1),XLOCK(B),UNLOCK(A),W(B1,a1),UNLOCK(B), XLOCK(A), x2=R(A),W(A,x2-a2),XLOCK(B),UNLOCK(A),W(B2,a2),UNLOCK(B)(4分)
【问题3】(4分)
(a)房间类别=:Rtype AND 日期 BETWEEN :Bdate AND :Edate(2分)
(b)COMMIT;Return 0;(2分)
包含此试题的试卷
你可能感兴趣的试题
Advancements in ( )have contributed to the growth of the automotive industry through the creation and evolution of self-driving vehicles.
-
- A.Artificial Intelligence
- B.Cloud Computing
- C.Internet of Things
- D.Big Data
- 查看答案
In project human resource management , ( )is not a source of power for the project manager.
-
- A.referent power
- B.expert power
- C.reward power
- D.audit power
- 查看答案
At the project establishment stage , the feasibility study mainly includes techinical feasibility analysis , ( ), operation environment feasibility analysis and other aspects of feasibility analysis.
-
- A.detail feasibility analysis
- B.opportunity analysis
- C.economic feasibility analysis
- D.risk analysis
- 查看答案
( )is a grid that shows the project resources assigned to each work package.
-
- A.Stakeholder engagement assessment matrix
- B.Requirements traceability matrix
- C.Probability and impact matrix
- D.Responsibility assignment matrix
- 查看答案
Xinhua News Agency reported in January 2022,Chian will further promote the developmet of a digital economy during the 14th Five-Year Plan eriod(2021-2025). The plan also emphasized industrial ( )transformation.
-
- A.digital
- B.networking
- C.intelligentize
- D.informatization
- 查看答案