Database Tuning and Physical Design: Execution of Transactions

Similar documents
XI. Transactions CS Computer App in Business: Databases. Lecture Topics

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Problems Caused by Failures

Intro to DB CHAPTER 15 TRANSACTION MNGMNT

Intro to Transactions

TRANSACTION MANAGEMENT

CSE 190D Database System Implementation

Overview. Introduction to Transaction Management ACID. Transactions

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

Transaction Management: Introduction (Chap. 16)

Transactions. ACID Properties of Transactions. Atomicity - all or nothing property - Fully performed or not at all

Concurrency Control & Recovery

Transaction Management & Concurrency Control. CS 377: Database Systems

Chapter 20 Introduction to Transaction Processing Concepts and Theory


Intro to Transaction Management

CSE 444: Database Internals. Lectures Transactions

Concurrency Control & Recovery

Database System Concepts

Transactions. Kathleen Durant PhD Northeastern University CS3200 Lesson 9

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI

Transactions. Transaction. Execution of a user program in a DBMS.

Goal of Concurrency Control. Concurrency Control. Example. Solution 1. Solution 2. Solution 3

Multi-User-Synchronization

Overview of Transaction Management

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

Chapter 22. Transaction Management

L i (A) = transaction T i acquires lock for element A. U i (A) = transaction T i releases lock for element A

Transaction Management Overview

Transaction Management. Pearson Education Limited 1995, 2005

Distributed Transaction Management

Advanced Databases (SE487) Prince Sultan University College of Computer and Information Sciences. Dr. Anis Koubaa. Spring 2014

Introduction to Data Management CSE 344

Transaction Management and Concurrency Control. Chapter 16, 17

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

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

Example: Transfer Euro 50 from A to B

CS 5300 module6. Problem #1 (10 Points) a) Consider the three transactions T1, T2, and T3, and the schedules S1 and S2.

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

CSE 344 MARCH 9 TH TRANSACTIONS

DATABASE DESIGN I - 1DL300

Part III Transactions

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

Transactions and Concurrency Control. Dr. Philip Cannata

Transactions and Concurrency Control

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

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

Chapter 15: Transactions

Transaction Processing. Introduction to Databases CompSci 316 Fall 2018

CS 347 Parallel and Distributed Data Processing

T ransaction Management 4/23/2018 1

UNIT 4 TRANSACTIONS. Objective

Introduction to Transaction Processing Concepts and Theory

CS 347 Parallel and Distributed Data Processing

Transaction Processing: Basics - Transactions

CSE 530A ACID. Washington University Fall 2013

Transaction Management: Concurrency Control, part 2

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

Transactions Processing (i)

Database Systems. Announcement

DB2 Lecture 10 Concurrency Control

Transaction Management: Concurrency Control

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

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

CS 370 Concurrency worksheet. T1:R(X); T2:W(Y); T3:R(X); T2:R(X); T2:R(Z); T2:Commit; T3:W(X); T3:Commit; T1:W(Y); Commit

Transactions. Silberschatz, Korth and Sudarshan

CSE 344 MARCH 25 TH ISOLATION

Mobile and Heterogeneous databases Distributed Database System Transaction Management. A.R. Hurson Computer Science Missouri Science & Technology

CSE 444: Database Internals. Lectures 13 Transaction Schedules

Introduction to Data Management. Lecture #18 (Transactions)

Concurrency Control. Transaction Management. Lost Update Problem. Need for Concurrency Control. Concurrency control

Transaction Processing Concepts and Theory. Truong Tuan Anh CSE-HCMUT

Implementing Isolation

Chapter 13: Transactions

COURSE 1. Database Management Systems

Transactions. Prepared By: Neeraj Mangla

Chapter 15 : Concurrency Control

Advances in Data Management Transaction Management A.Poulovassilis

! A lock is a mechanism to control concurrent access to a data item! Data items can be locked in two modes :

Database Management Systems 2010/11

Concurrency Control. [R&G] Chapter 17 CS432 1

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

Transaction Management

Transaction Concept. Two main issues to deal with:

Database Systems CSE 414

Introduction to Data Management CSE 344

UNIT IV TRANSACTION MANAGEMENT

Database Systems CSE 414

Copyright 2007 Ramez Elmasri and Shamkant B. Navathe. Slide 17-1

h p:// Authors: Tomáš Skopal, Irena Holubová Lecturer: Mar n Svoboda, mar

Topics in Reliable Distributed Systems

Transactions These slides are a modified version of the slides of the book Database System Concepts (Chapter 15), 5th Ed

Databases - Transactions

Introduction to Data Management CSE 414

Slides Courtesy of R. Ramakrishnan and J. Gehrke 2. v Concurrent execution of queries for improved performance.

