Topics in Reliable Distributed Systems

Similar documents
Introduction to Data Management CSE 344

CSE 344 MARCH 9 TH TRANSACTIONS

CSE 344 MARCH 25 TH ISOLATION

Introduction to Data Management CSE 344

Database Systems CSE 414

CSE 344 MARCH 5 TH TRANSACTIONS

CS122 Lecture 15 Winter Term,

Transactions. Kathleen Durant PhD Northeastern University CS3200 Lesson 9

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

Introduction to Data Management CSE 344

Introduction to Data Management CSE 344

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

Distributed Transaction Management

CSE 530A ACID. Washington University Fall 2013

5/17/17. Announcements. Review: Transactions. Outline. Review: TXNs in SQL. Review: ACID. Database Systems CSE 414.

Introduction to Data Management CSE 344

Transaction Processing. Introduction to Databases CompSci 316 Fall 2018

Database Systems CSE 414

CSE 444: Database Internals. Lectures 13 Transaction Schedules

Database Systems CSE 414

CSE 444: Database Internals. Lectures Transactions

Example: Transfer Euro 50 from A to B

Transactions. CS 475, Spring 2018 Concurrent & Distributed Systems

DATABASE DESIGN I - 1DL300

Introduction to Data Management CSE 414

) Intel)(TX)memory):) Transac'onal) Synchroniza'on) Extensions)(TSX))) Transac'ons)

CSE 544 Principles of Database Management Systems. Alvin Cheung Fall 2015 Lecture 14 Distributed Transactions

Announcements. Motivating Example. Transaction ROLLBACK. Motivating Example. CSE 444: Database Internals. Lab 2 extended until Monday

Concurrency Control & Recovery

Announcements. Transaction. Motivating Example. Motivating Example. Transactions. CSE 444: Database Internals

Transaction Management & Concurrency Control. CS 377: Database Systems

CS5412: TRANSACTIONS (I)

Database Management Systems CSEP 544. Lecture 9: Transactions and Recovery

) Intel)(TX)memory):) Transac'onal) Synchroniza'on) Extensions)(TSX))) Transac'ons)

L i (A) = transaction T i acquires lock for element A. U i (A) = transaction T i releases lock for element A

CONCURRENCY CONTROL, TRANSACTIONS, LOCKING, AND RECOVERY

CS 425 / ECE 428 Distributed Systems Fall 2017

Introduction to Transaction Management

Goal A Distributed Transaction

COURSE 1. Database Management Systems

Chapter 22. Transaction Management

Concurrency control 12/1/17

Overview of Transaction Management

Transactions and Concurrency Control. Dr. Philip Cannata

Database Tuning and Physical Design: Execution of Transactions

Transaction Management Exercises KEY

Introduction to Data Management. Lecture #18 (Transactions)

CSE 344 MARCH 21 ST TRANSACTIONS

CSE 190D Database System Implementation

) Intel)(TX)memory):) Transac'onal) Synchroniza'on) Extensions)(TSX))) Transac'ons)

Database System Concepts

The transaction. Defining properties of transactions. Failures in complex systems propagate. Concurrency Control, Locking, and Recovery

Database Management Systems

Transactions. Silberschatz, Korth and Sudarshan

Introduction. Storage Failure Recovery Logging Undo Logging Redo Logging ARIES

CS /15/16. Paul Krzyzanowski 1. Question 1. Distributed Systems 2016 Exam 2 Review. Question 3. Question 2. Question 5.

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

CS October 2017

Synchronization. Chapter 5

Concurrency Control & Recovery

Advances in Data Management Transaction Management A.Poulovassilis

Defining properties of transactions

Synchronization Part 2. REK s adaptation of Claypool s adaptation oftanenbaum s Distributed Systems Chapter 5 and Silberschatz Chapter 17

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

Distributed Commit in Asynchronous Systems

CS 5614: Transaction Processing 121. Transaction = Unit of Work Recall ACID Properties (from Module 1)


Security Mechanisms I. Key Slide. Key Slide. Security Mechanisms III. Security Mechanisms II

Chapter 6 Distributed Concurrency Control

Database Management Systems 2010/11

CS122 Lecture 19 Winter Term,

ATOMIC COMMITMENT Or: How to Implement Distributed Transactions in Sharded Databases

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

Multi-User-Synchronization

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

Transaction Management Overview

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

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

XI. Transactions CS Computer App in Business: Databases. Lecture Topics

CS 347 Parallel and Distributed Data Processing

Transactions and Concurrency Control

6.830 Lecture Transactions October 23, 2017

