某网上商品销售系统的业务流程如下:
(1)将客户的订单记录(订单号,客户ID,商品ID,购买数量)写入订单表;
(2)将库存表(商品ID,库存量)中订购商品的库存量减去该商品的购买数量。
针对上述业务流程,完成下列问题:
【问题1】(3分)
假设库存量有大于等于0的约束,可能出现如下情况:当订单记录写入订单表后,修改库存表时因违法约束而无法执行,应如何处理?(100字以内)
【问题2】(6分)
引入如下伪指令:将商品A的订单记录插入订单表记为I(A);读取商品A的库存量到变量x,记为x=R(A);变量x值写入商品A中的库存量,记为W(A,x)。则客户i的销售业务伪指令序列为:Ii(A),xi=Ri (A),xi=xi-ai,Wi (A,Xi)。其中ai为商品的购买数量。
假设当前库存量足够,不考虑发生修改后库存量小于0的情况。若客户1、客户2同时购买同一种商品时,可能出现的执行序列为:I1(A),I2 (A),X1=R1 (A),X2= R2 (A),x1= x1-a1 , W1 (A, xi), X2 =X2- a2, W2(A,X2)。
(1)此时会出现什么问题(100字以内)
(2)为了解决上述问题,引入共享锁指令SLock(A)和独占锁指令XLock(A)对数据A进行加锁,解锁指令Unlock(A)对数据A进行解锁,客户i的加锁指令用SLocki(A)表示,其他类同。插入订单表的操作不需要引入锁指令。请补充上述执行序列,使其满足2PL协议,并使持有锁的时间最短。
【问题3】(6分)
下面是用E-SQL实现的销售业务程序的一部分,请补全空缺处的代码。
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
INSERT INTO 订单表VALUES(:OID,:CID,:MID,:qty);
If error then {ROLLBACK; (a) ;}
UPDATE库存表
SET库存量=库存量-:qty
WHERE (b) ;
If error then {ROLLBACK; return;}
(c)
正确答案及解析
正确答案
解析
【问题1】(3分)
将写订单记录和修改库存表作为一个完整的事务来处理,当修改库存表无法执行时,回滚事务,则会撤销写入的订单记录,数据库保持一致。
【问题2】(6分)
(1)出现问题:客户购买后写入的库存量值被覆盖,库存量不能体现客户1已购买,属于丢失修改造成的数据库不一致性。(3分)
(2)重写后的序列:(3分)
I1(A), I2(A), XLock1 (A), x1 = R1 (A), x1=x1- a1, W1 (A, x1), Unlock1 (A),XLock2(A),
X2 = R2 (A), x2=x2-a2, W2 (A, X2), Unlock2 (A)。
注:若锁持续时间不是最短,可扣1分。
【问题3】 (6分,各2分)
(a) return
(b) 商品ID=:MID
(c) COMMIT
包含此试题的试卷
你可能感兴趣的试题
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
- 查看答案