eecs 491 introduction to distributed systems · initialize album1 and add photo1 read album1’s...

17
EECS 491 Introduction to Distributed Systems Fall 2019 Harsha V. Madhyastha

Upload: others

Post on 25-Sep-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: EECS 491 Introduction to Distributed Systems · Initialize album1 and add photo1 Read album1’s content and add photo2 Read album1’s content and add photo3 Album1 may eventually

EECS 491Introduction to Distributed

Systems

Fall 2019

Harsha V. Madhyastha

Page 2: EECS 491 Introduction to Distributed Systems · Initialize album1 and add photo1 Read album1’s content and add photo2 Read album1’s content and add photo3 Album1 may eventually

Consistency vs. availability

● Replica can execute client requests only if in same partition as majority

● What consistency can we offer if we want anyreplica to always serve client requests?

October 10, 2019 EECS 491 – Lecture 12 2

Replica

Replica

Replica

Replica

Replica

Page 3: EECS 491 Introduction to Distributed Systems · Initialize album1 and add photo1 Read album1’s content and add photo2 Read album1’s content and add photo3 Album1 may eventually

● If no new updates, all replicas eventually converge● Approach: Apply updates in same order at all

replicas in a manner that preserves causal ordering◆ Use Lamport clocks

● Principles to enable any client to always serve reqs:◆ Maintain log to apply updates immediately, roll back later◆ Exchange updates, not state, when syncing◆ Use version vector for efficient sync◆ Include conflict resolution policy in update

3

Eventual Consistency

October 10, 2019 EECS 491 – Lecture 12

Page 4: EECS 491 Introduction to Distributed Systems · Initialize album1 and add photo1 Read album1’s content and add photo2 Read album1’s content and add photo3 Album1 may eventually

● Never know whether some write from the past may yet reach your node◆ So all entries in log must be tentative forever◆ All nodes must store entire log forever

● To commit updates and garbage collect them◆ Rely on highly available primary to order updates◆ Order chosen by primary must preserve causality

4

Eventual Consistency

October 10, 2019 EECS 491 – Lecture 12

Page 5: EECS 491 Introduction to Distributed Systems · Initialize album1 and add photo1 Read album1’s content and add photo2 Read album1’s content and add photo3 Album1 may eventually

Committing Updates

● At any replica:◆ Stable state◆ Log of tentatively ordered updates (order based on

Lamport clock timestamps)

● Upon sync with primary◆ Receive updates in order◆ Apply updates to stable state and prune log

October 10, 2019 EECS 491 – Lecture 12 5

Page 6: EECS 491 Introduction to Distributed Systems · Initialize album1 and add photo1 Read album1’s content and add photo2 Read album1’s content and add photo3 Album1 may eventually

Replicated State Machines● Logical clock based RSM

◆ Cannot progress if any replica is unavailable◆ Eventually consistent even if intermittent connectivity

● Primary backup replication◆ Can replace primary/backup upon failure◆ Unavailable until failed replica is replaced

● Paxos based RSM◆ Available as long as majority in same partition

October 10, 2019 EECS 491 – Lecture 12 6

Page 7: EECS 491 Introduction to Distributed Systems · Initialize album1 and add photo1 Read album1’s content and add photo2 Read album1’s content and add photo3 Album1 may eventually

Consistency Spectrum

October 10, 2019 EECS 491 – Lecture 12 7

LinearizabilitySequentialCausalEventual

Consistency

Read-after-write

Ease of programming

Latency

Availability

Page 8: EECS 491 Introduction to Distributed Systems · Initialize album1 and add photo1 Read album1’s content and add photo2 Read album1’s content and add photo3 Album1 may eventually

Web Services in the Cloud

8

VM

Storage Service

VM VM

October 10, 2019 EECS 491 – Lecture 12

Page 9: EECS 491 Introduction to Distributed Systems · Initialize album1 and add photo1 Read album1’s content and add photo2 Read album1’s content and add photo3 Album1 may eventually

Example Scenario● Photo sharing web service deployed in AWS● Use Amazon S3 for storage

