CSC271 Database Systems Lecture # 32.

Slides:



Advertisements
Similar presentations
Lecture plan Transaction processing Concurrency control
Advertisements

Database Systems (資料庫系統)
Concurrency Control WXES 2103 Database. Content Concurrency Problems Concurrency Control Concurrency Control Approaches.
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.
Transaction Management: Concurrency Control CS634 Class 17, Apr 7, 2014 Slides based on “Database Management Systems” 3 rd ed, Ramakrishnan and Gehrke.
TRANSACTION PROCESSING SYSTEM ROHIT KHOKHER. TRANSACTION RECOVERY TRANSACTION RECOVERY TRANSACTION STATES SERIALIZABILITY CONFLICT SERIALIZABILITY VIEW.
Principles of Transaction Management. Outline Transaction concepts & protocols Performance impact of concurrency control Performance tuning.
Lock-Based Concurrency Control
Transaction Management Transparencies
Lecture 11 Recoverability. 2 Serializability identifies schedules that maintain database consistency, assuming no transaction fails. Could also examine.
Sekolah Tinggi Ilmu Statistik (STIS) 1 Dr. Said Mirza Pahlevi, M.Eng.
Data and Database Administration Chapter 12. Outline What is Concurrency Control? Background Serializability  Locking mechanisms.
Lecture 5. Some solutions on the written examination: Primary key: Unique identifier for each row in a table. Not allowed to be null. Cascade update:
Transaction Management and Concurrency Control
1 Minggu 8, Pertemuan 16 Transaction Management (cont.) Matakuliah: T0206-Sistem Basisdata Tahun: 2005 Versi: 1.0/0.0.
Manajemen Basis Data Pertemuan 6 Matakuliah: M0264/Manajemen Basis Data Tahun: 2008.
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
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
1 Minggu 8, Pertemuan 15 Transaction Management Matakuliah: T0206-Sistem Basisdata Tahun: 2005 Versi: 1.0/0.0.
Chapter 9 Transaction Management and Concurrency Control
9 Chapter 9 Transaction Management and Concurrency Control Hachim Haddouti.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 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.
DBSQL 7-1 Copyright © Genetic Computer School 2009 Chapter 7 Transaction Management, Database Security and Recovery.
1 Chapter 6 : Transaction Management Pearson Education © 2009.
Transaction Processing Concepts
Security and Transaction Nhi Tran CS 157B - Dr. Lee Fall, 2003.
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 10 Transaction Management.
Chapterb19 Transaction Management Transaction: An action, or series of actions, carried out by a single user or application program, which reads or updates.
Databases Illuminated
Transaction Support Chapter 9. Transaction  Transaction  An action or series of actions, carried out by a single user or application program, which.
Lecture 12 Recoverability and failure. 2 Optimistic Techniques Based on assumption that conflict is rare and more efficient to let transactions proceed.
Transaction Management, Concurrency Control and Recovery Chapter 20 1.
1 Chapter 20 Transaction Management Transparencies Last Updated: 17 th March 2011 By M. Arief
Transactions CPSC 356 Database Ellen Walker Hiram College (Includes figures from Database Systems by Connolly & Begg, © Addison Wesley 2002)
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.
7c.1 Silberschatz, Galvin and Gagne ©2003 Operating System Concepts with Java Module 7c: Atomicity Atomic Transactions Log-based Recovery Checkpoints Concurrent.
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.
1 Advanced Database Concepts Transaction Management and Concurrency 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.
3 Database Systems: Design, Implementation, and Management CHAPTER 9 Transaction Management and Concurrency Control.
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.
SYSTEMS IMPLEMENTATION TECHNIQUES TRANSACTION PROCESSING DATABASE RECOVERY DATABASE SECURITY CONCURRENCY CONTROL.
Lecture 3 Concurrency control techniques
Transaction Management and Concurrency Control
Transaction Management Transparencies
Transaction Management
Transaction Properties
Concurrency.
Chapter 10 Transaction Management and Concurrency Control
Concurrency Control WXES 2103 Database.
Transaction Management, Concurrency Control and Recovery
Database Security Transactions
Introduction of Week 13 Return assignment 11-1 and 3-1-5
Transaction management
Presentation transcript:

CSC271 Database Systems Lecture # 32

Summary: Previous Lecture Database security Countermeasure: computer-based controls DBMSs and web security Transaction management Transaction Properties of transaction

