Ho Chi Minh City University of Technology Faculty of Computer Science and Engineering Chapter 5: Introduction to Transaction Processing Concepts and Theory Database Management Systems (CO3021) Computer Science Program Dr. Võ Thị Ngọc Châu (chauvtn@hcmut.vn) Semester 1 – 2020-2021 Course outline Chapter 1. Overall Introduction to Database Management Systems Chapter 2. Disk Storage and Basic File Structures Chapter 3.
Indexing Structures for Files Chapter 4. Query Processing and Optimization Chapter 5. Introduction to Transaction Processing Concepts and Theory Chapter 6. Concurrency Control Techniques Chapter 7.
Database Recovery Techniques 2 References [1] R. Navathe, Fundamentals of Database Systems- 6th Edition, Pearson- Addison Wesley, 2011. Navathe, Fundamentals of Database Systems- 7th Edition, Pearson, 2016. Widom, Database System Implementation, Prentice-Hall, 2000.
Widom, Database Systems: The Complete Book, Prentice-Hall, 2002 [4] A. Sudarshan, Database System Concepts –3rd Edition, McGraw-Hill, 1999. Introduction to Transaction Processing 5. Transaction and System Concepts 5.
Desirable Properties of Transactions 5. Characterizing Schedules based on Recoverability 5. Characterizing Schedules based on Serializability 5. Transaction Support in SQL 4 5.
Introduction to Transaction Processing Transaction processing systems are systems with large databases and hundreds of concurrent users executing database transactions. High availability and fast response time for hundreds of concurrent users Examples: airline reservations, banking, credit card processing, online retail purchasing, stock markets, supermarket checkouts, etc. the concept of a transaction, which is used to represent a logical unit of database processing that must be completed in its entirety to ensure correctness 5 5. Introduction to Transaction Processing Single-user vs.
multi-user database systems Concurrent execution of transactions in a multi- user system Recovery from transaction failures when transactions fail while executing The number of users who can use the system concurrently-that is, at the same time Single-user if at most one user at a time can use the system Multiuser if many users can use the system - and hence access the database - concurrently 6 5. Introduction to Transaction Processing Interleaved processing versus parallel processing of concurrent transactions Figure 20. 747 Concurrent execution of processes is actually interleaved. Interleaving keeps the CPU busy If the computer system has when a process requires an input or output multiple hardware processors (I/O) operation, such as reading a block from disk.
The CPU is switched to execute another (CPUs), parallel processing of process rather than remaining idle during I/O multiple processes is possible. Interleaving also prevents a long 7 process from delaying other processes. Introduction to Transaction Processing A Transaction: logical unit of database processing that includes one or more database access operations (read – retrieval, write – insert, update, delete). Typically implemented by a computer program that includes database commands The database operations that form a transaction can either be embedded within an application program or they can be specified interactively via a high-level query language such as SQL.
Transaction boundaries: Begin and End transaction statements. An application program may contain several transactions separated by the transaction boundaries. Introduction to Transaction Processing SIMPLE MODEL OF A DATABASE (for purposes of discussing transactions): A database - collection of named data items Granularity of data - a field, a record , or a whole disk block (Concepts are independent of granularity) Basic operations are read and write read_item(X): Reads a database item named X into a program variable. To simplify our notation, we assume that the program variable is also named X.
write_item(X): Writes the value of program variable X into the database item named X. Introduction to Transaction Processing 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. Copy that disk block into a buffer in main memory (if that disk block is not already in some main memory buffer). Copy item X from the buffer to the program variable named X. Introduction to Transaction Processing READ AND WRITE OPERATIONS: write_item(X) command includes the following steps: 1.
Find the address of the disk block that contains item X. Copy that disk block into a buffer in main memory (if that disk block is not already in some main memory buffer). Copy item X from the program variable named X into its correct location in the buffer. Store the updated block from the buffer back to disk (either immediately or at some later point in time).
Introduction to Transaction Processing Two sample transactions. Introduction to Transaction Processing Why concurrency control is needed The problems encountered with the transactions running concurrently if uncontrolled The lost update problem The temporary update (or dirty read) problem The incorrect summary problem The unrepeatable problem The phantom problem 13 5. Introduction to Transaction Processing The lost update problem This problem occurs when two transactions that access the same database items have their operations interleaved in a way that makes the value of some database items incorrect. Introduction to Transaction Processing The temporary update (or dirty read) problem This problem occurs when one transaction updates a database item and then the transaction fails for some reason.
The updated item is accessed by another transaction before it is changed. 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 16 updated and others after they are updated. Introduction to Transaction Processing The unrepeatable (nonrepeatable) problem A transaction T reads an item twice and the item is changed by another transaction T' between the two reads. Hence, T receives different values for its two reads of the same item.
Introduction to Transaction Processing The phantom problem 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 used in T1, into the table used by T1. If T1 is repeated, then T1 will see a phantom, a row that previously did not exist. Introduction to Transaction Processing Why recovery is needed Whenever a transaction is submitted to a DBMS for execution, the system is responsible for making sure: either (1) all the operations in the transaction are completed successfully and their effect is recorded permanently in the database, or (2) the transaction has no effect whatsoever on the database or on any other transactions.
The DBMS must not permit some operations of a transaction T to be applied to the database while other operations of T are not. This may happen if a transaction fails after executing some of its operations but before executing all of them. Introduction to Transaction Processing Several possible reasons for a transaction to fail in the middle of execution: 1. A transaction or system error 3.
Local errors or exception conditions detected by the transaction 4. Concurrency control enforcement 5. Physical problems and catastrophes Recovery and backup 20 5. Introduction to Transaction Processing 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. 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. Introduction to Transaction Processing Why recovery is needed: 3. Local errors or exception conditions detected by the transaction: - certain conditions necessitate cancellation of the transaction. For example, data for the transaction may not be found.
A condition, such as insufficient account balance in a banking database, may cause a transaction, such as a fund withdrawal from that account, to be canceled. - a programmed abort in the transaction causes it to fail. Concurrency control enforcement: The concurrency control method may decide to abort the transaction, to be restarted later, because it violates serializability or because several transactions are in a state of deadlock. Introduction to Transaction Processing Why recovery is needed: 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. 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. Transaction and System Concepts A transaction is an atomic (logical) unit of work that is either completed in its entirety or not done at all.
Transaction states: Active state Partially committed state Committed state Failed state Terminated State 24 5. Transaction and System Concepts State transition diagram illustrating the states for transaction execution. Transaction and System Concepts Transaction states Active state: a transaction goes into an active state immediately after it starts execution, where it can issue READ and WRITE operations. Partially committed: when the transaction ends, some recovery protocols need to ensure that a system failure will not result in an inability to record the changes of the transaction permanently (usually by recording changes in the system log).
Committed: once this check is successful, the transaction is said to have reached its commit point. Once a transaction is committed, it has concluded its execution successfully and all its changes must be recorded permanently in the database. Failed: if one of the checks fails or if the transaction is aborted during its active state. The transaction may then have to be rolled back to undo the effect of its WRITE operations on the database.
Failed or aborted transactions may be restarted later - either automatically or after being resubmitted by the user-as brand new transactions. Terminated: the transaction leaving the system. The transaction information that is maintained in system tables while the transaction has been running is removed when the transaction terminates. Transaction and System Concepts For recovery purposes, the system needs to keep track of when the transaction starts, terminates, and commits or aborts.
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.
Transaction and System Concepts For recovery purposes, the system needs to keep track of when the transaction starts, terminates, and commits or aborts. commit_transaction: This signals a successful end of the transaction so that any changes (updates) executed by the transaction can be safely committed to the database and will not be undone.