Synchronization: Theoretical Foundation

Introduction
• A DS is a collection of computers that are spatially separated and do not share a common memory • Processes communicate by exchanging messages over communication channel • Messages are delivered after an arbitrary transmission delay • DS suffers some inherent limitations because of lack of common memory and a systemwide common clock • How these limitations can be overcome?

or – Having synchronized clocks.Absence of a Global Clock • There is no system-wide common clock in a DS • Solutions can be: – Either having a global clock common to al the computers. one at each computer • Both of the above solutions are impractical due to following reasons: – If one global clock is provided in the ds: • Two processes will observe a global clock value at different instants due to unpredictable delays • So two processes will falsely perceive two different instants in physical time to be a single instant in physical time – if the clocks of different systems are tried to synchronize: • These clocks can drift from the physical time and the drift rate may vary from clock to clock due to technological limitations • This may also end up with the same result • We cannot have a system of perfectly synchronized clocks .

Impact of the absence of global time • Temporal ordering of events is integral to the design and development of DS • E.g. an up-to-date state of the entire system is not available to any individual process • It is necessary for reasoning about the system’s behavior. – an OS is responsible for scheduling processes – A basic criterion used in scheduling is the temporal order in which requests to execute processes arrive – Due to the absence of the global time. the up-to-date state of the system is harder to collect Absence of shared memory • Due to the lack of shared memory. it is difficult to reason about the temporal order of events in a DS – Hence. debugging and recovery • A process in a DS can obtain a coherent but partial view or a complete but incoherent view of the system • A view is said to be coherent if all the observations of different processes are made at the same physical time • A complete view includes the local views (local states) at all the computers and any messages that are in transit in the DS • A complete view is also referred to as global state . algorithms for DS are more difficult to design and debug – Also.

sending a message constitutes one event and receiving a message constitutes one event. the execution of a procedure could be one event or the execution of an instruction could be one event – When processes exchange messages. – The execution of processes is characterized by a sequence of events – Depending on the application. .Example Local state of A Local state of B (a) $500 S1: A Communication Channel $200 S2: B (b) $450 S1: A $200 S2: B (c) $500 S1: A $250 7 Lamport’s Logical Clock: Basic Concepts • Lamport proposed the following scheme to order events in a distributed system using logical clocks.

i. then a c . Lamport’s Logical Clock • a b. if a and b are events in the same process and a occurred before b. • If a b and b c .Lamport’s Logical Clock: Happened before relationship • Due to the absence of perfectly synchronized clocks and global time in distributed systems. " " relation is transitive • In distributed systems. debugging. the order in which two events occur at two different computers cannot be determined based on the local time at which they occur • under certain conditions. The relation + is defined in the following slide. it is possible to ascertain the order in which two events occur based solely on the behavior exhibited by the underlying computation.. • a b. and understanding the sequence of execution in distributed computation.e. i. processes interact with each other and affect the outcome ot events of processes • Being able to ascertain order between events is very important for designing. • The happened before relation(--->) captures the causal dependencies between events.e.. . if a is the event of sending a message m in a process and b is the event of receipt of the same message rn by another process. whether two events are causally related or not.

which in turn influences the occurrence and outcome of future events • past events influence future events and this influence among causally related events (those events that can be ordered by “ “ ) is referred to as causal affects. • CONCURRENT EVENTS: Two distinct events a and b are said to be concurrent (denoted by a||b) if a / b and b/ a. • For any two events a and b in a system.Lamport’s Logical Clock: Events • In general. b a. Lamport’s Logical Clock: Events • CASUALLY RELATED EVENTS: Event a causally affects event b if a b. or a||b . either a. an event changes the system state.

and hence the name logical clocks. Lecture 5:Theoretical Foundations of DS 1 Lamport’s Logical Clock:Events • In order to realize the relation . – There is a clock Ci at each process Pi in the system. the timestamp of an event is the value of the clock when it occurs. at Pi. – The clock Ci can be thought of as a function that assigns a number Ci(a) to any event a. called the timestamp of event a.Lamport’s Logical Clock: Events e11 P1 Space e12 e13 e14 e21 P2 e22 e23 Global time e24 COT3002 Distributed Computing Systems  A. – The numbers assigned by the system of clocks have no relation to physical time. . Lamport introduced the following system of logical clocks. – The logical clocks take monotonically increasing values. Typically. These clocks can be implemented by counters.Zaslavsky.

Cj is set to a value greater than or equal to its present value and greater than tm Cj := max(Cj. if a occurs before b. then C(a) < C(b) • The happened before relation ““ can now be realized by using the logical clocks if the following two conditions are met: – [C1] For any two events a and b in a process Pi. tm + d) (d > 0) . = Ci(a) (note that the value of Ci(a) is obtained after applying rule IRI). a b. then message m is assigned a timestamp tm.Lamport’s Logical Clock: Conditions • For any events a and b: if a b. then Ci(a) < Ci(b) – [C2] If a is the event of sending a message m in process Pi and b is the event of receiving the same message m at process Pj. and b are two successive events in Pi and Ci(b) = Ci(a) + d. then Ci(a) < Cj(b) • The following implementation rules (IR) for the clocks guarantee that the clocks satisfy the correctness conditions Cl and C2: Lamport Logical Clock: Implementation Rules – [IR1] Clock Ci is incremented between any two successive events in process Pi: Ci:=Ci+d (d>0) lf a. then – [IR2] If event a is the sending of message m by process Pi. On receiving the same message m by process Pj.

if i < j. Lamport’s logical Clock: How does it advance? e11 P1 Space Clock values e12 (2) (2) e13 (3) e14 (4) (3) e15 (5) e16 (6) (4) e17 (7) (7) (1) (1) e21 P2 e22 e23 e24 e25 Global time 1 . () defines an irreflexive partial order among the events • The set of all the events in a distributed computation can be totally ordered (the ordering relation is denoted by Þ) using the above system of clocks as follows: – If a is any event at process Pi and b is any event at process Pj then a Þ b if and only if either • Ci(a) < Cj(b) or Ci(a) = Cj(b) and Pi < Pjwhere < is any arbitrary relation that totally orders the processes to break ties • A simple way to implement < is to assign unique identification numbers to each process and then Pi < Pj .Lamport’s logical Clock: How does it advance? • Lamport's “happened before relation”.

if a and b are events in different processes and C(a) < C(b). the reverse is not necessarily true if the events have occurred in different processes • i. events a and b may be causally related or may not be causally related • So.Lamport’s Logical Clock: Limitations • In Lamport's system of logical clocks.e. Lamport's system of clocks is not powerful enough to capture such situations Lamport’s Logical Clock: Limitations e11 P1 P2 Space (1) e12 (2) e21 (1) e22 (3) P3 e31 (1) e32 (2) Global time e33 (3) . if a b then C(a) < C(b) • But. then a b is not necessarily true.

Vector Clock • The system of vector clocks was independently proposed by Fidge and Mattern: – Let n be the number of processes in a distributed system – Each process Pi is equipped with a clock Ci(a). Ci[I] the ith entry of Ci. which is an integer vector of length n – The clock Ci can be thought of as a function that assigns a vector Ci(a) to any event a – Ci(a) is referred to as the timestamp of event e1 at Pi. the jth entry of Ci indicates the time of occurrence of the last event at Pj which "happened before" the current point in time at Pi – This "happened before" relationship could be established directly by communication from Pj to Pi or indirectly through communication with other processes. the system of vector clocks allows us to order events and decide whether two events are causally related or not by simply looking at the timestamps of the events • If we know the processes where the events occur. • The figure illustrates an example of how clocks advance and the dissemination of time occurs in a system using vector clocks (d is assumed to be 1 and all clock values are initially zero) • Thus. More specifically. corresponds to Pi's own logical time – Ci[j] is Pi's best guess of the logical time at Pj. the above test can be further simplified . at any point in time.

3.0.0.1) P2 e21 P3 (0.2) e24 e32 Global State • Recording the consistent global state is a challenging task due to the absence of a global clock and shared memory • A global state is a combination of local states of all machines and the channel • A recorded global state may be inconsistent if n>n’.(1. n’ is the number of messages sent by A along the channel before the channel’s state is recorded • Similarly.0) (3.0) e12 (2.4.4. a consistent global state requires n=n’ .0.1.1) e13 (2.1) e22 e31 Global time e23 (0.0) (2.0. – Where n is the number of messages sent by A along the channel before A’s state was recorded – And.2.1) P1 Space e11 (0.0) (2.

LS3. of sites. denoted by.……….Example Local state of A Local state of B (a) $500 S1: A C1:Empty $200 C2:Empty C1:Transfer $50 S2: B (b) $450 S1: A $200 C2:Empty C1:Empty S2: B (c) $500 $250 C2:Empty 25 Definitions • Local State: For a site Si. where n is the no. LS2. its local state at a given time is defined by the local context of the distributed application. LSi • Global State: A global state GS of a system is a collection of the local states of its sites GS={LS1. in the system • Consistent Global State: For every received message a corresponding sent event is recorded in the global state .LSn{.

• Strongly consistent state: A state is strongly consistent if it is consistent and transitless – In a strongly consistent state.• Inconsistent global state: in an inconsistent global state. not only the send events of all the recorded received events are recorded. all communication channels are empty. there is atleast one message whose received event is recorded but its send event is not recorded in the global state • Transitless state: A global state is transitless if and only if. but the receive events of all the recorded send events are also recorded Global State: S1 S2 S3 LS11 LS21 LS12 LS22 LS23 LS31 LS32 LS32 .

P sends a marker along C before P sends further messages along C • Marker Receiving Rule for a process Q If Q has not recorded its state. then begin Record the state of C as an empty sequence Follow the “Marker Sending Rule” end Else Record 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 .Chandy-Lamport’s Global State Recording Algorithm • First proposal to capture a consistent global state • Algorithm uses a marker to initiate the algorithm and the marker has not effect on the underlying computation • Communication channels are assumed to be FIFO • Recorded global state is also referred to as a snapshot of the system state Algorithm • Marker Sending Rule for a process P – P records its state – For each outgoing channel C from P on which a marker has not been already sent.