Logical Clocks and Casual Ordering

Slides:



Advertisements
Similar presentations
Last Class: Clock Synchronization
Advertisements

Virtual Time “Virtual Time and Global States of Distributed Systems” Friedmann Mattern, 1989 The Model: An asynchronous distributed system = a set of processes.
Lecture 8: Asynchronous Network Algorithms
SES Algorithm SES: Schiper-Eggli-Sandoz Algorithm. No need for broadcast messages. Each process maintains a vector V_P of size N - 1, N the number of processes.
1 Global State $500$200 A B C1: Empty C2: Empty Global State 1 $450$200 A B C1: Tx $50 C2: Empty Global State 2 $450$250 A B C1: Empty C2: Empty Global.
Uncoordinated Checkpointing The Global State Recording Algorithm.
Uncoordinated Checkpointing The Global State Recording Algorithm Cristian Solano.
Time and Global States Part 3 ECEN5053 Software Engineering of Distributed Systems University of Colorado, Boulder.
Synchronization Chapter clock synchronization * 5.2 logical clocks * 5.3 global state * 5.4 election algorithm * 5.5 mutual exclusion * 5.6 distributed.
Distributed Computing 5. Snapshot Shmuel Zaks ©
Theoretical Aspects Logical Clocks Causal Ordering
Dr. Kalpakis CMSC 621, Advanced Operating Systems. Logical Clocks and Global State.
Distributed Systems Dinesh Bhat - Advanced Systems (Some slides from 2009 class) CS 6410 – Fall 2010 Time Clocks and Ordering of events Distributed Snapshots.
Ordering and Consistent Cuts Presented By Biswanath Panda.
CMPT 431 Dr. Alexandra Fedorova Lecture VIII: Time And Global Clocks.
Distributed Systems Fall 2009 Logical time, global states, and debugging.
Ordering and Consistent Cuts
Ordering and Consistent Cuts Presented by Chi H. Ho.
EEC-681/781 Distributed Computing Systems Lecture 11 Wenbing Zhao Cleveland State University.
1 Distributed Process Management: Distributed Global States and Distributed Mutual Exclusion.
Computer Science Lecture 10, page 1 CS677: Distributed OS Last Class: Clock Synchronization Physical clocks Clock synchronization algorithms –Cristian’s.
Dr. Kalpakis CMSC 621, Advanced Operating Systems. Fall 2003 URL: Logical Clocks and Global State.
Chapter 5.
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.
Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Project Reference Some slides are in courtesy of Dr. Erciyes,
Distributed Computing 5. Snapshot Shmuel Zaks ©
Logical Clocks n event ordering, happened-before relation (review) n logical clocks conditions n scalar clocks condition implementation limitation n vector.
Page 1 Logical Clocks Paul Krzyzanowski Distributed Systems Except as otherwise noted, the content of this presentation is.
Lamport’s Logical Clocks & Totally Ordered Multicasting.
“Virtual Time and Global States of Distributed Systems”
Communication & Synchronization Why do processes communicate in DS? –To exchange messages –To synchronize processes Why do processes synchronize in DS?
Distributed Systems Fall 2010 Logical time, global states, and debugging.
Event Ordering Greg Bilodeau CS 5204 November 3, 2009.
CIS825 Lecture 2. Model Processors Communication medium.
D ISTRIBUTED S YSTEM UNIT-2 Theoretical Foundation for Distributed Systems Prepared By: G.S.Mishra.
Logical Clocks. Topics r Logical clocks r Totally-Ordered Multicasting.
Event Ordering. CS 5204 – Operating Systems2 Time and Ordering The two critical differences between centralized and distributed systems are: absence of.
Ordering of Events in Distributed Systems UNIVERSITY of WISCONSIN-MADISON Computer Sciences Department CS 739 Distributed Systems Andrea C. Arpaci-Dusseau.
1 Chapter 11 Global Properties (Distributed Termination)
11-Jun-16CSE 542: Operating Systems1 Distributed systems Time, clocks, and the ordering of events in a distributed system Leslie Lamport. Communications.
Logical Clocks event ordering, happened-before relation (review) logical clocks conditions scalar clocks  condition  implementation  limitation vector.
Ordering of Events in Distributed Systems UNIVERSITY of WISCONSIN-MADISON Computer Sciences Department CS 739 Distributed Systems Andrea C. Arpaci-Dusseau.
Logical time Causality between events is fundamental to the design of parallel and distributed systems. In distributed systems, it is not possible to have.
Global state and snapshot
Global State Recording
Global state and snapshot
Distributed Mutual Exclusion
Lecture 3: State, Detection
Theoretical Foundations
Lecture 9: Asynchronous Network Algorithms
Overview of Ordering and Logical Time
Global State Recording
Outline Theoretical Foundations - continued Vector clocks - review
湖南大学-信息科学与工程学院-计算机与科学系
Outline Theoretical Foundations - continued Lab 1
Time And Global Clocks CMPT 431.
Event Ordering.
Non-Distributed Excercises
Outline Theoretical Foundations
Chien-Liang Fok Distribution Seminar Chien-Liang Fok
CS 425 / ECE 428  2013, I. Gupta, K. Nahrtstedt, S. Mitra, N. Vaidya, M. T. Harandi, J. Hou.
Chapter 5 (through section 5.4)
Uncoordinated Checkpointing
Slides for Chapter 11: Time and Global State
Outline Theoretical Foundations - continued
Jenhui Chen Office number:
Distributed algorithms
CIS825 Lecture 5 1.
CSE 542: Operating Systems
Outline Theoretical Foundations
Presentation transcript:

