下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、第14讲:(第12章) 事务管理技术 重庆大学计算机学院,课程名称: 数据库系统 -,A transaction is a unit of program execution that accesses and possibly updates various data items. A transaction must see a consistent database. During transaction execution the database may be temporarily inconsistent. When the transaction completes succe
2、ssfully (is committed), the database must be consistent. After a transaction commits, the changes it has made to the database persist, even if there are system failures. Multiple transactions can execute in parallel. Two main issues to deal with: Failures of various kinds,such as hardware failures a
3、nd system crashes Concurrent execution of multiple transactions,Transaction Concept,原子性Atomicity. Either all operations of the transaction are properly reflected in the database or none are. 一致性Consistency. Execution of a transaction in isolation preserves the consistency of the database. 隔离性Isolati
4、on. Although multiple transactions may execute concurrently, each transaction must be unaware of other concurrently executing transactions. (Intermediate transaction results must be hidden from other concurrently executed transactions) That is, for every pair of transactions Ti and Tj , it appears t
5、o Ti that either Tj finished execution before Ti started, or Tj started execution after Ti finished.(即每个事务都感觉不到其它事务在并行执行) 持久性Durability. After a transaction completes successfully, the changes it has made to the database persist, even if there are system failures.,ACID Properties,To preserve the int
6、egrity of data the database system must ensure:,Transaction to transfer $50 from account A to account B: 1.read(A) 2.A := A 50 3.write(A) 4.read(B) 5.B := B + 50 6.write(B) Atomicity requirement if the transaction fails after step 3 and before step 6, the system should ensure that its updates are no
7、t reflected in the database, else an inconsistency will result. Consistency requirement the sum of A and B is unchanged by the execution of the transaction.,Example of Fund Transfer资金转账,Isolation requirement if between steps 3 and 6, another transaction is allowed to access the partially updated dat
8、abase, it will see an inconsistent database (the sum A + B will be less than it should be). Isolation can be ensured trivially by running transactions serially, that is one after the other. However, executing multiple transactions concurrently has significant benefits, as we will see later. Durabili
9、ty requirement once the user has been notified that the transaction has completed (i.e., the transfer of the $50 has taken place), the updates to the database by the transaction must persist despite failures (after step 3 and before step 6).,Example of Fund Transfer资金转账(续),Active the initial state;
10、the transaction stays in this state while it is executing Partially committed after the final statement has been executed. Failed - after the discovery that normal execution can no longer proceed. Aborted after the transaction has been rolled back and the database restored to its state prior to the
11、start of the transaction. Two options after it has been aborted: restart the transaction; can be done only if no internal logical error kill the transaction Committed after successful completion.,Transaction State,Transaction State,Schedule a sequences of instructions that specify the chronological按
12、时间顺序排列的 order in which instructions of concurrent transactions are executed a schedule for a set of transactions must consist of all instructions of those transactions must preserve the order in which the instructions appear in each individual transaction. A transaction that successfully completes i
13、ts execution will have a commit instructions as the last statement (will be omitted if it is obvious) A transaction that fails to successfully complete its execution will have an abort instructions as the last statement (will be omitted if it is obvious),Schedules,Let T1 transfer $50 from A to B, an
14、d T2 transfer 10% of the balance from A to B. A serial schedule in which T1 is followed by T2:,Schedule 1,Schedule 2,A serial schedule where T2 is followed by T1,Let T1 and T2 be the transactions defined previously. The following schedule is not a serial schedule, but it is equivalent to Schedule 1.
15、,Schedule 3,In Schedules 1, 2 and 3, the sum A + B is preserved. 合理转账,The following concurrent schedule does not preserve the value of (A + B). 不合理转账,Schedule 4,Basic Assumption Each transaction preserves database consistency. Thus serial execution of a set of transactions preserves database consist
16、ency. A (possibly concurrent) schedule is serializable if it is equivalent to a serial schedule. Different forms of schedule equivalence give rise to the notions of: conflict serializability冲突可串行化 view serializability视图可串行化 We ignore operations other than read and write instructions, and we assume t
17、hat transactions may perform arbitrary computations on data in local buffers in between reads and writes. And so our simplified schedules consist of only read and write instructions.,Serializability,冲突指令:Instructions li and lj of transactions Ti and Tj respectively conflict if and only if there exis
18、ts some item Q accessed by both li and lj, and at least one of the two instructions wrote Q. 1. li = read(Q), lj = read(Q). li and lj dont conflict. 2. li = read(Q), lj = write(Q). They conflict. 3. li = write(Q), lj = read(Q). They conflict 4. li = write(Q), lj = write(Q). They conflict Intuitively
19、, a conflict between li and lj forces a (logical) temporal order between them. If li and lj are consecutive in a schedule and they do not conflict, their results would remain the same even if they had been interchanged in the schedule.,Conflicting Instructions for each pair of transactions Ti and Tj
20、 , such that Tj reads a data item previously written by Ti , the commit operation of Ti appears before the read operation of Tj . (若Tj读了由Ti所写的数据,则Ti先于Tj提交) 显然:Every cascadeless schedule is also recoverable It is desirable to restrict the schedules to those that are cascadeless,Cascadeless Schedules
21、-无级联调度,可串行化:保证可串行化调度 可重复读:只允许读取已提交数据,且在一个事务两次读取一个数据项期间,其他事务不得更新该数据。 已提交读:只允许读取已提交数据,但不要求可重复读。 未提交读:允许读取未提交数据。,事务隔离性级别,A database must provide a mechanism that will ensure that all possible schedules are either conflict or view serializable, and are recoverable and preferably cascadeless A policy in
22、which only one transaction can execute at a time generates serial schedules, but provides a poor degree of concurrency Are serial schedules recoverable/cascadeless? 问题如何解决? 提高事务并发执行度! Testing a schedule for serializability after it has executed is a little too late! Goal to develop concurrency control protocols that will assure serializability.,Concurrency Control,Concurrency-control protocols allow concurrent schedul
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 家政服务员岗前水平评估考核试卷含答案
- 2026年长白山职业技术学院高职单招笔试数学历年参考题库含答案解析
- 2026年重庆文化艺术职业学院高职单招笔试语文历年参考题库含答案解析
- 2026年重庆安全技术职业学院高职单招笔试职业适应性测验历年参考题库含答案解析
- 健身器材制作工规划强化考核试卷含答案
- 2021年护理文件书写
- 急性中耳炎的护理宣教
- 临床护理风险分析
- 量子计算赋能保险业的可行性分析报告
- 健康宣教中心推广-标准模板
- 松下-GF2-相机说明书
- 专题18 传送带模型(学生版)新高一物理多维度导学与分层专练
- 布比卡因脂质体注射液-临床用药解读
- 统计学基础与应用课件
- 传感器的应用与调试高职全套教学课件
- 2023上尿路结石患者围手术期感染控制及抗菌药物应用专家意见(完整版)
- 【影片中的非线性叙事结构的实例研究(论文)】
- 口腔组织病理学口腔颌面部发育练习题
- 为孩子培养良好的习惯【一年级家长会】讲座用课件
- 2023学年完整公开课版孔子论孝
- JJG 452-2021黑白密度片
评论
0/150
提交评论