CMPT 401 Summer 2007 Dr. Alexandra Fedorova Lecture X: Transactions.

Slides:



Advertisements
Similar presentations
Lecture plan Transaction processing Concurrency control
Advertisements

Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 16.
IDA / ADIT Lecture 10: Database recovery Jose M. Peña
CSC271 Database Systems Lecture # 32.
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.
1 CSIS 7102 Spring 2004 Lecture 8: Recovery (overview) Dr. King-Ip Lin.
Jinze Liu. Have studied C.C. mechanisms used in practice - 2 PL - Multiple granularity - Tree (index) protocols - Validation.
Recovery CPSC 356 Database Ellen Walker Hiram College (Includes figures from Database Systems by Connolly & Begg, © Addison Wesley 2002)
Database Systems, 8 th Edition Concurrency Control with Time Stamping Methods Assigns global unique time stamp to each transaction Produces explicit.
Jan. 2014Dr. Yangjun Chen ACS Database recovery techniques (Ch. 21, 3 rd ed. – Ch. 19, 4 th and 5 th ed. – Ch. 23, 6 th ed.)
CMPT Dr. Alexandra Fedorova Lecture X: Transactions.
Crash Recovery. Review: The ACID properties A A tomicity: All actions in the Xaction happen, or none happen. C C onsistency: If each Xaction is consistent,
Transaction Management and Concurrency Control
Quick Review of May 1 material Concurrent Execution and Serializability –inconsistent concurrent schedules –transaction conflicts serializable == conflict.
Transaction Management and Concurrency Control
Persistent State Service 1 Distributed Object Transactions  Transaction principles  Concurrency control  The two-phase commit protocol  Services for.
1 Transaction Management Overview Yanlei Diao UMass Amherst March 15, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
Chapter 17: Transaction Management
Chapter 19 Database Recovery Techniques. Slide Chapter 19 Outline Databases Recovery 1. Purpose of Database Recovery 2. Types of Failure 3. Transaction.
Transaction Management
1 Transaction Management Database recovery Concurrency control.
DBMS Functions Data, Storage, Retrieval, and Update
©Silberschatz, Korth and Sudarshan17.1Database System Concepts Chapter 17: Recovery System Failure Classification Storage Structure Recovery and Atomicity.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
CMPT Dr. Alexandra Fedorova Lecture XI: Distributed Transactions.
TRANSACTION PROCESSING TECHNIQUES BY SON NGUYEN VIJAY RAO.
CMPT Dr. Alexandra Fedorova Lecture XI: Distributed Transactions.
Transactions and Recovery
Distributed Deadlocks and Transaction Recovery.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 16.
1 Chapter 6 : Transaction Management Pearson Education © 2009.
1 Transaction Management Overview Chapter Transactions  Concurrent execution of user programs is essential for good DBMS performance.  Because.
Database Management Systems, 2 nd Edition. R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 18.
08_Transactions_LECTURE2 DBMSs should guarantee ACID properties (Atomicity, Consistency, Isolation, Durability). This is typically done by guaranteeing.
Data Concurrency Control And Data Recovery
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
Lecture 12 Recoverability and failure. 2 Optimistic Techniques Based on assumption that conflict is rare and more efficient to let transactions proceed.
Database Systems/COMP4910/Spring05/Melikyan1 Transaction Management Overview Unit 2 Chapter 16.
1 Chapter 20 Transaction Management Transparencies Last Updated: 17 th March 2011 By M. Arief
1 Transaction Management Overview Chapter Transactions  Concurrent execution of user programs is essential for good DBMS performance.  Because.
Chapter 16 Recovery Yonsei University 1 st Semester, 2015 Sanghyun Park.
II.I Selected Database Issues: 2 - Transaction ManagementSlide 1/20 1 II. Selected Database Issues Part 2: Transaction Management Lecture 4 Lecturer: Chris.
Transactions and Concurrency Control. Concurrent Accesses to an Object Multiple threads Atomic operations Thread communication Fairness.
Chapter 10 Recovery System. ACID Properties  Atomicity. Either all operations of the transaction are properly reflected in the database or none are.
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 Transparencies. ©Pearson Education 2009 Chapter 14 - Objectives Function and importance of transactions. Properties of transactions.
Chapter 17: Recovery System
Database System Concepts ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 17: Recovery System.
NOEA/IT - FEN: Databases/Transactions1 Transactions ACID Concurrency Control.
Lecture 8 Transactions & Concurrency UFCE8K-15-M: Data Management.
Motivation for Recovery Atomicity: –Transactions may abort (“Rollback”). Durability: –What if DBMS stops running? (Causes?) crash! v Desired Behavior after.
SYSTEMS IMPLEMENTATION TECHNIQUES TRANSACTION PROCESSING DATABASE RECOVERY DATABASE SECURITY CONCURRENCY CONTROL.
Database recovery techniques
Database Recovery Techniques
File Processing : Recovery
Transaction Management Transparencies
Transaction Management
Chapter 10 Transaction Management and Concurrency Control
Recovery System.
Introduction of Week 13 Return assignment 11-1 and 3-1-5
Database Recovery 1 Purpose of Database Recovery
SE305 Database System Technology
Transaction Communication
Transactions, Properties of Transactions
Presentation transcript:

CMPT 401 Summer 2007 Dr. Alexandra Fedorova Lecture X: Transactions

2 CMPT 401 Summer 2007 © A. Fedorova Transactions A transaction is a collection of actions logically belonging together To the outside world, a transaction must appear as a single indivisible operation

3 CMPT 401 Summer 2007 © A. Fedorova Use of Transactions In Distributed Systems Correct concurrent operations –Example: updating the bank account [1] Read the current balance in the account [2] Compute the new balance [3] Update the database to record the new balance –On concurrent access, operations done by multiple threads may interleave –This leads to incorrect operation –Transactions ensure proper operation Masking failures –In a replicated bank database – the account is updated at two sites –One site is updated, the other one crashes before the update is complete –The system’s state is inconsistent –Transactions ensure proper recovery

4 CMPT 401 Summer 2007 © A. Fedorova ACID Properties of Transactions Atomicity – transaction is indivisible – it completes entirely or not at all, despite failures Consistency –system rules (invariants) are maintained despite crashes or concurrent access Isolation – transactions appear indivisible to each other despite concurrent access –If multiple threads execute transactions the effect is the same as if transactions were executed sequentially in some order Durability – effects of committed transactions are very likely to survive subsequent failures

5 CMPT 401 Summer 2007 © A. Fedorova Maintaining ACID Properties To maintain ACID properties, transaction processing systems must implement: –Concurrency control (Isolation, Consistency) –Failure Recovery (Atomicity, Durability)

6 CMPT 401 Summer 2007 © A. Fedorova Concurrency Control Implemented using locks (or other synchronization primitives) A naïve approach: one global lock – no transactions can proceed simultaneously. Horrific performance A better approach: associate a lock with each data item (or group of items) Acquire locks on items used in transactions Turns out how you acquire locks is very important

7 CMPT 401 Summer 2007 © A. Fedorova Concurrency Control Transaction 1 lock(x) update (x) unlock (x) … abort Transaction 2 … lock(x) read(x) unlock (x) commit saw inconsistent data!

8 CMPT 401 Summer 2007 © A. Fedorova Strict Two-Phase Locking Phase 1: A transaction can acquire locks, but cannot release locks Phase 2: A transaction releases locks at the end – when it aborts or commits Non-strict two-phase locking allows releasing locks before the end of the transaction, but after the transaction acquired all the locks it needed Non-strict two-phase locking is often impractical, because: –We do not know when the transaction has acquired all its locks – lock acquisition is data dependent –Cascading aborts: early lock release requires aborting all transactions that saw inconsistent data “If I tell you this, I’ll have to kill you”

