0
Transaction
 
Transaction definition <ul><li>Supports daily operations of an organization </li></ul><ul><li>Collection of database opera...
Airline Transaction Example <ul><li>START TRANSACTION </li></ul><ul><li>Display greeting </li></ul><ul><li>Get reservation...
ATM transaction example <ul><li>START TRANSACTION </li></ul><ul><li>Display greeting </li></ul><ul><li>Get account number,...
 
Transaction Properties <ul><li>Atomic: all or nothing </li></ul><ul><li>Consistent: database must be consistent before and...
 
 
 
 
 
Serializable schedule <ul><li>A serializable schedule is a linear  arrangement of the database calls from several transact...
Serializability thru lock <ul><li>A lock is an access privilege on a database object, which the DBMS grant to a particular...
 
 
Transaction Management with SQL <ul><li>Transaction support is provided by two SQL statements: COMMIT and ROLLBACK. </li><...
 
 
 
 
 
Serializability Testing and Precedence Graphs/Dependency Graph <ul><li>So we need a simple method to test a schedule S and...
<ul><li>Compute a precedence graph for schedule B (right) </li></ul><ul><li>three vertices (T1, T2, T3) </li></ul><ul><li>...
 
Examples of Conflicts <ul><li>A  conflict  exists when two transactions access the same item, and at least one of the acce...
Serializable schedule <ul><li>A  schedule  is a partial ordering of operations for a set of transactions  {T,S,...},  such...
Legal Interleaved schedule <ul><li>1. avoid  lost update  problem </li></ul><ul><ul><ul><li>T : transfer $100 from  A  to ...
Defining legal schedule <ul><li>. To be serializable, the conflicting operations of  T  and  S  must be ordered as if eith...
Upcoming SlideShare
Loading in...5
×

Transaction unit1 topic 2

468

Published on

