Issues with Clocks Context The tree correction protocol was based - - PowerPoint PPT Presentation

issues with clocks context
SMART_READER_LITE
LIVE PREVIEW

Issues with Clocks Context The tree correction protocol was based - - PowerPoint PPT Presentation

Issues with Clocks Context The tree correction protocol was based on the idea of local detection and correction. Protocols of this type are complex to build We will study some of the classic protocols that help solve different


slide-1
SLIDE 1

Issues with Clocks

slide-2
SLIDE 2

Context

  • The tree correction protocol was based
  • n the idea of local detection and

correction.

  • Protocols of this type are complex to

build

  • We will study some of the classic

protocols that help solve different problems

slide-3
SLIDE 3

Models

  • We reviewed the idea of different

models

– Higher level models make it easier to write the programs – Lower level models are easy to implement

slide-4
SLIDE 4

Strongest vs Weakest Model

  • What is strongest model?

– No private memory – Can update all variables at once – Essentially a centralized program

  • What is the weakest model

– Process speed arbitrary – No bounds on delays – No global time

  • Which should we study first?
slide-5
SLIDE 5

Asynchronous Model

  • Fairly weak model

– No global clock – No shared memory – Arbitrary process speed – Arbitrary message delays – We will assume messages are eventually delivered but after arbitrary delay

slide-6
SLIDE 6

Problems in Asynchronous Systems

  • We will study problems that we solve

easily in centralized systems

– Examples:

  • Clocks
  • Ordering among events
  • Checkpoints
  • ..
  • We will study solving these problems in

asynchronous systems

slide-7
SLIDE 7

Use of Clocks

  • Clocks allow us to order events
  • In asynchronous systems, there is no

notion of time.

  • What is the purpose of time

– To say: something happened at 5pm

  • We cannot do this in asynchronous systems

– To say: x1 happened first then y1

  • We can do this sometimes in asynchronous

systems

– E.g., the class began before it ended

slide-8
SLIDE 8

Problem

  • Lack of global time

– Need to compare different events in a distributed system

  • In asynchronous systems, time cannot

be used to order events

– We need to develop an alternative to order events in such a system

slide-9
SLIDE 9

Problem (Continued)

  • Consider the problem of detecting insider

trading in a stock exchange

– Assume that no communication occurs outside the computer systems – Each entity is represented by a computer and they communicate among themselves – Whenever a process sends a message, it includes ALL the information it has learnt so far

  • Lets not worry about the cost of implementing this

– Each entity is required to follow the protocol you choose

slide-10
SLIDE 10

Problem (Continued)

  • Consider two events

– An inside event, say e, that affects the company A – An event f, where an officer, X, of company A sells stock

  • Question

– Is it possible that X is guilty of insider trading?

slide-11
SLIDE 11

Situation 1

  • Assume global time

– Event e occurred at 8am – Event f occurred at 10am (same day) – Answer: – Event e occurred at 10am – Event f occurred at 8am (same day) – Answer:

slide-12
SLIDE 12

Approach

  • What we need is a way to define

causality

– Can event e affect event f? – This is defined as the happened before relation – Please do not confuse it with the English meaning of this

slide-13
SLIDE 13

A Realistic Variation

  • Consider a experiment that you are

performing that includes

– Events e and event f – Event f is a safety violation – Can changing what happens in event e affect what happens in f?

  • Important in debugging, checkpointing,

etc.

slide-14
SLIDE 14

An Example

Consider the following code segment x = 2; GOTO L1 x = 3 L2 z = y /x L1 x = x - 2 GOTO L2

slide-15
SLIDE 15

Another Problem from Debugging

  • Consider the requirement:

– Valve must be open if pressure exceeds 10 – Event e : at time 8:00:00:valve = open – Event f : at time 8:00:01, pressure = 11 – Looks ok. – But is it possible that due to some race conditions (e.g., processor @e being slow) delays e and violates this constraint.

slide-16
SLIDE 16

happened before

  • Let a, b, c be events

– An event can be a local event, send event or a receive event

  • Definition :
  • a  b (read as a happened before b) iff either
  • ne of the following condition is true

– a and b are events on the same process and a

  • ccurred before b

– a is a send event and b is the corresponding receive event – there exists event c such that a  c and c  b

slide-17
SLIDE 17

Revisiting the Previous Problems

  • Consider two events

– An inside event, say e, that affects the company A – An event f, where an officer, X, of company A sells stock

  • If e  f then X is guilty of insider trading
slide-18
SLIDE 18

Revisiting the Previous Problems

  • Parallel experiment
  • If e  f then changing what happens in

e can affect what happens in f

slide-19
SLIDE 19

Concurrent Events

  • a || b iff (NOT (a  b)) & (NOT (b  a))

– Question?

  • (a || b) & (b || c) => (a || c) ?
slide-20
SLIDE 20

Using Event Diagrams to Understand Causality

slide-21
SLIDE 21

Logical Clocks

  • Goal of logical clock is

– Assign each event a timestamp – If e  f then the timestamp of e should be less than that of f. – To solve this, each process maintains a logical clock cl

  • cl.j : clock value of process j
  • cl.m : clock value of message m
  • cl.a : clock value of event a
slide-22
SLIDE 22

Program for Logical Timestamps

  • Let a be a new event

– If a is a local event at j

  • cl.j := cl.j + 1
  • cl.a := cl.j

– If a is a send event at j

  • cl.j := cl.j + 1
  • cl.m := cl.j
  • cl.a := cl.j

– If a is a receive of message m at j

  • cl.j := max(cl.j, cl.m) + 1
  • cl.a := cl.j
slide-23
SLIDE 23

Properties of Logical Clocks

  • If a  b then cl.a < cl.b
slide-24
SLIDE 24

Proving Properties of Logical Clocks

  • Theorem: At any time, the following statement

is true for all events (that have occurred in the system so far)

– ∀ x, y :: x  y ⇒ cl.x < cl.y, – where x and y range over all the events, processes (latest event on the process) and messages (corresponding send event)

  • Proof by induction
  • Base case

– No events created. Hence, trivially true – Show that whenever a new event is created

slide-25
SLIDE 25

Invariant

  • The predicate

– a  b ⇒ cl.a < cl.b – Is an invariant of the logical timestamp program.

slide-26
SLIDE 26

Logical Timestamps

  • The time associated with an event is a pair,

the clock and the process where the event

  • ccurred.
  • For event a at process j, the timestamp ts.a is

– ts.a = <cl.a, j>

Lexicographical comparison < x1, x2 > < <y1, y2> iff x1 < y1 ∨ ( (x1 = y1) ∧ (x2 < y2) )

slide-27
SLIDE 27

Observation about Logical Clocks

  • For any two distinct events a and b,

either

  • ts.a < ts.b ∨ ts.b < ts.a
  • The event timestamps form a total
  • rder.
slide-28
SLIDE 28

So What?

  • Consider two events

– An inside event, say e, that affects the company A – An event f, where an officer, X, of company A sells stock

  • Question

– Is it possible that X is guilty of insider trading?

  • Case 1

– cl.e = 8, cl.f = 10 – Answer:

  • Case 2

– cl.e = 10, cl.f = 8 – Answer:

slide-29
SLIDE 29

Problem

  • Logical timestamps provide a partial

information about causality.

  • Extending logical timestamps for

complete knowledge of causality

slide-30
SLIDE 30

Accurate Causality Information

  • Desire

– a  b  clock.a < clock.b

  • Can clock.a be an integer?
slide-31
SLIDE 31

Accurate Causality Information

  • To obtain accurate causality

information, clock must consist of several integers

– It turns out that accurate causality information requires clocks to consist of n values

slide-32
SLIDE 32

Vector Clocks

  • Each process maintains a vector vc

– vc.j is the clock maintained by j – vc.j is an array

  • vc.j.k denotes the knowledge that j has about

the clock of k => vc.j.j denotes the clock of j

slide-33
SLIDE 33

Updating Vector Clocks

  • Let a be a new event

– If a is a send event at j

  • vc.j.j++
  • vc.m := vc.j
  • vc.a := vc.j

– If a is a receive of message m at j

  • vc.j := max(vc.j, vc.m)
  • vc.j.j++
  • vc.a := vc.j
slide-34
SLIDE 34

Causality Checking with Vector Clocks

  • vc.a < vc.b iff

– (Subject to requirement a  b iff vc.a < vc.b)

slide-35
SLIDE 35

Causality Checking with Vector Clocks

  • Suppose a is an event at process j and

b is an event at process k

– vc.a < vc.b iff

slide-36
SLIDE 36

Size of Vector Clocks

  • Our implementation requires clocks of

size n

– Can we do better?

slide-37
SLIDE 37

Lower bound on size of VC

  • Consider the network with n processes

– Consider the following communication

  • Initial event on process j is aj
  • Each process j sends a message to everyone

except (j-1) mod n

  • Each process receives all messages intended

for it.

– All receives are after all sends

  • Final event on process j is bj
slide-38
SLIDE 38

Lower bound on VC (continued)

  • Observations

– aj+1 || bj – For j≠k

  • ak+1  bj
slide-39
SLIDE 39
  • Suppose in contradiction, there is a way

to implement vector clocks with k- vectors of reals, where k < n.

  • aj+1 || bj

=> V(aj+1) and V(bj) are incomparable => V(aj+1) is larger than V(bj) in some coordinate Denote this value by h(i)

  • h : {0,…,n-1} → {0,…,k-1}
slide-40
SLIDE 40
  • h cannot be a one-to-one function

– There exists j and k such that h(j) = j(k)

  • Let this value be r
  • Compare V(bj), V(aj+1), V(bj) and V(ak+1)

– Evaluate with respect to element r

slide-41
SLIDE 41

Causal Delivery

  • Problem requirement

– Given two messages m1 and m2 sent to the same process

  • If send(m1)  send(m2)
  • Then Delivery(m1)  Delivery(m2)
slide-42
SLIDE 42

Solving Causal Broadcast

  • Special case of causal delivery where

all messages are broadcast in nature

– Applications in checkpointing etc.

  • Variables

– num.j.k = knowledge that j has about the number of messages sent by k

  • num.j.j = number of messages sent by j
slide-43
SLIDE 43

Solving Causal Broadcast

  • Algorithm

– When j sends a message

  • Num.j.j++

– When j receives a message.

  • Buffer it until j is certain that causal delivery

constraints wont be violated

  • Constraint j should check before delivering a

message from k

slide-44
SLIDE 44
  • Suppose j has a message m from k in its
  • buffer. J can deliver it iff the following

condition is satisfied:

  • Comparison between num.j.k & num.m.k

– Check if num.j.k = num.m.k – 1

  • Comparison between num.j.l and num.m.l,

where l is any process other than k

– Check if num.j.l >= num.m.l

  • If all these conditions are satisfied then

deliver m

  • How do I update num upon delivery?

– Num.j.k++

slide-45
SLIDE 45

Observations Regarding Vector Clocks

  • Could we have used a `reasonably fine-

grained’ physical clock to obtain vc.j.j?

slide-46
SLIDE 46

Augmented Time (Brief Overview)

  • What if clocks are synchronized within some

epsilon and we are interested in ordering events in the system.

  • For example, let epsilon = 10

– Can we say something about events e and f such that

  • ph.e = 10, ph.f = 15
  • ph.e = 10, ph.f = 1000

– Note that this was not possible without clock synchronization

slide-47
SLIDE 47

Augmented Time

  • Create timestamp with clocks

synchronized upto epsilon

– Need to order these events

  • ph.e = 10, ph.f = 15

– No need to order these events

  • ph.e = 10, ph.f = 1000
slide-48
SLIDE 48

Idea

  • Each process maintains at.j.k

– at.j.k = knowledge j has about clock of k

  • How would this variable be updated?

– Upon send? – Upon receive?

slide-49
SLIDE 49

Space requirement for augmented time

  • Worst case
  • Average case?
  • Can we optimize?
slide-50
SLIDE 50

Properties of Augmented Time

  • If two events are close
  • If two events are far off
slide-51
SLIDE 51

Augmented Logical Time

slide-52
SLIDE 52

Observations (Continued)

  • What if this physical clock was accurate

within some time bound

– Notion of communication via time – This could potentially bound the size of vector clocks

slide-53
SLIDE 53

Observations (Continued)

  • Does the clock have to be a vector of

size n?

– In general yes – But under certain topologies, it can be reduced

slide-54
SLIDE 54

Observations (Continued)

  • Causality captures whether event e

can potentially affect event f

– Illustration with simple code below:

  • 1. ptr = NULL;
  • 2. X = 0
  • 3. ptr->next = …
  • event2 happened before event3
slide-55
SLIDE 55

Applications of Causality

  • Checkpointing and Recovery
  • Concurrent database updates