1 / 36

Transaction Processing Concepts

Transaction Processing Concepts. 1. Introduction To transaction Processing. 1.1 Single User VS Multi User Systems One criteria to classify Database is according to number of user that concurrently connect to the system. Single User: only one user use the system in each time

efrem
Download Presentation

Transaction Processing Concepts

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. Transaction Processing Concepts

  2. 1. Introduction To transaction Processing • 1.1 Single User VS Multi User Systems • One criteria to classify Database is according to number of user that concurrently connect to the system. • Single User: only one user use the system in each time • Multi User: many users use the system in the same time

  3. What is a Transaction? • A transactionis 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 inconsistent. • When the transaction is committed, the database must be consistent.

  4. Transaction is an executing program that forms a logical unit of database processing. • A transaction include one or more database access operations. • The database operation can be embedded within an application or can be specified by high level query language. • Specified boundary by Begin and End transaction statements • If the database operations in a transaction do not update the database, it is called “Read-only transaction”

  5. Example of transaction • Let Ti be a transaction that transfer money from account A (5000) to account B. The transaction can be defined as • Ti: read (A) (withdraw from A) A := A – 5000 write (A); (update A) read (B) (deposit B) B := B + 5000 write (B) (update B)

  6. Example Of Transfer • Transaction to transfer 5000 from Checking account A to Saving account B: 1. read(A) 2. A := A – 5000 3. write(A) 4. read(B) 5. B := B + 5000 6. write(B) • Consistency requirement – the sum of A and B is unchanged by the execution of the transaction. • Atomicity requirement — if the transaction fails after step 3 and before step 6, the system should ensure that its updates are not reflected in the database, else an inconsistency will result.

  7. Transfer Example (Cont.) • Durability requirement — once the user has been notified that the transaction has completed (i.e., the transfer of the 5000 has taken place), the updates to the database by the transaction must persist despite failures. • Isolation requirement — if between steps 3 and 6, another transaction is allowed to access the partially updated database, it will see an inconsistent database.

  8. Desirable properties of transaction : ACID properties • To ensure integrity of data, we require that the database system maintain the following properties of the transactions: • Atomicity. • Consistency preservation. • Isolation. • Durability or permanency.

  9. ACID • Atomicity. Either all operations of the transaction are reflected properly in the database, or none are. • Consistency. Execution of a transaction in isolations (that is, with no other transaction executing concurrently) • 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, • or Tj started execution after Ti finished. • Thus, each transaction is unaware of other transactions executing concurrently in the system. (Execution of transaction should not be interfered with by any other transactions executing concurrently) • Durability. After a transaction completes successfully, the changes it has made to the database persist, even if there are system failures. (The changes must not be lost because of any failure)

  10. Consistency • Consistency. • The consistency requirement here is that the sum of A and B be unchanged by the execution of the transaction. • Without consistency requirement, money could be created or destroyed by the transaction. • It can be verified, • If the database is consistency before an execution of the transaction, the database remains consistent after the execution of the transaction.

  11. Atomicity • Atomicity. Either all operations of the transaction are reflected properly in the database, or none are. • State before the execution of transaction Ti • The value of A = 50,000 • The value of B = 100 • Failure occur (ex. Hardware failure) • Failure happen after the WRITE(A) operation • (at this moment A = 50000 – 5000 = 45000) • And the value of B = 100 (inconsistency state) • In consistency state A = 45000 and B = (5100)

  12. (cont.) • Idea behind ensuring atomicity is following: • The database system keeps track of the old values of any data on which a transaction performs a write • If the transaction does not complete, the DBMS restores the old values to make it appear as though the transaction have never execute.

  13. Durability or permanency • Durability or permanency. After a transaction completes successfully, the changes it has made to the database persist, even if there are system failures. • These changes must not be lost because of any failure • ensures that, transaction has been committed, that transaction’s updates do not get lost, even if there is a system failure

  14. Isolation • 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, • or Tj started execution after Ti finished. • Thus, each transaction is unaware of other transactions executing concurrently in the system. • ( Execution of transaction should not be interfered with by any other transactions executing concurrently )

  15. State of transaction • Active, the initial state; 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 backed and the database has been restored to its state prior to the start of transaction. • Committed, after successful completion

  16. Partially Committed committed Read Write Commit Begin Transaction Active Abort Abort Failed Aborted (Terminate) State diagram of a transition A transaction must be in one of these states.

  17. The transaction has committed only if it has entered the committed state. • The transaction has aborted only if it has entered the aborted state. • The transaction is said to have terminated if has either committed or aborted.

  18. Concurrency Control

  19. Concurrent Executions • Transaction processing permit • Multiple transactions to run concurrently. • Multiple transactions to update data concurrently • Cause • Complications with consistency of data

  20. Reason for allowing concurrency • Improved throughputof transactions and system resource utilization • Reduced waiting time of transactions

  21. Concurrent Executions • Multiple transactions are allowed to run concurrently in the system. Advantages are: • 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 disk • reduced waiting time for transactions: short transactions need not wait behind long ones.

  22. Possible Problems • Lost update problem • Temporary update problem • Incorrect summary problem

  23. T1 T2 Read_item(A) A := A – 50 Read_item(A) temp := 0.1*A A:= A-temp Write_item(A) Read_item(B) Write_item(A) Read_item(B) B := B + 50 Write_item(B) B := B + temp Write_item(B) A = 1000, B =2000 Lost update problem A = 1000 A = 950 A = 950 temp = 95 A=950-95 = 855 A = 950 B = 2000 A = 855 B = 2000 B = 2050 B = 2050 B = 2095 B = 2095

  24. T1 T2 - Write_item(R) Read_item(R) - - RollBack Temporary update problem R = 3000 R = 1000 R = 1000 R = 3000

  25. T1 T2 Read_item(A) SUM = Sum+A Read_item(B) SUM = A + B Read_item(C) C = C - 10 Write_item(C) Read_item(A) A = A + 10 Write_item(A) COMMIT Read_item(C) SUM = SUM + C Inconsistency problem A = 40 , B = 50, C = 30 A = 40 A+B+C = 40+50+30 = 120 Sum = 40 B = 50 SUM = 40+50 = 90 C = 30 C = 30-10 =20 C = 20 A = 40 After A+B+C = 50+50+20 = 120 A = 40+10 =50 A = 50 C = 20 Sum = 90 + 20 = 110

  26. Schedules • Schedules – sequences that indicate the chronological 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.

  27. Example Schedules • Let T1 transfer $50 from A to B, and T2 transfer 10% of the balance from A to B. The following is a serial schedule (Schedule 1 in the text), in which T1 is followed by T2.

  28. Cont. • Let T1 and T2 be the transactions defined previously. The following schedule is not a serial schedule, but it is equivalent to Schedule 1.

  29. Cont. • The following concurrent schedule does not preserve the value of the the sum A + B.

  30. Serializability • Basic Assumption – Each 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 serializability 2. view serializability

  31. Conflict Serializability • Instructions li and lj of transactions Ti and Tj 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 ljdon’t conflict.2. li = read(Q), lj = write(Q). They conflict.3. li = write(Q), lj = read(Q). They conflict4. li = write(Q), lj = write(Q). They conflict

  32. Conflict Serializability (Cont.) • 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. • We say that a schedule S is conflict serializable if it is conflict equivalent to a serial schedule • Example of a schedule that is not conflict serializable: T3T4read(Q)write(Q)write(Q)We are unable to swap instructions in the above schedule to obtain either the serial schedule < T3, T4 >, or the serial schedule < T4, T3 >.

  33. Conflict Serializability (Cont.) • Schedule 3 below can be transformed into Schedule 1, a serial schedule where T2 follows T1, by series of swaps of non-conflicting instructions. Therefore Schedule 3 is conflict serializable.

  34. View Serializability • Let S and S´ be two schedules with the same set of transactions. S and S´ are view equivalentif the following three conditions are met: 1. For each data item Q, if transaction Tireads the initial value of Q in schedule S, then transaction Ti must, in schedule S´, also read the initial value of Q. 2. For each data item Q if transaction Tiexecutes read(Q) in schedule S, and that value was produced by transaction Tj(if any), then transaction Ti must in schedule S´ also read the value of Q that was produced by transaction Tj . 3. For each data item Q, the transaction (if any) that performs the final write(Q) operation in schedule S must perform the finalwrite(Q) operation in schedule S´. As can be seen, view equivalence is also based purely on reads and writes alone.

  35. View Serializability (Cont.) • A schedule S is view serializable it is view equivalent to a serial schedule. • Every conflict serializable schedule is also view serializable. • Schedule 9 (from text) — a schedule which is view-serializable but not conflict serializable.Every view serializable schedule that is not conflict serializable has blind writes.

More Related