Transaction Management: Introduction (Chap. 16)

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

Agreement and Consensus. SWE 622, Spring 2017 Distributed Software Engineering

Introduction to Data Management. Lecture #26 (Transactions, cont.)

Transactions and Concurrency Control

Intro to Transaction Management

Distributed Data Analytics Transactions

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

Control. CS432: Distributed Systems Spring 2017

Distributed Data Management Transactions

CSE 544 Principles of Database Management Systems. Magdalena Balazinska Fall 2007 Lecture 13 - Distribution: transactions

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

Database System Concepts

Transaction Management: Concurrency Control, part 2

Locking for B+ Trees. Transaction Management: Concurrency Control, part 2. Locking for B+ Trees (contd.) Locking vs. Latching

7 Fault Tolerant Distributed Transactions Commit protocols

Motivating Example. Motivating Example. Transaction ROLLBACK. Transactions. CSE 444: Database Internals

CHAPTER 3 RECOVERY & CONCURRENCY ADVANCED DATABASE SYSTEMS. Assist. Prof. Dr. Volkan TUNALI

Transcription:

Topics in Reliable Distributed Systems 049017 1 T R A N S A C T I O N S Y S T E M S

What is A Database? Organized collection of data typically persistent organization models: relational, object-based, hierarchal Retrieval using query languages Concurrently accessed by many users supports transactions Managed by DBMS (DataBase Management System) software 2

Relational Database A collection of tables (relations) A table is defined with a fixed set of attributes (columns) e.g., person table attributes: id, name, age, address Data is stored in rows (tuples) Attribute (column) 3 Row (tuple) Table (relation)

Querying Relational Databases High-level query languages based on set-theory, relations SQL most popular Select data from tables conditionally select based on attributes e.g., where name = Smith and age > 16 project keep only some columns e.g., only name and address join combine info from multiple tables Use set theory operations on the results union, difference, Cartesian product 4

Student ID Join Example Course Registration Table Course Course Exam Date 123456789 046209 046209 25/6 5 Exam Dates Table We can retrieve student IDs of all students who have exams on 25/6

Transactions [Gray 78] A collection of query and update operations executed atomically may succeed and commit may fail and abort by the programmer or by the DBMS So-called ACID properties: Atomicity: all-or-nothing Consistency: correct execution Isolation: no partial results observed Durability: persistence 6 Serializability

Transactions and Concurrency Concurrent transactions are allowed, unless they conflict 7 read x; write(y, 7) OK to commit both read a; write(b, 8) need to abort one read b; write(a, 6) time

Formal Criterion: Serializability There is some sequential execution of the same transactions that looks like the concurrent one T1 read(a) write(a,1) time T2 read(a)=1 write(a,2) 8 read(b) write(b,1) OK to commit both read(b)=1 write(b,2) T1 Looks like: read(a) write(a,1) read(b) write(b,1) T2 read(a) write(a,2) read(b) write(b,2)

When Serializability is Violated T1 read a; write(b, 8) 9 time T2 read b; write(a, 6) Can t order T1 before T2 why? reads old value of a And vice-versa What do we do?

Ensuring ACID DBMSs use two complementary mechanisms to achieve the ACID properties 1. Concurrency control controls concurrent executions 2. Recovery 10 kicks in on recovery from crash

x Concurrency Control Approaches Pessimistic approach a transaction locks all items before accessing them releases locks at the end (2-phase locking) downsides? Optimistic approach ongoing transactions write to private copy recall the old value of every read object at the end check if old values changed what do we do if they changed? 11

Tradeoffs Pessimistic may deadlock Optimistic may lead to livelock Optimistic may allow more parallelism commit in more cases Optimistic may waste more work 12 because of being too optimistic

2-Phase Locking (2PL) Transaction T must obtain a lock on every item before accessing it Two types of locks (readers-writers problem) exclusive for writes shared for reads conflicts: read-write or write-write If T releases some lock, it cannot acquire any locks afterwards Ensures serializability 13 # locks Time

When To Release? To release, we need to know T won t need any more locks typically not known before T tries to commit Moreover, if we release exclusive locks before commit, other transactions may read dirty values this may lead to cascading aborts Solution: Strict 2PL 14 release locks after commit/abort

Deadlock Happens Construct a deadlock scenario with 2 concurrent transactions Possible solutions: periodic cycle detection 15 timeout-based: if a transaction waits for a lock for too long it aborts

