题目详情

某网上商品销售系统的业务流程如下:(1)将客户的订单记录(订单号,客户D,商品ID,购买数量)写入订单表;(2)将库存表(商品D,库存量)中订购商品的库存量减去该商品的购买数量。

【问题1】假设库存量有大于等于0 的约束,可能出现如下情况:当订单记录写入订单表后,修改库存表时因违法约束而无法执行,应如何处理? (100字以内)

【问题2】引入如下伪指令:将商品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, x1),x2= x2–a2, W2(A, x2)

(1)此时会出现什么问题?(100字以内)

(2)为了解决上述问题,引入共享锁指令SLock(A)和独占锁指令XLock(A)对数据A 进行加锁,解锁指令Unlock(A)对数据A 进行解锁,客户i 的加锁指令用SLocki(A)表示,其他类同。插入订单表的操作不需要引入锁指令。请补充上述执行序列,使其满足2PL 协议,并使持有锁的时间最短。

【问题2】下面是用E-SQL 实现的销售业务程序的一部分,请补全空缺处的代码。SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;INSERT INTO 订单表VALUES ( :OID, :CID, :MID, :qty);if error then { ROLLBACK;(a);}UPDATE 库存表SET 库存量=库存量- :qtyWHERE(b);if error then { ROLLBACK; return; }(c)

正确答案及解析

正确答案
解析

【问题1】将写订单记录和修改库存表作为一个完整的事务来处理,当修改库存表无法执行时,回滚事务,则会撤销写入的订单记录,数据库保持一致。

【问题2】(1)出现问题:客户1 购买后写入的库存量值被覆盖,库存量不能体现客户l已购买,属于丢失修改造成的数据库不一致性。(2)加锁后的执行序列: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)

【问题3】(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
查看答案

相关题库更多 +