Transaction processing concepts Manal Ahmed Project Coordinator Outline

  • Slides: 19
Download presentation
Transaction processing concepts Manal Ahmed Project Coordinator

Transaction processing concepts Manal Ahmed Project Coordinator

Outline 1. Introduction to Transaction Processing 2. Transaction and System Concepts 3. Desirable Properties

Outline 1. Introduction to Transaction Processing 2. Transaction and System Concepts 3. Desirable Properties of Transactions

What is a transaction? �A transaction is an executing program that performs a single

What is a transaction? �A transaction is an executing program that performs a single unit of database processing. � What is a single unit of data process? -> Insertion -> Deletion -> Updating -> Selection / Retrieval

Introduction to Transaction processing � Single-User � At System: most one user at a

Introduction to Transaction processing � Single-User � At System: most one user at a time can use the system. � Multiuser � Many System: users can access the system concurrently. � Concurrency � Interleaved � Concurrent CPU � Parallel processing: execution of processes is interleaved in a single processing: � Processes are concurrently executed in multiple CPUs

Introduction to Transaction processing SIMPLE MODEL OF A DATABASE (for purposes of discussing transactions):

Introduction to Transaction processing SIMPLE MODEL OF A DATABASE (for purposes of discussing transactions): � 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

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: 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 (contd. ): � write_item(X) command includes

Introduction to Transaction processing READ AND WRITE OPERATIONS (contd. ): � write_item(X) command includes the following steps: 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: � (a) Transaction T 1 � (b)

Introduction to Transaction processing Two sample transactions: � (a) Transaction T 1 � (b) Transaction T 2

Problems with concurrent execution � Problems 1. 2. 3. with concurrent execution of transaction

Problems with concurrent execution � Problems 1. 2. 3. with concurrent execution of transaction The Lost Update Problem The Temporary Update (or Dirty Read) Problem The Incorrect Summary Problem

The Lost Update Problem �This occurs when two transactions that access the same database

The Lost Update Problem �This occurs when two transactions that access the same database items have their operations interleaved in a way that makes the value of some database item incorrect. T 1 Read(X) X=x+10 T 2 Read(x) X=x-20 Write(x)

The Temporary Update (or Dirty Read) Problem • • This occurs when one transaction

The Temporary Update (or Dirty Read) Problem • • This 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 back to its original value. T 1 T 2 Read(X) X=x+10 Write(x) Read(x) X=x-20 Write(x) Fail

The Incorrect Summary Problem � If one transaction is calculating an aggregate summary function

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. T 1 Sum=0 Sum= sum + A. . . Sum= sum + Z T 2 read(p) P = p + 10 Write (p)

Transaction states § § § Active state Partially committed state Committed state Failed state

Transaction states § § § Active state Partially committed state Committed state Failed state Terminated State

Active state

Active state

Properties of Transaction � ACID properties � Atomicity � Consistency � Isolation � Durability

Properties of Transaction � ACID properties � Atomicity � Consistency � Isolation � Durability

Properties of Transaction �Atomicity A transaction is an atomic unit of processing, and it

Properties of Transaction �Atomicity A transaction is an atomic unit of processing, and it either has to be performed in its entirety or not at all.

Properties of Transaction �Consistency A successful execution of a transaction must take a consistent

Properties of Transaction �Consistency A successful execution of a transaction must take a consistent database state to a (new) consistent database state.

Properties of Transaction �Isolation A transaction must not make its modifications visible to other

Properties of Transaction �Isolation A transaction must not make its modifications visible to other transactions until it is committed, i. e. , each transaction is unaware of other transactions executing concurrently in the system.

Properties of Transaction �Durability Once a transaction has committed its changes, these changes must

Properties of Transaction �Durability Once a transaction has committed its changes, these changes must never get lost due to subsequent (system) failures.