CS 162 Discussion Section Week 9 11/11 – 11/15. Today’s Section ●Project discussion (5 min) ●Quiz (10 min) ●Lecture Review (20 min) ●Worksheet and Discussion.

Slides:



Advertisements
Similar presentations
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 16.
Advertisements

Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 16.
TRANSACTION PROCESSING SYSTEM ROHIT KHOKHER. TRANSACTION RECOVERY TRANSACTION RECOVERY TRANSACTION STATES SERIALIZABILITY CONFLICT SERIALIZABILITY VIEW.
1 Transaction Management Overview Chapter Transactions  Concurrent execution of user programs is essential for good DBMS performance.  Because.
Transaction Management Overview. Transactions Concurrent execution of user programs is essential for good DBMS performance. –Because disk accesses are.
ICOM 6005 – Database Management Systems Design Dr. Manuel Rodríguez-Martínez Electrical and Computer Engineering Department Lecture 16 – Intro. to Transactions.
Transaction Management Overview R & G Chapter 16 There are three side effects of acid. Enhanced long term memory, decreased short term memory, and I forget.
Transaction Processing Lecture ACID 2 phase commit.
Transaction Management Overview R & G Chapter 16 There are three side effects of acid. Enhanced long term memory, decreased short term memory, and I forget.
1 Concurrency Control and Recovery Module 6, Lecture 1.
1 Transaction Management Overview Yanlei Diao UMass Amherst March 15, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
Concurrency. Busy, busy, busy... In production environments, it is unlikely that we can limit our system to just one user at a time. – Consequently, it.
Concurrency. Correctness Principle A transaction is atomic -- all or none property. If it executes partly, an invalid state is likely to result. A transaction,
CS194-3/CS16x Introduction to Systems Lecture 8 Database concurrency control, Serializability, conflict serializability, 2PL and strict 2PL September.
1 Lecture 08: Transaction management overview
Concurrency Control 18.1 – 18.2 Chiu Luk CS257 Database Systems Principles Spring 2009.
Transaction Processing
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 16.
1 Transaction Management Overview Chapter Transactions  Concurrent execution of user programs is essential for good DBMS performance.  Because.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 16.
1 Transaction Management Overview Chapter Transactions  A transaction is the DBMS’s abstract view of a user program: a sequence of reads and writes.
Database Management Systems, 2 nd Edition. R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 18.
Transactions Sylvia Huang CS 157B. Transaction A transaction is a unit of program execution that accesses and possibly updates various data items. A transaction.
TRANSACTIONS. Objectives Transaction Concept Transaction State Concurrent Executions Serializability Recoverability Implementation of Isolation Transaction.
Database Management Systems, 2 nd Edition. R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Lecture 21 Ramakrishnan - Chapter 18.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 16.
Database Systems/COMP4910/Spring05/Melikyan1 Transaction Management Overview Unit 2 Chapter 16.
1 Transaction Management Overview Chapter Transactions  Concurrent execution of user programs is essential for good DBMS performance.  Because.
1 Transaction Processing Chapter Transaction Concept A transaction is a unit of program execution that accesses and possibly updates various data.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 136 Database Systems I SQL Modifications and Transactions.
Introduction to Database Systems1. 2 Basic Definitions Mini-world Some part of the real world about which data is stored in a database. Data Known facts.
©Silberschatz, Korth and Sudarshan15.1Database System Concepts Chapter 15: Transactions Transaction Concept Transaction State Implementation of Atomicity.
Transactions. What is it? Transaction - a logical unit of database processing Motivation - want consistent change of state in data Transactions developed.
ICS 321 Fall 2011 The Database Language SQL (iv) Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 10/26/20111Lipyeow.
Chapter 15: Transactions Loc Hoang CS 157B. Definition n A transaction is a discrete unit of work that must be completely processed or not processed at.
Chapter 14 Transactions Yonsei University 1 st Semester, 2015 Sanghyun Park.
1 Concurrency Control Lecture 22 Ramakrishnan - Chapter 19.
Transaction Management Overview. Transactions Concurrent execution of user programs is essential for good DBMS performance. – Because disk accesses are.
Transaction Management and Recovery, 2 nd Edition. R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 18.
ICOM 6005 – Database Management Systems Design Dr. Manuel Rodríguez-Martínez Electrical and Computer Engineering Department Lecture 16 – Intro. to Transactions.
Jinze Liu. ACID Atomicity: TX’s are either completely done or not done at all Consistency: TX’s should leave the database in a consistent state Isolation:
MULTIUSER DATABASES : Concurrency and Transaction Management.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 16.
April 7, 2014 Anthony D. Joseph CS162 Operating Systems and Systems Programming Lecture 18 Transactions April 7, 2014.
Anthony D. Joseph and Ion Stoica
April 8, 2013 Anthony D. Joseph CS162 Operating Systems and Systems Programming Lecture 18 Transactions April 8, 2013.
Transaction Management Overview
CS216: Data-Intensive Computing Systems
Transaction Management
Transaction Management Overview
Anthony D. Joseph and John Canny
Anthony D. Joseph and John Canny
CS122B: Projects in Databases and Web Applications Winter 2018
April 4, 2011 Ion Stoica CS162 Operating Systems and Systems Programming Lecture 18 Transactions April 4, 2011 Ion.
Transaction Management Overview
Transaction Management
Transaction Management Overview
Lecture 21: Concurrency & Locking
October 31, 2012 Ion Stoica CS162 Operating Systems and Systems Programming Lecture 18 TCP’s Flow Control, Transactions.
CS162 Operating Systems and Systems Programming Review (II)
Lecture 21: Intro to Transactions & Logging III
Transaction Management Overview
Transaction Management
Transaction Management Overview
CS122B: Projects in Databases and Web Applications Winter 2019
CS122B: Projects in Databases and Web Applications Spring 2018
Transaction Management Overview
Presentation transcript:

