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

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

Lecture 7: Concurrency control. Rasmus Pagh

Concurrency Control. Module 6, Lectures 1 and 2

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

Database Tuning and Physical Design: Execution of Transactions

CMSC724: Concurrency

Transaction Management Overview

Concurrency control. Concurrency problems. Database Management System

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

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

Applying Attribute Level Locking to Decrease the Deadlock on Distributed Database

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

Implementing New Approach for Enhancing Performance and Throughput in a Distributed Database

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

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

CS 245 Final Exam Winter 2013

Transactional properties of DBS

CSE 326: Data Structures B-Trees and B+ Trees

Introduction to Database Management Systems

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

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

Physical Data Organization

Database Internals (Overview)

B-Trees. Algorithms and data structures for external memory as opposed to the main memory B-Trees. B -trees

From Last Time: Remove (Delete) Operation

Database Concurrency Control and Recovery. Simple database model

Textbook and References

Physical DB design and tuning: outline

Full and Complete Binary Trees

PostgreSQL Concurrency Issues

Concurrency Control: Locking, Optimistic, Degrees of Consistency

Databases and Information Systems 1 Part 3: Storage Structures and Indices

Chapter 6 The database Language SQL as a tutorial

CSE 544 Principles of Database Management Systems. Magdalena Balazinska Fall 2007 Lecture 5 - DBMS Architecture

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

High-Performance Concurrency Control Mechanisms for Main-Memory Databases

Big Data and Scripting. Part 4: Memory Hierarchies

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

Previous Lectures. B-Trees. External storage. Two types of memory. B-trees. Main principles

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

Outline BST Operations Worst case Average case Balancing AVL Red-black B-trees. Binary Search Trees. Lecturer: Georgy Gimel farb

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

GRANULARITY OF LOCKS IN A SHARED DATA BASE. IBM Research Laboratory San Jose, California 95193

System Copy GT Manual 1.8 Last update: 2015/07/13 Basis Technologies

DATABASE DESIGN - 1DL400

Chapter 10. Backup and Recovery

Chapter 12 File Management

Chapter 12 File Management. Roadmap

Transactions. SET08104 Database Systems. Napier University

W I S E. SQL Server 2008/2008 R2 Advanced DBA Performance & WISE LTD.

CS2Bh: Current Technologies. Introduction to XML and Relational Databases. The Relational Model. The relational model

Graham Kemp (telephone , room 6475 EDIT) The examiner will visit the exam room at 15:00 and 17:00.

Lecture 1: Data Storage & Index

Overview of Storage and Indexing

Simple Solution for a Location Service. Naming vs. Locating Entities. Forwarding Pointers (2) Forwarding Pointers (1)

Guerrilla Warfare? Guerrilla Tactics - Performance Testing MS SQL Server Applications

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

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

DDB Functionalities by Major DMBS Products. Haibin Liu Shcherbak Maryna Nassrat Hatem

Recovery System C H A P T E R16. Practice Exercises

Redo Recovery after System Crashes

David Dye. Extract, Transform, Load

Tashkent: Uniting Durability with Transaction Ordering for High-Performance Scalable Database Replication

How to Implement Multi-way Active/Active Replication SIMPLY

VALLIAMMAI ENGNIEERING COLLEGE SRM Nagar, Kattankulathur

COS 318: Operating Systems

Naming vs. Locating Entities

DATABASE REPLICATION A TALE OF RESEARCH ACROSS COMMUNITIES

F1: A Distributed SQL Database That Scales. Presentation by: Alex Degtiar (adegtiar@cmu.edu) /21/2013

Binary Search Trees CMPSC 122

CSCI-UA: Database Design & Web Implementation. Professor Evan Sandhaus sandhaus@cs.nyu.edu evan@nytimes.com

Heaps & Priority Queues in the C++ STL 2-3 Trees

SOFT 437. Software Performance Analysis. Ch 5:Web Applications and Other Distributed Systems

