10 Transaction Management and Concurrency Control MIS 304 Winter 2005.

Slides:



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

Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 16.
1 Lecture 11: Transactions: Concurrency. 2 Overview Transactions Concurrency Control Locking Transactions in SQL.
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.
Data and Database Administration Chapter 12. Outline What is Concurrency Control? Background Serializability  Locking mechanisms.
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
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
What is a Transaction? Logical unit of work
Transaction Management
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-1 COS 346 Day 18.
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.
Academic Year 2014 Spring Academic Year 2014 Spring.
Client/Server Databases and the Oracle 10g Relational Database
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. 
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.
ITEC 3220M Using and Designing Database Systems Instructor: Prof. Z. Yang Course Website: 3220m.htm
1 Chapter 20 Transaction Management Transparencies Last Updated: 17 th March 2011 By M. Arief
Ch 10: Transaction Management and Concurrent Control.
1 IT420: Database Management and Organization Session Control Managing Multi-user Databases 24 March 2006 Adina Crăiniceanu
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.
Sekolah Tinggi Ilmu Statistik (STIS) 1 Dr. Said Mirza Pahlevi, M.Eng.
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 Overview. Transactions Concurrent execution of user programs is essential for good DBMS performance. – Because disk accesses are.
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.
©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.
ITEC 3220M Using and Designing Database Systems Instructor: Prof. Z.Yang Course Website: c3220m.htm Office: TEL.
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
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
Transactions, Properties of Transactions
Presentation transcript:

10 Transaction Management and Concurrency Control MIS 304 Winter 2005

10 2 Review from last week The Internet is largely dependent on database technology Database “Middleware” links HTML and HTTP based systems to traditional Relational Database. The HTML and HTTP architectures can make it more difficult to implement user friendly interfaces.

10 3 A leftover from last time. Demonstration of Altova XML Spy feature to created Relational tables from an XML document.

10 4 Goals for this class Understand how transactions are used in the databases and their applications. Understand the technology of the database transactions. Understand concurrency and locking technology and how they effect databases.

10 5 TRANSACTION

10 6 Sources of Transaction What are the sources of transactions? What generates the data?

10 7 Consistent State

10 8 Table: Stock X = 40 PartNo=12345 Consistent state Table: Stock X = 30 PartNo=12345 Consistent state UPDATE Stock SET X = X – 10 WHERE PartNo = Transaction(s) Example of a Transaction

10 9 What is a Transaction? Any action that reads from and/or writes to a database may consist of –Simple SELECT statement to generate a list of table contents –A series of related UPDATE statements to change the values of attributes in various tables –A series of INSERT statements to add rows to one or more tables –A combination of SELECT, UPDATE, and INSERT statements

10 What is a Transaction? ( continued ) A logical unit of work that must be either entirely completed or aborted Successful transaction changes the database from one consistent state to another –One in which all data integrity constraints are satisfied Most real-world database transactions are formed by two or more database requests –The equivalent of a single SQL statement in an application program or transaction

10 11 The Relational Schema for the Ch09_SaleCo Database

10 12 Double Entry Bookkeeping The bane of the database programmer. WHY?

10 13 Accounting Transactions Represent a large component of “all” Transactions. “Double Entry” Bookkeeping means that there are at least TWO components per transaction.

10 14 Evaluating Transaction Results An accountant wishes to register the credit sale of 100 units of product X to customer Y in the amount of $500.00: –Reducing product X’s Quantity on hand by 100. –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’; If the above two transactions are not completely executed, the transaction yields an inconsistent database.

10 15 Evaluating Transaction Results Not all transactions update the database SQL code represents a transaction because database was accessed Improper or incomplete transactions can have a devastating effect on database integrity –Some DBMSs provide means by which user can define enforceable constraints based on business rules –Other integrity rules are enforced automatically by the DBMS when table structures are properly defined, thereby letting the DBMS validate some transactions

10 16 Tracing the Transaction in the Ch09_SaleCo Database Figure 9.2

10 17 Transaction Properties Atomicity –Requires that all operations (SQL requests) of a transaction be completed Durability –Indicates permanence of database’s consistent state

10 18 Transaction Properties ( continued ) Serializability –Ensures that the concurrent execution of several transactions yields consistent results Isolation –Data used during execution of a transaction cannot be used by second transaction until first one is completed

10 19 Transaction Management with SQL ANSI has defined standards that govern SQL database transactions Transaction support is provided by two SQL statements: COMMIT and ROLLBACK ANSI standards require that, when a transaction sequence is initiated by a user or an application program, –it must continue through all succeeding SQL statements until one of four events occurs

10 20 The Transaction Log Stores –A record for the beginning of transaction –For each transaction component (SQL statement) Type of operation being performed (update, delete, insert) Names of objects affected by the transaction (the name of the table) “Before” and “after” values for updated fields Pointers to previous and next transaction log entries for the same transaction –The ending (COMMIT) of the transaction

10 21 A Transaction Log

10 22 Concurrency Control Coordination of simultaneous transaction execution in a multiprocessing database system Objective is to ensure transaction serializability in a multiuser database environment