Logical Clocks and Casual Ordering CS60002: Distributed Systems Pallab Dasgupta Professor, Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

Why do we need global clocks? For causally ordering events in a distributed system Example: Transaction T transfers Rs 10,000 from S1 to S2 Consider the situation when: State of S1 is recorded after the deduction and state of S2 is recorded before the addition State of S1 is recorded before the deduction and state of S2 is recorded after the addition Should not be confused with the clock-synchronization problem What data is being transmitted? 0101? Yes, if this is the clock If this is the clock, then 01110001 The receiver needs to know the clock of the sender INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

Ordering of Events Lamport’s Happened Before relationship: For two events a and b, a → b if a and b are events in the same process and a occurred before b, or a is a send event of a message m and b is the corresponding receive event at the destination process, or a → c and c → b for some event c INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

Causally Related versus Concurrent Causally related events: Event a causally affects event b if a  b Concurrent events: Two distinct events a and b are said to be concurrent ( denoted by a||b ) if a  b and b  a e11 e12 e13 e14 e21 e22 e23 e24 P1 P2 e11 and e21 are concurrent e14 and e23 are concurrent e22 causally affects e14 A space-time diagram INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

Lamport’s Logical Clock Each process i keeps a clock Ci Each event a in i is time-stamped Ci(a), the value of Ci when a occurred Ci is incremented by 1 for each event in i In addition, if a is a send of message m from process i to j, then on receive of m, Cj = max (Cj, Ci(a)+1) INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

How Lamport’s clocks advance (1) (2) (3) (4) (5) (6) (7) INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

Points to note if a → b, then C(a) < C(b) → is a partial order Total ordering possible by arbitrarily ordering concurrent events by process numbers INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

Limitation of Lamport’s Clock a → b implies C(a) < C(b) BUT C(a) < C(b) doesn’t imply a → b !! So not a true clock !! INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

Solution: Vector Clocks Each process Pi has a clock Ci, which is a vector of size n The clock Ci assigns a vector Ci(a) to any event a at Pi Update rules: Ci[i]++ for every event at process I If a is send of message m from i to j with vector timestamp tm, then on receipt of m: Cj[k] = max(Cj[k], tm[k]) for all k INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

Partial Order between Timestamps For events a and b with vector timestamps ta and tb, Equal: ta = tb iff i, ta[i] = tb[i] Not Equal: ta ≠ tb iff i, ta[i] ≠ tb[i] Less or equal: ta ≤ tb iff i, ta[i] ≤ tb[i] Not less or equal: ta ≤ tb iff i, ta[i] > tb[i] Less than: ta < tb iff (ta ≤ tb and ta ≠ tb) Not less than: ta < tb iff (ta ≤ tb and ta ≠ tb) Concurrent: ta || tb iff (ta < tb and tb < ta) INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

