More Concurrency. Database Systems Lecture 17 Natasha Alechina

Similar documents
Last Lecture. More Concurrency. Concurrency So Far. In This Lecture. Serialisability. Schedules. Database Systems Lecture 15

In This Lecture. Exam revision. Main topics. Exam format. Particular topics. How to revise. Exam format Main topics How to revise

Comp 5311 Database Management Systems. 14. Timestamp-based Protocols

Concurrency Control. Concurrency Control Ensures interleaving of operations amongst concurrent transactions result in serializable schedules

CSIT5300: Advanced Database Systems

Multiversion schemes keep old versions of data item to increase concurrency. Multiversion Timestamp Ordering Multiversion Two-Phase Locking Each

Graph-based protocols are an alternative to two-phase locking Impose a partial ordering on the set D = {d 1, d 2,..., d h } of all data items.

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

Multiversion Schemes to achieve Snapshot Isolation Timestamped Based Protocols

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

Lecture 22 Concurrency Control Part 2

Chapter 9: Concurrency Control

Concurrency Control Overview. COSC 404 Database System Implementation. Concurrency Control. Lock-Based Protocols. Lock-Based Protocols (2)

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

Chapter 12 : Concurrency Control

Concurrency Control 9-1

Chapter 16 : Concurrency Control

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

References. Concurrency Control. Administração e Optimização de Bases de Dados 2012/2013. Helena Galhardas e

2 nd Semester 2009/2010

Multi-User-Synchronization

Chapter 13 : Concurrency Control

Distributed Databases Systems

Chapter 15 : Concurrency Control

Concurrency Control! Snapshot isolation" q How to ensure serializability and recoverability? " q Lock-Based Protocols" q Other Protocols"

Distributed Transaction Management. Distributed Database System

Transaction Processing: Basics - Transactions

Lecture 13 Concurrency Control

Distributed Systems. 13. Distributed Deadlock. Paul Krzyzanowski. Rutgers University. Fall 2017

Concurrency Control Algorithms

CS5412: TRANSACTIONS (I)

Implementing Isolation

CS 541 Database Systems. Two Phase Locking 2

DB2 Lecture 10 Concurrency Control

Transactions: Definition. Concurrent transactions: Problems

Deadlock Prevention (cont d) Deadlock Prevention. Example: Wait-Die. Wait-Die

Concurrency Control. Data Base Management Systems. Inherently Concurrent Systems: The requirements

Chapter 7: Deadlocks. Operating System Concepts with Java 8 th Edition

Transaction Management. Pearson Education Limited 1995, 2005

Answers to G51DBS exam

Transaction Management

Database System Concepts

CMP-3440 Database Systems

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

Transaction Processing Concurrency control

Introduction to Database Systems CSE 444

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

Chapter 22. Transaction Management

Lock-based concurrency control. Q: What if access patterns rarely, if ever, conflict? Serializability. Concurrency Control II (OCC, MVCC)

Transactions and Concurrency Control

CSE120 Principles of Operating Systems. Prof Yuanyuan (YY) Zhou Deadlock

Advanced Databases. Lecture 9- Concurrency Control (continued) Masood Niazi Torshiz Islamic Azad University- Mashhad Branch

CS Reading Packet: "Transaction management, part 2"

Concurrency. Consider two ATMs running in parallel. We need a concurrency manager. r1[x] x:=x-250 r2[x] x:=x-250 w[x] commit w[x] commit

10. Replication. CSEP 545 Transaction Processing Philip A. Bernstein Sameh Elnikety. Copyright 2012 Philip A. Bernstein


Distributed Databases

Concurrency Control in Distributed Systems. ECE 677 University of Arizona

Chapter 10: Concurrency Control! Chapter 10 : Concurrency Control! Intuition of Lock-based Protocols! Lock-Based Protocols!

Chapter 10 : Concurrency Control!

Last Class: Monitors. Real-world Examples

Silberschatz and Galvin Chapter 18

Pessimistic v.s. Optimistic. Outline. Timestamps. Timestamps. Timestamps. CSE 444: Database Internals. Main invariant:

6.033: Fault Tolerance: Isolation Lecture 17 Katrina LaCurts,

Module 6: Process Synchronization. Operating System Concepts with Java 8 th Edition

Distributed Transaction Management

11/7/2018. Event Ordering. Module 18: Distributed Coordination. Distributed Mutual Exclusion (DME) Implementation of. DME: Centralized Approach

Chapter 10 : Concurrency Control

Time stamp ordering. 5 Non-locking concurrency Control

Operating Systems. Lecture3.2 - Deadlock Management. Golestan University. Hossein Momeni

Transactions. Silberschatz, Korth and Sudarshan

Quiz Answers. CS 537 Lecture 9 Deadlock. What can go wrong? Readers and Writers Monitor Example

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

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

T ransaction Management 4/23/2018 1

transaction - (another def) - the execution of a program that accesses or changes the contents of the database

Operating Systems. Operating Systems Sina Meraji U of T

Chapter 6 Distributed Concurrency Control

NOTES W2006 CPS610 DBMS II. Prof. Anastase Mastoras. Ryerson University

Chapter 16: Distributed Synchronization

Chapter 13: Transactions

Chapter 15: Transactions

Transactions and Concurrency Control. Dr. Philip Cannata

12.3 Nonlocking schedulers. Timestamp ordering. TO concurrency control guarantees conflict-serializable schedules

Transaction Management. Chapter 14

CS420: Operating Systems. Deadlocks & Deadlock Prevention

Checkpoints. Logs keep growing. After every failure, we d have to go back and replay the log. This can be time consuming. Checkpoint frequently

Mutual Exclusion in DS

Chapter 18: Distributed

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

Concurrency Control. Chapter 17. Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1

BİL 354 Veritabanı Sistemleri. Transaction (Hareket)

Lecture 21 Concurrency Control Part 1

Isolation levels. Introduction to Database Design 2012, Lecture 14. Rasmus Ejlers Møgelberg. Questions class about one week before exam

CS 347 Parallel and Distributed Data Processing

What is the Race Condition? And what is its solution? What is a critical section? And what is the critical section problem?

Deadlock CS 241. March 19, University of Illinois

Resources. Lecture 4. Deadlocks. Resources (2) Resources (1) Four Conditions for Deadlock. Introduction to Deadlocks

CS 571 Operating Systems. Midterm Review. Angelos Stavrou, George Mason University

Transaction Concept. Two main issues to deal with:

Transcription:

More Concurrency Database Systems Lecture 17 Natasha Alechina

In This Lecture Deadlock detection Deadlock prevention Timestamping For more information Connolly and Begg chapter 20

Deadlocks A deadlock is an impasse that may result when two or more transactions are waiting for locks to be released which are held by each other. For example: has a lock on X and is waiting for a lock on Y, and T2 has a lock on Y and is waiting for a lock on X. Given a schedule, we can detect deadlocks which will happen in this schedule using a wait-for graph (WFG).

Precedence/Wait-For Graphs Precedence graph Each transaction is a vertex Arcs from to T2 if reads X before T2 writes X writes X before T2 reads X writes X before T2 writes X Wait-for Graph Each transaction is a vertex Arcs from T2 to if read-locks X then T2 tries to write-lock it write-locks X then T2 tries to read-lock it write-locks X then T2 tries to write-lock it

Example T2 Write(X) T2 T3 Read(Z) T3 Write(Z) T3 Write(Y) T2 T3 Wait for graph T2 T3 Precedence graph

Example T2 Write(X) T2 T3 Read(Z) T3 Write(Z) T3 Write(Y) T2 T3 Wait for graph T2 T3 Precedence graph

Example T2 Write(X) T2 T3 Read(Z) T3 Write(Z) T3 Write(Y) T2 T3 Wait for graph T2 T3 Precedence graph

Example T2 Write(X) T2 T3 Read(Z) T3 Write(Z) T3 Write(Y) T2 T3 Wait for graph T2 T3 Precedence graph

Example read-locks(x) T2 read-locks(y) Write(X) write-lock(x) T2 tries read-lock(x) T3 Read(Z) T3 Write(Z) T3 Write(Y) T2 T3 Wait for graph T2 T3 Precedence graph

Example read-locks(x) T2 read-locks(y) Write(X) write-lock(x) T2 tries read-lock(x) T3 Read(Z) read-lock(z) T3 Write(Z) write-lock(z) read-lock(y) T3 tries read-lock(x) Write(Y) T2 T3 Wait for graph T2 T3 Precedence graph

Example read-locks(x) T2 read-locks(y) Write(X) write-lock(x) T2 tries read-lock(x) T3 Read(Z) read-lock(z) T3 Write(Z) write-lock(z) read-lock(y) T3 tries read-lock(x) Write(Y) tries write-lock(y) T2 T3 Wait for graph T2 T3 Precedence graph