10 23 Concurrency Control –Important  simultaneous execution of transactions over a shared database can create several data integrity and consistency problems lost updates uncommitted data inconsistent retrievals

10 24 Normal Execution of Two Transactions

10 25 Lost Updates

10 26 Correct Execution of Two Transactions

10 27 An Uncommitted Data Problem

10 28 Retrieval During Update

10 29 Transaction Results: Data Entry Correction

10 30 Inconsistent Retrievals

10 31 The Scheduler Special DBMS program: establishes order of operations within which concurrent transactions are executed Interleaves the execution of database operations to ensure serializability and isolation of transactions

10 32 The Scheduler ( continued ) Bases its actions on concurrency control algorithms Ensures computer’s central processing unit (CPU) is used efficiently Facilitates data isolation to ensure that two transactions do not update the same data element at the same time

10 33 Read/Write Conflict Scenarios: Conflicting Database Operations Matrix

10 34 Concurrency Control with Locking Methods Lock –Guarantees exclusive use of a data item to a current transaction –Required to prevent another transaction from reading inconsistent data Lock manager –Responsible for assigning and policing the locks used by the transactions

10 35 Lock Granularity Indicates the level of lock use Locking can take place at the following levels: –Database –Table –Page –Row –Field (attribute)

10 36 Lock Granularity ( continued ) Database-level lock –Entire database is locked Table-level lock –Entire table is locked Page-level lock –Entire diskpage is locked

10 37 Lock Granularity ( continued ) Row-level lock –Allows concurrent transactions to access different rows of the same table, even if the rows are located on the same page Field-level lock –Allows concurrent transactions to access the same row, as long as they require the use of different fields (attributes) within that row

10 38 A Database-Level Locking Sequence

10 39 An Example of a Table-Level Lock

10 40 Example of a Page-Level Lock

10 41 An Example of a Row-Level Lock

10 42 Lock Types Binary lock –Has only two states: locked (1) or unlocked (0) Exclusive lock –Access is specifically reserved for the transaction that locked the object –Must be used when the potential for conflict exists Shared lock –Concurrent transactions are granted Read access on the basis of a common lock

10 43 An Example of a Binary Lock

10 44 Two-Phase Locking to Ensure Serializability Defines how transactions acquire and relinquish locks Guarantees serializability, but it does not prevent deadlocks –Growing phase, in which a transaction acquires all the required locks without unlocking any data –Shrinking phase, in which a transaction releases all locks and cannot obtain any new lock

10 45 Two-Phase Locking to Ensure Serializability ( continued ) Governed by the following 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— that is, until the transaction is in its locked point

10 46 Two-Phase Locking Protocol

10 47 Deadlocks Condition that occurs when two transactions wait for each other to unlock data Possible only if one of the transactions wants to obtain an exclusive lock on a data item –No deadlock condition can exist among shared locks Control through –Prevention –Detection –Avoidance

10 48 How a Deadlock Condition Is Created

10 49 Concurrency Control with Time Stamping Methods Assigns a global unique time stamp to each transaction Produces an explicit order in which transactions are submitted to the DBMS Uniqueness –Ensures that no equal time stamp values can exist Monotonicity –Ensures that time stamp values always increase

10 50 Wait/Die and Wound/Wait Schemes Wait/die –Older transaction waits and the younger is rolled back and rescheduled Wound/wait –Older transaction rolls back the younger transaction and reschedules it

10 51 Wait/Die and Wound/Wait Concurrency Control Schemes

10 52 Concurrency Control with Optimistic Methods Optimistic approach –Based on the assumption that the majority of database operations do not conflict –Does not require locking or time stamping techniques –Transaction is executed without restrictions until it is committed –Phases are read, validation, and write

10 53 Database Recovery Management Database recovery –Restores database from a given state, usually inconsistent, to a previously consistent state –Based on the atomic transaction property All portions of the transaction must be treated as a single logical unit of work, in which all operations must be applied and completed to produce a consistent database –If transaction operation cannot be completed, transaction must be aborted, and any changes to the database must be rolled back (undone)

10 54 Transaction Recovery Makes use of deferred-write and write-through Deferred write –Transaction operations do not immediately update the physical database –Only the transaction log is updated –Database is physically updated only after the transaction reaches its commit point using the transaction log information

10 55 Transaction Recovery ( continued ) Write-through –Database is immediately updated by transaction operations during the transaction’s execution, even before the transaction reaches its commit point

10 56 A Transaction Log for Transaction Recovery Examples

10 57 Summary Transaction –Sequence of database operations that access the database –Represents real-world events –Must be a logical unit of work No portion of the transaction can exist by itself –Takes a database from one consistent state to another One in which all data integrity constraints are satisfied

10 58 Summary ( continued ) SQL provides support for transactions through the use of two statements: COMMIT and ROLLBACK Concurrency control coordinates the simultaneous execution of transactions Scheduler is responsible for establishing order in which concurrent transaction operations are executed

10 59 Summary ( continued ) Lock guarantees unique access to a data item by a transaction Database recovery restores the database from a given state to a previous consistent state