CS 162 Discussion Section Week 9 11/11 – 11/15

Today’s Section ●Project discussion (5 min) ●Quiz (10 min) ●Lecture Review (20 min) ●Worksheet and Discussion (20 min)

Project 3 ●Due 11/12 (Today!) at 11:59 PM submit proj3-initial-design ●Due 11/21 (Next Thursday) at 11:59 PM submit proj3-code ●Questions?

Quiz…

Lec /6/13 Anthony D. Joseph and John Canny CS162 ©UCB Fall 2013 Short Answer: 1.What are the 4 properties of an ACID transaction (2 points)? True/False: Choose 3 (stolen from lecture slides again) 2.A relational data model is the most used data model T 3.Transactions are not guaranteed to preserve the consistency of a storage system F 4.A DBMS uses a log to implement atomicity T 5.Durability isolates the reads and writes of a transaction from all other transactions F Quiz 18.2: Databases

Lec /6/13 Anthony D. Joseph and John Canny CS162 ©UCB Fall 2013 Short Answer: 1.What are the 4 properties of an ACID transaction (2 points)? True/False: 2.A relational data model is the most used data model 3.Transactions are not guaranteed to preserve the consistency of a storage system 4.A DBMS uses a log to implement atomicity 5.Durability isolates the reads and writes of a transaction from all other transactions Quiz 18.2: Databases

Lecture Review

Lec /6/13 Anthony D. Joseph and John Canny CS162 ©UCB Fall 2013 What is a Database A large organized collection of data Models real world, e.g., enterprise –Entities (e.g., teams, games) –Relationships, e.g., Cal plays against Stanford in The Big Game

Lec /6/13 Anthony D. Joseph and John Canny CS162 ©UCB Fall 2013 Key Concept: Structured Data A data model is a collection of entities and their relationships A schema is an instance of a data model –E.g., describes the fields in the database; how the database is organized A relational data model is the most used data model –Relation, a table with rows and columns –Every relation has a schema which describes the fields in the columns

Lec /6/13 Anthony D. Joseph and John Canny CS162 ©UCB Fall 2013 What is a Database System? A Database Management System (DBMS) is a software system designed to store, manage, and facilitate access to databases. A DBMS provides: –Data Definition Language (DDL) »Define relations, schema –Data Manipulation Language (DML) »Queries – to retrieve, analyze and modify data. –Guarantees about durability, concurrency, semantics, etc