Causal Ordering a → b iff ta < tb Events a and b are causally related iff ta < tb or tb < ta, else they are concurrent Note that this is still not a total order INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

Use of Vector Clocks in Causal Ordering of Messages If send(m1) → send(m2), then every recipient of both message m1 and m2 must “deliver” m1 before m2. “deliver” – when the message is actually given to the application for processing INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

Birman-Schiper-Stephenson Protocol To broadcast m from process i, increment Ci(i), and timestamp m with VTm = Ci[i] When j ≠ i receives m, j delays delivery of m until Cj[i] = VTm[i] –1 and Cj[k] ≥ VTm[k] for all k ≠ i Delayed messages are queued in j sorted by vector time. Concurrent messages are sorted by receive time. When m is delivered at j, Cj is updated according to vector clock rule. INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

Problem of Vector Clock Message size increases since each message needs to be tagged with the vector Size can be reduced in some cases by only sending values that have changed INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

Global State Recording CS60002: Distributed Systems Pallab Dasgupta Professor, Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

Global State Collection Applications: Checking “stable” properties, checkpoint & recovery Issues: Need to capture both node and channel states system cannot be stopped no global clock INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

Notations Some notations: LSi: Local state of process I send(mij) : Send event of message mij from process i to process j rec(mij) : Similar, receive instead of send time(x) : Time at which state x was recorded time (send(m)) : Time at which send(m) occurred INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

Definitions send(mij) є LSi iff time(send(mij)) < time(LSi) rec(mij) є LSj iff time(rec(mij)) < time(LSj) transit(LSi, LSj) = { mij | send(mij) є LSi and rec(mij)  LSj } inconsistent(LSi, LSj) = { mij | send(mij)  LSi and rec(mij) є LSj } INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

Definitions Global state: collection of local states GS = {LS1, LS2,…, LSn} GS is consistent iff for all i, j, 1 ≤ i, j ≤ n, inconsistent(LSi, LSj) = Ф GS is transitless iff transit(LSi, LSj) = Ф GS is strongly consistent if it is consistent and transitless. INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

Chandy-Lamport’s Algorithm Uses special marker messages. One process acts as initiator, starts the state collection by following the marker sending rule below. Marker sending rule for process P: P records its state and For each outgoing channel C from P on which a marker has not been sent already, P sends a marker along C before any further message is sent on C INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

Chandy Lamport’s Algorithm contd.. When Q receives a marker along a channel C: If Q has not recorded its state then Q records the state of C as empty; Q then follows the marker sending rule If Q has already recorded its state, it records the state of C as the sequence of messages received along C after Q’s state was recorded and before Q received the marker along C INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

Notable Points Markers sent on a channel distinguish messages sent on the channel before the sender recorded its states and the messages sent after the sender recorded its state The state collected may not be any state that actually happened in reality, rather a state that “could have” happened Requires FIFO channels Message complexity O(|E|), where E = no. of links INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

Termination Detection CS60002: Distributed Systems Pallab Dasgupta Professor, Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

Termination Detection Model processes can be active or idle only active processes send messages idle process can become active on receiving a computation message active process can become idle at any time Termination: all processes are idle and no computation message are in transit Can use global snapshot to detect termination also INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

Huang’s Algorithm One controlling agent, has weight 1 initially All other processes are idle initially and has weight 0 Computation starts when controlling agent sends a computation message to a process An idle process becomes active on receiving a computation message B(DW) – computation message with weight DW. Can be sent only by the controlling agent or an active process C(DW) – control message with weight DW, sent by active processes to controlling agent when they are about to become idle INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

Weight Distribution and Recovery Let current weight at process = W Send of B(DW): Find W1, W2 such that W1 > 0, W2 > 0, W1 + W2 = W Set W = W1 and send B(W2) Receive of B(DW): W = W + DW; if idle, become active Send of C(DW): send C(W) to controlling agent Become idle Receive of C(DW): W = W + DW if W = 1, declare “termination” INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR