Distributed transactions ppt

transactions in distributed systems ppt and transitions for powerpoint presentation
Prof.EvanBaros Profile Pic
Prof.EvanBaros,United Kingdom,Teacher
Published Date:26-07-2017
Your Website URL(Optional)
Comment
Lecture 7 Lecture 7: Intro to Transactions & LoggingLecture 7 Today’s Lecture 1. Transactions 2. Properties of Transactions: ACID 3. Logging 6Lecture 7 Section 1 1. Transactions 7Lecture 7 Section 1 What you will learn about in this section 1. Our “model” of the DBMS / computer 2. Transactions basics 3. Motivation: Recovery & Durability 4. Motivation: Concurrency next lecture 8Lecture 7 Section 3 Our model High-level: Disk vs. Main Memory • Disk: Cylinder Spindle Tracks Disk head • Slow • Sequential access Sector • (although fast sequential reads) • Durable • We will assume that once on disk, data is safe Platters Arm movement • Cheap Arm assembly 9Lecture 7 Section 3 Our model High-level: Disk vs. Main Memory • Random Access Memory (RAM) or Main Memory: • Fast • Random access, byte addressable • 10x faster for sequential access • 100,000x faster for random access • Volatile • Data can be lost if e.g. crash occurs, power goes out, etc • Expensive • For 100, get 16GB of RAM vs. 2TB of disk 10Lecture 7 Section 3 Our model Our model: Three Types of Regions of Local Global Memory Main Memory 1 2 4 (RAM) 1. Local: In our model each process in a DBMS has its own local memory, where it stores values that only Disk 3 it “sees” 2. Global: Each process can read from / write to Log is a sequencefrom shared data in main memory main memory - disk 3. Disk: Global memory can read from / flush to disk “Flushingto disk” = writing to disk from main memory 4. Log: Assume on stable disk storage- spans both main memory and disk…Lecture 7 Section 3 Our model High-level: Disk vs. Main Memory • Keep in mind the tradeoffs here as motivation for the mechanisms we introduce • Main memory: fast but limited capacity, volatile • Vs. Disk: slow but large capacity, durable How do we effectively utilize bothensuring certain critical guarantees? 12Lecture 7 Section 1 Transactions Basics Transactions 13Lecture 7 Section 1 Transactions Basics Transactions: Basic Definition In the real world, a TXN transaction (“TXN”) A is a sequence either happened operations of one or more (reads or completely or not at all a single real- writes) which reflects world transition . START TRANSACTION UPDATE Product SET Price = Price – 1.99 WHERE pname = ‘Gizmo’ COMMITLecture 7 Section 1 Transactions Basics Transactions: Basic Definition In the real world, a TXN transaction (“TXN”) A is a sequence of one or either happened operations more (reads or writes) which reflects completely or not at all a single real-world transition . Examples: • Transfer money between accounts • Purchase a group of products • Register for a class (either waitlist or allocated)Lecture 7 Section 1 Transactions Basics Transactions in SQL • In “ad-hoc” SQL: • Default: each statement = one transaction • In a program, multiple statements can be grouped together as a transaction: START TRANSACTION UPDATE Bank SET amount = amount – 100 WHERE name = ‘Bob’ UPDATE Bank SET amount = amount + 100 WHERE name = ‘Joe’ COMMIT 16Lecture 7 Section 1 Transactions Basics Model of Transaction for CS 145 Note: For 145, we assume that the DBMS only sees reads and writes to data • User may do much more • In real systems, databases do have more info...Lecture 7 Section 1 Motivation Motivation for Transactions Grouping user actions (reads & writes) into transactions helps with two goals: 1. Recovery & Durability: Keeping the DBMS data This lecture consistent and durable in the face of crashes, aborts, system shutdowns, etc. 2. Concurrency: Achieving better performance by Next lecture parallelizing TXNs withoutcreating anomaliesLecture 7 Section 1 Motivation: Recovery & Durability Motivation 1. Recovery & Durabilityof user data is essential for reliable DBMS usage • The DBMS may experience crashes (e.g. power outages, etc.) • Individual TXNs may be aborted (e.g. by the user) Idea: Make sure that TXNs are either durably stored in full, or not at all; keep log to be able to “roll-back” TXNsLecture 7 Section 1 Motivation: Recovery & Durability Protection against crashes / aborts Client 1: INSERT INTO SmallProduct(name, price) SELECT pname, price FROM Product Crash / abort WHERE price = 0.99 DELETE Product WHERE price =0.99 What goes wrong? 20Lecture 7 Section 1 Motivation: Recovery & Durability Protection against crashes / aborts Client 1: START TRANSACTION INSERT INTO SmallProduct(name, price) SELECT pname, price FROM Product WHERE price = 0.99 DELETE Product WHERE price =0.99 COMMIT OR ROLLBACK Now we’d be fine We’ll see how / why this lecture 21Lecture 7 Section 1 Motivation: Concurrency Motivation 2. Concurrentexecution of user programs is essential for good DBMS performance. • Disk accesses may be frequent and slow-optimize for throughput ( of TXNs), trade for latency (time for any one TXN) • Users should still be able to execute TXNs as if in isolationand such that consistency is maintained Idea: Have the DBMS handle running several user TXNs concurrently, in order to keep CPUs humming…Lecture 7 Section 1 Motivation: Concurrency Multiple users: single statements Client 1: UPDATE Product SET Price = Price – 1.99 WHERE pname = ‘Gizmo’ Client 2: UPDATE Product SET Price = Price0.5 WHERE pname=‘Gizmo’ Two managers attempt to discount products concurrently- What could go wrong? 23Lecture 7 Section 1 Motivation: Concurrency Multiple users: single statements Client 1: START TRANSACTION UPDATE Product SET Price = Price – 1.99 WHERE pname = ‘Gizmo’ COMMIT Client 2: START TRANSACTION UPDATE Product SET Price = Price0.5 WHERE pname=‘Gizmo’ COMMIT Now works like a charm-we’ll see how / why next lecture… 24

Advise: Why You Wasting Money in Costly SEO Tools, Use World's Best Free SEO Tool Ubersuggest.