Page 1. Quiz 18.1: Flow-Control" Goals for Today" Quiz 18.1: Flow-Control" CS162 Operating Systems and Systems Programming Lecture 18 Transactions"

Similar documents
Page 1. Goals for Today" What is a Database " Key Concept: Structured Data" CS162 Operating Systems and Systems Programming Lecture 13.

Introduction to Database Management Systems

Database Management Systems. Chapter 1

Introduction to Database Systems. Chapter 1. Instructor: . Database Management Systems, R. Ramakrishnan and J. Gehrke 1

The Relational Model. Database Management Systems

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

Concurrency Control & Recovery

Page 1. CS194-3/CS16x Introduction to Systems. Lecture 8. Database concurrency control, Serializability, conflict serializability, 2PL and strict 2PL

COURSE 1. Database Management Systems

Database Management Systems Chapter 1 Instructor: Oliver Schulte Database Management Systems 3ed, R. Ramakrishnan and J.

Introduction to Database Systems CS432. CS432/433: Introduction to Database Systems. CS432/433: Introduction to Database Systems

Introduction to Transaction Management

BBM371- Data Management. Lecture 1: Course policies, Introduction to DBMS

Introduction to Data Management. Lecture #1 (Course Trailer )

Introduction to Data Management. Lecture #1 (Course Trailer ) Instructor: Chen Li

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

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

Lock Granularity and Consistency Levels (Lecture 7, cs262a) Ali Ghodsi and Ion Stoica, UC Berkeley February 7, 2018

Introduction to Data Management. Lecture #4 (E-R Relational Translation)

Introduction to Data Management. Lecture #1 (Course Trailer )

Introduction and Overview

Introduction TRANSACTIONS & CONCURRENCY CONTROL. Transactions. Concurrency

The Relational Model. Relational Data Model Relational Query Language (DDL + DML) Integrity Constraints (IC)

Introduction and Overview

Database Management Systems. Chapter 3 Part 1

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

Concurrency Control & Recovery

Big Data Processing Technologies. Chentao Wu Associate Professor Dept. of Computer Science and Engineering

Review. The Relational Model. Glossary. Review. Data Models. Why Study the Relational Model? Why use a DBMS? OS provides RAM and disk

Database Systems ( 資料庫系統 ) Practicum in Database Systems ( 資料庫系統實驗 ) 9/20 & 9/21, 2006 Lecture #1

Why Transac'ons? Database systems are normally being accessed by many users or processes at the same 'me.

Introduction to Data Management. Lecture #5 Relational Model (Cont.) & E-Rà Relational Mapping

The Relational Data Model. Data Model

Introduction to Transaction Management

Relational data model

CMPUT 291 File and Database Management Systems

Introduction to Data Management. Lecture #18 (Transactions)

Introduction to Data Management. Lecture #24 (Transactions)

A Few Tips and Suggestions. Database System II Preliminaries. Applications (contd.) Applications

CMPT 354: Database System I. Lecture 11. Transaction Management

Lecture 2 SQL. Instructor: Sudeepa Roy. CompSci 516: Data Intensive Computing Systems

Transaction Management Overview

CS275 Intro to Databases. File Systems vs. DBMS. Why is a DBMS so important? 4/6/2012. How does a DBMS work? -Chap. 1-2

Relational Algebra Homework 0 Due Tonight, 5pm! R & G, Chapter 4 Room Swap for Tuesday Discussion Section Homework 1 will be posted Tomorrow

Comp 5311 Database Management Systems. 4b. Structured Query Language 3

Introduction to Database Systems

CS 5614: (Big) Data Management Systems. B. Aditya Prakash Lecture #6: Transac/ons 1: Intro. to ACID

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

Administration Naive DBMS CMPT 454 Topics. John Edgar 2

Database Management System

Data! CS 133: Databases. Goals for Today. So, what is a database? What is a database anyway? From the textbook:

Transaction Management & Concurrency Control. CS 377: Database Systems

Transactions Processing (i)

Intro to Transaction Management

Intro to Transactions

Database Applications (15-415)

CS 4604: Introduc0on to Database Management Systems. B. Aditya Prakash Lecture #17: Transac0ons 1: Intro. to ACID

Database Systems ( 資料庫系統 )

Fall Semester 2002 Prof. Michael Franklin

A Few Tips and Suggestions. Database System I Preliminaries. Applications (contd.) Applications

Introduction to Data Management. Lecture #1 (The Course Trailer )

Goals for Today. CS 133: Databases. Relational Model. Multi-Relation Queries. Reason about the conceptual evaluation of an SQL query

A Few Tips and Suggestions. Database System II Preliminaries. Applications (contd.) Applications

Transaction Management and Concurrency Control. Chapter 16, 17

The Relational Model. Chapter 3

The Relational Model of Data (ii)

Database Systems. Announcement

Transactions. Kathleen Durant PhD Northeastern University CS3200 Lesson 9

The Relational Model. Chapter 3. Database Management Systems, R. Ramakrishnan and J. Gehrke 1

Overview. Introduction to Transaction Management ACID. Transactions

Lecture 2 SQL. Announcements. Recap: Lecture 1. Today s topic. Semi-structured Data and XML. XML: an overview 8/30/17. Instructor: Sudeepa Roy

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

Administrivia. The Relational Model. Review. Review. Review. Some useful terms

Integrity Constraints, Triggers, Transactions and Procedures

Lectures 8 & 9. Lectures 7 & 8: Transactions

Week 1 Part 1: An Introduction to Database Systems

TRANSACTION MANAGEMENT

Database Applications (15-415)

Transaction Management: Introduction (Chap. 16)

Transactions & Update Correctness. April 11, 2018

Introduction to Data Management. Lecture #4 (E-R à Relational Design)

The Relational Model. Why Study the Relational Model? Relational Database: Definitions

SQL: Transactions. Announcements (October 2) Transactions. CPS 116 Introduction to Database Systems. Project milestone #1 due in 1½ weeks

COGS 121 HCI Programming Studio. Week 03 - Tech Lecture

Introduction to Data Management CSE 344

John Edgar 2

Database Management Systems MIT Introduction By S. Sabraz Nawaz

CompSci 516 Database Systems. Lecture 2 SQL. Instructor: Sudeepa Roy

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

CSE 344 MARCH 5 TH TRANSACTIONS

CMPT 354: Database System I. Lecture 3. SQL Basics

Database Management System

Transactions. 1. Transactions. Goals for this lecture. Today s Lecture

Data Modeling. Yanlei Diao UMass Amherst. Slides Courtesy of R. Ramakrishnan and J. Gehrke

CSC 261/461 Database Systems Lecture 24

ECE 650 Systems Programming & Engineering. Spring 2018

Lecture 2 08/26/15. CMPSC431W: Database Management Systems. Instructor: Yu- San Lin

Database Management System

Relational Model. Topics. Relational Model. Why Study the Relational Model? Linda Wu (CMPT )

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

Transcription:

Quiz 18.1: Flow-Control" CS162 Operating Systems and Systems Programming Lecture 18 Transactions" April 8, 2013 Anthony D. Joseph http://inst.eecs.berkeley.edu/~cs162 Q1: True _ False _ Flow control is responsible for detecting packet losses and retransmissions Q2: True _ False _ Flow control always allows a sender to resend a lost packet Q3: True _ False _ With TCP, the receiving OS can deliver data to the application out-of-sequence (i.e., with gaps) Q4: True _ False _ Flow control makes sure the sender doesnʼt overflow the receiver Lec 18.2 Q1: True _ False _ X Flow control is responsible for detecting packet losses and retransmissions Q2: True _ X False _ Flow control always allows a sender to resend a lost packet Q3: True _ False _ X With TCP, the receiving OS can deliver data to the application out-of-sequence (i.e., with gaps) Q4: True X _ False _ Flow control makes sure the sender doesnʼt overflow the receiver Quiz 18.1: Flow-Control" What is a database? Goals for Today" Transactions (ACID semantics) Note: Some slides and/or pictures in the following are" adapted from lecture notes by Mike Franklin." Lec 18.3 Lec 18.4 Page 1

What is a Database " A large integrated collection of data Key Concept: Structured Data" A data model is a collection of entities and their relationships Models real world, e.g., enterprise Entities (e.g., teams, games) Relationships, e.g., Cal plays against Stanford in The Big Game 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 column Lec 18.5 Lec 18.6 Example: University Database" Conceptual schema: Students(sid: string, name: string, age: integer, gpa:real) Courses(cid: string, cname:string, credits:integer) Enrolled(sid:string, cid:string, grade:string) FOREIGN KEY sid REFERENCES Students FOREIGN KEY cid REFERENCES Courses External Schema (View): Course_info(cid:string,enrollment:integer) Create View Course_info AS SELECT cid, Count (*) as enrollment FROM Enrolled GROUP BY cid Example: An Instance of Students Relation" sid name login age gpa 53666 Jones jones@cs 18 3.4 53688 Smith smith@eecs 18 3.2 53650 Smith smith@math 19 3.8 Lec 18.7 Lec 18.8 Page 2

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 Key Concepts: Queries, Query Plans, and Operators" SELECT sid, name, gpa FROM Students S WHERE S.gpa > 3 System handles query plan generation & optimization; ensures correct execution. Projection" Select" Students" " Students" Courses" Enrolled" Pick columns: (sid, name, gpa) Select all students with GPA>3 Select all students with GPA > 3.0 Lec 18.9 Lec 18.10 Key Concepts: Queries, Query Plans, and Operators" SELECT COUNT DISTINCT (E.sid) FROM Enrolled E, Courses C WHERE E.cid = C.cid AND C.credits = 4 System handles query plan generation & optimization; ensures correct execution. Enrolled" Courses" " Students" Courses" Enrolled" Number of students who take a 4 credit class Count distinct sids Count distinct" Select rows Select" with credits=4 Columns: Join" (sid,cid, credits, ) Columns: (sid,cid,..) Columns: (cid,credits,..) Lec 18.11 Key concept: Transaction" An atomic sequence of database actions (reads/writes) Takes DB from one consistent state to another transaction consistent state 1 consistent state 2 Lec 18.12 Page 3

Example" From Multiprogramming to Transactions" checking: $200 savings: $1000 transaction checking: $300 savings: $900 Users would like the illusion of running their programs on the machine alone Why not run the entire program in a critical section? Here, consistency is based on our knowledge of banking semantics In general, up to writer of transaction to ensure transaction preserves consistency DBMS provides (limited) automatic enforcement, via integrity constraints (IC) e.g., balances must be >= 0 Users want fast response time and operators want to increase machine utilization à increase concurrency Interleave executions of multiple programs How can DBMS help? Lec 18.13 Lec 18.14 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. What granularity to lock? Database Tables Rows Locking Granularity" Database Table 1 Row Table 3 Table 2 Table 4 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 Lec 18.15 Lec 18.16 Page 4

Need for Transactions in Distributed Systems" Example: assume two clients updating same value in a keyvalue (KV) store at the same time Client A subtracts 75; client B adds 25 get(17) 100 100-75 = 25 put(17, 25) Client A Client B get(17) 100 100+25 = 25 put(17, 125) time KV Store K V 17 100 17 125 17 25 Client Bʼs update has been lost Lec 18.17 Solution?" How did we solve such problem on a single machine? Critical section, e.g., use locks Letʼs apply same solution here lock_acquire() get(17) 100 100-75 = 25 put(17, 25) lock_release() Client A Client B lock_acquire() KV Store K V 17 100 Client B canʼt acquire lock (A holds it) 17 25 Now, B can time get the lock Lec 18.18 Discussion" How does client B get the lock? Polling: periodically check whether the lock is free KV storage system keeps a list of clients waiting for the lock, and gives the lock to next client in the list What happens if the client holding the lock crashes? Network latency might be higher than update operation Most of the time in critical section spent waiting for messages Better Solution" Interleave reads and writes from different clients Provide the same semantics as clients were running one at a time Transaction database/storage sytemʼs abstract view of a user program, i.e., a sequence of reads and writes What is the lock granularity? Do you lock every key? Do you lock the entire storage? What are the tradeoffs? Lec 18.19 Lec 18.20 Page 5

Classic Example: Transaction BEGIN; --BEGIN TRANSACTION UPDATE accounts SET balance = balance - 100.00 WHERE name = 'Alice'; UPDATE branches SET balance = balance - 100.00 WHERE name = (SELECT branch_name FROM accounts WHERE name = 'Alice'); UPDATE accounts SET balance = balance + 100.00 WHERE name = 'Bob'; UPDATE branches SET balance = balance + 100.00 WHERE name = (SELECT branch_name FROM accounts WHERE name = 'Bob'); COMMIT; --COMMIT WORK Transfer $100 from Alice s account to Bobʼs account Lec 18.21 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 18.22 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 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 18.23 Lec 18.24 Page 6

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 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 18.25 Lec 18.26 Quiz 18.2: Databases" Administrivia" Q1: True _ False _ A relational data model is the most used data model Q2: True _ False _ Transactions are not guaranteed to preserve the consistency of a storage system Q3: True _ False _ A DBMS uses a log to implement atomicity Q4: True _ False _ Durability isolates the reads and writes of a transaction from all other transactions Project 3 initial design documents due tonight before 11:59PM Autograder will be available this week Thank the readers Lec 18.27 Lec 18.28 Page 7

Quiz 18.2: Databases" 5min Break" Q1: True X _ False _ A relational data model is the most used data model Q2: True _ False X _ Transactions are not guaranteed to preserve the consistency of a storage system Q3: True X _ False _ A DBMS uses a log to implement atomicity Q4: True _ False _ X Durability isolates the reads and writes of a transaction from all other transactions Lec 18.29 Lec 18.30 This Lecture" Example" Deal with (I)solation, by focusing on concurrency control Next lecture focus on (A)tomicity, and partially on (D)urability Consider two transactions: T1: moves $100 from account A to account B T1:A := A-100; B := B+100; T2: moves $50 from account B to account A T2:A := A+50; B := B-50; Each operation consists of (1) a read, (2) an addition/ subtraction, and (3) a write Example: A = A-100 Read(A); // R(A) A := A 100; Write(A); // W(A) Lec 18.31 Lec 18.32 Page 8

Example (contʼd)" Database only sees reads and writes Database View T1: A:=A-100; B:=B+100; à T1:R(A),W(A),R(B),W(B) T2: A:=A+50; B:=B-50; à T2:R(A),W(A),R(B),W(B) Assume initially: A = $1000 and B = $500 What is the legal outcome of running T1 and T2? A = $950 B = $550 T1: A:=A-100; B:=B+100; T2: A:=A+50; B:=B-50; Example (contʼd)" What is the outcome of the following execution? T1:R(A),W(A),R(B),W(B) T2: A=900 B=600 R(A),W(A),R(B),W(B) What is the outcome of the following execution? T1: R(A),W(A),R(B),W(B) T2:R(A),W(A),R(B),W(B) A=950 B=550 A=1050 B=450 Initial values: A:=1000 B:=500 A=950 B=550 Lec 18.33 Lec 18.34 T1: A:=A-100; B:=B+100; T2: A:=A+50; B:=B-50; Example (contʼd)" What is the outcome of the following execution? T1:R(A),W(A), R(B),W(B) T2: A=900 R(A),W(A),R(B),W(B) B=550 A=950 What is the outcome of the following execution? T1:R(A), W(A),R(B),W(B) T2: R(A),W(A),R(B),W(B) A=900 B=550 A=1050 Initial values: A:=1000 B:=500 B=450 B=450 Lost $50" Lec 18.35 Transaction Scheduling" Why not run only one transaction at a time? Answer: low system utilization Two transactions cannot run simultaneously even if they access different data Lec 18.36 Page 9

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 Serial schedule (T1, then T2): R, W, R, W, R, W, R, R, W Serial schedule (T2, then T1): R, W, R, R, W, R, W, R, W Two Key Questions" 1) Is a given schedule equivalent to a serial execution of transactions? Schedule:R, R, W, W, R, R, R, W, W?? Serial schedule (T1, then T2): Serial schedule (T2, then T1): R, : W, R, W, R, W, R, R, W R, W, R, R, W, R, W, R, W 2) How do you come up with a schedule equivalent to a serial schedule? Lec 18.37 Lec 18.38 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) Lec 18.39 Page 10