Distributed Systems Spring 2009

Slides:



Advertisements
Similar presentations
Synchronization Chapter clock synchronization * 5.2 logical clocks * 5.3 global state * 5.4 election algorithm * 5.5 mutual exclusion * 5.6 distributed.
Advertisements

Distributed Computing
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED.
CS 582 / CMPE 481 Distributed Systems Synchronization.
Distributed Systems Fall 2009 Logical time, global states, and debugging.
1. Explain why synchronization is so important in distributed systems by giving an appropriate example When each machine has its own clock, an event that.
Synchronization Clock Synchronization Logical Clocks Global State Election Algorithms Mutual Exclusion.
Teaching material based on Distributed Systems: Concepts and Design, Edition 3, Addison-Wesley Copyright © George Coulouris, Jean Dollimore, Tim.
Lecture 13 Synchronization (cont). EECE 411: Design of Distributed Software Applications Logistics Last quiz Max: 69 / Median: 52 / Min: 24 In a box outside.
Logical Time and Logical Clocks
EEC-681/781 Distributed Computing Systems Lecture 11 Wenbing Zhao Cleveland State University.
Clock Synchronization and algorithm
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
Lecture 12 Synchronization. EECE 411: Design of Distributed Software Applications Summary so far … A distributed system is: a collection of independent.
Lecture 14 Synchronization (cont). EECE 411: Design of Distributed Software Applications Logistics Project P01 deadline on Wednesday November 3 rd. Non-blocking.
Computer Science Lecture 12, page 1 CS677: Distributed OS Last Class Vector timestamps Global state –Distributed Snapshot Election algorithms.
Lecture 9: Time & Clocks CDK4: Sections 11.1 – 11.4 CDK5: Sections 14.1 – 14.4 TVS: Sections 6.1 – 6.2 Topics: Synchronization Logical time (Lamport) Vector.
Time, Clocks, and the Ordering of Events in a Distributed System Leslie Lamport (1978) Presented by: Yoav Kantor.
Distributed Systems Foundations Lecture 1. Main Characteristics of Distributed Systems Independent processors, sites, processes Message passing No shared.
Election Algorithms. Topics r Issues r Detecting Failures r Bully algorithm r Ring algorithm.
Lecture 9 – Time Synchronization Distributed Systems.
PHYSICAL AND LOGICAL TIME EE324 Lecture 11 Last Time– RPC  Why remote procedure calls?  Simple way to pass control and data  Elegant transparent way.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
CIS 720 Distributed algorithms. “Paint on the forehead” problem Each of you can see other’s forehead but not your own. I announce “some of you have paint.
Distributed Mutex EE324 Lecture 11.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved Chapter 6 Synchronization.
Lecture 5: Sun: 1/5/ Distributed Algorithms - Distributed Databases Lecturer/ Kawther Abas CS- 492 : Distributed system &
1 Causal Delivery Advanced Networks PhD. Saúl Pomares Hernández.
Computer Science Lecture 10, page 1 CS677: Distributed OS Last Class: Naming Name distribution: use hierarchies DNS X.500 and LDAP.
Computer Science Lecture 12, page 1 CS677: Distributed OS Last Class Vector timestamps Global state –Distributed Snapshot Election algorithms –Bully algorithm.
Page 1 Logical Clocks Paul Krzyzanowski Distributed Systems Except as otherwise noted, the content of this presentation is.
Synchronization CSCI 4780/6780. Mutual Exclusion Concurrency and collaboration are fundamental to distributed systems Simultaneous access to resources.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
Synchronization. Why we need synchronization? It is important that multiple processes do not access shared resources simultaneously. Synchronization in.
Logical Clocks. Topics Logical clocks Totally-Ordered Multicasting Vector timestamps.
Lamport’s Logical Clocks & Totally Ordered Multicasting.
Vector Clock Each process maintains an array of clocks –vc.j.k denotes the knowledge that j has about the clock of k –vc.j.j, thus, denotes the clock of.
Synchronization Chapter 5. Outline 1.Clock synchronization 2.Logical clocks 3.Global state 4.Election algorithms 5.Mutual exclusion 6.Distributed transactions.
Synchronization Chapter 5.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
Distributed Systems Fall 2010 Logical time, global states, and debugging.
Lecture 9: Time and clocks (Chap 11) Haibin Zhu, PhD. Assistant Professor Department of Computer Science Nipissing University © 2002.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
Lecture 10 – Mutual Exclusion Distributed Systems.
CIS825 Lecture 2. Model Processors Communication medium.
D u k e S y s t e m s Asynchronous Replicated State Machines (Causal Multicast and All That) Jeff Chase Duke University.
Logical Clocks. Topics Logical clocks Totally-Ordered Multicasting Vector timestamps.
Distributed Process Coordination Presentation 1 - Sept. 14th 2002 CSE Spring 02 Group A4:Chris Sun, Min Fang, Bryan Maden.
DISTRIBUTED SYSTEMS Principles and Paradigms Second Edition ANDREW S
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
Page 1 Mutual Exclusion & Election Algorithms Paul Krzyzanowski Distributed Systems Except as otherwise noted, the content.
Logical Clocks. Topics r Logical clocks r Totally-Ordered Multicasting.
6 SYNCHRONIZATION. introduction processes synchronize –exclusive access. –agree on the ordering of events much more difficult compared to synchronization.
Synchronization. Clock Synchronization In a centralized system time is unambiguous. In a distributed system agreement on time is not obvious. When each.
COMP 655: Distributed/Operating Systems Summer 2011 Dr. Chunbo Chu Week 6: Synchronyzation 3/5/20161 Distributed Systems - COMP 655.
Distributed Mutual Exclusion Synchronization in Distributed Systems Synchronization in distributed systems are often more difficult compared to synchronization.
Synchronization Chapter 5. Clock Synchronization When each machine has its own clock, an event that occurred after another event may nevertheless be assigned.
Mutual Exclusion Algorithms. Topics r Defining mutual exclusion r A centralized approach r A distributed approach r An approach assuming an organization.
Lecture on Synchronization Submitted by
Revisiting Logical Clocks: Mutual Exclusion Problem statement: Given a set of n processes, and a shared resource, it is required that: –Mutual exclusion.
Distributed Mutex EE324 Lecture 11.
SYNCHORNIZATION Logical Clocks.
EECS 498 Introduction to Distributed Systems Fall 2017
DISTRIBUTED SYSTEMS Principles and Paradigms Second Edition ANDREW S
Distributed Systems CS
Chapter 5 (through section 5.4)
Prof. Leonardo Mostarda University of Camerino
Last Class: Naming Name distribution: use hierarchies DNS
Presentation transcript:

15-446 Distributed Systems Spring 2009 L-9 Logical Time

Announcements Project 1 update – Thursday Due 2/26 HW 1 – due Thursday

Last Lecture – Clock Sync Important Lessons Clocks on different systems will always behave differently Skew and drift between clocks Time disagreement between machines can result in undesirable behavior Two paths to solution: synchronize clocks or ensure consistent clocks Clock synchronization Rely on a time-stamped network messages Estimate delay for message transmission Can synchronize to UTC or to local source

Today's Lecture Lamport Clocks Vector Clocks Mutual Exclusion Election

Example: Totally Ordered Multicasting Updating a replicated database and leaving it in an inconsistent state

Logical time and logical clocks (Lamport 1978) Events at three processes

Logical time and logical clocks (Lamport 1978) Animation explains the following: In Figure 10.5 a -> b (at p1) c->d at p2 and b->c because of m1 also d-> f because of m2. Not all events are related by -> (happened before) consider a and e. (different processes and no chain of messages to relate them) Happened before relation - relation of causal ordering HB1, HB2 and HB3 (page 397) are formal statements of the three points on the slide Instead of synchronizing clocks, event ordering can be used If two events occurred at the same process pi (i = 1, 2, … N) then they occurred in the order observed by pi, that is  when a message, m is sent between two processes, send(m) happened before receive(m) The happened before relation is transitive the happened before relation is the relation of causal ordering

Logical time and logical clocks (Lamport 1978) Animation explains the following: In Figure 10.5 a -> b (at p1) c->d at p2 and b->c because of m1 also d-> f because of m2. Not all events are related by -> (happened before) consider a and e. (different processes and no chain of messages to relate them) Happened before relation - relation of causal ordering HB1, HB2 and HB3 (page 397) are formal statements of the three points on the slide a  b (at p1) c d (at p2) b  c because of m1 also d  f because of m2

