Consistency: Relaxed. SWE 622, Spring 2017 Distributed Software Engineering

Similar documents
Consistency: Strict & Sequential. SWE 622, Spring 2017 Distributed Software Engineering

Consistency. CS 475, Spring 2018 Concurrent & Distributed Systems

Distributed Systems. Lec 12: Consistency Models Sequential, Causal, and Eventual Consistency. Slide acks: Jinyang Li

Distributed Systems. Catch-up Lecture: Consistency Model Implementations

Today CSCI Data Replication. Example: Distributed Shared Memory. Data Replication. Data Consistency. Instructor: Abhishek Chandra

Replication and Consistency

Lecture 6 Consistency and Replication

Distributed Systems. Lec 11: Consistency Models. Slide acks: Jinyang Li, Robert Morris

Distributed Systems. Lec 9: Distributed File Systems NFS, AFS. Slide acks: Dave Andersen

Distributed Systems. Fundamentals Shared Store. Fabienne Boyer Reprise du cours d Olivier Gruber. Université Joseph Fourier. Projet ERODS (LIG)

DISTRIBUTED COMPUTER SYSTEMS

Important Lessons. Today's Lecture. Two Views of Distributed Systems

Consistency examples. COS 418: Distributed Systems Precept 5. Themis Melissaris

Availability versus consistency. Eventual Consistency: Bayou. Eventual consistency. Bayou: A Weakly Connected Replicated Storage System

CS555: Distributed Systems [Fall 2017] Dept. Of Computer Science, Colorado State University

Time and distributed systems. Just use time stamps? Correct consistency model? Replication and Consistency

Memory Consistency. Minsoo Ryu. Department of Computer Science and Engineering. Hanyang University. Real-Time Computing and Communications Lab.

CS6450: Distributed Systems Lecture 11. Ryan Stutsman

Example File Systems Using Replication CS 188 Distributed Systems February 10, 2015

Causal Consistency and Two-Phase Commit

Consistency & Replication

Data-Centric Consistency Models. The general organization of a logical data store, physically distributed and replicated across multiple processes.

EECS 498 Introduction to Distributed Systems

Distributed Systems (5DV147)

Distributed Systems Principles and Paradigms. Chapter 07: Consistency & Replication

Data Replication CS 188 Distributed Systems February 3, 2015

Performance and Forgiveness. June 23, 2008 Margo Seltzer Harvard University School of Engineering and Applied Sciences

Consistency in Distributed Storage Systems. Mihir Nanavati March 4 th, 2016

Replication. Feb 10, 2016 CPSC 416

Chapter 4: Distributed Systems: Replication and Consistency. Fall 2013 Jussi Kangasharju

CS6450: Distributed Systems Lecture 13. Ryan Stutsman

June Gerd Liefländer System Architecture Group Universität Karlsruhe, System Architecture Group

Computing Parable. The Archery Teacher. Courtesy: S. Keshav, U. Waterloo. Computer Science. Lecture 16, page 1

SCALABLE CONSISTENCY AND TRANSACTION MODELS

Consistency and Replication 1/65

10. Replication. CSEP 545 Transaction Processing Philip A. Bernstein Sameh Elnikety. Copyright 2012 Philip A. Bernstein

殷亚凤. Consistency and Replication. Distributed Systems [7]

Foundations of the C++ Concurrency Memory Model

416 Distributed Systems. Distributed File Systems 4 Jan 23, 2017

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

10. Replication. Motivation

Eventual Consistency 1

Building Consistent Transactions with Inconsistent Replication

Recall use of logical clocks

Important Lessons. A Distributed Algorithm (2) Today's Lecture - Replication

What is consistency?

MASSACHUSETTS INSTITUTE OF TECHNOLOGY Distributed System Engineering: Spring Quiz I Solutions. Grade histogram for Quiz I

Replication in Distributed Systems

Replication and Consistency. Fall 2010 Jussi Kangasharju

CSE 444: Database Internals. Lecture 25 Replication

Distributed File Systems

Consistency and Replication

Don t Give Up on Serializability Just Yet. Neha Narula

GFS: The Google File System

Module 7 - Replication

Distributed systems. Lecture 6: distributed transactions, elections, consensus and replication. Malte Schwarzkopf

6.824 Distributed System Engineering: Spring Quiz I Solutions

Distributed Systems: Consistency and Replication

Ch06. NoSQL Part III.

NoSQL systems: sharding, replication and consistency. Riccardo Torlone Università Roma Tre

G Bayou: A Weakly Connected Replicated Storage System. Robert Grimm New York University

Distributed Systems 16. Distributed File Systems II

Consistency and Replication

Exam in Distributed Systems

Consistency and Replication 1/62

Distributed Computation Models

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

Replications and Consensus

Causal Consistency. CS 240: Computing Systems and Concurrency Lecture 16. Marco Canini

Transactions. CS 475, Spring 2018 Concurrent & Distributed Systems

Distributed Shared Memory

Consistency and Replication. Why replicate?

Replication of Data. Data-Centric Consistency Models. Reliability vs. Availability

Data Modeling and Databases Ch 14: Data Replication. Gustavo Alonso, Ce Zhang Systems Group Department of Computer Science ETH Zürich

ZooKeeper & Curator. CS 475, Spring 2018 Concurrent & Distributed Systems

Exam in Distributed Systems

CS5412: TRANSACTIONS (I)

Choosing a MySQL HA Solution Today. Choosing the best solution among a myriad of options

Distributed Data Store

CS 347 Parallel and Distributed Data Processing

Shared Memory. SMP Architectures and Programming

Distributed Systems. Lec 10: Distributed File Systems GFS. Slide acks: Sanjay Ghemawat, Howard Gobioff, and Shun-Tak Leung

Cache Coherence. CMU : Parallel Computer Architecture and Programming (Spring 2012)

Eventual Consistency Today: Limitations, Extensions and Beyond

6.830 Lecture Recovery 10/30/2017

CSE 5306 Distributed Systems. Consistency and Replication

ò Server can crash or be disconnected ò Client can crash or be disconnected ò How to coordinate multiple clients accessing same file?

CSE 5306 Distributed Systems

CMU SCS CMU SCS Who: What: When: Where: Why: CMU SCS

NFS. Don Porter CSE 506

GFS: The Google File System. Dr. Yingwu Zhu

Relaxed Memory-Consistency Models

Quiz I Solutions MASSACHUSETTS INSTITUTE OF TECHNOLOGY Spring Department of Electrical Engineering and Computer Science

Database Management System Prof. D. Janakiram Department of Computer Science & Engineering Indian Institute of Technology, Madras Lecture No.

Indirect Communication

Exam 2 Review. Fall 2011

Eventual Consistency Today: Limitations, Extensions and Beyond

EECS 482 Introduction to Operating Systems

CS 31: Intro to Systems Threading & Parallel Applications. Kevin Webb Swarthmore College November 27, 2018

Birth of Optimistic Methods. On Optimistic Methods for Concurrency Control. Basic performance arg

Transcription:

Consistency: Relaxed SWE 622, Spring 2017 Distributed Software Engineering

Review: HW2 What did we do? Cache->Redis Locks->Lock Server Post-mortem feedback: http://b.socrative.com/ click on student login, then SWE622 as room name 2

Review: The Sleeping Barber Barber: Cuts 1 person s hair at a time When finished, dismiss customer. Check waiting room for more customers. If more, then cut next customer s hair. If no more, take a nap Customer: Walks in, sees if barber is napping, if so, wakes barber, else, goes to waiting room 3

Review: The Sleeping Barber Barber Old Customer New Customer Cutting Hair Finishes cutting Checks waiting room Escorts to chair, cuts hair In Chair Leaves Sees barber cutting hair Goes to waiting room Follows barber to get hair cut 4

Review: The Sleeping Barber Barber Old Customer New Customer Cutting Hair Finishes cutting Checks waiting room Goes to sleep In Chair Leaves Sees barber cutting hair Walks slowly to waiting room Sits in waiting room 5

Review: The Sleeping Barber Barber Old Customer New Customer Cutting Hair In Chair Finishes cutting Leaves Gets lock to check on barber Gets lock to check waiting room (blocked) Walks slowly to waiting room Sits in waiting room Releases lock Acquires lock Checks waiting room, finds customer Fix: Barber can not check or new customers while customers are entering 6

Review: What s the output? class MyObj { int x = 0; int y = 0; "" } void thread0() { x = 1; if(y==0) System.out.println( OK"); } void thread1() { y = 1; if(x==0) System.out.println( OK"); } "OK" "OK" "OK" WTF? 7

Review: Java Memory Model CPU 1 thread0() 7ns CPU 1 Cache 100ns CPU 2 Main Memory thread1() CPU 2 Cache 8

Review: Consistency This is a consistency model! Constraints on the system state that are observable by applications When I write y=1, any future reads must say y=1 except in Java, if it s a non-volatile variable Clearly, this often comes at a cost (see simple example with volatile ) 9

Review: Sequential Consistency Strict consistency is often not practical Requires globally synchronizing clocks Sequential consistency gets close, in an easier way: There is some total order of operations so that: Each CPUs operations appear in order All CPUs see results according to that order (read most recent writes) 10

Sequential Consistency: P1 W(X) a Quiz There is some total order of operations so that: Each CPUs operations appear in order All CPUs see results according to that order (read most recent writes) P2 W(X) b P3 R(X) b R(X) a P4 R(X) b R(X) a Sequentially consistent but not strictly consistent. W(X)b, R(X)b,R(X)b,W(X)a, R(X)a, R(X)a 11

Sequential Consistency: Quiz There is some total order of operations so that: Each CPUs operations appear in order All CPUs see results according to that order (read most recent writes) P1 W(X) a P2 W(X) b P3 R(X) b R(X) a P4 R(X) a R(X) b Not sequentially consistent 12

Sequential Consistency: Activity http://b.socrative.com/ click on student login, then SWE622 as room name 13

Review: Ivy Architecture Each node keeps a cached copy of each piece of data it reads cached data x=0 x=1 invalidate x Write X=1 Today: What if it s OK for some replica to read the wrong value? If some data doesn t exist locally, request it from remote node ead X read x read x Faster? More available? Partition tolerant? Yes! cached data cached data x=0 Read X 14

Today Are relaxed consistency models easier to fit in CAP? Causal consistency Eventual consistency File synchronization Disconnected synchronization HW 3 15

Relaxing Consistency We can relax two design principles: How stale reads can be The ordering of writes across the replicas 16

Allowing Stale Reads P1 W(X) 0 R(X) R(X) R(X) P2 W(X) 1 R(X) W (X) 0 R(X) P3 R(X) R(X) R(X) 17

Allowing Stale Reads class MyObj { int x = 0; int y = 0; "" } void thread0() { x = 1; if(y==0) System.out.println( OK"); } void thread1() { y = 1; if(x==0) System.out.println( OK"); } "OK" "OK" "OK" Java s memory model is relaxed in that you can have stale reads 18

Relaxing Consistency Intuition: less constraints means less coordination overhead, less prone to partition failure P1 W(X) 0 R(X) [0,1] R(X) [0,1] R(X) [0,1] P2 W(X) 1 R(X) [0,1] W (X) 0 R(X) [0,1] P3 R(X) [0,1] R(X) [0,1] R(X) [0,1] 19

Naïve DSM Assume each machine has a complete copy of memory Reads from local memory Writes broadcast update to other machines, then immediately continue class Machine1 { DSMInt x = 0; DSMInt y = 0; class Machine2 { DSMInt x = 0; DSMInt y = 0; } static void main(string[] args) { x = 1; if(y==0) System.out.println( OK"); } } static void main(string[] args) { y = 1; if(x==0) System.out.println( OK"); } 20

Naïve DSM Assume each machine has a complete copy of memory Reads from local memory Writes broadcast update to other machines, then immediately continue class Machine1 { DSMInt x = 10; DSMInt y = 0; class Machine2 { DSMInt x = 0; DSMInt y = 0; 1 } static void main(string[] args) { x = 1; if(y==0) System.out.println( OK"); } } static void main(string[] args) { y = 1; if(x==0) System.out.println( OK"); } 21

Naïve DSM Assume each machine has a complete copy of memory Reads from local memory Writes broadcast update to other machines, then immediately continue class Machine1 { DSMInt x = 10; DSMInt y = 0; class Machine2 { DSMInt x = 0; DSMInt y = 0; 1 1 Is this correct? } static void main(string[] args) { x = 1; if(y==0) System.out.println( OK"); } } static void main(string[] args) { y = 1; if(x==0) System.out.println( OK"); } 22

Naïve DSM It definitely is not sequentially consistent Are there any guarantees that it provides though? Reads can be stale Writes can be re-ordered Not really. Can we come up with something more clever though with SOME guarantee? (Not as is, but with some modifications maybe it s ) 23

Causal Consistency An execution is causally-consistent if all causallyrelated read/write operations are executed in an order that reflects their causality Reads are fresh ONLY for writes that they are dependent on Causally-related writes appear in order, but not in order to others Concurrent writes can be seen in different orders Recall: Lamport clocks 24

Causal Consistency P1 W(X)a W(X)c P2 R(X)a W(X)b P3 R(X)a R(X)c R(X)b P4 R(X)a R(X)b R(x)c Causally Consistent. W(X) b and W(X) c are not related, hence could have happened one either order. 25

Causal Consistency P1 W(X)a P2 R(X)a W(X)b P3 R(x)b R(x)a P4 R(x)a R(x)b NOT Causally Consistent. X couldn t have been b after it was a P1 W(X)a P2 W(X)b P3 R(x)b R(x)a P4 R(x)a R(x)b Causally Consistent. X can be a or b concurrently 26

Why Causal Consistency? It is clearly weaker than sequential consistency (Note that anything that is sequentially consistent is also causally consistent) Many more operations for concurrency Parallel (non-dependent) operations can occur in parallel in different places Sequential would enforce a global ordering E.g. if W(X) and W(Y) occur at the same time, and without dependencies, then they can occur without any locking 27

Eventual Consistency Allow stale reads, but ensure that reads will eventually reflect the previously written values Eventually: milliseconds, seconds, minutes, hours, years Writes are NOT ordered as executed Allows for conflicts. Consider: Dropbox Git is eventually consistent 28

Eventual Consistency More concurrency than strict, sequential or causal These require highly available connections to send messages, and generate lots of chatter Far looser requirements on network connections Partitions: OK! Disconnected clients: OK! Always available! Possibility for conflicting writes :( 29

Review: Ivy Architecture Each node keeps a cached copy of each piece of data it reads cached data x=0 x=1 invalidate x All of these messages Write X=1 All of the clients must always be online! Relax! If some data doesn t exist locally, request it from remote node read x read x ead X cached data cached data x=0 Read X 30

Sequential vs Eventual Consistency Sequential: Pessimistic concurrency control Assume that everything could cause a conflict, decide on an update order as things execute, then enforce it Eventual: Optimistic concurrency control Just do everything, and if you can t resolve what something should be, sort it out later Can be tough to resolve in general case 31

Eventual Consistency: Distributed Filesystem When everything can talk, it s easy to synchronize, right? Goal: Everything eventually becomes synchronized. No lost updates (don t replace new version with old) 32

Eventual Consistency: Distributed Filesystem Fix: Add coordinating sync server When everything can talk, it s easy to synchronize, right? Goal: Everything eventually becomes synchronized. No lost updates (don t replace new version with old) 33

Eventual Consistency: Distributed Filesystem Role of the sync server: Resolve conflicting changes, report conflicts to user Do not allow sync between clients Detect if updates are sequential Enforce ordering constraints 34

Detecting Conflicts Do we just use timestamps? t=0 write x = a t=1 write x = b 35

Detecting Conflicts Do we just use timestamps? t=0 write x = a t=1 write x = b NO, what if clocks are out of sync? NO does not actually detect conflicts 36

Detecting Conflicts Solution: Track version history on clients v=0 write x = a v=0 write x = b Still doesn t tell us what to do with a conflict 37

Client-Centric Consistency What can we guarantee in disconnected operation? Monotinic-reads: any future reads will return the same or newer value (never older) Monotonic-writes: A processes writes are always processed in order Read-you-writes Writes follow reads 38

Choosing a consistency model Sequential consistency All over - it s the most intuitive Causal consistency Increasingly useful Eventual consistency Very popular in industry and academia File synchronizers, Amazon s Bayou and more 39

Sequentially Consistent + Available Set A=5 Read A OK! 6! Set A=5 Assume replica failed A B A B 65 7 6 7 40

Sequentially Consistent + Not Partition Tolerant Set A=5 OK! Set A=5 Read A 6! Assume replica failed A B A B 65 7 6 7 41

CAP Theorem Pick two of three: Consistency: All nodes see the same data at the same time (strong consistency) Availability: Individual node failures do not prevent survivors from continuing to operate Partition tolerance: The system continues to operate despite message loss (from network and/or node failure) You can not have all three, ever* If you relax your consistency guarantee (we ll talk about in a few weeks), you might be able to guarantee THAT 42

Eventually Consistent + Available + Partition Tolerant Set A=5 OK! Set A=5 Read A 6! 5! Assume replica failed A B A B 65 7 65 7 43

Filesystem consistency What consistency guarantees do a filesystem provide? read, write, sync, close On sync, guarantee writes are persisted to disk Readers see most recent What does a network file system do? 44

Network Filesystem Consistency How do you maintain these same semantics? (Cheat answer): Very, very expensive EVERY write needs to propagate out EVERY read needs to make sure it sees the most recent write Oof. Just like Ivy. 45

Ivy Architecture Each node keeps a cached copy of each piece of data it reads cached data x=0 x=1 invalidate x Write X=1 If some data doesn t exist locally, request it from remote node read x read x Read X cached data cached data x=0 Read X 46

Open-Close Semantics This is what AFS (CMU s internal filesystem) does Simplify it. When you open a file, you get a copy. When you close it, you commit your changes. Allows for stale reads But, maybe it s OK? 47

Redis Replication Redis supports master-slave replication What consistency guarantees does it provide and how does it work? Replication is asynchronous Only the master receives writes, slaves are read only Reduces coordination, useful for read-heavy workloads 48

Redis Replication 1: Write key foo = bar Client 2: Acknowledge write foo=bar Master 3: Send update Read foo foo=bar Client Slave Slave 49

Redis Replication 1: Write key foo = bar Client 2: Acknowledge write foo=bar Master 3: Send update Read foo foo=??? Client Slave Slave 50

Redis Replication t=0 t=1 Client 1 Write Foo Client 2 Read Foo Nothing tells us/redis that Client 2 must see Client 1 s update (consider this like eventual consistency - eventually client 2 will see it, but it might see a stale one) 51

Redis Wait command Client 1: Write key foo = bar. WAIT 4: Acknowledge write foo=bar Master 2: Send update Read foo 3: Acknowledge Client foo=??? Slave Slave 52

Redis Wait command What does WAIT give us? t=0 t=1 Client 1 Write Foo. WAIT Client 2 Read Foo t=0 t=1 Client 1 Write Foo. WAIT Client 2 Read Foo Client 2 can still read either. But we *know* which happened. 53

Redis Wait command One more confusing bit: Is Redis replication + WAIT going to give us sequential consistency? NO: WAIT only guarantees that the replica received the update, not that it processed and committed it. But, it s probably better than nothing. 54

HW3: Replicate Redis What happens if Redis fails? Solution: Redis has built in replication! What consistency guarantees does that provide? We want to maintain what we ve got. You ll use WAIT after writes All writes -> master, reads -> slave (note: now each client has its own redis slave) Add heartbeat to know how many replicas there are 55

Lab: Heartbeats Goal: make sure all replicas have received most recent update Problem: how many replicas are there? How many are online? 56

Redis Wait command Client 1: Write key foo = bar. WAIT 4: Acknowledge write foo=bar Master 2: Send update Read foo 3: Acknowledge Client foo=??? Slave Slave 57

Lab: Heartbeats Your task: implement a simple protocol: a server that will keep track of the number of live replicas at any time High level question: What s a live replica? Is able to send a message saying its alive? Has seen most recent updates? Has seen most recent updates and processed them? For HW3 and this lab: enough to just say the client is alive 58