Introduction to Database Systems CSE 444. Lecture 11 Transactions: concurrency control (part 1)

Similar documents
Course Content. Transactions and Concurrency Control. Objectives of Lecture 4 Transactions and Concurrency Control

Concurrency Control: Locking, Optimistic, Degrees of Consistency

Concurrency Control. Module 6, Lectures 1 and 2

Textbook and References

Transaction Management Overview

Transactions and Recovery. Database Systems Lecture 15 Natasha Alechina

Module 3 (14 hrs) Transactions : Transaction Processing Systems(TPS): Properties (or ACID properties) of Transactions Atomicity Consistency

Lecture 7: Concurrency control. Rasmus Pagh

Homework 8. Revision : 2015/04/14 08:13

Transactions and Concurrency Control. Goals. Database Administration. (Manga Guide to DB, Chapter 5, pg , ) Database Administration

Transactions. SET08104 Database Systems. Napier University

Database Tuning and Physical Design: Execution of Transactions

Goals. Managing Multi-User Databases. Database Administration. DBA Tasks. (Kroenke, Chapter 9) Database Administration. Concurrency Control

Concurrency control. Concurrency problems. Database Management System

Concurrency Control. Chapter 17. Comp 521 Files and Databases Fall

Roadmap DB Sys. Design & Impl. Detailed Roadmap. Paper. Transactions - dfn. Reminders: Locking and Consistency

2 nd Semester 2008/2009

Chapter 15: Recovery System

Transactions and the Internet

Transactional properties of DBS

Introduction to Database Systems. Module 1, Lecture 1. Instructor: Raghu Ramakrishnan UW-Madison

Review: The ACID properties

Transactions: Definition. Transactional properties of DBS. Transactions: Management in DBS. Transactions: Read/Write Model

Figure 19.1 Interleaved processing versus parallel processing of concurrent transactions.

In This Lecture. More Concurrency. Deadlocks. Precedence/Wait-For Graphs. Example. Example

(Pessimistic) Timestamp Ordering. Rules for read and write Operations. Pessimistic Timestamp Ordering. Write Operations and Timestamps

How To Write A Transaction System

Recovery Theory. Storage Types. Failure Types. Theory of Recovery. Volatile storage main memory, which does not survive crashes.

Database Concurrency Control and Recovery. Simple database model

Database Sample Examination

Distributed Transactions

Chapter 10. Backup and Recovery

Transaction Processing Monitors

CHAPTER 6: DISTRIBUTED FILE SYSTEMS

THE UNIVERSITY OF TRINIDAD & TOBAGO

Introduction to Database Systems CS4320. Instructor: Christoph Koch CS

Chapter 3 - Data Replication and Materialized Integration

Week 1 Part 1: An Introduction to Database Systems. Databases and DBMSs. Why Use a DBMS? Why Study Databases??

Chapter 10: Distributed DBMS Reliability

b. Examine the following histories. Draw their serialization graph and identify which of them is serializable given reasons.

Recovery and the ACID properties CMPUT 391: Implementing Durability Recovery Manager Atomicity Durability

DATABASE MANAGEMENT SYSTEMS. Question Bank:

Comp 5311 Database Management Systems. 16. Review 2 (Physical Level)

Database Management System Prof. D. Janakiram Department of Computer Science & Engineering Indian Institute of Technology, Madras Lecture No.

PostgreSQL Concurrency Issues

Topics. Introduction to Database Management System. What Is a DBMS? DBMS Types

Ph.D. Thesis Proposal Database Replication in Wide Area Networks

Serializable Isolation for Snapshot Databases

Chapter 6 The database Language SQL as a tutorial

Big Data Management and NoSQL Databases

OS OBJECTIVE QUESTIONS

Hagit Attiya and Eshcar Hillel. Computer Science Department Technion

The ConTract Model. Helmut Wächter, Andreas Reuter. November 9, 1999

INTRODUCTION TO DATABASE SYSTEMS

Distributed Databases

Lesson 12: Recovery System DBMS Architectures

Module 8: Server Management

CMSC724: Concurrency

Entangled Transactions. Nitin Gupta, Milos Nikolic, Sudip Roy, Gabriel Bender, Lucja Kot, Johannes Gehrke, Christoph Koch

Recovery: Write-Ahead Logging

Synchronization and recovery in a client-server storage system

! Volatile storage: ! Nonvolatile storage:

Introduction to Database Management Systems

CS 245 Final Exam Winter 2013

Recovery algorithms are techniques to ensure transaction atomicity and durability despite failures. Two main approaches in recovery process

Data Management in the Cloud

Distributed Versioning: Consistent Replication for Scaling Back end Databases of Dynamic Content Web Sites

Failure Recovery Himanshu Gupta CSE 532-Recovery-1

Concurrent VSAM Access for Batch and CICS: A white paper series

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

Generalized Isolation Level Definitions

Low Overhead Concurrency Control for Partitioned Main Memory Databases

VALLIAMMAI ENGNIEERING COLLEGE SRM Nagar, Kattankulathur

Chapter 14: Recovery System

Cost-Based Adaptive Concurrency Control in the Cloud

Information Systems. Computer Science Department ETH Zurich Spring 2012

Transaction Management in Distributed Database Systems: the Case of Oracle s Two-Phase Commit

Sign-up Tool User Manual

Redo Recovery after System Crashes

How To Recover From Failure In A Relational Database System

The first time through running an Ad Hoc query or Stored Procedure, SQL Server will go through each of the following steps.

Chapter 5. Foundations of of Information Systems Systems (WS (WS 2008/09) Database Management Systems. Database Management Systems

Logistics. Database Management Systems. Chapter 1. Project. Goals for This Course. Any Questions So Far? What This Course Cannot Do.

SSC - Concurrency and Multi-threading Java multithreading programming - Synchronisation (I)

Administração e Optimização de BDs 2º semestre

Geo-Replication in Large-Scale Cloud Computing Applications

Post-Intrusion Recovery Using Data Dependency Approach

System model. Section 7.1. Operating Systems: Deadlock p. 1/15

Recovery: An Intro to ARIES Based on SKS 17. Instructor: Randal Burns Lecture for April 1, 2002 Computer Science Johns Hopkins University

Database Replication with Oracle 11g and MS SQL Server 2008

Chapter 16: Recovery System

CAP Theorem and Distributed Database Consistency. Syed Akbar Mehdi Lara Schmidt

Today. Intro to real-time scheduling Cyclic executives. Scheduling tables Frames Frame size constraints. Non-independent tasks Pros and cons

Universiteit Twente. Design of an object-oriented framework for atomic transactions

A Hybrid Approach to. Concurrency Control for Object-Oriented. Database Systems. Ye-In Chang, Chung-Che Wu and Hsing-Yen Ann

Consistency Management for Multiple Perspective Software Development

New method for data replication in distributed heterogeneous database systems

Issues in Designing Concurrency Control Techniques for Mobile Ad-hoc Network Databases

Storage Class Extensibility in the Brown Object Storage System

TRANSACÇÕES. PARTE I (Extraído de SQL Server Books Online )

Transcription:

Introduction to Database Systems CSE 444 Lecture 11 Transactions: concurrency control (part 1) CSE 444 - Spring 2009

Outline Serial and Serializable Schedules (18.1) Conflict Serializability (18.2) Locks (18.3) CSE 444 - Spring 2009 2

The Problem Multiple transactions are running concurrently T 1, T 2, They read/write some common elements A 1, A 2, How can we prevent unwanted interference? The SCHEDULER is responsible for that CSE 444 - Spring 2009 3

Some Famous Anomalies What could go wrong if we didn t have concurrency control: Dirty reads (including inconsistent reads) Unrepeatable reads Lost updates Many other things can go wrong too CSE 444 - Spring 2009 4

Dirty Reads Write-Read Conflict T 1 : WRITE(A) T 2 : READ(A) T 1 : ABORT CSE 444 - Spring 2009 5

Inconsistent Read Write-Read Conflict T 1 : A := 20; B := 20; T 1 : WRITE(A) T 1 : WRITE(B) T 2 : READ(A); T 2 : READ(B); CSE 444 - Spring 2009 6

Unrepeatable Read Read-Write Conflict T 1 : WRITE(A) T 2 : READ(A); T 2 : READ(A); CSE 444 - Spring 2009 7

Lost Update Write-Write Conflict T 1 : READ(A) T 1 : A := A+5 T 1 : WRITE(A) T 2 : READ(A); T 2 : A := A*1.3 T 2 : WRITE(A); CSE 444 - Spring 2009 8

Schedules Given multiple transactions A schedule is a sequence of interleaved actions from all transactions CSE 444 - Spring 2009 9

Example T1 T2 READ(A, t) READ(A, s) t := t+100 s := s*2 WRITE(A, t) WRITE(A,s) READ(B, t) READ(B,s) t := t+100 s := s*2 WRITE(B,t) WRITE(B,s) CSE 444 - Spring 2009 10

A Serial Schedule T1 READ(A, t) t := t+100 WRITE(A, t) READ(B, t) t := t+100 WRITE(B,t) T2 READ(A,s) s := s*2 WRITE(A,s) READ(B,s) s := s*2 WRITE(B,s) CSE 444 - Spring 2009 11

Serializable Schedule A schedule is serializable if it is equivalent to a serial schedule CSE 444 - Spring 2009 12

A Serializable Schedule T1 READ(A, t) t := t+100 WRITE(A, t) READ(B, t) t := t+100 WRITE(B,t) Notice: This is NOT a serial schedule T2 READ(A,s) s := s*2 WRITE(A,s) READ(B,s) s := s*2 WRITE(B,s) CSE 444 - Spring 2009 13

A Non-Serializable Schedule T1 READ(A, t) t := t+100 WRITE(A, t) READ(B, t) t := t+100 WRITE(B,t) T2 READ(A,s) s := s*2 WRITE(A,s) READ(B,s) s := s*2 WRITE(B,s) CSE 444 - Spring 2009 14

Ignoring Details Sometimes transactions actions can commute accidentally because of specific updates Serializability is undecidable! Scheduler should not look at transaction details Assume worst case updates Only care about reads r(a) and writes w(a) Not the actual values involved CSE 444 - Spring 2009 15

Notation T 1 : r 1 (A); w 1 (A); r 1 (B); w 1 (B) T 2 : r 2 (A); w 2 (A); r 2 (B); w 2 (B) CSE 444 - Spring 2009 16

Conflict Serializability Conflicts: Two actions by same transaction T i : r i (X); w i (Y) Two writes by T i, T j to same element w i (X); w j (X) w i (X); r j (X) Read/write by T i, T j to same element r i (X); w j (X) CSE 444 - Spring 2009 17

Conflict Serializability A schedule is conflict serializable if it can be transformed into a serial schedule by a series of swappings of adjacent non-conflicting actions Example: r 1 (A); w 1 (A); r 2 (A); w 2 (A); r 1 (B); w 1 (B); r 2 (B); w 2 (B) r 1 (A); w 1 (A); r 1 (B); w 1 (B); r 2 (A); w 2 (A); r 2 (B); w 2 (B) CSE 444 - Spring 2009 18

The Precedence Graph Test Is a schedule conflict-serializable? Simple test: Build a graph of all transactions T i Edge from T i to T j if T i makes an action that conflicts with one of T j and comes first The test: if the graph has no cycles, then it is conflict serializable! CSE 444 - Spring 2009 19

Example 1 r 2 (A); r 1 (B); w 2 (A); r 3 (A); w 1 (B); w 3 (A); r 2 (B); w 2 (B) B A 1 2 3 This schedule is conflict-serializable CSE 444 - Spring 2009 20

Example 2 r 2 (A); r 1 (B); w 2 (A); r 2 (B); r 3 (A); w 1 (B); w 3 (A); w 2 (B) B 1 A B 2 3 This schedule is NOT conflict-serializable CSE 444 - Spring 2009 21

Conflict Serializability A serializable schedule need not be conflict serializable, even under the worst case update assumption Lost write w 1 (Y); w 2 (Y); w 2 (X); w 1 (X); w 3 (X); w 1 (Y); w 1 (X); w 2 (Y); w 2 (X); w 3 (X); Equivalent, but can t swap CSE 444 - Spring 2009 22

Scheduler The scheduler is the module that schedules the transaction s actions, ensuring serializability How? We discuss three techniques in class: Locks Time stamps (next lecture) Validation (next lecture) CSE 444 - Spring 2009 23

Locking Scheduler Simple idea: Each element has a unique lock Each transaction must first acquire the lock before reading/writing that element If the lock is taken by another transaction, then wait The transaction must release the lock(s) CSE 444 - Spring 2009 24

Notation l i (A) = transaction T i acquires lock for element A u i (A) = transaction T i releases lock for element A CSE 444 - Spring 2009 25

Example T1 L 1 (A); READ(A, t) t := t+100 WRITE(A, t); U 1 (A); L 1 (B) READ(B, t) t := t+100 WRITE(B,t); U 1 (B); T2 L 2 (A); READ(A,s) s := s*2 WRITE(A,s); U 2 (A); L 2 (B); DENIED GRANTED; READ(B,s) s := s*2 WRITE(B,s); U 2 (B); Scheduler has ensured a conflict-serializable schedule 26

T1 L 1 (A); READ(A, t) t := t+100 WRITE(A, t); U 1 (A); L 1 (B); READ(B, t) t := t+100 WRITE(B,t); U 1 (B); Example T2 L 2 (A); READ(A,s) s := s*2 WRITE(A,s); U 2 (A); L 2 (B); READ(B,s) s := s*2 WRITE(B,s); U 2 (B); Locks did not enforce conflict-serializability!!! 27

Two Phase Locking (2PL) The 2PL rule: In every transaction, all lock requests must preceed all unlock requests This ensures conflict serializability! (why?) CSE 444 - Spring 2009 28

Example: 2PL transactions T1 L 1 (A); L 1 (B); READ(A, t) t := t+100 WRITE(A, t); U 1 (A) READ(B, t) t := t+100 WRITE(B,t); U 1 (B); T2 L 2 (A); READ(A,s) s := s*2 WRITE(A,s); L 2 (B); DENIED GRANTED; READ(B,s) s := s*2 WRITE(B,s); U 2 (A); U 2 (B); Now it is conflict-serializable 29

What about Aborts? 2PL enforces conflict-serializable schedules But what if a transaction releases its locks and then aborts? Serializable schedule definition only considers transactions that commit Relies on assumptions that aborted transactions can be undone completely CSE 444 - Spring 2009 30

T1 L 1 (A); L 1 (B); READ(A, t) t := t+100 WRITE(A, t); U 1 (A) READ(B, t) t := t+100 WRITE(B,t); U 1 (B); Example with Abort T2 L 2 (A); READ(A,s) s := s*2 WRITE(A,s); L 2 (B); DENIED GRANTED; READ(B,s) s := s*2 WRITE(B,s); U 2 (A); U 2 (B); Abort Commit 31

Strict 2PL Strict 2PL: All locks held by a transaction are released when the transaction is completed Ensures that schedules are recoverable Transactions commit only after all transactions whose changes they read also commit Avoids cascading rollbacks CSE 444 - Spring 2009 32

Deadlock Trasaction T 1 waits for a lock held by T 2 ; But T 2 waits for a lock held by T 3 ; While T 3 waits for..........and T 73 waits for a lock held by T 1!! Could be avoided, by ordering all elements (see book); or deadlock detection + rollback CSE 444 - Spring 2009 33

Lock Modes S = shared lock (for READ) X = exclusive lock (for WRITE) U = update lock Initially like S Later may be upgraded to X I = increment lock (for A := A + something) Increment operations commute Recommended reading: chapter 18.4 CSE 444 - Spring 2009 34

The Locking Scheduler Taks 1: Add lock/unlock requests to transactions Examine all READ(A) or WRITE(A) actions Add appropriate lock requests Ensure 2PL! Recommended reading: chapter 18.5 CSE 444 - Spring 2009 35

The Locking Scheduler Task 2: Execute the locks accordingly Lock table: a big, critical data structure in a DBMS! When a lock is requested, check the lock table Grant, or add the transaction to the element s wait list When a lock is released, re-activate a transaction from its wait list When a transaction aborts, release all its locks Check for deadlocks occasionally Recommended reading: chapter 18.5 36