Components of DBMS

Components of Database Manager

DBMS Transaction Subsystem

Objective of Database A major objective in developing a database is to enable many users to access shared data concurrently Concurrent access is relatively easy if all users are only reading data, as there is no way that they can interfere with one another However, when two or more users are accessing the database simultaneously and at least one is updating data, there may be interference that can result in inconsistencies

Concurrency Control The process of managing simultaneous operations on the database without having them interfere with one another Prevents interference when two or more users are accessing database simultaneously and at least one is updating data Although two transactions may be correct in themselves, interleaving of operations may produce an incorrect result

Need for Concurrency Control Three examples of potential problems caused by concurrency: Lost update problem Uncommitted dependency problem Inconsistent analysis problem

Lost Update Problem Successfully completed update is overridden by another user T1 withdrawing £10 from an account with balx, initially £100 T2 depositing £100 into same account Serially, final balance would be £190

Lost Update Problem The loss of T2’s update is avoided by preventing T1 from reading the value of balx until after T2’s update has been completed

Uncommitted Dependency Problem Also called dirty read problem This problem occurs when one transaction can see intermediate results of another transaction before it has committed T4 updates balx to £200 but it aborts, so balx should be back at original value of £100 T3 has read new value of balx (£200) and uses value as basis of £10 reduction, giving a new balance of £190, instead of £90

Uncommitted Dependency Problem

Uncommitted Dependency Problem The uncommitted dependency (dirty read) problem is avoided by preventing T3 from reading balx until after the decision has been made to either commit or abort T4’s effects The two problems in these examples concentrate on transactions that are updating the database and their interference may corrupt the database However, transactions that only read the database can also produce inaccurate results if they are allowed to read partial results of incomplete transactions that are simultaneously updating the database

Inconsistent Analysis Problem Occurs when transaction reads several values but second transaction updates some of them during execution of first T6 is totaling balances of account x (£100), account y (£50), and account z (£25) Meantime, T5 has transferred £10 from balx to balz, so T6 now has wrong result (£10 too high)

Inconsistent Analysis Problem

Inconsistent Analysis Problem This problem is avoided by preventing transaction T6 from reading balx and balz until after T5 has completed its updates

Some Other Problems Non-repeatable (or fuzzy) Read Phantom Read When a transaction T rereads a data item it has previously read but, in between, another transaction has modified it. Thus, T receives two different values for the same data item Phantom Read Transaction T executes a query that retrieves a set of tuples from a relation satisfying a certain predicate, re-executes the query at a later time but finds that the retrieved set contains an additional (phantom) tuple that has been inserted by another transaction in the meantime

Serializability Objective of a concurrency control protocol is to schedule transactions in such a way as to avoid any interference Could run transactions serially, but this limits degree of concurrency or parallelism in system Serializability identifies those executions of transactions guaranteed to ensure consistency

Serializability Schedule Serial Schedule Sequence of reads/writes by set of concurrent transactions Serial Schedule Schedule where operations of each transaction are executed consecutively without any interleaved operations from other transactions No guarantee that results of all serial executions of a given set of transactions will be identical

Serializability Non-serial Schedule Schedule where operations from set of concurrent transactions are interleaved Objective of serializability is to find non-serial schedules that allow transactions to execute concurrently without interfering with one another, and thereby produce a database state that could be produced by a serial execution

Serializability If a set of transactions executes concurrently, we say that the (non-serial) schedule is correct if it produces the same results as some serial execution Such a schedule is called serializable

Serializability In serializability, the ordering of read and write operations is important: If two transactions only read a data item, they do not conflict and order is not important If two transactions either read or write completely separate data items, they do not conflict and order is not important If one transaction writes a data item and another either reads or writes the same data item, the order of execution is important

Conflict Serializability

Conflict Serializability A conflict serializable schedule orders any conflicting operations in the same way as some serial execution

Concurrency Control Techniques Conservative (or pessimistic) Methods They cause transactions to be delayed in case they conflict with other transactions at some time in the future e.g. locking, timestamping etc. Optimistic Methods Based on the premise that conflict is rare so they allow transactions to proceed unsynchronized and only check for conflicts at the end, when a transaction commits

Concurrency Control Techniques Locking A procedure used to control concurrent access to data When one transaction is accessing the database, a lock may deny access to other transactions to prevent incorrect results Most widely used approach to ensure serializability Generally, a transaction must claim a shared (read) or exclusive (write) lock on a data item before the corresponding database read or write operation

