Homework 5 (by Joy Arulraj) Solutions Due: Monday Nov 13, 11:59pm

Similar documents
Homework 5 (by Joy Arulraj) Due: Monday Nov 13, 11:59pm

15-415/615 Homework 8, Page 2 of 11 Thu, 4/24/2014, 1:30pm

Carnegie Mellon University Department of Computer Science /615 - Database Applications C. Faloutsos & A. Pavlo, Fall 2016

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

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

Concurrency Control. R &G - Chapter 19

Transaction Management and Concurrency Control. Chapter 16, 17

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

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

Review. Review. Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications. Lecture #21: Concurrency Control (R&G ch.

Concurrency Control CHAPTER 17 SINA MERAJI

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

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

Concurrency Control. Conflict Serializable Schedules. Example. Chapter 17

Transactions and Locking. April 16, 2018

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

Including Aborts in Serializability. Conflict Serializable Schedules. Recall Conflicts. Conflict Equivalent

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

Intro to Transactions

CS 4604: Introduc0on to Database Management Systems. B. Aditya Prakash Lecture #17: Transac0ons 2: 2PL and Deadlocks

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

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

doc. RNDr. Tomáš Skopal, Ph.D.

Homework 2 (by Ao Zeng) Solutions Due: Friday Sept 28, 11:59pm

CS 245 Final Exam Winter 2016

IMPORTANT: Circle the last two letters of your class account:

Page 1. Goals of Today s Lecture. The ACID properties of Transactions. Transactions

Overview of Transaction Management

Page 1. Goals of Today s Lecture" Two Key Questions" Goals of Transaction Scheduling"

Conflict serializability

Database transactions

Conflict Equivalent. Conflict Serializability. Example 1. Precedence Graph Test Every conflict serializable schedule is serializable

Page 1. Goals of Todayʼs Lecture" Two Key Questions" Goals of Transaction Scheduling"

Chapter 5. Concurrency Control Techniques. Adapted from the slides of Fundamentals of Database Systems (Elmasri et al., 2006)

Databases - Transactions II. (GF Royle, N Spadaccini ) Databases - Transactions II 1 / 22

Phantom Problem. Phantom Problem. Phantom Problem. Phantom Problem R1(X1),R1(X2),W2(X3),R1(X1),R1(X2),R1(X3) R1(X1),R1(X2),W2(X3),R1(X1),R1(X2),R1(X3)

CMSC 424 Database design Lecture 22 Concurrency/recovery. Mihai Pop

Implementing Isolation

Lecture 21 Concurrency Control Part 1

Homework 6 (by Sivaprasad Sudhir) Solutions Due: Monday Nov 27, 11:59pm

Database Management Systems

Homework 5 (by Tupac Shakur) Due: Monday Dec 3, 11:59pm

Transaction Management: Concurrency Control

Database Management System

DB2 Lecture 10 Concurrency Control

Final Exam CSE232, Spring 97

Intro to Transaction Management

Outline. Review questions. Carnegie Mellon Univ. Dept. of Computer Science Database Applications

Database Systems. Announcement

Transaction Processing. Introduction to Databases CompSci 316 Fall 2018

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

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

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

Homework 5 (by Tupac Shakur) Solutions Due: Monday Dec 3, 11:59pm

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

Concurrency Control. Himanshu Gupta CSE 532 CC 1

CSE 344 MARCH 9 TH TRANSACTIONS

Serializability of global history

CS 448 Database Systems. Serializability Issues

CS 541 Database Systems. Serializability Issues

Distributed Transaction Management. Distributed Database System

Lock-based Concurrency Control

CSE 444: Database Internals. Lectures Transactions

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

Chapter 13 : Concurrency Control

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

Transactions and Concurrency Control

Final Exam CSE232, Spring 97, Solutions

Transaction Management: Introduction (Chap. 16)

Today s Class. Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications. Formal Properties of Schedules. Conflicting Operations

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

Introduction to Data Management CSE 414

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

2 nd Semester 2009/2010

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

CAS CS 460/660 Introduction to Database Systems. Transactions and Concurrency Control 1.1

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

TRANSACTION MANAGEMENT

CS 245: Database System Principles

Chapter 18 Concurrency Control Techniques

Problem 1 (12P) Indicate whether each of the following statements is true or false; explain briey. a) In query optimization, it is always better to pe

Concurrency Control - Two-Phase Locking

Chapter 15 : Concurrency Control

Database Management Systems (COP 5725) Homework 3

0: BEGIN TRANSACTION 1: W = 1 2: X = W + 1 3: Y = X * 2 4: COMMIT TRANSACTION

Database design and implementation CMPSCI 645. Lectures 18: Transactions and Concurrency

Relational DBMS Internals Solutions Manual. A. Albano, D. Colazzo, G. Ghelli and R. Orsini

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

6.830 Lecture Transactions October 23, 2017

Database Management System 21 Concurrency Control

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

Lecture 13 Concurrency Control

Transactions. Concurrency. Consistency ACID. Modeling transactions. Transactions and Concurrency Control

Transaction Management Overview

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

230 Chapter 17. (c) Otherwise, T writes O and WTS(O) is set to TS(T).

CPSC 310: Database Systems / CSPC 603: Database Systems and Applications Final Exam Fall 2005

CSE232: Database System Principles

Chapter 12 : Concurrency Control

Transaction Management & Concurrency Control. CS 377: Database Systems

Transcription:

CARNEGIE MELLON UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE 15-445/645 DATABASE SYSTEMS (FALL 2017) PROF. ANDY PAVLO Homework 5 (by Joy Arulraj) Solutions Due: Monday Nov 13, 2017 @ 11:59pm IMPORTANT: Upload this PDF with your answers to Gradescope by 11:59pm on Monday Nov 13, 2017. Plagiarism: Homework may be discussed with other students, but all homework is to be completed individually. You have to use this PDF for all of your answers. For your information: Graded out of 100 points; 4 questions total Revision : 2017/12/10 13:51 Question Points Score Serializability and 2PL 20 Deadlock Detection and Prevention 30 Hierarchical Locking - A Blogging Website 30 B+ tree Locking 20 Total: 100 1

15-445/645 (Fall 2017) Homework 5 Page 2 of 11 Question 1: Serializability and 2PL............................[20 points] (a) Yes/No questions: i. [2 points] Schedules under Strict 2PL could have cascading aborts. ii. [2 points] A conflict serializable schedule need not always be view serializable. iii. [2 points] Schedules under Strict 2PL could have deadlocks. Yes No iv. [2 points] There could be schedules under 2PL that are not serializable. v. [2 points] If a precedence graph associated with a schedule has cycles, then it is not conflict serializable. Yes No Grading info: -2 for each incorrect answer (b) Serializability: Consider the schedule given below in Table 1. R( ) and W( ) stand for Read and Write, respectively. time t 1 t 2 t 3 t 4 t 5 t 6 t 7 t 8 t 9 t 10 T 1 R(A) W(A) W(E) R(B) W(B) R(C) W(C) R(D) W(D) T 2 R(A) W(A) R(D) W(D) W(E) W(A) T 3 R(C) W(C) R(F) W(F) Table 1: A schedule with 3 transactions i. [1 point] Is this schedule serial? Grading info: -1 for incorrect answer ii. [3 points] Give the dependency graph of this schedule. List each edge in the dependency graph like this: T x T y because of Z (i.e., Transaction T y reads/writes Z which was last written by T x.). Order the edges in ascending order with respect to x. T 1 T 2 because of A, E T 2 T 1 because of D T 3 T 1 because of C Grading info: -1 for each missing/incorrect edge. Question 1 continues...

15-445/645 (Fall 2017) Homework 5 Page 3 of 11 iii. [1 point] Is this schedule conflict serializable? Grading info: -1 for incorrect answer iv. [3 points] If you answer yes to (iii), provide the equivalent serial schedule. If you answer no, briefly explain why. This schedule is not conflict serializable because there exists a cycle (T 1 T 2 T 1 ) in the dependency graph. Grading info: -3 for a justification that does not agree with previous part v. [2 points] Is this schedule possible under 2PL? Grading info: -1 for incorrect answer Homework 5 continues...

15-445/645 (Fall 2017) Homework 5 Page 4 of 11 Question 2: Deadlock Detection and Prevention................ [30 points] (a) Deadlock Detection: Consider the following lock requests in Table 2. And note that S( ) and X( ) stand for shared lock and exclusive lock, respectively. T 1, T 2, and T 3 represent three transactions. LM stands for lock manager. Transactions will never release a granted lock. time t 1 t 2 t 3 t 4 t 5 t 6 t 7 T 1 S(A) S(B) S(C) T 2 S(B) X(C) X(B) T 3 X(A) LM g Table 2: Lock requests of 3 transactions i. [3 points] For the lock requests in Table 2, determine which lock will be granted or blocked by the lock manager. Please write g in the LM row to indicate the lock is granted and b to indicate the lock is blocked. For example, in the table, the first lock (S(D) at time t 1 ) is marked as granted. S(B) at t 2 : g X(A) at t 3 : b X(C) at t 4 : g S(B) at t 5 : g S(C) at t 6 : b X(B) at t 7 : b Grading info: Half points for one mistake in the schedule, no points > 1 mistake. ii. [4 points] Give the wait-for graph for the lock requests in Table 2. List each edge in the graph like this: T x T y because of Z (i.e., T x is waiting for T y to release its lock on resource Z). Order the edges in ascending order with respect to x. T 1 T 2 because of C Question 2 continues...

15-445/645 (Fall 2017) Homework 5 Page 5 of 11 T 2 T 1 because of B T 3 T 1 because of A Grading info: Half points for 1 missing directed edge, no points if missing > 1. iii. [3 points] Determine whether there exists a deadlock in the lock requests in Table 2, and briefly explain why. Deadlock exists because there is a cycle (T 1 T 2 T 1 ) in the dependency graph. Grading info: 2 points for not explaining why there is a deadlock (b) Deadlock Prevention: Consider the following lock requests in Table 3. Again, S( ) and X( ) stand for shared lock and exclusive lock, respectively. T 1, T 2, T 3, and T 4 represent four transactions. LM represents a lock manager. Transactions will never release a granted lock. time t 1 t 2 t 3 t 4 t 5 t 6 t 7 t 8 T 1 S(A) S(B) T 2 X(B) X(D) T 3 S(C) X(D) X(A) T 4 X(C) LM g Table 3: Lock requests of 4 transactions i. [3 points] For the lock requests in Table 3, determine which lock request will be granted, blocked or aborted by the lock manager (LM), if it has no deadlock prevention policy. Please write g for grant, b for block and a for abort. Again, example is given in the first column. X(B) at t 2 : g S(B) at t 3 : b S(C) at t 4 : g X(D) at t 5 : g Question 2 continues...

15-445/645 (Fall 2017) Homework 5 Page 6 of 11 X(C) at t 6 : b X(A) at t 7 : b X(D) at t 8 : b Grading info: Half points for one mistake in the schedule, no points > 1 mistake. ii. [4 points] Give the wait-for graph for the lock requests in Table 3. List each edge in the graph like this: T x T y because of Z (i.e., T x is waiting for T y to release its lock on resource Z). Order the edges in ascending order with respect to x. T 1 T 2 because of B T 2 T 3 because of D T 3 T 1 because of A T 4 T 3 because of C Grading info: Half points for 1 missing directed edge, no points if missing > 1. iii. [3 points] Determine whether there exists a deadlock in the lock requests in Table 3, and briefly explain why. Deadlock exists because there is a cycle (T 1 T 2 T 3 T 1 ) in the dependency graph. Grading info: 2 points for not explaining why there is a deadlock iv. [5 points] To prevent deadlock, we use the lock manager (LM) that adopts the Wait-Die policy. We assume that in terms of priority: T 1 > T 2 > T 3 > T 4. Here, T 1 > T 2 because T 1 is older than T 2 (i.e., older transactions have higher priority). Determine which lock request will be granted ( g ), blocked ( b ) or aborted ( a ). Follow the same format as the previous question. X(B) at t 2 : g S(B) at t 3 : b (T 1 waits for T 2.) S(C) at t 4 : g X(D) at t 5 : g X(C) at t 6 : a (T 4 dies for T 3.) X(A) at t 7 : a (T 3 dies for T 1.) Question 2 continues...

15-445/645 (Fall 2017) Homework 5 Page 7 of 11 X(D) at t 8 : g (T 2 is granted the lock, since T 3 is aborted.) Grading info: 2 points for one mistake in the schedule, no points > 1 mistake. v. [5 points] Now we use the lock manager (LM) that adopts the Wound-Wait policy. We assume that in terms of priority: T 1 > T 2 > T 3 > T 4. Here, T 1 > T 2 because T 1 is older than T 2 (i.e., older transactions have higher priority). Determine which lock request will be granted ( g ), blocked ( b ) or aborted ( a ). Follow the same format as the previous question. X(B) at t 2 : g S(B) at t 3 : g (T 1 wounds T 2.) S(C) at t 4 : g X(D) at t 5 : g X(C) at t 6 : b (T 4 waits for T 3.) X(A) at t 7 : b (T 3 waits for T 1.) X(D) at t 8 : (T 2 is dead.) Grading info: 2 points for one mistake in the schedule, no points > 1 mistake. Homework 5 continues...

