3 Database Systems: Design, Implementation, and Management CHAPTER 9 Transaction Management and Concurrency Control.

Slides:



Advertisements
Similar presentations
Concurrency Control WXES 2103 Database. Content Concurrency Problems Concurrency Control Concurrency Control Approaches.
Advertisements

Chapter 16 Concurrency. Topics in this Chapter Three Concurrency Problems Locking Deadlock Serializability Isolation Levels Intent Locking Dropping ACID.
TRANSACTION PROCESSING SYSTEM ROHIT KHOKHER. TRANSACTION RECOVERY TRANSACTION RECOVERY TRANSACTION STATES SERIALIZABILITY CONFLICT SERIALIZABILITY VIEW.
Lock-Based Concurrency Control
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.
Allowing Multi-user Access Grant – GRANT ON TO |WITH GRANT OPTION | –GRANT TO | WITH ADMIN OPTION| – can be PUBLIC or a role – can be ALL Revoke – REVOKE.
Transaction Management and Concurrency Control
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
Persistent State Service 1 Distributed Object Transactions  Transaction principles  Concurrency control  The two-phase commit protocol  Services for.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
What is a Transaction? Logical unit of work
Chapter 8 : Transaction Management. u Function and importance of transactions. u Properties of transactions. u Concurrency Control – Meaning of serializability.
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 WXES 2103 Database. Content What is transaction Transaction properties Transaction management with SQL Transaction log DBMS Transaction.
Transaction Management and Concurrency Control
Transaction. A transaction is an event which occurs on the database. Generally a transaction reads a value from the database or writes a value to the.
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.
Databases Illuminated
ITEC 3220M Using and Designing Database Systems Instructor: Prof. Z. Yang Course Website: 3220m.htm
Ch 10: Transaction Management and Concurrent Control.
Concurrency Control in Database Operating Systems.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 136 Database Systems I SQL Modifications and Transactions.
Chapter 9 Transaction Management and Concurrency Control Database Systems: Design, Implementation and Management Peter Rob & Carlos Coronel.
11/7/2012ISC329 Isabelle Bichindaritz1 Transaction Management & Concurrency Control.
Transactions and Locks A Quick Reference and Summary BIT 275.
II.I Selected Database Issues: 2 - Transaction ManagementSlide 1/20 1 II. Selected Database Issues Part 2: Transaction Management Lecture 4 Lecturer: Chris.
Chapter 16 Concurrency. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.16-2 Topics in this Chapter Three Concurrency Problems Locking Deadlock.
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
Module 11: Managing Transactions and Locks
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.
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 Properties
Chapter 10 Transaction Management and Concurrency Control
Concurrency Control WXES 2103 Database.
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
Transaction management
Presentation transcript:

3 Database Systems: Design, Implementation, and Management CHAPTER 9 Transaction Management and Concurrency Control

4 Chapter Overview 4 What is a transaction 4 Concurrency control 4 Locks 4 Two-Phase Locking protocol

5 What Is a Transaction? l A transaction is a logical unit of work that must be either entirely completed or aborted; no intermediate states are acceptable. u Most real-world database transactions are formed by two or more database requests. u A database request is the equivalent of a single SQL statement in an application program or transaction. u A transaction that changes the contents of the database must alter the database from one consistent database state to another.

6 What Is a Transaction? Figure 9.1 Example of a Transaction

7 What Is a Transaction? l Evaluating Transaction Results u Examining the current balance for an account: SELECT ACC_NUM, ACC_BALANCE FROM CHECKACC WHERE ACC_NUM = ‘ ’; l The database remains in a consistent state after the transaction.

8 What Is a Transaction? l Evaluating Transaction Results u An accountant wishes to register the credit sale of 100 units of product X to customer Y in the amount of $500.00: l Reducing product X’s Quantity on hand by 100. l Adding $ to customer Y’s accounts receivable. UPDATE PRODUCT SET PROD_QOH = PROD_QOH WHERE PROD_CODE = ‘X’; UPDATE ACCREC SET AR_BALANCE = AR_BALANCE WHERE AR_NUM = ‘Y’; l If the above two requests are not completely executed, the transaction yields an inconsistent database.

9 What Is a Transaction? l Transaction Properties u Atomicity requires that all operations of a transaction be completed; if not, the transaction is aborted. u Durability indicates the permanence of the database’s consistent state. u Serializability describes the result of the concurrent execution of several transactions. This property is important in multi-user and distributed databases. u Isolation means that the data used during the execution of a transaction cannot be used by a second transaction until the first one is completed. This is also relevant in a multi-user database. What about single-user systems with respect to each of these?

10 What Is a Transaction? l Transaction Management with SQL  Transaction support is provided by two SQL statements: COMMIT and ROLLBACK. u When a transaction sequence is initiated, it must continue through all succeeding SQL statements until one of the following four events occurs: l A COMMIT statement is reached. A ROLLBACK statement is reached. The end of a program is successfully reached ( COMMIT ). The program is abnormally terminated ( ROLLBACK ).

11 What Is a Transaction? l Transaction Management with SQL u Example: UPDATE PRODUCT SET PROD_QOH = PROD_QOH WHERE PROD_CODE = ‘345TYX’; UPDATE ACCREC SET AR_BALANCE = AR_BALANCE WHERE AR_NUM = ‘ ’; COMMIT;

12 What Is a Transaction? l The Transaction Log u A transaction log keeps track of all transactions that update the database. u The transaction log stores before-and-after data about the database and any of the tables, rows, and attribute values that participated in the transaction.  The information stored in the log is used by the DBMS for a recovery requirement triggered by a ROLLBACK statement or a system failure. u Roll back (for uncommitted) and Roll forward (for committed but not written to disk). u It is desirable to store the log file and the database files on separate disks to reduce the probability of simultaneous loss of both data.