9 CMPT 401 Summer 2007 © A. Fedorova Deadlock When we acquire more than one lock at once we are prone to deadlocks Techniques against deadlocks: –Prevention –Avoidance –Detection –… just like hear disease Prevention: lock ordering. Downside: may limit concurrency. Locks are held longer than necessary Avoidance: if a transaction waited for a lock for too long, abort the transaction. Downside: transactions are aborted unnecessarily Detection: wait-for graph (WFG) – who waits for whom. If there is a cycle, abort a transaction in a cycle. Downside: constructing WFGs is expensive in distributed systems.

10 CMPT 401 Summer 2007 © A. Fedorova Maintaining ACID Properties To maintain ACID properties, transaction processing systems must implement: –Concurrency control (Isolation, Consistency) –Failure Recovery (Atomicity, Durability)

11 CMPT 401 Summer 2007 © A. Fedorova Types of Failures Transaction abort – to resolve deadlock or as requested by the client Crash – loss of system memory state. Disk (or other non- volatile storage) is kept intact Disk failure Catastrophic failure – memory, disk and backup copies all disappear We will discuss these in detail

12 CMPT 401 Summer 2007 © A. Fedorova Abort Recovery Accomplished using transactional log Log is used to “remember” the state of the system in case recovery is needed How log is used depends on update semantics: –In-place updates (right away) –Deferred updates (at the end of transaction)

13 CMPT 401 Summer 2007 © A. Fedorova Abort Recovery For In-Place Updates We will show how –Database operation are enhanced with logging –How log records are used for recovery Update: record an undo record (e.g., the old value of the item being updated) in an undo log, and update the database Read: simply read the data from the database Commit: discard the transaction’s undo log Abort: Use the undo records in the log to back out the updates

14 CMPT 401 Summer 2007 © A. Fedorova Abort Recovery For Deferred Updates Update: Record a redo record (e.g., the new value of the item being updated) in a redo log Read: combine the redo log and the database to determine the desired data Commit: Update the database by applying the redo log in order Abort: Discard the transaction’s redo log

15 CMPT 401 Summer 2007 © A. Fedorova Crash Recovery A crash may leave the database inconsistent –The database may contain data from uncommitted or aborted transactions –The database may lack updates from committed transactions After the crash we would like –Remove data from uncommitted or aborted transactions –Re-apply updates from committed transactions We rely on log to perform the recovery. Log contains records of all operations –Undo records for updates – use them to remove data from uncommitted or aborted transactions –Commit records – use them to re-apply data from committed transactions

16 CMPT 401 Summer 2007 © A. Fedorova Crash Recovery After system reboots from crash: –Redo all updates for committed transactions (use commit records). Redo records must be idempotent, in case we crash during recovery –Undo all updates for aborted or uncommitted transactions (use undo records) What if the client committed transaction, but the system crashed before “commit” log record made it to disk? –Redo rule: We must flush the commit record to disk before telling the client that transaction is committed What if an update was written to database before the undo record was written to log? –Write-ahead log rule: A undo record must be flushed to disk before the corresponding update is reflected in the database

17 CMPT 401 Summer 2007 © A. Fedorova Performance Considerations: Disk Access Each transaction necessarily involves disk access (expensive) To reduce performance costs, log is kept on a separate disk than database Log is written sequentially under normal operation Sequential writes are fast Database is updated asynchronously, so it’s not a performance bottleneck

18 CMPT 401 Summer 2007 © A. Fedorova Performance Considerations: Log Size Log will keep on growing forever… To prevent this, we use checkpoints If the data has been flushed to the database disk, discard corresponding commit records For each transaction, keep a log sequence number (LSN) In the checkpoint record, record the smallest LSN of all active transactions Discard undo records with LSN below the current smallest LSN

19 CMPT 401 Summer 2007 © A. Fedorova Summary Transactions are used for concurrent operations and for masking failures ACID properties: –Atomicity –Consistency –Isolation –Durability To maintain these properties, databases implement: –Concurrency control (two-phase locking, deadlock resolution) –Failure recovery (logging, redo/undo)