Logical time and logical clocks (Lamport 1978) Animation explains the following: In Figure 10.5 a -> b (at p1) c->d at p2 and b->c because of m1 also d-> f because of m2. Not all events are related by -> (happened before) consider a and e. (different processes and no chain of messages to relate them) Happened before relation - relation of causal ordering HB1, HB2 and HB3 (page 397) are formal statements of the three points on the slide Not all events are related by  Consider a and e (different processes and no chain of messages to relate them) they are not related by  ; they are said to be concurrent written as a || e

Lamport Clock (1) Discuss LC1 and LC2 for Figure 10.6 (same as 10.5). Initially clocks all set to 0. (a -> 1) b->2 etc. For m1, 2 is piggybacked and c gets max(1,2) + 1. Same for m2. Note e -> e’ implies L(e) < L(e’). Converse not true. E.g. events b and e. (b || e) concurrent. A logical clock is a monotonically increasing software counter It need not relate to a physical clock. Each process pi has a logical clock, Li which can be used to apply logical timestamps to events Rule 1: Li is incremented by 1 before each event at process pi Rule 2: (a) when process pi sends message m, it piggybacks t = Li (b) when pj receives (m,t) it sets Lj := max(Lj, t) and applies rule 1 before timestamping the event receive (m)

Lamport Clock (1) each of p1, p2, p3 has its logical clock initialised to zero, the clock values are those immediately after the event. e.g. 1 for a, 2 for b. for m1, 2 is piggybacked and c gets max(0,2)+1 = 3