Ensuring Atomicity + Persistence Based on logs (journals) WAL Write Ahead Log: write to the log before writing to the DB Log records for writes includes T s id, old and new values T end commit or abort Used to undo (rollback) operations of aborted transactions redo updates lost due to crash (on recovery) Two approaches: write-in-place need to undo database updates of aborted transactions delayed-write write in log first, lazily write in place committed transactions only 16

Multi-Tier Distributed Architecture Clients access OMs either via TMs or directly 17 Transaction Managers init/commit/abort API OM TM OM TM OM OM Object Managers: read/write API k,v k,v k,v k,v k,v k,v k,v k,v k,v k,v k,v k,v Highly Available Key-Value Storage

Distributed Transactions Databases nowadays are often partitioned/sharded across multiple machines Data items are also replicated, but usually at a lower level of abstraction Highly Available (HA) Key-Value Store or Object Store Transactions may span multiple sites Need to ensure atomic commit: either a transaction commits at all sites, or aborts at all of them If any site needs to abort the transaction, it aborts 18

Non-Blocking Atomic Commit Uniform agreement: all processes that decide, decide on the same value decisions are not reversible Validity: commit can only be reached if all processes vote yes Non triviality: if all vote yes and there are no (suspicions of) failures, then the decision is commit Termination: all live processes eventually decide 19

2 Phase Commit (2PC) One node is the coordinator C C sends the transaction to everyone Every other node sends its vote to C C waits until either it receives replies from all, it receives one no vote, or some node fails (suspected to have failed) If all vote yes, then send commit to all Otherwise, send abort to all Other nodes do what C says 20

2PC Flow (Non-Coordinator) 21 Vote yes q Vote no w Received commit C Received abort A

2PC Properties Simple, fast most commonly used Problem? Blocking: if C fails, everyone is stuck 22 e.g., if everyone voted yes but did not receive an answer, it is unknown whether C committed or aborted before failing Skeen & Stonebraker proved that if the network can partition, blocking is unavoidable

3PC Protocol [Skeen 82] Avoids blocking when the coordinator crashes Assumes: 1. failures are accurately detected, aka fail-stop model or perfect failure detector 2. at most one process crashes during a transaction s execution Adds a prepare phase before commit the coordinator announces what it plans to decide before it decides 23

3PC Normal Operation Coordinator Send Transaction If all replied yes, send PreCommit Else send Abort If got ACKs from all, send Commit Else send Abort 24 Participant Send vote (Yes/No) If got PreCommit, send ACK If got Commit, commit If got Abort, abort

3PC Flow (Non-Coordinator) 25 Vote yes q Vote no w Received PC PC Received commit C Received abort A

Rationale Normal mode is correct: all do what C says, and C doesn t change its mind this was true for 2PC too Recovery from one failure now possible if C committed, then every other process is either in the C state or in the PC state if all remaining nodes are in the PC state (recall, only C failed), no node aborted no ambiguity on whether C committed or aborted before failing 26

3PC Recovery 27 On detecting C s failure (recall, this is accurate!) run recovery procedure: 1. Elect new coordinator C e.g., live node with smallest id 2. C collects the states of all live processes 3. C chooses its state as follows: if one process said Abort A if one process said Commit C if one process said PC PC else Abort (why is this valid?) 4. Continue as in the normal mode

Notes on 3PC 3PC is incorrect when there are false suspicions i.e., when nodes suspect a non-faulty coordinator doesn t work if the network can partition! 3PC is incorrect when C and one more node fail during the same transaction! C can send abort from PC state due to another node s failure other nodes cannot tell the difference between this and C sending commit Homework: construct two indistinguishable executions s.t. the recovery phase must commit in one and abort in the other 28

Quorum-based recovery A Correct Solution 29 coordinator needs majority to support any decision (commit or abort) add pre-abort state Option 1: Direct Quorum-based recovery, E3PC [Keidar, Dolev 98] Ensures safety with imperfect failure detection, network partitions, unbounded number of failures Requires live connected majority in order to make progress blocks otherwise (this is inherent) Option 2: Use 2PC, but replace coordinator with replicated state machine, e.g., using Paxos

Quorum-Based Recovery 30 Received PC PC Received commit C w Received PA PA Received abort A If some node committed, then a majority is in the C or PC states If some node aborted, then a majority is in the A state or PA states If we talk to a majority no ambiguity on whether the previous C committed or aborted before failing

Distributed Commit Summary Distributed transactions are tricky especially if we want to tolerate partitions Impossible to overcome unbounded message loss cf. 2-Generals Problem Impossible to ensure progress without a live, connected majority In real-life, 2PC is good enough may sometimes block 31 HA solutions replicate the coordinator