Tashkent: Uniting Durability with Transaction Ordering for High-Performance Scalable Database Replication

Distributed Databases

Chapter Outline. Chapter 2 Distributed Information Systems Architecture. Middleware for Heterogeneous and Distributed Information Systems

LDAP User Service Guide 30 June 2006

READPAST & Furious: Transactions, Locking and Isolation

TYPICAL QUESTIONS & ANSWERS

Contents RELATIONAL DATABASES

Web Data Extraction: 1 o Semestre 2007/2008

Lecture 18: Reliable Storage

Lecture 6: Query optimization, query tuning. Rasmus Pagh

DATABASE MANAGEMENT SYSTEMS. Question Bank:

Property Based Broadcast Encryption in the Face of Broadcasts

B+ Tree Properties B+ Tree Searching B+ Tree Insertion B+ Tree Deletion Static Hashing Extendable Hashing Questions in pass papers

Data Structures Fibonacci Heaps, Amortized Analysis

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

! Volatile storage: ! Nonvolatile storage:

Configuration Management Models in Commercial Environments

Managed File Transfer

Concurrency in SQL Server Kalen Delaney Solid Quality Learning Kalen Delaney

CS 525 Advanced Database Organization - Spring 2013 Mon + Wed 3:15-4:30 PM, Room: Wishnick Hall 113

Transaction Processing Monitors

Clustering UE 141 Spring 2013

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

Improving In-Memory Database Index Performance with Intel R Transactional Synchronization Extensions

A Proposal for a Multi-Master Synchronous Replication System

Definition of SOA. Capgemini University Technology Services School Capgemini - All rights reserved November 2006 SOA for Software Architects/ 2

INTRODUCTION TO DATABASE SYSTEMS

Transcription:

Carnegie Mellon Univ. Dept. of Computer cience 15-415/615 - DB Applications C. Faloutsos A. Pavlo Lecture#22: Concurrency Control Part 2 (R&G ch. 17) Last Class A concurrency control scheme uses locks and aborts to ensure correctness. Conflict vs. View erializability (trict) 2PL is popular. We need to handle deadlocks in 2PL: Detection: Waits-for graph Prevention: Abort some txns, defensively Faloutsos/Pavlo 15-415/615 2 Last Class Assumption Today s Class We assumed that the database was fixed collection of independent objects. No objects are added or deleted. No relationship between objects. No indexes. Lock Granularities Locking in B+Trees The Phantom Problem Transaction Isolation Levels Faloutsos/Pavlo 15-415/615 3 Faloutsos/Pavlo 15-415/615 4

Lock Granularities Database Lock Hierarchy When we say that a txn acquires a lock, what does that actually mean? On a field? Record? Page? Table? Ideally, each txn should obtain fewest number of locks that is needed Database Table 1 Table 2 Tuple 1 Tuple 2 Tuple n Attr 1 Attr 2 Attr n Faloutsos/Pavlo 15-415/615 5 Faloutsos/Pavlo 15-415/615 6 Example Example : Get the balance of Christos shady offshore bank account. T2: Increase all account balances by 1%. Q: What locks should they obtain? Q: What locks should they obtain? A: Multiple Exclusive + hared for leafs of lock tree. pecial Intention locks for higher levels Faloutsos/Pavlo 15-415/615 7 Faloutsos/Pavlo 15-415/615 8

Holds Intention Locks Intention Locks Intention locks allow a higher level node to be locked in or mode without having to check all descendent nodes. If a node is in an intention mode, then explicit locking is being done at a lower level in the tree. Intention-hared (I): Indicates explicit locking at a lower level with shared locks. Intention-Exclusive (I): Indicates locking at lower level with exclusive or shared locks. Faloutsos/Pavlo 15-415/615 9 Faloutsos/Pavlo 15-415/615 10 Intention Locks Compatibility Matrix hared+intention-exclusive (I): The subtree rooted by that node is locked explicitly in shared mode and explicit locking is being done at a lower level with exclusive-mode locks. T2 Wants I I I I I I Faloutsos/Pavlo 15-415/615 11 Faloutsos/Pavlo 15-415/615 12

Privileges Multiple Granularity Protocol Locking Protocol Weaker I Each txn obtains appropriate lock at highest level of the database hierarchy. I To get or I lock on a node, the txn must hold at least I on parent node. tronger I What if txn holds I on parent? on parent? To get, I, or I on a node, must hold at least I on parent node. Faloutsos/Pavlo 15-415/615 13 Faloutsos/Pavlo 15-415/615 14 Example Two-level Hierarchy Example Threesome I T2 Assume three txns execute at same time: : can R and update a few tuples. T2: can a portion of tuples in R. T3: can all tuples in R. T2 I Table R T2 Table R Tuple 1 Tuple 2 Tuple n Tuple 1 Tuple 2 Tuple n Read Write Faloutsos/Pavlo 15-415/615 15 Faloutsos/Pavlo 15-415/615 16

Example Threesome Example Threesome can R and update a few tuples. can all tuples in can R. a portion of tuples in R. T2 Tuple 1 Read I T2 I T3 T3 Table R Tuple 2 Read T2 Tuple n Write Read : Get an I lock on R, then get lock on tuples that are updated. T2: Get an I lock on R, and repeatedly get an lock on tuples of R. T3: Two choices: T3 gets an lock on R. OR, T3 could behave like T2; can use lock escalation to decide which. Faloutsos/Pavlo 15-415/615 17 Faloutsos/Pavlo 15-415/615 18 Lock Escalation Multiple Lock Granularities Lock escalation dynamically asks for coarser-grained locks when too many low level locks acquired. Reduces the number of requests that the lock manager has to process. Faloutsos/Pavlo 15-415/615 19 Useful in practice as each txn only needs a few locks. Intention locks help improve concurrency: Intention-hared (I): Intent to get lock(s) at finer granularity. Intention-Exclusive (I): Intent to get lock(s) at finer granularity. hared+intention-exclusive (I): Like and I at the same time. Faloutsos/Pavlo 15-415/615 20

Today s Class Locking in B+Trees Lock Granularities Locking in B+Trees The Phantom Problem Transaction Isolation Levels Q: What about locking indexes? A: They are not quite like other database elements so we can treat them differently: It s okay to have non-serializable concurrent access to an index as long as the accuracy of the index is maintained. Faloutsos/Pavlo 15-415/615 21 Faloutsos/Pavlo 15-415/615 22 Example Lock Crabbing wants to insert in H T2 wants to insert in I Q: Why not plain 2PL? A: Because txns have to hold on to their locks for too long! B D G H E A root C F I...... Improves concurrency for B+Trees. Get lock for parent; get lock for child; release lock for parent if safe. afe Nodes: Any node that won t split or merge when updated. Not full (on insertion) More than half-full (on deletion) Faloutsos/Pavlo 15-415/615 23 Faloutsos/Pavlo 15-415/615 24

Lock Crabbing earch: tart at root and go down; repeatedly, lock child then unlock parent Insert/Delete: tart at root and go down, obtaining locks as needed. Once child is locked, check if it is safe: If child is safe, release all locks on ancestors. Faloutsos/Pavlo 15-415/615 25 Example #1 earch 38 10 35 B It s safe to release the lock on A. 6 12 23 F 38 44 C 3 4 6 9 10 11 12 13 20 22 23 31 35 36 38 41 44 G H I D E Faloutsos/Pavlo 15-415/615 26 Example #2 Delete 38 Example #3 Insert 45 10 We may need to coalesce B, so we can t 6 release 12 the lock on 23 A. F 38 44 We know that C will not need to merge with F, so 3 4 6 9 10 11 12 13 20 22 23 31 35 36 38 41 44 it s safe to release A+B. G H I D E Faloutsos/Pavlo 15-415/615 27 35 B C 10 35 B We know that if C needs to split, B has room so 6 it s 12 safe to release 23 A. F 38 44 C 3 4 6 9 10 11 12 13 20 22 23 31 35 36 38 41 44 45 G E has H room so I it won t D E split, so we can Faloutsos/Pavlo 15-415/615 28 release B+C.

Example #4 Insert 25 10 35 B 6 12 23 31 F 38 44 C 3 4 6 9 10 11 12 13 20 22 23 31 25 35 36 38 41 44 We need to split H so we G H I D E need to keep the lock on Faloutsos/Pavlo 15-415/615 31 29 its parent node. Problems Q: What was the first step that all of the update examples did on the B+Tree? Delete 38 Insert 45 Faloutsos/Pavlo 15-415/615 30 Insert 25 Problems Better Tree Locking Algorithm Q: What was the first step that all of the update examples did on the B+Tree? A: Locking the root every time becomes a bottleneck with higher concurrency. Can we do better? Main Idea: Assume that the leaf is safe, and use -locks & crabbing to reach it, and verify. If leaf is not safe, then do previous algorithm. Rudolf Bayer, Mario chkolnick: Concurrency of Operations on B-Trees. Acta Inf. 9: 1-21 (1977) Faloutsos/Pavlo 15-415/615 31 Faloutsos/Pavlo 15-415/615 32

Better Tree Locking Algorithm earch: ame as before. Insert/Delete: et locks as if for search, get to leaf, and set lock on leaf. If leaf is not safe, release all locks, and restart txn using previous Insert/Delete protocol. Gambles that only leaf node will be modified; if not, locks set on the first pass to leaf are wasteful. Faloutsos/Pavlo 15-415/615 33 Example #2 Delete 38 10 35 B 6 12 23 F 38 44 C 3 4 6 9 10 11 12 13 20 22 23 31 35 36 38 41 44 G H I D E D will not need to Faloutsos/Pavlo coalesce, 15-415/615 so we re safe! 34 Example #4 Insert 25 10 35 B Another Alternative Textbook has a third variation, that uses lock-upgrades instead of restarting. This approach may lead to deadlocks. 6 12 23 31 F 38 44 C 3 4 6 9 10 11 12 13 20 22 23 31 25 35 36 38 41 44 We need to split H so we G H I D E have to restart and reexecute like Faloutsos/Pavlo 15-415/615 35 before. Faloutsos/Pavlo 15-415/615 36

TIME Additional Points Today s Class Q: Which order to release locks in multiplegranularity locking? A: From the bottom up Q: Which order to release locks in treelocking? A: As early as possible to maximize concurrency. Faloutsos/Pavlo 15-415/615 37 Lock Granularities Locking in B+Trees The Phantom Problem Transaction Isolation Levels Faloutsos/Pavlo 15-415/615 38 Dynamic Databases Recall that so far we have only dealing with transactions that read and update data. But now if we have insertions, updates, and deletions, we have new problems The Phantom Problem BEGIN ELECT MA(age) FROM sailors WHERE rating=1 ELECT MA(age) FROM sailors WHERE rating=1 chedule BEGIN 72 T2 INERT INTO sailors (age=96, rating=1) 96 COMMIT COMMIT Faloutsos/Pavlo 15-415/615 39 Faloutsos/Pavlo 15-415/615 40

How did this happen? Predicate Locking Because locked only existing records and not ones under way! Conflict serializability on reads and writes of individual items guarantees serializability only if the set of objects is fixed. olution? Lock records that satisfy a logical predicate: Example: rating=1. In general, predicate locking has a lot of locking overhead. Index locking is a special case of predicate locking that is potentially more efficient. Faloutsos/Pavlo 15-415/615 41 Faloutsos/Pavlo 15-415/615 42 Index Locking Locking without an Index If there is a dense index on the rating field then the txn can lock index page containing the data with rating=1. If there are no records with rating=1, the txn must lock the index page where such a data entry would be, if it existed. If there is no suitable index, then the txn must obtain: A lock on every page in the table to prevent a record s rating from being changed to 1. The lock for the table itself to prevent records with rating=1 from being added or deleted. Faloutsos/Pavlo 15-415/615 43 Faloutsos/Pavlo 15-415/615 44