Lamport Clock (1) e e’ implies L(e)<L(e’) The converse is not true, that is L(e)<L(e') does not imply e e’ e.g. L(b) > L(e) but b || e

Today's Lecture Lamport Clocks Vector Clocks Mutual Exclusion Election

Vector Clocks Vector clocks overcome the shortcoming of Lamport logical clocks L(e) < L(e’) does not imply e happened before e’ Vector timestamps are used to timestamp local events They are applied in schemes for replication of data

Vector Clocks Vi [ i ] is the number of events that pi has timestamped Vi [ j ] ( j≠ i) is the number of events at pj that pi has been affected by Vector clock Vi at process pi is an array of N integers initially Vi[j] = 0 for i, j = 1, 2, …N before pi timestamps an event it sets Vi[i] := Vi[i] +1 pi piggybacks t = Vi on every message it sends when pi receives (m,t) it sets Vi[j] := max(Vi[j] , t[j]) j = 1, 2, …N ( then before next event adds 1 to own element using rule 2) Following points animated : Vector clocks overcome the shortcoming of Lamport logical clocks (L(e) < L(e’) does not imply e happened before e’) e.g. events e and c Vector timestamps are used to timestamp local events. Applied in schemes for replication of data e.g. Gossip (p 572), Coda (p585) and causal multicast The rules VC1-VC4 are for updating vector clocks Work through figure 10.7. At p1 a(1,0,0) b (2,0,0) send (2,0,0) on m1 At p2 on receipt of m1 get max((0,0,0), (2,0,0) = (2,0,0) add 1 -> (2,1,0). Meaning of =, <=, max etc for vector timestamps. Note that e-> e’ implies V(e) < V(e’). The converse is also true. But c || e parallel) because neither V(c) <= V(e) nor V(e) <= V(c).

Vector Clocks Following points animated : Vector clocks overcome the shortcoming of Lamport logical clocks (L(e) < L(e’) does not imply e happened before e’) e.g. events e and c Vector timestamps are used to timestamp local events. Applied in schemes for replication of data e.g. Gossip (p 572), Coda (p585) and causal multicast The rules VC1-VC4 are for updating vector clocks Work through figure 10.7. At p1 a(1,0,0) b (2,0,0) send (2,0,0) on m1 At p2 on receipt of m1 get max((0,0,0), (2,0,0) = (2,0,0) add 1 -> (2,1,0). Meaning of =, <=, max etc for vector timestamps. Note that e-> e’ implies V(e) < V(e’). The converse is also true. But c || e parallel) because neither V(c) <= V(e) nor V(e) <= V(c). At p1 a occurs at (1,0,0); b occurs at (2,0,0) piggyback (2,0,0) on m1 At p2 on receipt of m1 use max ((0,0,0), (2,0,0)) = (2, 0, 0) and add 1 to own element = (2,1,0) Meaning of =, <=, max etc for vector timestamps compare elements pairwise

Vector Clocks Note that e e’ implies L(e)<L(e’). The converse is also true Can you see a pair of parallel events? c || e( parallel) because neither V(c) <= V(e) nor V(e) <= V(c)

Vector Clocks How to ensure causality? Two rules for delaying message processing: VC must indicate that this is next message from source VC must indicate that you have all the other messages that “caused” this message

Today's Lecture Lamport Clocks Vector Clocks Mutual Exclusion Election

Mutual Exclusion A Centralized Algorithm Process 1 asks the coordinator for permission to access a shared resource  Permission is granted Process 2 then asks permission to access the same resource  The coordinator does not reply When process 1 releases the resource, it tells the coordinator, which then replies to 2

A Distributed Algorithm (1) Three different cases: If the receiver is not accessing the resource and does not want to access it, it sends back an OK message to the sender. If the receiver already has access to the resource, it simply does not reply. Instead, it queues the request. If the receiver wants to access the resource as well but has not yet done so, it compares the timestamp of the incoming message with the one contained in the message that it has sent everyone. The lowest one wins.

A Distributed Algorithm (2) Accesses Resource Accesses Resource Two processes want to access a shared resource at the same moment. Process 0 has the lowest timestamp, so it wins When process 0 is done, it sends an OK also, so 2 can now go ahead.

A Token Ring Algorithm An unordered group of processes on a network  A logical ring constructed in software Use ring to pass right to access resource

A Comparison of the Four Algorithms

Today's Lecture Lamport Clocks Vector Clocks Mutual Exclusion Election

Election Algorithms The Bully Algorithm: P sends an ELECTION message to all processes with higher numbers. If no one responds, P wins the election and becomes coordinator. If one of the higher-ups answers, it takes over. P’s job is done.

The Bully Algorithm (1) (a) Process 4 holds an election (b) Processes 5 and 6 respond, telling 4 to stop. (c) Now 5 and 6 each hold an election.

The Bully Algorithm (2) (d) Process 6 tells 5 to stop (e) Process 6 wins and tells everyone.

A Ring Algorithm

Elections in Wireless Environments (1) node a as the source The build-tree phase

Elections in Wireless Environments (2) Figure 6-22. Election algorithm in a wireless network, with node a as the source. (a) Initial network. (b)–(e) The build-tree phase

Elections in Wireless Environments (3) Reporting of best node to source.

Important Lessons Lamport & vector clocks both give a logical timestamps Total ordering vs. causal ordering Other issues in coordinating node activities Exclusive access to resources Choosing a single leader

Lamport’s Logical Clocks (1) The "happens-before" relation → can be observed directly in two situations: If a and b are events in the same process, and a occurs before b, then a → b is true. If a is the event of a message being sent by one process, and b is the event of the message being received by another process, then a → b

Lamport’s Logical Clocks (2) Three processes, each with its own clock. The clocks run at different rates.

Lamport’s Logical Clocks (3) Lamport’s algorithm corrects the clocks.

Lamport’s Logical Clocks (4) The positioning of Lamport’s logical clocks in distributed systems.

Lamport’s Logical Clocks (5) Updating counter Ci for process Pi Before executing an event Pi executes Ci ← Ci + 1. When process Pi sends a message m to Pj, it sets m’s timestamp ts (m) equal to Ci after having executed the previous step. Upon the receipt of a message m, process Pj adjusts its own local counter as Cj ← max{Cj , ts (m)}, after which it then executes the first step and delivers the message to the application.

Vector Clocks (1) Concurrent message transmission using logical clocks.

Vector Clocks (2) Vector clocks are constructed by letting each process Pi maintain a vector VCi with the following two properties: VCi [ i ] is the number of events that have occurred so far at Pi. In other words, VCi [ i ] is the local logical clock at process Pi . If VCi [ j ] = k then Pi knows that k events have occurred at Pj. It is thus Pi’s knowledge of the local time at Pj .

Vector Clocks (3) Steps carried out to accomplish property 2 of previous slide: Before executing an event Pi executes VCi [ i ] ← VCi [i ] + 1. When process Pi sends a message m to Pj, it sets m’s (vector) timestamp ts (m) equal to VCi after having executed the previous step. Upon the receipt of a message m, process Pj adjusts its own vector by setting VCj [k ] ← max{VCj [k ], ts (m)[k ]} for each k, after which it executes the first step and delivers the message to the application.

Enforcing Causal Communication