Tải bản đầy đủ (.pdf) (27 trang)

Lecture Operating systems: A concept-based approach (2/e): Chapter 16 - Dhananjay M. Dhamdhere

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (539.81 KB, 27 trang )

PROPRIETARY MATERIAL. ©  2007 The McGraw­Hill Companies, Inc. All rights reserved. No part of this PowerPoint slide  may be displayed, reproduced or distributed 
in any form or by any means, without the prior written permission of the publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw­Hill 
for their individual course preparation. If you are a student using this PowerPoint slide, you are using it without permission. 

Chapter 16: Theoretical issues
 in Distributed Systems 

Dhamdhere: Operating Systems—
A Concept­Based Approach , 2 ed

Slide No: 1
Copyright © 2008


Theoretical issues in distributed systems



An OS uses two key notions to organize its operation
– Time and state
* Time is used to keep track of when an event occurred, or the order
in which events occurred
* State of processes and resources are used in scheduling and
resource allocation

– These notions are hard to use in a distributed system
* Computers have their own clocks, which might show different times
 Hence time is not uniquely known
* Computers have memories
 So states of entities might be spread throughout the system


– We need to develop practical substitutes to these notions
Chapter 16: Theoretical issues
 in Distributed Systems 

Dhamdhere: Operating Systems—
A Concept­Based Approach , 2 ed

Slide No: 2
Copyright © 2008


Local and global states



Definitions
– Local state
* State of an entity, such as a process, CPU, or resource

– Global state
* Global state of a system at time t is the collection of local states of
all entities in it at time instant t

– We depict local and global states as follows:
* Local state of a process Pk at time t: skt
* Global state of the system at time t: St
 If a system contains n processes, its state is represented as
{ s1t, s2t, …, snt }

Chapter 16: Theoretical issues

 in Distributed Systems 

Dhamdhere: Operating Systems—
A Concept­Based Approach , 2 ed

Slide No: 3
Copyright © 2008


Change of state



The state changes as a result of an event
– An event could be the sending or receiving of a message
– We represent an event as follows:

< process state, old state, new state, event description, channel, message >

 

• Event ei is < Pk, s, s’, send, c, m >
Chapter 16: Theoretical issues
 in Distributed Systems 

Dhamdhere: Operating Systems—
A Concept­Based Approach , 2 ed

Slide No: 4
Copyright © 2008



Event Precedence



Event precedence indicates which event occurred before
or after another event
– Precedence is used to know the order in which events occurred
* It is called event ordering
* ei → ej indicates that event ei precedes ej, i.e., occurred before it

– Precedence of events in a process is known
– A causal relationship is a cause-and-effect relationship
* The event corresponding to a cause occurs before that corresponding to its effect, e.g., sending and receiving of a message
* It is used to find precedence of events in different processes

– Event precedence is transitive
* If ei → ej and ej → ek, then ei → ek
Chapter 16: Theoretical issues
 in Distributed Systems 

Dhamdhere: Operating Systems—
A Concept­Based Approach , 2 ed

Slide No: 5
Copyright © 2008


Event precedence via timing diagram


• e23 → e12 because e23 is a send event for m1 and e12 is a receive event
• e22 → e23 because both events occur in process P2
• Hence e22 → e12. Similarly e22 → e13, e21 → e12, etc.
Chapter 16: Theoretical issues
 in Distributed Systems 

Dhamdhere: Operating Systems—
A Concept­Based Approach , 2 ed

Slide No: 6
Copyright © 2008


Logical Clocks



Background
– A ‘global clock’ does not exist
– Computers have ‘local clocks’; these clocks can drift apart
– So we have a local clock in each process and synchronize local
clocks when needed
* A process Pi has a local clock LCi
* When Pk receives a message from Pi, synchronization is needed if
 Time in LCk is smaller than what was the time in LCi when Pi
sent the message
» This is so because of causal relationship

– Such clocks do not show ‘real’ time

* Hence they are called logical clocks
Chapter 16: Theoretical issues
 in Distributed Systems 

Dhamdhere: Operating Systems—
A Concept­Based Approach , 2 ed

Slide No: 7
Copyright © 2008


Time-stamps



When an event ei occurs in a process Pi
– The value of the local clock LCi is called the time-stamp of ei
* We represent the time-stamp of ei as ts(ei)

– When Pi sends a message m, it copies the time-stamp of the
send event in message m

Chapter 16: Theoretical issues
 in Distributed Systems 

Dhamdhere: Operating Systems—
A Concept­Based Approach , 2 ed

Slide No: 8
Copyright © 2008



Synchronization of Logical Clocks



Clock synchronization rules
R1: A process Pk increments LCk by 1 when any event occurs in it
R2: When Pk receives a message m containing the time-stamp
ts(send(m)), Pk undates LCk as follows:
LCk = max ( LCk, ts(send(m) + 1 )

Chapter 16: Theoretical issues
 in Distributed Systems 

Dhamdhere: Operating Systems—
A Concept­Based Approach , 2 ed

Slide No: 9
Copyright © 2008


Synchronization of logical clocks






The pair associated with an event shows clock times before and after

Logical clock in P2 is synchronized when it receives message m1
Logical clock in P1 is synchronized when P1 receives message m3
Logical clocks in P2 is synchronized when P2 receives message m4

Chapter 16: Theoretical issues
 in Distributed Systems 

Dhamdhere: Operating Systems—
A Concept­Based Approach , 2 ed

Slide No: 10
Copyright © 2008


Time-stamps using logical clocks



Can event precedence be determined by simply
comparing time-stamps of events?
– Time-stamps are not unique
* Uniqueness can be obtained by using a pair (local time, process id)
as the time-stamp
 If local times are identical, process id breaks the tie

– ts(ei) < ts(ej) if ei → ej
* However, ts(ei) < ts(ej) is possible even if ei does not precede ej
* Hence mere examination of time-stamps is not adequate for
obtaining event precedence




Vector time-stamps provide a way out of this difficulty

Chapter 16: Theoretical issues
 in Distributed Systems 

Dhamdhere: Operating Systems—
A Concept­Based Approach , 2 ed

Slide No: 11
Copyright © 2008


Vector clocks



A vector clock contains n elements, where n is the
number of processes
– Consider VCk, the vector clock in process Pk
* VCk[k] is the logical clock of Pk
* VCk[l], l ≠ k, is the highest value in VCl[l] that is known to Pk
* A vector time-stamp vts is obtained by copying the value of VCk



Clock synchronization rules
R3: Process Pk increments VCk[k] by 1 when an event occurs in it
R4: When Pk receives a message m, it performs

For all l, VCk[l] = max (VCk[l], vts(send(m))[l])

Chapter 16: Theoretical issues
 in Distributed Systems 

Dhamdhere: Operating Systems—
A Concept­Based Approach , 2 ed

Slide No: 12
Copyright © 2008


Synchronization of vector clocks

• Each triple is the vector time-stamp of an event
• P2 updates VC2[1] when it receives messages m1 and m4
• P3 updates VC3[1] and VC3[2] when it receives message m2
Chapter 16: Theoretical issues
 in Distributed Systems 

Dhamdhere: Operating Systems—
A Concept­Based Approach , 2 ed

Slide No: 13
Copyright © 2008


Time-stamps using vector clocks




Precedence between events can be determined by
comparing their time-stamps
– ei precedes ej
* If for all k: vts(ei)[k] ≤ vts(ej)[k] but vts(ei)[l] ≠ vts(ej)[l] for some l

– ei follows ej
* If for all k: vts(ei)[k] ≥ vts(ej)[k] but vts(ei)[l] ≠ vts(ej)[l] for some l

– ei, and ej are concurrent
* For some k, l : vts(ei)[k] < vts(ej)[k] and vts(ei)[l] > vts(ej)[l]



Vector time-stamps have the following property:
– vts(ei) < vts(ej) if and only if ei → ej
* Hence use of a pair (local time, process id) provides a total order
over events

Chapter 16: Theoretical issues
 in Distributed Systems 

Dhamdhere: Operating Systems—
A Concept­Based Approach , 2 ed

Slide No: 14
Copyright © 2008


The state of a distributed system




The state of a distributed system is the collection of
states of individual computer systems, i.e., collection of
local states
– Local states in the collection may be recorded at different times
* Such states may be inconsistent

Q: How to ensure consistency of local states?

Chapter 16: Theoretical issues
 in Distributed Systems 

Dhamdhere: Operating Systems—
A Concept­Based Approach , 2 ed

Slide No: 15
Copyright © 2008


The state of a distributed system



If $100 is transferred from account A to B, existing in
different nodes, and states of A and B are recorded
(a) Account A contains 900 dollars and B contains 300 dollars
(b) 800 and 400,
(c) 800 and 300 ($100 is in transit) and

(d) 900 and 400
Local states in (a), (b) and (c) are mutually consistent. In (d), they
are not consistent

Chapter 16: Theoretical issues
 in Distributed Systems 

Dhamdhere: Operating Systems—
A Concept­Based Approach , 2 ed

Slide No: 16
Copyright © 2008


Mutual Consistency of local states



Definition
– Local states of processes Pk and Pl are mutually consistent if
* Every message recorded as ‘received from Pl’ in Pk’s state is
recorded as ‘sent to Pk’ in Pl’s state
* Every message recorded as ‘received from Pk’ in Pl’s state is
recorded as ‘sent to Pl’ in Pk’s state



An algorithm for recording the state of a system should
ensure mutual consistency of local states of all
processes

* It is assumed that any message that has been sent but not yet
received by the destination process is ‘in the system’

Chapter 16: Theoretical issues
 in Distributed Systems 

Dhamdhere: Operating Systems—
A Concept­Based Approach , 2 ed

Slide No: 17
Copyright © 2008


A distributed computation for state recording



Assumptions
– Processes communicate over interprocess channels
– Each channel is unidirectional and has unlimited buffering
capacity

Chapter 16: Theoretical issues
 in Distributed Systems 

Dhamdhere: Operating Systems—
A Concept­Based Approach , 2 ed

Slide No: 18
Copyright © 2008



A timing diagram for the distributed computation



States of the processes are recorded at tP1– tP4
Q: Are these states mutually consistent?

Chapter 16: Theoretical issues
 in Distributed Systems 

Dhamdhere: Operating Systems—
A Concept­Based Approach , 2 ed

Slide No: 19
Copyright © 2008


A cut of a distributed system



A cut in a timing diagram is a curve that connects the
points at which states of processes are recorded
– Points to the left of the cut in the timing diagram are in the past
of the cut
– Points to the right are in the future of the cut
– A cut represents a consistent state recording of a distributed
system if the future of the cut is closed under the precedes

relation on events, i.e., under →
* That is, if a → b and is an event a in the future of the cut, b also lies
in the future of the cut

Chapter 16: Theoretical issues
 in Distributed Systems 

Dhamdhere: Operating Systems—
A Concept­Based Approach , 2 ed

Slide No: 20
Copyright © 2008


Consistency of a cut

• Cuts C1 and C2 are consistent; cut C3 is inconsistent
• A cut is inconsistent if some message has a
backward intersection with it, e.g. message P3 → P1
Chapter 16: Theoretical issues
 in Distributed Systems 

Dhamdhere: Operating Systems—
A Concept­Based Approach , 2 ed

Slide No: 21
Copyright © 2008


Chandy–Lamport Algorithm for state recording




Features of the algorithm
– Channels are assumed to be FIFO
* This property is used to identify messages that are in transit over a
channel

– The state of a process indicates the messages sent and
received by it
– A special message called a marker is sent to ask a process to
record its state
* A process receives markers over all channels incident on it
 It records the state of the channel over which it received the
marker
 If it is the first marker received by it, it also records its own state
Chapter 16: Theoretical issues
 in Distributed Systems 

Dhamdhere: Operating Systems—
A Concept­Based Approach , 2 ed

Slide No: 22
Copyright © 2008


Chandy–Lamport Algorithm




Steps in the algorithm
– When a process wishes to initiate the state recording
* Records its own state and sends markers over all outgoing channels

– When process Pj receives a marker over channel Chij
* If it is the first marker
 Record its own state
 Record state of Chij as empty
 Send markers over all outgoing channels
* Else record the state of the channel to contain messages
( Receivedij – Recorded_receivedij )@
: Receivedij : Messages received over Chij until this instant
Recorded_receivedij : Messages recorded as received over Chij in Pj’s state

@

Chapter 16: Theoretical issues
 in Distributed Systems 

Dhamdhere: Operating Systems—
A Concept­Based Approach , 2 ed

Slide No: 23
Copyright © 2008


Example of the Chandy–Lamport algorithm

• P1 sends m1 to P3 at time 0, P3
sends m2 to P2 at time 1

• P1 decides to record state of the
system at time 2
• (a), (b), (c) are states at 0, 2+, 5+

Chapter 16: Theoretical issues
 in Distributed Systems 

Dhamdhere: Operating Systems—
A Concept­Based Approach , 2 ed

Slide No: 24
Copyright © 2008


Recorded states of processes and channels

Chapter 16: Theoretical issues
 in Distributed Systems 

Dhamdhere: Operating Systems—
A Concept­Based Approach , 2 ed

Slide No: 25
Copyright © 2008


×