ICOM 5016 Database Systems. Chapter 15: Transactions. Transaction Concept. Chapter 15: Transactions. Transactions

Chapter 7 (Cont.) Transaction Management and Concurrency Control

Introduction to Data Management. Lecture #26 (Transactions, cont.)

Chapter 25: Advanced Transaction Processing

CSC 261/461 Database Systems Lecture 21 and 22. Spring 2017 MW 3:25 pm 4:40 pm January 18 May 3 Dewey 1101

Transcription:

Database Tuning and Physical Design: Execution of Transactions Spring 2018 School of Computer Science University of Waterloo Databases CS348 (University of Waterloo) Transaction Execution 1 / 20

Basics of Transaction Processing Query (and update) processing converts requests for sets of tuples to requests for reads and writes of physical objects in the database. database objects (depending on granularity) can be individual attributes records physical pages files (only for concurrency control purposes) Goals correct and concurrent execution of queries and updates guarantee that acknowledged updates are persistent (University of Waterloo) Transaction Execution 2 / 20

ACID Requirements Transactions are said to have the ACID properties: Atomicity: all-or-nothing execution Consistency: execution preserves database integrity Isolation: transactions execute independently (as if they were executed in the system alone) Durability: updates made by a committed transaction will not be destroyed by subsequent failures. Implementation of transactions in a DBMS comes in two parts: Concurrency Control: committed transactions do not interfere Recovery Management: committed transactions are durable, aborted transactions have no effect on the database (University of Waterloo) Transaction Execution 3 / 20

Concurrency Control: assumptions 1 we fix a database: a set of objects read/written by transactions: r i [x]: transaction T i reads object x w i [x]: transaction T i writes (modifies) object x 2 a transaction T i is a sequence of operations T i = r i [x 1 ], r i [x 2 ], w i [x 1 ],..., r i [x 4 ], w i [x 2 ], c i c i is the commit request of T i. 3 for a set of transactions T 1,..., T k we want to produce a schedule S of operations such that every operation o i T i appears also in S T i s operations in S are ordered the same way as in T i Goal: produce a correct schedule with maximal parallelism (University of Waterloo) Transaction Execution 4 / 20

Transactions and Schedules If T i and T j are concurrent transactions, then it is always correct to schedule the operations in such a way that: T i will appear to precede T j meaning that T j will see all updates made by T i, and T i will not see any updates made by T j, or T i will appear to follow T j, meaning that T i will see T j s updates and T j will not see T i s. Idea how to define Correctness: it must appear as if the transactions have been executed sequentially (in some serial order). (University of Waterloo) Transaction Execution 5 / 20

Serializable Schedules Definition An execution of is said to be serializable if it is equivalent to a serial execution of the same transactions. Example: An interleaved execution of two transactions: S a = w 1 [x] r 2 [x] w 1 [y] r 2 [y] An equivalent serial execution (T 1, T 2 ): S b = w 1 [x] w 1 [y] r 2 [x] r 2 [y] An interleaved execution with no equivalent serial execution: S c = w 1 [x] r 2 [x] r 2 [y] w 1 [y] (University of Waterloo) Transaction Execution 6 / 20

Conflict Equivalence How do we determine if two schedules are equivalent? Conflict Equivalence: cannot be based on any particular database instance two operations conflict if they (1) belong to different transactions (2) access the same data item x (3) at least one of them is a write operation w[x]. we require that in two conflict-equivalent histories all conflicting operations are ordered the same way. yields conflict-serializable schedules conflict-equivalent to a serial schedule View Equivalence: allows more schedules, but it is harder (NP-hard) to compute (University of Waterloo) Transaction Execution 7 / 20

Other Properties of Schedules Serializability guarantees correctness. However, we d like to avoid other unpleasant situations. Recoverable Schedules: (RC) transaction T j reads a value T i has written, T j succeeds to commit, and T i tries to abort (in this order) to abort T 2 we need to undo effects of a committed transaction T 1. commits only in order of the read-from dependency Cascadeless Schedules (ACA): if T j above didn t commit we can abort it: may lead to cascading aborts of many transactions no reading of uncommitted data (University of Waterloo) Transaction Execution 8 / 20

How to Get a Serializable Schedule? So how do we build schedulers that produce serializable and cascadeless schedules? The scheduler receives requests from the query processor(s). For each operation it chooses one of the following actions: execute it (by sending to a lower module), delay it (by inserting in some queue), or reject it (thereby causing abort of the transaction) ignore it (as it has no effect) Two main kinds of schedulers: conservative (favors delaying operations) aggressive (favors rejecting operations) (University of Waterloo) Transaction Execution 9 / 20

Two Phase Locking (2PL) Transactions must have a lock on objects before access: a shared lock is required to read an object an exclusive lock is required to write an object It is insufficient just to acquire a lock, access the data item, and then release it immediately... 2PL Protocol A transaction has to acquire all locks before it releases any of them. Theorem Two-phase locking guarantees that the produced transaction schedules are (conflict) serializable. In practice: STRICT 2PL (locks held till commit; this guarantees ACA) (University of Waterloo) Transaction Execution 10 / 20

Deadlocks and What to do With 2PL we may end with a deadlock: r 1 [x], r 2 [y], w 2 [x](blocked by T 1 ), w 1 [y](blocked by T 2 ) How do we deal with this: deadlock prevention: locks granted only if they can t lead to a deadlock. ordered data items and locks granted in this order. deadlock detection: wait for graphs and cycle detection. resolution: the system aborts one of the offending transactions (involuntary abort). in practice: detection (or often just a timeout) and abort (University of Waterloo) Transaction Execution 11 / 20

Variations on Locking Multi-granularity Locking not all locked objects have the same size advantageous in presence of bulk vs. tiny updates Predicate Locking locks based on selection predicate rather than on a value Tree Locking tries to avoid congestion in roots of (B-)trees allows relaxation of 2PL due to tree structure of data Lock Upgrade protocols... (University of Waterloo) Transaction Execution 12 / 20

Inserts and Deletes We have been assuming a fixed set of data items. what if we try to insert or delete an item? does plain 2PL (correctly) handle this situation? NO: one transaction tries to count records in a table second transactions adds/ deletes a record this situation is called the phantom problem. Solution: operations that ask for all records have to lock against insertion/deletion of a qualifying record locks on tables index locking and other techniques (University of Waterloo) Transaction Execution 13 / 20

Isolation Levels in SQL The guarantee of serializable executions may carries a heavy price. Performance may be poor because of blocked transactions and deadlocks. Four isolation levels are supported: Level 3: (Serializability) essentially table-level strict 2PL Level 2: (Repeatable Read) tuple-level strict 2PL; phantom tuples may occur Level 1: (Cursor Stability) tuple-level exclusive-lock only strict 2PL reading the same object twice: different values Level 0: neither read nor write locks are acquired transaction may read uncommitted updates (University of Waterloo) Transaction Execution 14 / 20

Recovery: Goals and Setting Two goals: 1 allow transactions to be committed (with a guarantee that the effects are permanent) or aborted(with a guarantee that the effects disappear) 2 allow the database to be recovered to a consistent state in case on HW/power/... failure. Input: a 2PL, ACA schedule of operations produced by TM. Output: a schedule of reads/writes/forced writes. (University of Waterloo) Transaction Execution 15 / 20

Approaches to Recovery Two essential approaches: 1 Shadowing copy-on-write and merge-on-commit approach poor clustering used in system R, but not in modern systems 2 Logging use of LOG (separate disk) to avoid forced writes good utilization of buffers preserves original clusters (University of Waterloo) Transaction Execution 16 / 20

Log-Based Approaches A log is a read/append only data structure (a file) transactions add log records about what they do Log records contain several types of information: UNDO information: old versions of objects that have been modified by a transaction. UNDO information can be used to undo database changes made by a transaction that aborts. REDO information: new versions of objects that have been modified by a transaction. REDO records can be used to redo the work done by a transaction that commits. BEGIN/COMMIT/ABORT records are recorded whenever a transaction begins, commits, or aborts. (University of Waterloo) Transaction Execution 17 / 20

Example of a LOG log head T 0,begin (oldest part) T 0,X,99,100 T 1,begin T 1,Y,199,200 T 2,begin T 2,Z,51,50 T 1,M,1000,10 T 1,commit T 3,begin T 2,abort T 3,Y,200,50 T 4,begin (newest part) T 4,M,10,100 log tail T 3,commit (University of Waterloo) Transaction Execution 18 / 20

Write-Ahead Logging (WAL) How do we make sure the LOG is consistent with the main database? Write-Ahead Logging (WAL) approach requires: 1 UNDO rule: a log record for an update is written to log disk before the corresponding data (page) is written to the main disk (guarantees Atomicity) 2 REDO rule: all log records for a transaction are written to log disk before commit (guarantees Durability) (University of Waterloo) Transaction Execution 19 / 20

Summary ACID properties of transactions guarantee correctness of concurrent access to the database and of data storage. consistency and isolation based on serializability leads to definition of correct schedulers responsibility of the transaction manager durability and atomicity responsibility of the recovery manager synchronous writing is too inefficient replaced by synchronous writes to a LOG and WAL (University of Waterloo) Transaction Execution 20 / 20