11/7/2012ISC329 Isabelle Bichindaritz1 Transaction Management & Concurrency Control.

Slides:



Advertisements
Similar presentations
TRANSACTION PROCESSING SYSTEM ROHIT KHOKHER. TRANSACTION RECOVERY TRANSACTION RECOVERY TRANSACTION STATES SERIALIZABILITY CONFLICT SERIALIZABILITY VIEW.
Advertisements

CSC271 Database Systems Lecture # 32.
Lecture 11 Recoverability. 2 Serializability identifies schedules that maintain database consistency, assuming no transaction fails. Could also examine.
Database Systems, 8 th Edition Concurrency Control with Time Stamping Methods Assigns global unique time stamp to each transaction Produces explicit.
Transaction Management and Concurrency Control
Concurrency Control. R/RR/W W/W User 2 ReadWrite User 1 Read Write R/W: Inconsistent Read problem. W/W: Lost Update problem.
10 1 Chapter 10 Transaction Management and Concurrency Control Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Transaction Management and Concurrency Control
Transaction Management and Concurrency Control
Transaction Management and Concurrency Control
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
Chapter 17: Transaction Management
What is a Transaction? Logical unit of work
Transaction Management
Chapter 9 Transaction Management and Concurrency Control
9 Chapter 9 Transaction Management and Concurrency Control Hachim Haddouti.
Database Administration Part 1 Chapter Six CSCI260 Database Applications.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
Transaction Management and Concurrency Control
Transaction Management Chapter 9. What is a Transaction? A logical unit of work on a database A logical unit of work on a database An entire program An.
Multi-user Database Processing Architectures Architectures Transactions Transactions Security Security Administration Administration.
1 Transactions BUAD/American University Transactions.
Recovery & Concurrency Control. What is a Transaction?  A transaction is a logical unit of work that must be either entirely completed or aborted. 
Security and Transaction Nhi Tran CS 157B - Dr. Lee Fall, 2003.
Database Systems: Design, Implementation, and Management Tenth Edition
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 10 Transaction Management.
Chapter 9 Transaction Management and Concurrency Control Database Systems: Design, Implementation and Management Peter Rob & Carlos Coronel.
Chapterb19 Transaction Management Transaction: An action, or series of actions, carried out by a single user or application program, which reads or updates.
1 What is database 2? What is normalization? What is SQL? What is transaction?
Databases Illuminated
ITEC 3220M Using and Designing Database Systems Instructor: Prof. Z. Yang Course Website: 3220m.htm
Lecture 12 Recoverability and failure. 2 Optimistic Techniques Based on assumption that conflict is rare and more efficient to let transactions proceed.
1 Chapter 20 Transaction Management Transparencies Last Updated: 17 th March 2011 By M. Arief
Ch 10: Transaction Management and Concurrent Control.
1 Transactions Chapter Transactions A transaction is: a logical unit of work a sequence of steps to accomplish a single task Can have multiple.
Concurrency Control in Database Operating Systems.
Chapter 9 Transaction Management and Concurrency Control Database Systems: Design, Implementation and Management Peter Rob & Carlos Coronel.
Chapter 15 Recovery. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.15-2 Topics in this Chapter Transactions Transaction Recovery System.
II.I Selected Database Issues: 2 - Transaction ManagementSlide 1/20 1 II. Selected Database Issues Part 2: Transaction Management Lecture 4 Lecturer: Chris.
The Relational Model1 Transaction Processing Units of Work.
Chapter 20 Transaction Management Thomas Connolly, Carolyn Begg, Database System, A Practical Approach to Design Implementation and Management, 4 th Edition,
Transaction Management Transparencies. ©Pearson Education 2009 Chapter 14 - Objectives Function and importance of transactions. Properties of transactions.
Transaction Processing Concepts
ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: Office: CSEB3020.
1 Advanced Database Concepts Transaction Management and Concurrency Control.
Overview of Transaction Management
Transaction Management and Concurrent Control
9 1 Chapter 9_B Concurrency Control Database Systems: Design, Implementation, and Management, Rob and Coronel.
NOEA/IT - FEN: Databases/Transactions1 Transactions ACID Concurrency Control.
10 1 Chapter 10_B Concurrency Control Database Systems: Design, Implementation, and Management, Rob and Coronel.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
10 Transaction Management and Concurrency Control MIS 304 Winter 2005.
©Bob Godfrey, 2002, 2005 Lecture 17: Transaction Integrity and Concurrency BSA206 Database Management Systems.
3 Database Systems: Design, Implementation, and Management CHAPTER 9 Transaction Management and Concurrency Control.
10 1 Chapter 10 - A Transaction Management Database Systems: Design, Implementation, and Management, Rob and Coronel.
18 September 2008CIS 340 # 1 Last Covered (almost)(almost) Variety of middleware mechanisms Gain? Enable n-tier architectures while not necessarily using.
Chapter 13 Managing Transactions and Concurrency Database Principles: Fundamentals of Design, Implementation, and Management Tenth Edition.
Transactions and Concurrency Control. 2 What is a Transaction?  Any action that reads from and/or writes to a database may consist of  Simple SELECT.
9 1 Chapter 9 Transaction Management and Concurrency Control Database Systems: Design, Implementation, and Management, Sixth Edition, Rob and Coronel.
SYSTEMS IMPLEMENTATION TECHNIQUES TRANSACTION PROCESSING DATABASE RECOVERY DATABASE SECURITY CONCURRENCY CONTROL.
Transaction Management and Concurrency Control
Transaction Management and Concurrency Control
Transaction Management Transparencies
Transaction Management
Transaction Properties
Chapter 10 Transaction Management and Concurrency Control
Chapter 10 Transaction Management and Concurrency Control
Chapter 9 Transaction Management and Concurrency Control
Introduction of Week 13 Return assignment 11-1 and 3-1-5
Transactions, Properties of Transactions
Presentation transcript:

11/7/2012ISC329 Isabelle Bichindaritz1 Transaction Management & Concurrency Control

11/7/2012ISC329 Isabelle Bichindaritz2 Learning Objectives What a database transaction is and what its properties are How database transactions are managed What concurrency control is and what role it plays in maintaining the database’s integrity What locking methods are and how they work How database recovery management is used to maintain database integrity

11/7/2012ISC329 Isabelle Bichindaritz3 Acknowledgments Some of these slides have been adapted from Thomas Connolly and Carolyn Begg

11/7/2012ISC329 Isabelle Bichindaritz4 A transaction is a logical unit of database processing work, which can include one or more database operations, such as insertion,deletion, modification, or retrieval operations. Transaction processing systems are systems with large databases and hundreds of concurrent users. Must be either entirely completed or aborted. No intermediate states are acceptable. Database moves from one consistent state to another one. What is a Transaction?

11/7/2012ISC329 Isabelle Bichindaritz5 What is a Transaction? A consistent database state is one in which all data integrity constraints are satisfied. Example: during transaction, no other transaction must access X.

11/7/2012ISC329 Isabelle Bichindaritz6 What is a Transaction? Integrity constraints: –Entity integrity and referential integrity are enforced automatically by DBMS. –Other constraints can be added so that they are enforced by the DBMS.

11/7/2012ISC329 Isabelle Bichindaritz7 Examine current account balance Consistent state before and after transaction No changes made to Database Example Transaction SELECT ACC_NUM, ACC_BALANCE FROM CHECKACC WHERE ACC_NUM = ‘ ’;

11/7/2012ISC329 Isabelle Bichindaritz8 Register credit sale of 100 units of product X to customer Y for $500 Consistent state only if both transactions are fully completed DBMS doesn’t guarantee transaction represents real-world event Example Transaction UPDATE PRODUCT SET PROD_QOH = PROD_QOH WHERE PROD_CODE = ‘X’; UPDATE ACCT_RECEIVABLE SET ACCT_BALANCE = ACCT_BALANCE WHERE ACCT_NUM = ‘Y’;

11/7/2012ISC329 Isabelle Bichindaritz9 Atomicity –All transaction operations must be completed –Incomplete transactions aborted Durability –Permanence of effects of committed transaction –Consistent state is permanently kept Serializability –Conducts transactions in serial order –Important in multi-user and distributed databases Isolation –Transaction data cannot be reused until its execution complete Transaction Properties

11/7/2012ISC329 Isabelle Bichindaritz10 Transaction support –COMMIT (permanently updates database) –ROLLBACK (does not modify database) User initiated transaction sequence must continue until: –COMMIT statement is reached –ROLLBACK statement is reached –End of a program reached –Program reaches abnormal termination (leads to ROLLBACK) Transaction Management with SQL

11/7/2012ISC329 Isabelle Bichindaritz11 Register credit sale of 100 units of product X to customer Y for $500 Transaction begins when first SQL statement is encountered, and ends at COMMIT or end Transaction Management with SQL UPDATE PRODUCT SET PROD_QOH = PROD_QOH WHERE PROD_CODE = ‘X’; UPDATE ACCT_RECEIVABLE SET ACCT_BALANCE = ACCT_BALANCE WHERE ACCT_NUM = ‘Y’; COMMIT;

11/7/2012ISC329 Isabelle Bichindaritz12 Tracks all transactions that update database May be used by ROLLBACK command May be used to recover from system failure Log stores –Record for beginning of transaction –Each SQL statement Operation type (retrieve, update, insert, delete) Names of objects Before and after values for updated fields Pointers to previous and next entries –Commit Statement Transaction Log

11/7/2012ISC329 Isabelle Bichindaritz13 Transaction Log Example TRL_ID: transaction log record ID TRX_NUM: transaction number PREV_PTR: pointer to previous transaction record NEXT_PTR: pointer to next transaction record

11/7/2012ISC329 Isabelle Bichindaritz14 Process of managing simultaneous operations on the database without having them interfere with one another –Ensure serializability of transactions in multiuser database environment –Potential problems in multiuser environments Lost updates Uncommitted data Inconsistent retrievals Concurrency Control

11/7/2012ISC329 Isabelle Bichindaritz15 Lost Updates PROD_QOH = PROD_QOH PROD_QOH = PROD_QOH - 30

11/7/2012ISC329 Isabelle Bichindaritz16 Uncommitted Data PROD_QOH = PROD_QOH (ROLLBACK) PROD_QOH = PROD_QOH - 30

11/7/2012ISC329 Isabelle Bichindaritz17 Inconsistent Retrievals

11/7/2012ISC329 Isabelle Bichindaritz18 Inconsistent Retrievals

11/7/2012ISC329 Isabelle Bichindaritz19 Establishes order of concurrent transaction execution Interleaves execution of database operations to ensure serializability Bases actions on concurrency control algorithms –Locking –Time stamping Ensures efficient use of computer’s CPU The Scheduler

11/7/2012ISC329 Isabelle Bichindaritz20 Read/Write Conflict Scenarios: Conflicting Database Operations Matrix

11/7/2012ISC329 Isabelle Bichindaritz21 Concurrency Control with Locking Methods Lock guarantees current transaction exclusive use of data item Acquires lock prior to access Lock released when transaction is completed DBMS automatically initiates and enforces locking procedures Managed by lock manager Lock granularity indicates level of lock use – database, table, page, row, or field lock levels.

11/7/2012ISC329 Isabelle Bichindaritz22 Database-Level Locking Sequence

11/7/2012ISC329 Isabelle Bichindaritz23 Table-Level Lock

11/7/2012ISC329 Isabelle Bichindaritz24 Page-Level Lock Example A page is a diskpage, a part of the disk of fixed size, such as 4K, 8K, 16K.

11/7/2012ISC329 Isabelle Bichindaritz25 Row-Level Lock Example Figure 9.5

11/7/2012ISC329 Isabelle Bichindaritz26 Two main lock types: –Binary locks –Shared/Exclusive locks DBMS manages the lock automatically – in MySQL, it is table-level lock in MS Access and SQL Server, it is row- level lock in Oracle, UDB, it is row-level lock Lock Types

11/7/2012ISC329 Isabelle Bichindaritz27 Two states –Locked (1) –Unlocked (0) Locked objects unavailable to other objects – managed by DBMS –Unlocked objects open to any transaction –Each transaction locks object –Transaction unlocks object when complete Is is possible to change DBMS default with LOCK TABLE and other SQL commands. Binary Locks

11/7/2012ISC329 Isabelle Bichindaritz28 Example of Binary Lock Table

11/7/2012ISC329 Isabelle Bichindaritz29 Shared/Exclusive Locks Shared –Exists when concurrent transactions granted READ access –Produces no conflict for read-only transactions –Issued when transaction wants to read and exclusive lock not held on item Exclusive –Exists when access reserved for locking transaction –Used when potential for conflict exists –Exclusive lock granted only if object does not have a lock yet –Issued when transaction wants to update unlocked data

11/7/2012ISC329 Isabelle Bichindaritz30 Problems with Locking Shared/exclusive lock requires important work from the lock manager: Type of lock must be known before access granted Several lock operations: READ_LOCK, WRITE_LOCK, UNLOCK. Transaction schedule may not be serializable –Managed through two-phase locking Schedule may create deadlocks –Managed by using deadlock detection and prevention techniques

11/7/2012ISC329 Isabelle Bichindaritz31 Two-Phase Locking Growing phase Shrinking phase Governing rules –Two transactions cannot have conflicting locks –No unlock operation can precede a lock operation in the same transaction –No data are affected until all locks are obtained

11/7/2012ISC329 Isabelle Bichindaritz32 Two-Phase Locking Protocol Figure 9.6

11/7/2012ISC329 Isabelle Bichindaritz33 Deadlocks Occurs when two transactions wait for each other to unlock data (T1  X,Y and T2  Y,X) Called deadly embrace Control techniques –Deadlock prevention (abort transaction before deadlock) –Deadlock detection (abort one of the deadlocked transactions) –Deadlock avoidance (get all the locks at once)

11/7/2012ISC329 Isabelle Bichindaritz34 How Deadlock Conditions Created Table 9.11

11/7/2012ISC329 Isabelle Bichindaritz35 Concurrency Control with Time Stamping Methods Assigns global unique time stamp to each transaction Produces order for transaction submission for conflicting operations Properties –Uniqueness –Monotonicity DBMS executes conflicting operations in time stamp order Each value requires two additional time stamps fields –Last time field read –Last update

11/7/2012ISC329 Isabelle Bichindaritz36 Concurrency Control with Optimistic Methods Assumes most database operations do not conflict Transaction executed without restrictions until committed Phases: –Read Phase –Validation Phase (check that changes will not affect database integrity) –Write Phase

11/7/2012ISC329 Isabelle Bichindaritz37 Restores a database to previously consistent state Based on the atomic transaction property Recovery of transactions, database, system Level of backup –Full database backup –Differential backup –Transaction log backup Database Recovery Management

11/7/2012ISC329 Isabelle Bichindaritz38 Software Hardware Programming Exemption Transaction External Causes of Database Failure

11/7/2012ISC329 Isabelle Bichindaritz39 Transaction recovery –Write-ahead protocol –Redundant transaction logs –Database buffers –Database checkpoints Transaction Recovery

11/7/2012ISC329 Isabelle Bichindaritz40 Deferred-write and Deferred-update –Changes are written to the transaction log –Database updated after transaction reaches commit point Write-through –Immediately updated during execution –Before the transaction reaches its commit point –Transaction log also updated –Transaction fails, database uses log information to ROLLBACK Transaction Recovery