13 What Is a Transaction? Table 9.1 Transaction Log

14 Concurrency Control l Concurrency control coordinates simultaneous execution of transactions in a multiprocessing database. u The objective of concurrency control is to ensure the serializability of transactions in a multi-user database environment. u Simultaneous execution of transactions over a shared database can create data integrity and consistency problems:

15 Concurrency Control l Example u Two concurrent transactions update PROD_QOH: TransactionComputation T1: Purchase 100 units  PROD_QOH = PROD_QOH T2: Sell 30 units  PROD_QOH = PROD_QOH - 30 u See Table 9.2 for the serial execution under normal circumstances. u See Table 9.3 for the lost update problems resulting from the execution of the second transaction before the first transaction is committed. Which property is violated?

16 Lost Updates, Uncommitted Data, Inconsistent Retrieval Table 9.2 Table 9.3 Lost Updates

17 Table 9.5 Table 9.4 Lost Updates, Uncommitted Data, Inconsistent Retrieval l T1 reads the data and modifies it and writes. l T2 reads the data not yet committed and modifies it l T1 rollsback l T2 writes Uncommitted Data

18 Table 9.6 Table 9.7 Lost Updates, Uncommitted Data, Inconsistent Retrieval l Inconsistent retrieval u Occurs when a transaction calculates some summary(aggregate) functions over a set of data while other transactions are updating it.

19 Inconsistent Retrievals (con’t.) Table 9.8

20 Concurrency Control l The Scheduler u The scheduler establishes the order in which the operations within concurrent transactions are executed. u The scheduler sequences the execution of database operations to ensure serializability. u To determine the appropriate order, the scheduler bases its actions on concurrency control algorithms. When two transactions access the same data and at least one involves a write operation, then there is potential for conflict.

21 LOCKS l Concurrency Control with Locking Methods u A lock guarantees exclusive use of a data item to a current transaction. u All lock information is managed by a lock manager. u Lock granularity indicates the level of lock use. l Database level l Table level l Page level l Row level l Field level

22 LOCKS l Database level Lock u Entire database is locked by a transaction u Good for batch processing but inefficient for on-line processing u When transaction T1 is accessing table A, transaction T2 has to wait for the lock to be released even if wants to access table B. l Table level Lock u Entire table is locked by a transaction u If a transaction requires access to several tables, each table may be locked u Less restrictive compared to database locks u Can cause unnecessary delays when two transactions need to access different parts of the same table u Not suitable for multi-user DBMS

23 Database-Level Locking Sequence Figure 9.2

24 Table-Level Lock Example Figure 9.3

25 LOCKS l Page Level Lock u A diskpage is locked by a transaction (4K or 8K or 16K) u A table may span many pages u A page contains many rows u This is most popular level of locking in multiuser databases l Row Level Lock u A row is locked by a transaction u Multiple transactions can access different rows in the same table concurrently u Less restrictive than page level locking u High overhead in lock management l Field Level Lock u Different transactions can lock different fields in the same row concurrently u Most flexible for mult-user data access u Requires very high overhead in managing locks

26 Page-Level Lock Example Figure 9.4

27 Row-Level Lock Example Figure 9.5

28 LOCKS l Binary Locks u A binary lock has only two states: locked (1) or unlocked (0). u If an object is locked by a transaction, no other transaction can use that object. u If an object is unlocked, any transaction can lock the object for its use. u A transaction must unlock the object after its termination. u Every transaction requires a lock and unlock operation for each data item that is accessed.

29 Example of Binary Lock Table Table 9.10

30 LOCKS l Exclusive Locks u An exclusive lock exists when access is specially reserved for the transaction that locked the object. u The exclusive lock must be used when the potential for conflict exists. u An exclusive lock is issued when a transaction wants to write a data item and no locks are currently held on that data item. l Shared Locks u A shared lock exists when concurrent transactions are granted READ access on the basis of a common lock. u A shared lock produces no conflict as long as the concurrent transactions are read only. u A shared lock is issued when a transaction wants to read data from the database and no exclusive lock is held on that data item.

31 Two-Phase Locking l The two-phase locking protocol defines how transactions acquire and relinquish locks. l In a growing phase, a transaction acquires all the required locks without unlocking any data. l Once all locks have been acquired, the transaction is in its locked point. All operations are executed at this time. l In a shrinking phase, a transaction releases all locks and cannot obtain any new locks. l This protocol guarantees serializability, but it does not prevent deadlocks. l No unlock operation can precede a lock operation in the same transaction. l No data are affected until all locks are obtained -- that is, until the transaction is in its locked point.

32 Two-Phase Locking Figure 9.6 Two-Phase Locking Protocol

33 Two-Phase Locking l Deadlocks (Deadly Embrace) u Deadlocks exist when two transactions T1 and T2 exist in the following mode: T1 = access data items X and Y T2 = access data items Y and X u If T1 has not unlocked data item Y, T2 cannot begin; and, if T2 has not unlocked data item X, T1 cannot continue. (See Table 9.11) u Several strategies have been developed to control deadlock situations.

34 Two-Phase Locking Table 9.11 How a Deadlock Condition Is Created

35 Two-Phase Locking l Deadlock Prevention u A transaction requesting for a new lock is aborted if there is a possibility of deadlock. Rollback and release acquired locks. l Deadlock Detection u DBMS periodically tests for existence of deadlock. If found kills one of the transactions. Rollback and release acquired locks. l Deadlock Avoidance u Must obtain all locks before it starts execution. It increases the response time. So, What is the best method?