15-445/645 (Fall 2017) Homework 5 Page 8 of 11 Question 3: Hierarchical Locking - A Blogging Website........ [30 points] Consider a Database (D) consisting of two tables, Users (U) and Posts (P). Specifically, Users(uid, first name, last name), spans 300 pages, namely U 1 to U 300 Posts(pid, uid, title, body), spans 600 pages, namely P 1 to P 600 Further, each page contains 100 records, and we use the notation U 3 : 20 to represent the 20 th record on the third page of the Users table. Similarly, P 5 : 10 represents the 10 th record on the fifth page of the Posts table. We use Multiple-granularity locking, with S, X, IS, IX and SIX locks, and four levels of granularity: (1) database-level (D), (2) table-level (U, P), (3) page-level (U 1 U 300, P 1 P 600 ), (4) record-level (U 1 : 1 U 300 : 100, P 1 : 1 P 600 : 100). For each of the following operations on the database, please determine the sequence of lock requests that should be generated by a transaction that wants to efficiently carry out these operations by maximizing concurrency. Please follow the format of the examples listed below: write IS(D) for a request of database-level IS lock write X(P 2 : 30) for a request of record-level X lock for the 30 th record on the second page of the Posts table write S(P 2 : 30 P 3 : 100) for a request of record-level S lock from the 30 th record on the second page of the Posts table to the 100 th record on the third page of the Posts table. (a) [6 points] Fetch the 10 th record on page P 100. IS(D), IS(P), IS(P 100 ), S(P 100 : 10) (b) [6 points] In remembrance of our TA (RIP Christopher Inf Wallace), set the last name of all the users to be Inf. IX(D), X(U) also acceptable: IX(D), IX(U), IX(U 1 U 300 ), X(U 1 : 1 U 300 : 100) (c) [6 points] Scan all the records on pages P 1 through P 20, and modify the record P 5 : 10. IX(D), SIX(P), IX(P 5 ), X(P 5 : 10); also acceptable: IX(D), IX(P), S(P 1 P 4 ), S(P 6 P 20 ), SIX(P 5 ), X(P 5 : 10) (d) [6 points] Order all the posts by their title. Question 3 continues...

15-445/645 (Fall 2017) Homework 5 Page 9 of 11 IS(D), S(P); (e) [6 points] Delete ALL the records from ALL tables. X(D) Homework 5 continues...

15-445/645 (Fall 2017) Homework 5 Page 10 of 11 Question 4: B+ tree Locking.................................. [20 points] Consider the following B+ tree: 50 A 20 B 77 C 5 10 D 28 E 55 F 79 G 1* 4* 5* 10* 15* 20* 24* 28* 29* 50* 52* 55* 64* 77* 78* 79* 81* H I J K L M N O P Figure 1: B+ tree locking To lock this B+ tree, we would like to use the Bayer-Schkolnick algorithm. Important: we use the version as presented in the lecture, which does not use lock upgrade. For each of the following transactions, give the sequence of lock/unlock requests. For example, please write S(A) for a request of shared lock on node A, X(B) for a request of exclusive lock on node B and U(C) for a request of unlock node C. Important notes: Each of the following transactions is applied on the original tree, i.e., ignore any tree changes described in other problems. For simplicity, ignore the changes on the pointers between leaves. (a) [5 points] Search for data entry 15* S(A), S(B), U(A), S(D), U(B), S(J), U(D), U(J) (b) [5 points] Delete data entry 28* S(A), S(B), U(A), S(E), U(B), X(L), U(E), U(L) (c) [5 points] Insert data entry 9* Question 4 continues...

15-445/645 (Fall 2017) Homework 5 Page 11 of 11 S(A), S(B), U(A), S(D), U(B), X(I), U(D), U(I) Also acceptable: S(A), S(B), U(A), S(D), X(I), U(B), U(D), U(I) (d) [5 points] Insert data entry 45* S(A), S(B), U(A), S(E), U(B), X(L), This leaf is not safe because we need to split. We must restart, U(E), U(L) X(A), X(B), U(A), X(E), U(B), X(L), U(E), U(L) Final answer: S(A), S(B), U(A), S(E), U(B), X(L), U(E), U(L), X(A), X(B), U(A), X(E), U(B), X(L), U(E), U(L) Grading info: No points deducted for swapping U(E) and U(L). We cannot release X(E) and X(L) until after the insertion (since we need to split) so we end up releasing both locks at roughly the same time. End of Homework 5