1 / 25

Chapter 7 Transactions

Chapter 7 Transactions. 7.1 Transaction Concept 7.2 Transaction State 7.3 Implementation of Atomicity and Durability 7.4 Concurrent Executions 7.5 Serializability 7.6 Recoverability 7.7 Testing for Serializability. 7.1 Transaction Concept.

fionn
Télécharger la présentation

Chapter 7 Transactions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 7 Transactions • 7.1 Transaction Concept • 7.2 Transaction State • 7.3 Implementation of Atomicity and Durability • 7.4 Concurrent Executions • 7.5 Serializability • 7.6 Recoverability • 7.7 Testing for Serializability

  2. 7.1 Transaction Concept • A transaction is a unit of program execution that accesses and possibly updates various data items. • Properties of the transactions: Atomicity Consistency Isolation Durability

  3. 7.1 Transaction Concept It can be verified easily that, if the database is consistent before an execution of the transaction, the database remains consistent after the execution of the transaction. Consistency.Execution of a transaction in isolation(that is, with no other transaction executing concurrently) preserves the consistency of the database.

  4. Ti: Read (A); $1000 A:=A-$50; Write (A); $950 inconsistent state Read (B); $2000 B:=B+$50; Write (B); $2050 7.1 Transaction Concept Atomicity. Either all operations of the transaction are reflected properly in the database, or none are.Transaction-management component A=$100 B=$2000 A+B= $2000 A=$950 B=$2000 A+B= $2950 X

  5. 7.1 Transaction Concept Durability. After a transaction completes successfully, the changes it has made to the database persist, even if there are system failures. Recovery-management component. we can guarantee durability by ensuring that either: ①The updates carried out by the transaction have been written to disk before the transaction completes. ②Information about the updates carried out by the transaction and written to disk is sufficient to enable the database to reconstruct the updates when the database system is restarted after the failure.

  6. 7.1 Transaction Concept Isolation.Even though multiple transactions may execute concurrently, the system guarantees that, for every pair of transactions Ti and Tj, it appears to Ti that either Tj finished execution before Ti started, of Tj started execution after Ti finished. Thus, each transaction is unaware of other transactions executing concurrently in the system. Concurrency-control component.

  7. 7.1 Transaction Concept Lost Update: Transaction Ti Transaction Tj Read (A); $1000 A:=A-$50; Write (A); $950 Read (A); $1000 A:=A-$50; Write (A); $950 ? <> $900

  8. Transaction Ti Transaction Tj Read (A); $1000 Read (B); $2000 C:=A+B; $3000 Read (B); $2000 B:=B*2; Write (B); $4000 Read (A); $1000 Read (B); $4000 C:=A+B; $5000 7.1 Transaction Concept Not-Repeatable Read: ?

  9. Transaction Ti Transaction Tj Read (C); $2000 C:=C*2; Write (C); $4000 Read (C); $4000 ROLLBACK; C:=$2000 7.1 Transaction Concept Dirty Read: ?

  10. 7.2 Transaction State • Aborted:a transaction that not complete its execution successfully. • Rolled back:the changes caused by an aborted transaction have been undone. • Compensation transaction:the only way to undo the effects of a committed transaction is to execute a compensation transaction. Ti: add &20 to an account compensation Tj: subtract $20 from the account.

  11. 7.2 Transaction State after successful completion after final statement has been executed Partially committed committed active hardware failure or logical errors after transaction roll back & the db restore write out information to disk aborted failed the initial state after the discovery that normal execution can no longer proceed system has two options:restart or kill

  12. 7.3 implementation of Atomicity and Durability • Shadow copy scheme: ① only one transaction is active at a time. ② the database is simply a file on disk. A pointer called db-pointer is maintained on disk; it points to the current copy of the database. db-pointer db-pointer ③ ② new copy of database old copy of database (to be deleted) old copy of database ① Before update After update

  13. 1000 1000 950 2000 900 2000 2050 950 2100 900 855 850 2050 2100 2145 2150 7.4 Concurrent Executions T2 read(A) temp:=A*0.1 A:=A-temp write(A) read(B) B:=B+temp write(B) T2 read(A) temp:=A*0.1 A:=A-temp write(A) read(B) B:=B+temp write(B) T1 read(A) A:=A-50 write(A) read(B) B:=B+50 write(B) T1 read(A) A:=A-50 write(A) read(B) B:=B+50 write(B)

  14. 1000 1000 950 1000 950 950 900 855 2000 2000 950 2000 2050 2050 2050 2145 2100 7.4 Concurrent Executions T2 read(A) temp:=A*0.1 A:=A-temp write(A) read(B) B:=B+temp write(B) T2 read(A) temp:=A*0.1 A:=A-temp write(A) read(B) B:=B+temp write(B) T1 read(A) A:=A-50 write(A) read(B) B:=B+50 write(B) A+B=3000 T1 read(A) A:=A-50 write(A) read(B) B:=B+50 write(B) ? A+B=3050

  15. 7.5 Serializability 7.5.1 Conflict Serializability a schedule S has two consecutive instructions Ii and Ij, of transactions Ti and Tj, respectively(i<>j).if Ii and Ij refer to different data items, then we can swap Ii and Ij without affecting the results of any instruction in the schedule. However, if Ii and Ij refer to the same data item Q, then the order of the two steps may matter. There are four cases that we need to consider:

  16. 7.5 Serializability 1.Ii=read(Q), Ij=read(Q). The order of Ii and Ij does not matter, since the same value of Q is read by Ti and Tj, regardless of the order. 2.Ii=read(Q), Ij=write(Q). If Ii comes before Ij, then Ti does not read the value of Q that is written by Tj in instruction Ij. If Ij comes before Ii, then Ti reads the value of Q that is written by Tj. Thus, the order of Ii and Ij matters. 1.Ii=write(Q), Ij=read(Q). The order of Ii and Ij matters for reasons similar to those of the previous case. 3.Ii=write(Q), Ij=write(Q). Since both instructions are write operations, the order of these instructions does not affect either Ti or Tj. However, the values obtained by the next read(Q) instruction of S is affected, since the result of only the latter of the two write instructions is preserved in the database.

  17. 7.5 Serializability • We say that Ii and Ij conflict if they are operations by different transactions on the same data item, and at least one of these instructions is a write operation. T2 read(A) write(A) read(B) write(B) T1 read(A) write(A) read(B) write(B) T2 read(A) write(A) read(B) write(B) T1 read(A) write(A) read(B) write(B)

  18. T4 write(Q) T3 read(Q) write(Q) schedule7 7.5 Serializability • Conflict equivalent: if a schedule S can be transformed into a schedule S’ by a series of swaps of non-conflicting instructions, we say that S and S’ are conflict equivalent. • Conflict serializable: if a schedule S is conflict equivalent to the serial schedule. not conflict serializable

  19. 1000 950 2000 1990 1990 conflicts 2040 950 960 7.5 Serializability Example: T5 read(B) B:=B-10 write(B) read(A) A:=A+10 write(A) T1 read(A) A:=A-50 write(A) read(B) B:=B+50 write(B) A+B=3000 There are less stringent definitions of schedule equivalence than conflict equivalence. A+B=3000

  20. 7.5.2 View Serializability The schedules S and S’ are said to be view equivalent if three conditions are met: 1. For each data item Q, if transaction Ti reads the initial values of Q in schedule S, then transaction Ti must, inschedule S’, also read the initial value of Q. 2. For each data item Q, if transaction Ti executes read(Q) in schedule S, and if that value was produced by a write(Q) operation of transaction Tj, then the read(Q) operation of transaction Ti must, in schedule S’, also read the value of Q that was produced by the same write(Q) operation of transaction Tj. 3. For each data item Q, the transaction that performs the final write(Q) operation in schedule S must perform the final write(Q) operation in schedule S’.

  21. T4 write(Q) T3 read(Q) write(Q) T6 write(Q) Schedule 9 7.5 Serializability • View serializable: if a schedule S is view equivalent to a serial schedule. equvalent to the serial schedule <T3,T4,T6> view serializable blind write

  22. T9 read(A) T8 read(A) A:=A+1 write(A) read(B) 5 6 6 7.6 Recoverability Recoverable schedule: for each pair of transactions Ti and Tj such that Tj reads a data item previously written by Ti, the commit operation of Ti appears before the commit operation of Tj Ti →T8 Tj →T9 commit immediately T8 fails before it commits T8 rollback:A(5)

  23. 7.6 Recoverability T12 read(A) T11 read(A) write(A) T10 read(A) read(B) write(A) Cascadeless schedule: for each pair of transactions Ti and Tj such that Tj reads a data item previously written by Ti, the commit operation of Ti appears before the read operation of Tj Cascading rollback T10 fails rollback T11 is dependent on T10, rollback T12 is dependent on T11, rollback

  24. 7.7 Testing for Serializability Precedence graph G=(V,E) V: a set of vertices consists of all the transactions participating in the schedule. E: a set of edges consists of all edges Ti→Tj for which one of three conditions holds: 1.Ti executes write(Q) before Tj executes read(Q). 2.Ti executes read(Q) before Tj executes write(Q). 3.Ti executes write(Q) before Tj executes write(Q).

  25. T1→ T2 T2→ T1 7.7 Testing for Serializability T2 read(A) temp:=A*0.1 A:=A-temp write(A) read(B) B:=B+temp write(B) T1 read(A) A:=A-50 write(A) read(B) B:=B+50 write(B) T2 read(A) temp:=A*0.1 A:=A-temp write(A) read(B) B:=B+temp write(B) T1 read(A) A:=A-50 write(A) read(B) B:=B+50 write(B) not contain cycles conflict serializable contain cycles not conflict serializable T1 T1 T2 T2

More Related