某航空售票系统负责所有本地起飞航班的机票销售,并设有多个机票销售网点。各售票网点使用相同的售票程序。假设售票程序中用到的伪指令如下表1-1所示:
假设某售票网点一次售出a张航班A 的机票,则售票程序的伪指令序列为:R(A, x);W(A,x-a)。根据上述业务及规则,完成下列问题:
【问题1】(5 分)
若两个售票网点同时销售航班A的机票,在数据库服务器端可能出现如下的调度:
A:R1(A, x),R2(A, x),W1(A, x–1),W2(A, x–2);
B:R1(A, x),R2(A, x),W2(A, x–2),W1(A, x–1);
C:R1(A, x),W1(A, x–1),R2(A, x),W2(A, x–2);
其中Ri(A, x),Wi(A, x)分别表示第i个销售网点的读写操作,其余类同。
假设当前航班 A 剩余 10 张机票,分析上述三个调度各自执行完后的剩余票数,并指出错误的调度及产生错误的原因。
【问题2】(6 分)
(1)判定事务并发执行正确性的准则是什么?如何保证并发事务正确地执行?
(2)引入相应的加解锁指令,重写售票程序的伪指令序列,以保证正确的并发调度。
【问题3】(4 分)
下面是用E-SQL实现的机票销售程序的一部分,请补全空缺处的代码。
EXEC SQL SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
EXEC SQL SELECT balance INTO :x FROM tickets WHERE flight = ’A’ ;
printf("航班A 当前剩余机票数为:%d\n请输入购票数:", x );
scanf("%d", &a);
x = x – a ;
if (x<0)
EXEC SQL ROLLBACK WORK;
printf("票数不够,购票失败!");
else{
EXEC SQL UPDATE tickets SET (a) ;
if (SQLCA.sqlcode <> SUCCESS)
EXEC SQL ROLLBACK WORK;
else
(b) ;
}
正确答案及解析
正确答案
解析
【问题1】
调度A结果:8 调度B结果:9 调度C结果:7
调度A、B结果错误,因为破坏了事务的隔离性。一个事务的执行结果被另一个所
覆盖。
【问题2】
(l)判定事务并发执行正确性的准则是满足可串行化调度。要保证并发事务正确地
执行,采用两段锁协议(2PL)。
(2)重写后的售票程序伪指令序列:
Xlock(A);R(A,x);W(A,x-a);Unlock(A);
【问题3】
(a)balance=:x WHERE flight=’A’
(b)EXEC SQL COMMIT WORK
包含此试题的试卷
你可能感兴趣的试题
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
- 查看答案