版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、Chapter 15: Transactions Chapter 15: TransactionsTransaction ConceptTransaction StateConcurrent ExecutionsSerializabilityRecoverabilityImplementation of IsolationTransaction Definition in SQLTesting for Serializability.Transaction ConceptA transaction is a unit of program execution that accesses and
2、 possibly updates various data items. During transaction execution the database may be temporarily inconsistent.When the transaction completes successfully (is committed), the database must be consistent.After a transaction commits, the changes it has made to the database persist持久, even if there ar
3、e system failures. Multiple transactions can execute in parallel.Two main issues to deal with:Failures of various kinds, such as hardware failures and system crashesConcurrent execution of multiple transactionsACID PropertiesAtomicity原子性. Either all operations of the transaction are properly reflect
4、ed in the database or none are.Consistency一致性. Execution of a transaction in isolation preserves the consistency of the database.Isolation 隔離性. Although multiple transactions may execute concurrently, each transaction must be unaware of other concurrently executing transactions. Intermediate transac
5、tion results must be hidden from other concurrently executed transactions. That is, for every pair of transactions T1and T2, it appears to T1that either , or .Durability 持久性. After a transaction completes successfully, the changes it has made to the database persist, even if there are system failure
6、s. preserve the integrity of data the database system must ensure:Example of Fund TransferTransaction to transfer $50 from account A to account B:1.read(A)2.A := A 503.write(A)4.read(B)5.B := B + 506.write(B)Atomicity requirement if the transaction fails after step 3 and before step 6, the system sh
7、ould ensure that its updates are not 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 (Cont.)Isolation requirement if between steps 3 and 6, another transaction is allowe
8、d to access the partially updated database, 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 effi
9、ciency benefits, as we will see later.Durability 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.Transaction StateActive 激活 the initial state;
10、the transaction stays in this state while it is executingPartially 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 errorkill the transactionCommitted 提交 after successful completion.Transaction State (Cont.)Implementation of Atomicity and DurabilityThe recovery-management component of a
12、 database system implements the support for atomicity and durability.The shadow-database scheme:assume that only one transaction is active at a time.a pointer called db_pointer always points to the current copy of the database.Before execution, create a new copy. all updates are made on a this new c
13、opy. The original copy are called shadow copy. 影子副本 db_pointer is made to point to the updated new copy only after the transaction reaches partial commit and all updated pages have been flushed to disk. in case transaction fails, deletes the new copy.Implementation of Atomicity and Durability (Cont.
14、)Assumes disks do not failUseful for text editors, but extremely inefficient for large databases (why?)Does not handle concurrent transactions Will study better schemes in Chapter 17.The shadow-database scheme:Concurrent ExecutionsMultiple transactions are allowed to run concurrently in the system.
15、Advantages are:類(lèi)似os中的并發(fā)進(jìn)程increased processor and disk utilization, leading to better transaction throughput: one transaction can be using the CPU while another is reading from or writing to the diskreduced average response time for transactions: short transactions need not wait behind long ones.Conc
16、urrency control schemes mechanisms to achieve isolation; that is, to control the interaction among the concurrent transactions in order to prevent them from destroying the consistency of the databaseWill study in Chapter 16, after studying notion of correctness of concurrent executions.Schedules調(diào)度Sc
17、hedule a sequences of instructions that specify the chronological order 時(shí)間順序 in which instructions of concurrent transactions are executeda schedule for a set of transactions must consist of all instructions of those transactionsmust preserve the order in which the instructions appear in each indivi
18、dual transaction.A transaction that successfully completes its 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 i
19、t is obvious)Schedule 1 A+B is preservedLet T1 transfer $50 from A to B, and T2 transfer 10% of the balance from A to B. A serial schedule in which T1 is followed by T2:Schedule 2-A+B is preserved A serial schedule where T2 is followed by T1Schedule 3-A+B is preservedLet T1 and T2 be the transaction
20、s defined previously. The following schedule is not a serial schedule串行調(diào)度, but it is equivalent to Schedule 1.In Schedules 1, 2 and 3, the sum A + B is preserved.Schedule 4-A+B is not preservedThe following concurrent schedule does not preserve the value of (A + B).SerializabilityBasic Assumption Ea
21、ch transaction preserves database consistency.Thus serial execution of a set of transactions preserves database consistency.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:1.conflict serial
22、izability 重點(diǎn)2.view serializability 不要求We ignore operations other than read and write instructions, and we assume that transactions may perform arbitrary computations on data in local buffers in between reads and writes. Our simplified schedules consist of only read and write instructions.Conflicting
23、 Instructions Instructions li and lj of transactions T1and T2 respectively, conflict if and only if there exists some item Q accessed by both li and lj, and at least one of these instructions wrote Q. 1. li = read(Q), lj = read(Q). li and lj dont conflict. 2. li = read(Q), lj = write(Q). They confli
24、ct. 3. li = write(Q), lj = read(Q). They conflict 4. li = write(Q), lj = write(Q). They conflictIf 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.Conflict SerializabilityIf a schedule S can be t
25、ransformed into a schedule S2 by a series of swaps of non-conflicting instructions, we say that S and S2 are conflict equivalent.沖突等價(jià)We say that a schedule S is conflict serializable 沖突可串行化 if it is conflict equivalent to a serial scheduleConflict Serializability (Cont.)Schedule 3 can be transformed
26、 into Schedule 6, a serial schedule where T2 follows T1, by series of swaps of non-conflicting instructions. Therefore Schedule 3 is conflict serializable.Schedule 3Schedule 6Conflict Serializability (Cont.)Example of a schedule that is not conflict serializable:We are unable to swap instructions in
27、 the above schedule to obtain either the serial schedule , or the serial schedule .View Serializability 不作要求Let S and S be two schedules with the same set of transactions. S and S are view equivalent if the following three conditions are met:1.For each data item Q, if transaction T1reads the initial
28、 value of Q in schedule S, then transaction T1 must, in schedule S, also read the initial value of Q.2.For each data item Q if transaction T1executes read(Q) in schedule S, and that value was produced by transaction T2 (if any), then transaction T1must in schedule S also read the value of Q that was
29、 produced by transaction T2 .3.For each data item Q, the transaction (if any) that performs the final write(Q) operation in schedule S must perform the final write(Q) operation in schedule S.As can be seen, view equivalence is also based purely on reads and writes alone.View Serializability (Cont.)A
30、 schedule S is view serializable it is view equivalent to a serial schedule.Every conflict serializable schedule is also view serializable.Below is a schedule which is view-serializable but not conflict serializable.What serial schedule is above equivalent to?Every view serializable schedule that is
31、 not conflict serializable has blind writes.Other Notions of Serializability不作要求The schedule below produces same outcome as the serial schedule , yet is not conflict equivalent or view equivalent to it.Determining such equivalence requires analysis of operations other than read and write.Testing for
32、 SerializabilityConsider some schedule of a set of transactions T1, T2, ., TnPrecedence graph 優(yōu)先順序圖 a direct graph where the vertices are the transactions (names).We draw an arc T1T2 , if one of three conditions holds: 1. T1executes write(Q) before T2 executes read(Q). 2. T1executes read(Q) before T
33、2 executes write(Q). 3. T1executes write(Q) before T2 executes write(Q).Example Schedule (Schedule A) + Precedence GraphT1 T2 T3 T4 T5read(X)read(Y)read(Z)read(V)read(W)read(W)read(Y)write(Y)write(Z)read(U)read(Y)write(Y)read(Z)write(Z)read(U)write(U)T3T4T1T2Test for Conflict SerializabilityA schedu
34、le is conflict serializable if and only if its precedence graph is acyclic.Cycle-detection algorithms exist which take order n2 time, where n is the number of vertices in the graph. (Better algorithms take order n + e where e is the number of edges.)If precedence graph is acyclic, the serializabilit
35、y order can be obtained by a topological sorting of the graph. This is a linear order consistent with the partial order of the graph.For example, a serializability order for Schedule A would beT5 T1 T3 T2 T4Are there others?Test for View Serializability 不做要求The precedence graph test for conflict ser
36、ializability cannot be used directly to test for view serializability.Extension to test for view serializability has cost exponential in the size of the precedence graph.The problem of checking if a schedule is view serializable falls in the class of NP-complete problems. Thus existence of an effici
37、ent algorithm is extremely unlikely.However practical algorithms that just check some sufficient conditions for view serializability can still be used.Recoverable SchedulesRecoverable schedule if a transaction T2 reads a data item previously written by a transaction T1, then the commit operation of
38、T1 appears before the commit operation of T2. 寫(xiě)數(shù)據(jù)的事務(wù)先提交The following schedule (Schedule 11) is not recoverable if T9 commits immediately after the readIf T8 abort, T9 would have read (and possibly shown to the user) an inconsistent database state. Hence, database must ensure that schedules are recov
39、erable.Need to address the effect of transaction failures on concurrently running transactions.Cascading Rollbacks級(jí)聯(lián)回滾Cascading rollback a single transaction failure leads to a series of transaction rollbacks. Consider the following schedule where none of the transactions has yet committed (so the s
40、chedule is recoverable)If T10 fails, T11 and T12 must also be rolled back.Can lead to the undoing of a significant amount of workCascadeless Schedules無(wú)級(jí)聯(lián)調(diào)度Cascadeless schedules cascading rollbacks cannot occur; for each pair of transactions such that T2 reads a data item previously written by T1, th
41、e commit operation of T1 appears before the read operation of T2. 寫(xiě)數(shù)據(jù)的事務(wù)先提交Every cascadeless schedule is also recoverableIt is desirable to restrict the schedules to those that are cascadelessConcurrency ControlA database must provide a mechanism that will ensure that all possible schedules are eith
42、er conflict or view serializable, and are recoverable and preferably cascadelessA policy in which only one transaction can execute at a time generates serial schedules, but provides a poor degree of concurrencyAre serial schedules recoverable/cascadeless?Testing a schedule for serializability after
43、it has executed is a little too late!Goal to develop concurrency control protocols that will assure serializability.Concurrency Control vs. Serializability TestsConcurrency-control protocols allow concurrent schedules, but 同時(shí) ensure that the schedules are conflict/view serializable, and are recovera
44、ble and cascadeless.Concurrency control protocols generally do not examine the precedence graph as it is being createdInstead a protocol imposes a discipline that avoids nonseralizable schedules.We study such protocols in Chapter 16.Different concurrency control protocols provide different tradeoffs
45、 between the amount of concurrency they allow and the amount of overhead that they incur.Tests for serializability help us understand why a concurrency control protocol is correct. Weak Levels of ConsistencySome applications are willing to live with weak levels of consistency, allowing schedules tha
46、t are not serializableE.g. a read-only transaction that wants to get an approximate total balance of all accounts E.g. database statistics computed for query optimization can be approximate (why?)Such transactions need not be serializable with respect to other transactionsTradeoff accuracy for performanceLevels of Consistency in SQL-92Serializable defaultRepeatable read only committed records to be read, repeated reads of same record must return same value.
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年度主題餐飲店長(zhǎng)創(chuàng)意管理聘用協(xié)議3篇
- 2024版新媒體內(nèi)容創(chuàng)作與分發(fā)合同
- 2025年度醫(yī)療器械代工與品牌推廣管理協(xié)議4篇
- 2025年度新型瓷磚研發(fā)生產(chǎn)合作協(xié)議范本4篇
- 2024版箱式變壓器的采購(gòu)合同范本
- 2024版鋁合金辦公室隔斷門(mén)制作與安裝協(xié)議
- 中國(guó)片壯晶石項(xiàng)目投資可行性研究報(bào)告
- 2025年版?zhèn)€人房產(chǎn)出售交易資金監(jiān)管及風(fēng)險(xiǎn)控制合同2篇
- 2025年度個(gè)人房產(chǎn)買(mǎi)賣(mài)合同(含物業(yè)費(fèi))4篇
- 2025年度個(gè)人消費(fèi)貸款合同補(bǔ)充協(xié)議(綠色金融)4篇
- 品牌策劃與推廣-項(xiàng)目5-品牌推廣課件
- 信息學(xué)奧賽-計(jì)算機(jī)基礎(chǔ)知識(shí)(完整版)資料
- 發(fā)煙硫酸(CAS:8014-95-7)理化性質(zhì)及危險(xiǎn)特性表
- 數(shù)字信號(hào)處理(課件)
- 公路自然災(zāi)害防治對(duì)策課件
- 信息簡(jiǎn)報(bào)通用模板
- 社會(huì)組織管理概論全套ppt課件(完整版)
- 火災(zāi)報(bào)警應(yīng)急處置程序流程圖
- 耳鳴中醫(yī)臨床路徑
- 安徽身份證號(hào)碼前6位
- 分子生物學(xué)在動(dòng)物遺傳育種方面的應(yīng)用
評(píng)論
0/150
提交評(píng)論