Lec /6/13 Anthony D. Joseph and John Canny CS162 ©UCB Fall 2013 Key Concepts: Queries, Query Plans, and Operators System handles query plan generation & optimization; ensures correct execution. SELECT sid, name, gpa FROM Students S WHERE S.gpa > 3 Students Select Projection StudentsCoursesEnrolled Select all students with GPA > 3.0 Select all students with GPA>3 Pick columns:(sid, name, gpa)

Lec /6/13 Anthony D. Joseph and John Canny CS162 ©UCB Fall 2013 Key concept: Transaction An atomic sequence of database actions (reads/writes) Takes DB from one consistent state to another consistent state 1consistent state 2 transaction

Lec /6/13 Anthony D. Joseph and John Canny CS162 ©UCB Fall 2013 Concurrent Execution & Transactions Concurrent execution essential for good performance – Disk slow, so need to keep the CPU busy by working on several user programs concurrently DBMS only concerned about what data is read/written from/to the database –Not concerned about other operations performed by program on data Transaction – DBMS’s abstract view of a user program, i.e., a sequence of reads and writes. Locks are an important part of concurrency control.

Lec /6/13 Anthony D. Joseph and John Canny CS162 ©UCB Fall 2013 Locking Granularity What granularity to lock? –Database –Tables –Rows Fine granularity (e.g., row)  high concurrency –Multiple users can update the database and same table simultaneously Coarse granularity (e.g., database, table)  simple, but low concurrency Database Table 1 Row Table 2Table 4 Table 3

Lec /6/13 Anthony D. Joseph and John Canny CS162 ©UCB Fall 2013 The ACID properties of Transactions Atomicity: all actions in the transaction happen, or none happen Consistency: transactions maintain data integrity, e.g., –Balance cannot be negative –Cannot reschedule meeting on February 30 Isolation: execution of one transaction is isolated from that of all others; no problems from concurrency Durability: if a transaction commits, its effects persist despite crashes

Lec /6/13 Anthony D. Joseph and John Canny CS162 ©UCB Fall 2013 Atomicity A transaction –might commit after completing all its operations, or –it could abort (or be aborted) after executing some operations Atomic Transactions: a user can think of a transaction as always either executing all its operations, or not executing any operations at all – Database/storage system logs all actions so that it can undo the actions of aborted transactions

Lec /6/13 Anthony D. Joseph and John Canny CS162 ©UCB Fall 2013 Consistency Data follows integrity constraints (ICs) If database/storage system is consistent before transaction, it will be after System checks ICs and if they fail, the transaction rolls back (i.e., is aborted) –A database enforces some ICs, depending on the ICs declared when the data has been created –Beyond this, database does not understand the semantics of the data (e.g., it does not understand how the interest on a bank account is computed)

Lec /6/13 Anthony D. Joseph and John Canny CS162 ©UCB Fall 2013 Isolation Each transaction executes as if it was running by itself – It cannot see the partial results of another transaction Techniques: – Pessimistic – don’t let problems arise in the first place – Optimistic – assume conflicts are rare, deal with them after they happen

Lec /6/13 Anthony D. Joseph and John Canny CS162 ©UCB Fall 2013 Durability Data should survive in the presence of –System crash –Disk crash  need backups All committed updates and only those updates are reflected in the database – Some care must be taken to handle the case of a crash occurring during the recovery process!

Lec /6/13 Anthony D. Joseph and John Canny CS162 ©UCB Fall 2013 This Lecture Deal with (I)solation, by focusing on concurrency control Next lecture focus on (A)tomicity, and partially on (D)urability

Lec /6/13 Anthony D. Joseph and John Canny CS162 ©UCB Fall 2013 Goals of Transaction Scheduling Maximize system utilization, i.e., concurrency –Interleave operations from different transactions Preserve transaction semantics –Semantically equivalent to a serial schedule, i.e., one transaction runs at a time T1: R, W, R, W T2: R, W, R, R, W R, W, R, W, R, W, R, R, W Serial schedule (T1, then T2): R, W, R, R, W, R, W, R, W Serial schedule (T2, then T1):

Lec /6/13 Anthony D. Joseph and John Canny CS162 ©UCB Fall 2013 Two Key Questions 1)Is a given schedule equivalent to a serial execution of transactions? 2)How do you come up with a schedule equivalent to a serial schedule? R, W, R, W, R, W, R, R, W R, W, R, R, W, R, W, R, W R, R, W, W, R, R, R, W, W Schedule: Serial schedule (T1, then T2): : Serial schedule (T2, then T1):