Published in: Technology, Real Estate
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
468
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
20
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Transaction unit1 topic 2"

  1. 1. Transaction
  2. 3. Transaction definition <ul><li>Supports daily operations of an organization </li></ul><ul><li>Collection of database operations </li></ul><ul><li>Reliably and efficiently processed as one unit of work </li></ul><ul><li>No lost data </li></ul><ul><ul><li>Interference among multiple users </li></ul></ul><ul><ul><li>Failures </li></ul></ul>
  3. 4. Airline Transaction Example <ul><li>START TRANSACTION </li></ul><ul><li>Display greeting </li></ul><ul><li>Get reservation preferences from user </li></ul><ul><li>SELECT departure and return flight records </li></ul><ul><li>If reservation is acceptable then </li></ul><ul><li>UPDATE seats remaining of departure flight record </li></ul><ul><li>UPDATE seats remaining of return flight record </li></ul><ul><li>INSERT reservation record </li></ul><ul><li>Print ticket if requested </li></ul><ul><li>End If </li></ul><ul><li>On Error: ROLLBACK </li></ul><ul><li>COMMIT </li></ul>
  4. 5. ATM transaction example <ul><li>START TRANSACTION </li></ul><ul><li>Display greeting </li></ul><ul><li>Get account number, pin, type, and amount </li></ul><ul><li>SELECT account number, type, and balance </li></ul><ul><li>If balance is sufficient then </li></ul><ul><li>UPDATE account by posting debit </li></ul><ul><li>INSERT history record </li></ul><ul><li>Display message and dispense cash </li></ul><ul><li>Print receipt if requested </li></ul><ul><li>End If </li></ul><ul><li>On Error: ROLLBACK </li></ul><ul><li>COMMIT </li></ul>
  5. 7. Transaction Properties <ul><li>Atomic: all or nothing </li></ul><ul><li>Consistent: database must be consistent before and after a transaction </li></ul><ul><li>Isolated: no unwanted interference from other users </li></ul><ul><li>Durable: database changes are permanent after the transaction completes </li></ul>
  6. 13. Serializable schedule <ul><li>A serializable schedule is a linear arrangement of the database calls from several transactions with the property: the final database state obtained by executing the calls in schedule order is the same as that obtained by running the transactions in some unspecified serial order . </li></ul>
  7. 14. Serializability thru lock <ul><li>A lock is an access privilege on a database object, which the DBMS grant to a particular transaction </li></ul><ul><li>Exclusive locks prevent any current access. A shared lock lets you read an object, but you need an exclusive lock to update it. </li></ul>
  8. 17. Transaction Management with SQL <ul><li>Transaction support is provided by two SQL statements: COMMIT and ROLLBACK. </li></ul><ul><li>A COMMIT statement is reached, in which case all changes are permanently recorded within the database. The COMMIT statement automatically ends the SQL transaction. </li></ul><ul><li>A ROLLBACK statement is reached in which case all changes are aborted and the database is rolled back to its previous consistent state. </li></ul>
  9. 23. Serializability Testing and Precedence Graphs/Dependency Graph <ul><li>So we need a simple method to test a schedule S and discover whether it is serializable. </li></ul><ul><li>Simple method involves constructing a directed graph called a Precedence Graph from S </li></ul><ul><li>Construct a precedence graph as follows: </li></ul><ul><ul><li>a vertex labelled Ti for every transaction in S </li></ul></ul><ul><ul><li>an edge from Ti to Tj if any of these three conditions holds: </li></ul></ul><ul><ul><ul><li>Ti executes write(Q) before Tj executes read(Q) </li></ul></ul></ul><ul><ul><ul><li>Ti executes read(Q) before Tj executes write(Q) </li></ul></ul></ul><ul><ul><ul><li>Ti executes write(Q) before Tj executes write(Q) </li></ul></ul></ul><ul><ul><li>if the graph has a cycle, S is not serializable </li></ul></ul>
  10. 24. <ul><li>Compute a precedence graph for schedule B (right) </li></ul><ul><li>three vertices (T1, T2, T3) </li></ul><ul><li>edge from Ti to Tj if </li></ul><ul><ul><li>Ti writes Q before Tj reads Q </li></ul></ul><ul><ul><li>Ti reads Q before Tj writes Q (T1-T2) </li></ul></ul><ul><ul><li>Ti writes Q before Tj writes Q </li></ul></ul>
  11. 26. Examples of Conflicts <ul><li>A conflict exists when two transactions access the same item, and at least one of the accesses is a write. </li></ul><ul><li>1. lost update problem </li></ul><ul><ul><ul><li>T : transfer $100 from A to C: R(A) W(A) R(C) W(C) </li></ul></ul></ul><ul><ul><ul><li>S: transfer $100 from B to C: R(B) W(B) R(C) W(C) </li></ul></ul></ul><ul><li>2. inconsistent retrievals problem ( dirty reads violate consistency) </li></ul><ul><ul><ul><li>T : transfer $100 from A to C: R(A) W(A) R(C) W(C) </li></ul></ul></ul><ul><ul><ul><li>S : compute total balance for A and C : R(A) R(C) </li></ul></ul></ul><ul><li>3. nonrepeatable reads </li></ul><ul><ul><ul><li>T : transfer $100 from A to C: R(A) W(A) R(C) W(C) </li></ul></ul></ul><ul><ul><ul><li>S : check balance and withdraw $100 from A : R(A) R(A) W(A) </li></ul></ul></ul>
  12. 27. Serializable schedule <ul><li>A schedule is a partial ordering of operations for a set of transactions {T,S,...}, such that: </li></ul><ul><ul><li>The operations of each action execute serially. </li></ul></ul><ul><ul><li>The schedule specifies an order for conflicting operations. </li></ul></ul><ul><ul><ul><li>Any two schedules for {T,S,...} that order the conflicting operations in the same way are equivalent . </li></ul></ul></ul><ul><li>A schedule for {T,S,...} is serializable if it is equivalent to some serial schedule on {T,S,...} . </li></ul><ul><ul><ul><li>There may be other serializable schedules on {T,S,...} that do not meet this condition, but if we enforce this condition we are safe. </li></ul></ul></ul><ul><ul><ul><li>Conflict serializability : detect conflicting operations and enforce a serial- equivalent order. </li></ul></ul></ul>
  13. 28. Legal Interleaved schedule <ul><li>1. avoid lost update problem </li></ul><ul><ul><ul><li>T : transfer $100 from A to C: R(A) W(A) R(C) W(C) </li></ul></ul></ul><ul><ul><ul><li>S: transfer $100 from B to C: R(B) W(B) R(C) W(C) </li></ul></ul></ul><ul><li>2. avoid inconsistent retrievals problem </li></ul><ul><ul><ul><li>T : transfer $100 from A to C: R(A) W(A) R(C) W(C) </li></ul></ul></ul><ul><ul><ul><li>S : compute total balance for A and C : R(A) R(C) </li></ul></ul></ul><ul><li>3. avoid non-repeatable reads </li></ul><ul><li>T : transfer $100 from A to C R(A) W(A) R(C) W(C) </li></ul><ul><li>S : check balance and withdraw $100 from A : R(A) R(A) W(A) </li></ul>
  14. 29. Defining legal schedule <ul><li>. To be serializable, the conflicting operations of T and S must be ordered as if either T or S had executed first. </li></ul><ul><ul><ul><li>We only care about the conflicting operations: everything else will take care of itself. </li></ul></ul></ul><ul><li>2. Suppose T and S conflict over some shared item(s) x . </li></ul><ul><li>3. In a serial schedule, T ’s operations on x would appear before S ’s, or vice versa....for every shared item x . </li></ul><ul><ul><ul><li>As it turns out, this is true for all the operations, but again, we only care about the conflicting ones. </li></ul></ul></ul><ul><li>4. A legal (conflict-serializable) interleaved schedule of T and S must exhibit the same property. </li></ul><ul><ul><ul><li>Either T or S “wins” in the race to x ; serializability dictates that the “winner take all”. </li></ul></ul></ul>
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×