◆ User name à (# of photos, <List of album names>)◆ Album name à <List of photo URLs>◆ Photo URL à Image data

● Problems application must cope with because GETs may not reflect all completed PUTs?◆ Think through how to serve requests to upload

photos and add them albumsOctober 10, 2019 EECS 491 – Lecture 12 9

Page 10: EECS 491 Introduction to Distributed Systems · Initialize album1 and add photo1 Read album1’s content and add photo2 Read album1’s content and add photo3 Album1 may eventually

Problems with Eventual Consistency● Lack of referential integrity

◆ Total # of photos != sum of # of photos in each album● Updates may get lost

◆ Initialize album1 and add photo1◆ Read album1’s content and add photo2◆ Read album1’s content and add photo3◆ Album1 may eventually have only photo1 and photo3

● Why is Amazon S3 still useful at all?◆ Read-after-write consistency for initial PUT◆ Most data is write-once

October 10, 2019 EECS 491 – Lecture 12 10

Page 11: EECS 491 Introduction to Distributed Systems · Initialize album1 and add photo1 Read album1’s content and add photo2 Read album1’s content and add photo3 Album1 may eventually

● How to satisfy following goals?◆ Minimize latency for reads and writes◆ Ensure total ordering of writes◆ Okay to respond to reads with stale data but

minimize occurrences

Design Challenge

October 10, 2019 EECS 491 – Lecture 12 11

Webservers

Storage

Data center AWebservers

Storage

Data center BWebservers

Storage

Data center C

Page 12: EECS 491 Introduction to Distributed Systems · Initialize album1 and add photo1 Read album1’s content and add photo2 Read album1’s content and add photo3 Album1 may eventually

Facebook Architecture

October 10, 2019 EECS 491 – Lecture 12 12

How often does this system violate linearizability?

Page 13: EECS 491 Introduction to Distributed Systems · Initialize album1 and add photo1 Read album1’s content and add photo2 Read album1’s content and add photo3 Album1 may eventually

Linearizability checker● Many clients continually issue reads and writes● For each op, log time of request/response● For each read, log response value

● Construct graph with one vertex per operation● Directed edge from Op1 to Op2 if

◆ Op2 was issued after response for Op1 received◆ Op2 read value written by Op1

● Merge reads into writes● Cycle à Linearizability violation

October 10, 2019 EECS 491 – Lecture 12 13

Page 14: EECS 491 Introduction to Distributed Systems · Initialize album1 and add photo1 Read album1’s content and add photo2 Read album1’s content and add photo3 Album1 may eventually

Linearizability checker

October 10, 2019 EECS 491 – Lecture 12 14

Page 15: EECS 491 Introduction to Distributed Systems · Initialize album1 and add photo1 Read album1’s content and add photo2 Read album1’s content and add photo3 Album1 may eventually

Consistency at Facebook

● 0.0004% of reads violate linearizability◆ Despite system not designed for linearizability!

● Implication:◆ Whether a system offers linearizable consistency

cannot be ascertained via measurements◆ Must reason about system’s design

October 10, 2019 EECS 491 – Lecture 12 15

Page 16: EECS 491 Introduction to Distributed Systems · Initialize album1 and add photo1 Read album1’s content and add photo2 Read album1’s content and add photo3 Album1 may eventually

PACELC● If partition,

◆ Choose availability vs. consistency

● Else,◆ Choose latency vs.

consistency

● Externally visible effects may not reveal if system chooses latency over consistency

October 10, 2019 EECS 491 – Lecture 12 16

R

RR

R

R

Page 17: EECS 491 Introduction to Distributed Systems · Initialize album1 and add photo1 Read album1’s content and add photo2 Read album1’s content and add photo3 Album1 may eventually

Announcements

● Project 3:◆ Paxos-based key-value store (due Oct. 31st)◆ Overview of project at next Friday’s discussion

● Tomorrow’s discussion:◆ Implementing eventually consistent key-value store

● Use Fall break to review material for mid-term

October 10, 2019 EECS 491 – Lecture 12 17