Course Database Management Systems - Chapter 4: Introduction to Transaction Processing Concepts and Theory - Nguyen Thanh Tung

1 Introduction to Transaction Processing
2 Transaction and System Concepts
3 Desirable Properties of Transactions
4 Characterizing Schedules based on Recoverability
5 Characterizing Schedules based on Serializability
6 Transaction Support in SQL 
pdf 54 trang xuanthi 30/12/2022 1860
Bạn đang xem 20 trang mẫu của tài liệu "Course Database Management Systems - Chapter 4: Introduction to Transaction Processing Concepts and Theory - Nguyen Thanh Tung", để tải tài liệu gốc về máy hãy click vào nút Download ở trên.

File đính kèm:

  • pdfcourse_database_management_systems_c4_introduction_to_transa.pdf

Nội dung text: Course Database Management Systems - Chapter 4: Introduction to Transaction Processing Concepts and Theory - Nguyen Thanh Tung

  1. Chapter Outline 1 Introduction to Transaction Processing 2 Transaction and System Concepts 3 Desirable Properties of Transactions 4 Characterizing Schedules based on Recoverability 5 Characterizing Schedules based on Serializability 6 Transaction Support in SQL 2
  2. Introduction to Transaction Processing (2)  A Transaction: logical unit of database processing that includes one or more access operations (read -retrieval, write - insert or update, delete).  A transaction (set of operations) may be stand- alone specified in a high level language like SQL submitted interactively, or may be embedded within a program.  Transaction boundaries: Begin and End transaction.  An application program may contain several transactions separated by the Begin and End transaction boundaries. 4
  3. Introduction to Transaction Processing (4) READ AND WRITE OPERATIONS:  Basic unit of data transfer from the disk to the computer main memory is one block. In general, a data item (what is read or written) will be the field of some record in the database, although it may be a larger unit such as a record or even a whole block.  read_item(X) command includes the following steps: 1. Find the address of the disk block that contains item X. 2. Copy that disk block into a buffer in main memory (if that disk block is not already in some main memory buffer). 3. Copy item X from the buffer to the program variable named X. 6
  4. FIGURE 4.2 Two sample transactions. (a) Transaction T1. (b) Transaction T2. 8
  5. Introduction to Transaction Processing (8) Why Concurrency Control is needed (cont.):  The Incorrect Summary Problem . If one transaction is calculating an aggregate summary function on a number of records while other transactions are updating some of these records, the aggregate function may calculate some values before they are updated and others after they are updated. 10
  6. FIGURE 4.3 (continued) Some problems that occur when concurrent execution is uncontrolled. (b) The temporary update problem. 12
  7. Introduction to Transaction Processing (11) Why recovery is needed: (What causes a Transaction to fail) 1. A computer failure (system crash): A hardware or software error occurs in the computer system during transaction execution. If the hardware crashes, the contents of the computer’s internal memory may be lost. 2. A transaction or system error : Some operation in the transaction may cause it to fail, such as integer overflow or division by zero. Transaction failure may also occur because of erroneous parameter values or because of a logical programming error. In addition, the user may interrupt the transaction during its execution. 14
  8. Introduction to Transaction Processing (13) Why recovery is needed (cont.): 5. Disk failure: Some disk blocks may lose their data because of a read or write malfunction or because of a disk read/write head crash. This may happen during a read or a write operation of the transaction. 6. Physical problems and catastrophes: This refers to an endless list of problems that includes power or air-conditioning failure, fire, theft, sabotage, overwriting disks or tapes by mistake, and mounting of a wrong tape by the operator. 16
  9. Transaction and System Concepts (2) Recovery manager keeps track of the following operations:  begin_transaction: This marks the beginning of transaction execution.  read or write: These specify read or write operations on the database items that are executed as part of a transaction.  end_transaction: This specifies that read and write transaction operations have ended and marks the end limit of transaction execution. At this point it may be necessary to check whether the changes introduced by the transaction can be permanently applied to the database or whether the transaction has to be aborted because it violates concurrency control or for some other reason. 18
  10. Transaction and System Concepts (4) Recovery techniques use the following operators:  undo: Similar to rollback except that it applies to a single operation rather than to a whole transaction.  redo: This specifies that certain transaction operations must be redone to ensure that all the operations of a committed transaction have been applied successfully to the database. 20
  11. Transaction and System Concepts (6) The System Log  Log or Journal : The log keeps track of all transaction operations that affect the values of database items. This information may be needed to permit recovery from transaction failures. The log is kept on disk, so it is not affected by any type of failure except for disk or catastrophic failure. In addition, the log is periodically backed up to archival storage (tape) to guard against such catastrophic failures.  T in the following discussion refers to a unique transaction-id that is generated automatically by the system and is used to identify each transaction: 22
  12. Transaction and System Concepts (8) The System Log (cont):  protocols for recovery that avoid cascading rollbacks do not require that READ operations be written to the system log, whereas other protocols require these entries for recovery.  strict protocols require simpler WRITE entries that do not include new_value. 24
  13. Transaction and System Concepts (10) Commit Point of a Transaction:  Definition: A transaction T reaches its commit point when all its operations that access the database have been executed successfully and the effect of all the transaction operations on the database has been recorded in the log. Beyond the commit point, the transaction is said to be committed, and its effect is assumed to be permanently recorded in the database. The transaction then writes an entry [commit,T] into the log.  Roll Back of transactions: Needed for transactions that have a [start_transaction,T] entry into the log but no commit entry [commit,T] into the log. 26
  14. 3 Desirable Properties of Transactions (1) ACID properties:  Atomicity: A transaction is an atomic unit of processing; it is either performed in its entirety or not performed at all.  Consistency preservation: A correct execution of the transaction must take the database from one consistent state to another. 28
  15. 4 Characterizing Schedules based on Recoverability (1)  Transaction schedule or history: When transactions are executing concurrently in an interleaved fashion, the order of execution of operations from the various transactions forms what is known as a transaction schedule (or history).  A schedule (or history) S of n transactions T1, T2, , Tn : It is an ordering of the operations of the transactions subject to the constraint that, for each transaction Ti that participates in S, the operations of T1 in S must appear in the same order in which they occur in T1. Note, however, that operations from other transactions Tj can be interleaved with the operations of Ti in S. 30
  16. Characterizing Schedules based on Recoverability (3) Schedules classified on recoverability (cont.):  Strict Schedules: A schedule in which a transaction can neither read or write an item X until the last transaction that wrote X has committed. 32
  17. Characterizing Schedules based on Serializability (2)  Result equivalent: Two schedules are called result equivalent if they produce the same final state of the database.  Conflict equivalent: Two schedules are said to be conflict equivalent if the order of any two conflicting operations is the same in both schedules.  Two operations in a schedule are said to conflict if they belong to different transactions, access the same data item, and at least one of the two operations is a write_item operation.  Conflict serializable: A schedule S is said to be conflict serializable if it is conflict equivalent to some serial schedule S’.  In such a case, we can reorder the nonconflicting operations in S until we form the equivalent serial schedule S’. 34
  18. Characterizing Schedules based on Serializability (4)  Serializability is hard to check.  Interleaving of operations occurs in an operating system through some scheduler  Difficult to determine beforehand how the operations in a schedule will be interleaved. 36
  19. Characterizing Schedules based on Serializability Testing for conflict serializability Algorithm 4.1: 1. Looks at only read_Item (X) and write_Item (X) operations 2. Constructs a precedence graph (serialization graph) - a graph with directed edges 3. An edge is created from Ti to Tj if one of the operations in Ti appears before a conflicting operation in Tj 4. The schedule is serializable if and only if the precedence graph has no cycles. 38
  20. Figure 4.5 (b) (b) T1 T2 read_item(X); X:= X+M; write_item(X); read_item(X); Time X:= X-N; write_item(X); read_item(Y); Y:=Y+N; write_item(Y); Schedule B 40
  21. Figure 4.5 (d) T1 T2 read_item(X); X:= X-N; write_item(X); read_item(X); Time X:= X+M; write_item(X); read_item(Y); Y:=Y+N; write_item(Y); Schedule D: r1(X); w1(X); r2(X); w2(X); r1(Y); w1(Y); 42
  22. FIGURE 4.8 Another example of serializability testing. (a) The READ and WRITE operations of three transactions T1, T2, and T3. 44
  23. FIGURE 4.8 (continued) Another example of serializability testing. (c) Schedule F. 46
  24. 6 Transaction Support in SQL2 (1)  A single SQL statement is always considered to be atomic. Either the statement completes execution without error or it fails and leaves the database unchanged.  With SQL, there is no explicit Begin Transaction statement. Transaction initiation is done implicitly when particular SQL statements are encountered.  Every transaction must have an explicit end statement, which is either a COMMIT or ROLLBACK. 48
  25. Transaction Support in SQL2 (3) Characteristics specified by a SET TRANSACTION statement in SQL2 (cont.):  Isolation level , where can be READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ or SERIALIZABLE. The default is SERIALIZABLE. With SERIALIZABLE: the interleaved execution of transactions will adhere to our notion of serializability. However, if any transaction executes at a lower level, then serializability may be violated. 50
  26. Transaction Support in SQL2 (5) Potential problem with lower isolation levels (cont.):  Phantoms: New rows being read using the same read with a condition. A transaction T1 may read a set of rows from a table, perhaps based on some condition specified in the SQL WHERE clause. Now suppose that a transaction T2 inserts a new row that also satisfies the WHERE clause condition of T1, into the table used by T1. If T1 is repeated, then T1 will see a row that previously did not exist, called a phantom. 52
  27. Transaction Support in SQL2 (7) Possible violation of serializabilty: Type of Violation ___ Isolation Dirty nonrepeatable level read read phantom ___ ___ ___ ___ READ UNCOMMITTED yes yes yes READ COMMITTED no yes yes REPEATABLE READ no no yes SERIALIZABLE no no no 54