Concurrency Control Techniques If a transaction has a shared lock on a data item, it can read the item but not update it If a transaction has an exclusive lock on a data item, it can both read and update the item Since read operations cannot conflict, it is permissible for more than one transaction to hold shared locks simultaneously on the same item On the other hand, an exclusive lock gives a transaction exclusive access to that item Some systems allow transaction to upgrade read lock to an exclusive lock, or downgrade exclusive lock to a shared lock

Concurrency Control Techniques Locks are used in the following way: Any transaction that needs to access a data item must first lock the item, shared or an exclusive lock If the item is not already locked, the lock will be granted If the item is currently locked (shared), shared lock request will be granted; otherwise, the transaction must wait until the existing lock is released A transaction continues to hold a lock until it explicitly releases it either during execution or when it terminates (aborts or commits) It is only when the exclusive lock has been released that the effects of the write operation will be made visible to other transactions

Concurrency Control Techniques

Example: Incorrect Locking Schedule Using locks in transactions, does not guarantee serializability of schedules by themselves For two transactions (T9, T10), a valid schedule using these rules is: S = {write_lock(T9, balx), read(T9, balx), write(T9, balx), unlock(T9, balx), write_lock(T10, balx), read(T10, balx), write(T10, balx), unlock(T10, balx), write_lock(T10, baly), read(T10, baly), write(T10, baly), unlock(T10, baly), commit(T10), write_lock(T9, baly), read(T9, baly), write(T9, baly), unlock(T9, baly), commit(T9) }

Example: Incorrect Locking Schedule If at start, balx = 100, baly = 400, result should be: balx = 220, baly = 330, if T9 executes before T10, or balx = 210, baly = 340, if T10 executes before T9 However, result gives balx = 220 and baly = 340 S is not a serializable schedule

Example: Incorrect Locking Schedule Problem is that transactions release locks too soon, resulting in loss of total isolation and atomicity To guarantee serializability, need an additional protocol concerning the positioning of lock and unlock operations in every transaction

Two-Phase Locking (2PL) Transaction follows 2PL protocol if all locking operations precede first unlock operation in the transaction Two phases for transaction: Growing phase: acquires all locks but cannot release any locks Shrinking phase: releases locks but cannot acquire any new locks

Preventing Lost Update Problem using 2PL

Preventing Uncommitted Dependency Problem using 2PL

Preventing Inconsistent Analysis Problem using 2PL

Deadlock An impasse that may result when two (or more) transactions are each waiting for locks held by the other to be released Only one way to break deadlock, abort one or more of the transactions Deadlock should be transparent to user, so DBMS should restart transaction(s) Three general techniques for handling deadlock: Timeouts Deadlock prevention Deadlock detection and recovery

Timestamping A concurrency control protocol that orders transactions in such a way that older transactions, transactions with smaller timestamps, get priority in the event of conflict Conflict is resolved by rolling back and restarting transaction No locks so no deadlock

Database Recovery The process of restoring the database to a correct state in the event of a failure Need for Recovery Control Two types of storage: volatile (main memory) and nonvolatile Volatile storage does not survive system crashes Stable storage represents information that has been replicated in several nonvolatile storage media with independent failure modes

Types of Failures System crashes due to hardware or software errors, resulting in loss of main memory Media failures, such as head crashes or unreadable media, resulting in the loss of parts of secondary storage Application software errors, such as logical errors in the program that is accessing the database, which cause one or more transactions to fail Natural physical disasters, such as fires, floods, earthquakes, or power failures Carelessness or unintentional destruction of data or facilities by operators or users Sabotage, or intentional corruption or destruction of data, hardware, or software facilities

Recovery Facilities A DBMS should provide the following facilities to assist with recovery: A backup mechanism, which makes periodic backup copies of the database Logging facilities, which keep track of the current state of transactions and database changes A checkpoint facility, which enables updates to the database that are in progress to be made permanent A recovery manager, which allows the system to restore the database to a consistent state following a failure

Main Recovery Techniques Three main recovery techniques: Deferred Update Immediate Update Shadow Paging

Summary Concurrency control Database recovery

References All the material (slides, diagrams etc.) presented in this lecture is taken (with modifications) from the Pearson Education website : http://www.booksites.net/connbegg