Isolation (High Low) Today s Class Weaker Levels of Consistency Lock Granularities Locking in B+Trees The Phantom Problem Weaker Levels of Consistency erializability is useful because it allows programmers to ignore concurrency issues. But enforcing it may allow too little concurrency and limit performance. We may want to use a weaker level of consistency to improve scalability. Faloutsos/Pavlo 15-415/615 45 Faloutsos/Pavlo 15-415/615 46 Isolation Levels Isolation Levels Controls the extent that a txn is exposed to the actions of other concurrent txns. Provides for greater concurrency at the cost of exposing txns to uncommitted changes: Dirty Reads Unrepeatable Reads Phantom Reads ERIALIZABLE: No phantoms, all reads repeatable, no dirty reads. REPEATABLE READ: Phantoms may happen. READ COMMITTED: Phantoms and unrepeatable reads may happen. READ UNCOMMITTED: All of them may happen. Faloutsos/Pavlo 15-415/615 47 Faloutsos/Pavlo 15-415/615 48

Isolation Levels Isolation Levels READ UNCOMMITTED Dirty Read Unrepeatable Read Phantom Maybe Maybe Maybe READ COMMITTED No Maybe Maybe REPEATABLE READ No No Maybe ERIALIZABLE No No No ERIALIZABLE: Obtain all locks first; plus index locks, plus strict 2PL. REPEATABLE READ: ame as above, but no index locks. READ COMMITTED: ame as above, but locks are released immediately. READ UNCOMMITTED: ame as above, but allows dirty reads (no locks). Faloutsos/Pavlo 15-415/615 49 Faloutsos/Pavlo 15-415/615 50 QL-92 Isolation Levels Isolation Levels ET TRANACTION IOLATION LEVEL <isolation-level>; Default: Depends Not all DBM support all isolation levels in all execution scenarios (e.g., replication). Default Maximum Actian Ingres 10.0/10 ERIALIZABLE ERIALIZABLE Aerospike READ COMMITTED READ COMMITTED Greenplum 4.1 READ COMMITTED ERIALIZABLE MyQL 5.6 REPEATABLE READ ERIALIZABLE MemQL 1b READ COMMITTED READ COMMITTED M QL erver 2012 READ COMMITTED ERIALIZABLE Oracle 11g READ COMMITTED NAPHOT IOLATION Postgres 9.2.2 READ COMMITTED ERIALIZABLE AP HANA READ COMMITTED ERIALIZABLE caledb 1.02 READ COMMITTED READ COMMITTED VoltDB ERIALIZABLE ERIALIZABLE ource: Peter Bailis, When is ACID ACID? Rarely. January 2013 Faloutsos/Pavlo 15-415/615 51 Faloutsos/Pavlo 15-415/615 52

Access Modes You can also provide hints to the DBM about whether a txn will modify the database. Only two possible modes: READ WRITE READ ONLY QL-92 QL-92 Access Modes ET TRANACTION <access-mode>; Postgres + MyQL 5.6 TART TRANACTION <access-mode>; Default: READ WRITE Not all DBMs will optimize execution if you set a txn to in READ ONLY mode. Faloutsos/Pavlo 15-415/615 53 Faloutsos/Pavlo 15-415/615 54 Transaction Demo ummary Faloutsos/Pavlo 15-415/615 55 Multiple granularity locking: leads to few locks, at appropriate levels Tree-structured indexes: Lock crabbing and safe nodes Important distinction: Multiple granularity locking releases locks bottom-up. Tree-locking releases top-down to maximize concurrency. Faloutsos/Pavlo 15-415/615 56

ummary The Phantom Problem occurs if insertions/deletions Use Predicate locking to prevent this: Index Locking Table Locking Faloutsos/Pavlo 15-415/615 57