Deadlock Prevention Deadlocks can arise with 2PL Deadlock is less of a problem than an inconsistent DB We can detect and recover from deadlock It would be nice to avoid it altogether Conservative 2PL All locks must be acquired before the transaction starts Hard to predict what locks are needed Low lock utilisation - transactions can hold on to locks for a long time, but not use them much

Deadlock Prevention We impose an ordering on the resources Transactions must acquire locks in this order Transactions can be ordered on the last resource they locked This prevents deadlock If is waiting for a resource from T2 then that resource must come after all of s current locks All the arcs in the wait-for graph point forwards - no cycles

Example of resource ordering Suppose resource order is: X < Y This means, if you need locks on X and Y, you first acquire a lock on X and only after that a lock on Y (even if you want to write to Y before doing anything to X) It is impossible to end up in a situation when is waiting for a lock on X held by T2, and T2 is waiting for a lock on Y held by.

Timestamping Transactions can be run concurrently using a variety of techniques We looked at using locks to prevent interference An alternative is timestamping Requires less overhead in terms of tracking locks or detecting deadlock Determines the order of transactions before they are executed

Timestamping Each transaction has a timestamp, TS, and if starts before T2 then TS() < TS(T2) Can use the system clock or an incrementing counter to generate timestamps Each resource has two timestamps R(X), the largest timestamp of any transaction that has read X W(X), the largest timestamp of any transaction that has written X

Timestamp Protocol If T tries to read X If TS(T) < W(X) T is rolled back and restarted with a later timestamp If TS(T) W(X) then the read succeeds and we set R(X) to be max(r(x), TS(T)) T tries to write X If TS(T) < W(X) or TS(T) < R(X) then T is rolled back and restarted with a later timestamp Otherwise the write succeeds and we set W(X) to TS(T)

Timestamping Example Given and T2 we will assume The transactions make alternate operations Timestamps are allocated from a counter starting at 1 goes first Y = Y + X Write(Y) T2 Z = Y - X Write(Z)

Timestamp Example X Y Z Y = Y + X Write(Y) T2 Z = Y - X Write(Z) R W TS T2

Timestamp Example X Y Z Y = Y + X Write(Y) T2 Z = Y - X Write(Z) R W TS 1 1 T2

Timestamp Example X Y Z Y = Y + X Write(Y) T2 Z = Y - X Write(Z) R W TS 2 T2 1 2

Timestamp Example X Y Z Y = Y + X Write(Y) T2 Z = Y - X Write(Z) R W TS 2 1 T2 1 2

Timestamp Example X Y Z Y = Y + X Write(Y) T2 Z = Y - X Write(Z) R W TS 2 2 T2 1 2

Timestamp Example X Y Z Y = Y + X Write(Y) T2 Z = Y - X Write(Z) R W TS 2 2 T2 1 2

Timestamp Example X Y Z Y = Y + X Write(Y) T2 Z = Y - X Write(Z) R W TS 2 2 T2 1 2

Timestamp Example X Y Z Y = Y + X Write(Y) T2 Z = Y - X Write(Z) R W TS 2 2 T2 1 2

Timestamp Example X Y Z Y = Y + X Write(Y) T2 Z = Y - X Write(Z) R W TS 2 2 T2 3 2

Timestamp Example X Y Z Y = Y + X Write(Y) T2 Z = Y - X Write(Z) R W TS 2 2 T2 3 2 2

Timestamp Example X Y Z Y = Y + X Write(Y) T2 Z = Y - X Write(Z) R W TS 3 2 T2 3 2 2

Timestamp Example X Y Z Y = Y + X Write(Y) T2 Z = Y - X Write(Z) R W TS 3 3 T2 3 2 2

Timestamp Example X Y Z Y = Y + X Write(Y) T2 Z = Y - X Write(Z) R W TS 3 3 T2 3 2 2

Timestamp Example X Y Z Y = Y + X Write(Y) T2 Z = Y - X Write(Z) R W TS 3 3 3 T2 3 2 2

Timestamping The protocol means that transactions with higher times take precedence Equivalent to running transactions in order of their final time values Transactions don t wait - no deadlock Problems Long transactions might keep getting restarted by new transactions - starvation Rolls back old transactions, which may have done a lot of work

Next Lecture After the break: Java and SQL (not in the exam, just for information) Feedback on coursework 5 (normalisation) Exam revision