DB Goals. Concurrency Control & Recovery. Transactions. Std. example - Durability

Similar documents
CS122 Lecture 15 Winter Term,

Transaction Management & Concurrency Control. CS 377: Database Systems

CS 5614: Transaction Processing 121. Transaction = Unit of Work Recall ACID Properties (from Module 1)

The transaction. Defining properties of transactions. Failures in complex systems propagate. Concurrency Control, Locking, and Recovery

Announcements. Motivating Example. Transaction ROLLBACK. Motivating Example. CSE 444: Database Internals. Lab 2 extended until Monday

CSE 444: Database Internals. Lectures 13 Transaction Schedules

Lecture 21: Logging Schemes /645 Database Systems (Fall 2017) Carnegie Mellon University Prof. Andy Pavlo

Overview of Transaction Management

Announcements. Transaction. Motivating Example. Motivating Example. Transactions. CSE 444: Database Internals

Last Class Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications

Transaction Management. Pearson Education Limited 1995, 2005

Intro to Transaction Management

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI

) Intel)(TX)memory):) Transac'onal) Synchroniza'on) Extensions)(TSX))) Transac'ons)

In This Lecture. Transactions and Recovery. Transactions. Transactions. Isolation and Durability. Atomicity and Consistency. Transactions Recovery

What are Transactions? Transaction Management: Introduction (Chap. 16) Major Example: the web app. Concurrent Execution. Web app in execution (CS636)

Problems Caused by Failures

Introduction. Storage Failure Recovery Logging Undo Logging Redo Logging ARIES

Transaction Management: Introduction (Chap. 16)

Transactions. Kathleen Durant PhD Northeastern University CS3200 Lesson 9

CSE 190D Database System Implementation

) Intel)(TX)memory):) Transac'onal) Synchroniza'on) Extensions)(TSX))) Transac'ons)

Intro to Transactions

CSE 444: Database Internals. Lectures Transactions

Recoverability. Kathleen Durant PhD CS3200

Crash Recovery CMPSCI 645. Gerome Miklau. Slide content adapted from Ramakrishnan & Gehrke

ECE 650 Systems Programming & Engineering. Spring 2018

Transaction Processing. Introduction to Databases CompSci 316 Fall 2018

Introduction to Transaction Management

Motivating Example. Motivating Example. Transaction ROLLBACK. Transactions. CSE 444: Database Internals

) Intel)(TX)memory):) Transac'onal) Synchroniza'on) Extensions)(TSX))) Transac'ons)

Review: The ACID properties. Crash Recovery. Assumptions. Motivation. Preferred Policy: Steal/No-Force. Buffer Mgmt Plays a Key Role

Concurrency Control & Recovery

Transaction Management: Crash Recovery (Chap. 18), part 1

some sequential execution crash! Recovery Manager replacement MAIN MEMORY policy DISK

Chapter 22. Transaction Management

CS122 Lecture 19 Winter Term,

CHAPTER 3 RECOVERY & CONCURRENCY ADVANCED DATABASE SYSTEMS. Assist. Prof. Dr. Volkan TUNALI

T ransaction Management 4/23/2018 1

Topics in Reliable Distributed Systems

COURSE 1. Database Management Systems

CS5460: Operating Systems Lecture 20: File System Reliability

Database Tuning and Physical Design: Execution of Transactions

Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications. Last Class. Today s Class. Faloutsos/Pavlo CMU /615

ACID Properties. Transaction Management: Crash Recovery (Chap. 18), part 1. Motivation. Recovery Manager. Handling the Buffer Pool.

CS 4604: Introduc0on to Database Management Systems. B. Aditya Prakash Lecture #19: Logging and Recovery 1

A tomicity: All actions in the Xact happen, or none happen. D urability: If a Xact commits, its effects persist.

Carnegie Mellon Univ. Dept. of Computer Science Database Applications. General Overview NOTICE: Faloutsos CMU SCS

CAS CS 460/660 Introduction to Database Systems. Recovery 1.1

Intro to DB CHAPTER 15 TRANSACTION MNGMNT

System Malfunctions. Implementing Atomicity and Durability. Failures: Crash. Failures: Abort. Log. Failures: Media

CSE 344 MARCH 21 ST TRANSACTIONS

Transaction Management: Concurrency Control, part 2

Locking for B+ Trees. Transaction Management: Concurrency Control, part 2. Locking for B+ Trees (contd.) Locking vs. Latching

Log-Based Recovery Schemes

Outline. Failure Types

Chapter 13: Transactions

Weak Levels of Consistency

Chapter 9: Transactions

Database Recovery. Haengrae Cho Yeungnam University. Database recovery. Introduction to Database Systems

Transactions Processing (i)

Database Management Systems CSEP 544. Lecture 9: Transactions and Recovery

Transaction Management Overview. Transactions. Concurrency in a DBMS. Chapter 16

Crash Recovery Review: The ACID properties

Introduction to Transaction Management

Database Systems. Announcement

Outline. Purpose of this paper. Purpose of this paper. Transaction Review. Outline. Aries: A Transaction Recovery Method

Recovery System These slides are a modified version of the slides of the book Database System Concepts (Chapter 17), 5th Ed McGraw-Hill by

Roadmap of This Lecture

Chapter 15: Transactions

Architecture and Implementation of Database Systems (Summer 2018)

Crash Recovery. The ACID properties. Motivation

Database Management Systems 2010/11

Advanced Databases. Transactions. Nikolaus Augsten. FB Computerwissenschaften Universität Salzburg

Crash Recovery. Chapter 18. Sina Meraji

Chapter 20 Introduction to Transaction Processing Concepts and Theory

Concurrency Control & Recovery

Transaction Processing: Concurrency Control ACID. Transaction in SQL. CPS 216 Advanced Database Systems. (Implicit beginning of transaction)

References. Transaction Management. Database Administration and Tuning 2012/2013. Chpt 14 Silberchatz Chpt 16 Raghu

CSE 344 MARCH 5 TH TRANSACTIONS

Overview. Introduction to Transaction Management ACID. Transactions

Lectures 8 & 9. Lectures 7 & 8: Transactions

Atomicity: All actions in the Xact happen, or none happen. Consistency: If each Xact is consistent, and the DB starts consistent, it ends up

Transactions. Silberschatz, Korth and Sudarshan

Transactions and Concurrency Control. Dr. Philip Cannata

Transactions. Lecture 8. Transactions. ACID Properties. Transaction Concept. Example of Fund Transfer. Example of Fund Transfer (Cont.

Review: The ACID properties. Crash Recovery. Assumptions. Motivation. More on Steal and Force. Handling the Buffer Pool

Database Management Systems

Transaction Concept. Two main issues to deal with:

Chapter 17: Recovery System

CS5412: TRANSACTIONS (I)

Transaction Management Overview

RECOVERY CHAPTER 21,23 (6/E) CHAPTER 17,19 (5/E)

Database Recovery Techniques. DBMS, 2007, CEng553 1

Topics. File Buffer Cache for Performance. What to Cache? COS 318: Operating Systems. File Performance and Reliability

Chapter 14: Transactions

Transaction Processing: Concurrency Control. Announcements (April 26) Transactions. CPS 216 Advanced Database Systems

) Intel)(TX)memory):) Transac'onal) Synchroniza'on) Extensions)(TSX))) Transac'ons)

Transaction Concept. Chapter 15: Transactions. Example of Fund Transfer. ACID Properties. Example of Fund Transfer (Cont.)

3. Concurrency Control for Transactions Part One

Transcription:

DB Goals Concurrency Control & Recovery Haeder83: Theo Haerder, Andreas Reuter, ACM Computing Surveys, vol 15, no 4, Dec 1983. Concurrency Control: Individual users see consistent states Even though ops for many users may be interleaved Recovery: Database is fault-tolerant State not corrupted from software, system, media failure Why? Write apps w/out explicit concern for either All about programmer productivity, safety, etc. 2 Transactions Std. example - Durability Multiple users manipulating data safely ACID properties of a transaction Atomicity: transform is all or nothing Consistency: make only correct changes Often expressed as declarative integrity constraints Salary of grad student cannot exceed min. wage/2 Isolation: partial changes hidden from others Pretend that yours is the only Tx running Durability: committed changes survive subsequent failures AID provided by DBMS, C by programmer DB is consistent iff contents result only from successful transactions; Rest of C requires run-time triggers, etc. - ignore for now. Transfer() A_bal -= 50 Write(A, A_bal) B_bal = Read(B) If Crash: $50 disappears! B_bal += 50 Write(B, B_bal) Those are underlying ops actually performed. In SQL, could be expressed as: update accounts set balance=balance-50 where user= A update accounts set balance=balance+50 where user= B But same challenges apply... 4

Isolation ReportSum() B_bal = Read(B) printf( Riches: %d\n, A_bal + B_bal); But consider interleaving: Transfer() A_bal -= 50 Write(A, A_bal) B_bal = Read(B) B_bal += 50 Write(B, B_bal) prints $300 ReportSum() prints $250 B_bal = Read(B) printf( Riches: %d\n, A_ba + B_bal); 5 Why diff from filesystems? Both isolation and fault tolerance Most filesystems don t provide isolation App must explicitly lock/etc. Many don t provide guaranteed recovery Some - ext2 - don t even guarantee that the FS itself will be usable after a crash. (!) Powerful combination But also very complex and w/high overhead Reasonable - FS is more general, etc. And DBs let you pick... 6 Context: SQL, etc Single statements that affect multiple data objects UPDATE grades set grade=grade+1; Can be quite hairy -- conditionals, format conversion, etc. BEGIN TRANSACTION insert into grades VALUES ( dave, F ) COMMIT TRANSACTION Likely used by procedural language driving the transaction But same machinery needed to make individual statements atomic! For perf: Can often select isolation level / read-only tx Can also just LOCK TABLE (to avoid row-level locks and transaction overhead ) 7 Failures Transaction failure Code aborts, based on input/database inconsistency [programmer escapes complexity] Mechanical aborts caused by concurrency control solutions to isolation Frequent events, instant recovery needed System failure (fail-stop) DBMS bug, OS fault, HW failure: wipe out volatile memory but durable memory (disk) survives Infrequent events, minutes to recover Media failure (fail-stop) IO code bugs, disk HW failures: loss of disk info Rare events, hours to recover from checkpoints & audit logs Note not talking about corruption (

Recoverable System Model UNDO: rollback aborted transaction Transaction (transaction failure) or global (system failure) Employs short term log REDO: repeat complete transaction on old DB data Partial (system failure) or global (media failure) Employs long term history log (tape) Tools for protecting internal consistency! static mappings " if they don t change, they don t cause problems " most people don t think of this one most of the time! atomicity of writes " ala the tri-state post-write guarantee of per-sector ECC " Atomic unit often called a page by DB folk! update ordering " simply ensuring that one update propagates before another! real atomicity " ensuring that a set of updates all occur or none do 15-712, Fall 2003, Greg Ganger 10 Atomicity of writes as a tool! Unwritten guarantee provided by per-sector ECC " because the ECC check will fail if only partially written! Same trick can be used by FS or applications! Good for grouping inter-related updates " but increases likelihood of data loss due to the third state # data is lost when write is only partially completed # while uncommon, such loss is more likely than a grown defect! especially if not physically co-located " as a result, this mechanism is used for limited cases # e.g., internal consistency of directory chunks and inodes 15-712, Fall 2003, Greg Ganger 11 Update ordering as a tool! Just what it sounds like! We ve seen this a lot so far " Softupdates " B-link tree updates! Good for single-direction dependencies " just do one before the other! Problem: doesn t work for bidirectional dependencies " which, unfortunately, is most of them! Solution: some can be converted to single-direction " because some directions are more important than others ;) " clean-up must be done after system failures 15-712, Fall 2003, Greg Ganger 12

Views of the Database Current DB: on disk + memory buffers Some transactions are in flight with data and metadata changes in memory buffers that might not occur Materialized DB: crash restart before applying log processing Some logically completed changes may not be visible on disk because some memory buffers were lost Recovery: Go from materialized DB -> Current DB Physical DB: on disk All disk blocks including out-of-date blocks, incomplete data structures and free space Sequencing Views Changing non-volatile memory Modifications of current DB may cause writes to physical DB that are not part of materialized DB until pointer structs are updated, ie. propagated (like LFS updates, which learned from DB theory) Some DBs overwrite prior copes so write=propagate, but this makes changes in materialized DB non-atomic (harder to recover) Implementing atomic disk changes via non-overwrite propagation is based on writing a collection of new versions of buffer pages into free space then writing one block: a root data structure pointer, a current maximum timestamp, a pointer to the new page table, etc Stealing & Forcing Recall: Buffer manager decides to write memory pages out to disk If uncommitted Tx modifications can overwrite most recent committed item on non-vol storage: STEAL (otherwise NO-STEAL) STEAL is ugly - must UNDO NO-STEAL could require too much mem or swapping If buffer ensures all updates by Tx are reflected on nonvolatile storage b4 commit, FORCE (otherwise NO- FORCE) 15 Temporary Log Files Redundant info for coping with failure: write ahead logging On-disk temporary (write-ahead) log file contains all that is needed to transform materialized DB to current DB Memory pressure can push uncommitted dirty data to database; in overwrite DBs this requires UNDO log records (STEAL) written before propagation; in non-overwrite DBs such writes are forgotten when memory is lost Commit logically forces propagation (FORCE), but efficiency concerns cause DBs to avoid synchronous IO, instead writing REDO log records before transaction commit Point: WAL allows STEAL/NO-FORCE buffer management (asynchrony!) Log types Physical vs Logical: capture data values or operations giving values State or transition: capture full values or differences from last values Page or record: capture full page values or only the records changing

Physiological Logging Crash Recovery In practice, many systems: Log records refer to single page May reflect logical operations on page e.g., Insert would specify new value of tuple Would not specify free-space manip. or reorganization on page as a result of insert REDO logic would have to do that Tuple insert that touched multiple pages would require 1 log record for each page updated. Avoids consistency problem 17 but reducing somewhat the log size from physical logging. Checkpoint Checkpoints limit REDO processing REDO goes to beginning of log, but that can be really slow FORCE propagation = no REDO (UNDOs on pre-written pages) Transaction consistent checkpoint: Quiesce all transactions, propagate all dirty data, write log entry (long unavailability) Allows partial REDO to start here and global UNDO recovery processing to stop here Action consistent checkpoint: Quiesce transaction-caused actions (calls into DBMS), propagate all dirty data, write log entry Allows partial REDO recovery processing to start here, but UNDO may go back further to find BEGIN for oldest incomplete transaction Fuzzy checkpoints are those that propagate committed writes only to log (pointer to log address of REDO record), to reduce REDO processing on restart Notice unpropagated in successive checkpoints & propagate Comparisons

Nesting, Savepoints, Chaining Various tools for programmer convenience Nesting: embedded transactions (code reuse) outer transaction durable; abort cascades to top allows isolation for concurrent nesting Savepoints: tryagain within transaction rollback to savepoint; not durable until commit Allows partial transaction rollback Chaining: series of related transactions language trick for back2back transactions intermediate commit makes durable changes 21 Eval Taxonomy/survey paper no evaluation other than explaining tradeoffs in principle Extensive reference to implementations, but all quite old now Locking Selective Isolation Common: two-phase locking Once a transaction has released a lock, it may not obtain any additional locks Growing phase, shrinking phase Ensures serializability 2PL implemented by DBMS lock manager Grants/blocks locks Deals with deadlock Avoidance? Detection? Avoid: pre-declare locks, abort instead of block Detect: timeouts (how long???), waits-for graph cycle (abort/rollback) 23 Serializability may be too expensive Consider data analysis prog that aggregates over 1,000,000s of tuples Think Sawzall examples - approx. top-10 list One or two inconsistent views may not matter Relaxed consistency is a huge deal in many pragmatic systems see, e.g., TACT paper - tunable availability and consistency trade-offs for distributed sys. Example: Airline reservations may tolerate += 1 available seat using existing overbooking mechanisms 24

Read uncommitted No isolation! (fast & ugly) Read committed A re-read of data may see data modified since start (but those mods. only done by committed Tx) Allows DB to write committed Tx Repeatable read On re-execute query, different result set may be returned (though values the same) Allows deletes, etc. to be written 25