Lec /6/13 Anthony D. Joseph and John Canny CS162 ©UCB Fall 2013 Transaction Scheduling Serial schedule: A schedule that does not interleave the operations of different transactions –Transactions run serially (one at a time) Equivalent schedules: For any storage/database state, the effect (on storage/database) and output of executing the first schedule is identical to the effect of executing the second schedule Serializable schedule: A schedule that is equivalent to some serial execution of the transactions –Intuitively: with a serializable schedule you only see things that could happen in situations where you were running transactions one-at-a-time

Lec /6/13 Anthony D. Joseph and John Canny CS162 ©UCB Fall 2013 Conflict Serializable Schedules Two operations conflict if they –Belong to different transactions –Are on the same data –At least one of them is a write Two schedules are conflict equivalent iff: –Involve same operations of same transactions –Every pair of conflicting operations is ordered the same way Schedule S is conflict serializable if S is conflict equivalent to some serial schedule

Lec /6/13 Anthony D. Joseph and John Canny CS162 ©UCB Fall 2013 If you can transform an interleaved schedule by swapping consecutive non-conflicting operations of different transactions into a serial schedule, then the original schedule is conflict serializable Example: T1:R(A),W(A), R(B),W(B) T2: R(A),W(A), R(B),W(B) T1:R(A),W(A), R(B), W(B) T2: R(A), W(A), R(B),W(B) T1:R(A),W(A),R(B), W(B) T2: R(A),W(A), R(B),W(B) Conflict Equivalence – Intuition

Lec /6/13 Anthony D. Joseph and John Canny CS162 ©UCB Fall 2013 Conflict Equivalence – Intuition If you can transform an interleaved schedule by swapping consecutive non-conflicting operations of different transactions into a serial schedule, then the original schedule is conflict serializable Example: T1:R(A),W(A),R(B), W(B) T2: R(A),W(A), R(B),W(B) T1:R(A),W(A),R(B), W(B) T2: R(A), W(A),R(B),W(B) T1:R(A),W(A),R(B),W(B) T2: R(A),W(A),R(B),W(B)

Lec /6/13 Anthony D. Joseph and John Canny CS162 ©UCB Fall 2013 Dependency Graph Dependency graph: –Transactions represented as nodes –Edge from Ti to Tj: »an operation of Ti conflicts with an operation of Tj »Ti appears earlier than Tj in the schedule Theorem: Schedule is conflict serializable if and only if its dependency graph is acyclic

Lec /6/13 Anthony D. Joseph and John Canny CS162 ©UCB Fall 2013 Example Conflict serializable schedule: No cycle! T1T2 A Dependency graph B T1:R(A),W(A), R(B),W(B) T2: R(A),W(A), R(B),W(B)

Lec /6/13 Anthony D. Joseph and John Canny CS162 ©UCB Fall 2013 Example Conflict that is not serializable: Cycle: The output of T1 depends on T2, and vice- versa T1:R(A),W(A), R(B),W(B) T2: R(A),W(A),R(B),W(B) T1T2 A B Dependency graph

Lec /6/13 Anthony D. Joseph and John Canny CS162 ©UCB Fall 2013 T1:R(A), W(A), T2: W(A), T3: WA Serializability ≠ Conflict Serializability Following schedule is not conflict serializable However, the schedule is serializable since its output is equivalent with the following serial schedule Note: deciding whether a schedule is serializable (not conflict-serializable) is NP-complete T1T2 A Dependency graph T1:R(A),W(A), T2: W(A), T3: WA T3 A A A

Lec /6/13 Anthony D. Joseph and John Canny CS162 ©UCB Fall 2013 Summary Transaction: a sequence of storage operations ACID: –Atomicity: all operations in a transaction happen, or none happens –Consistency: if database/storage starts consistent, it ends up consistent –Isolation: execution of one transaction is isolated from another –Durability: the results of a transaction persists Serial schedule: A schedule that does not interleave the operations of different transactions –Transactions run serially (one at a time)

Worksheet…