global predicate detection and event ordering

116
Global Predicate Detection and Event Ordering

Upload: zihna

Post on 06-Jan-2016

25 views

Category:

Documents


0 download

DESCRIPTION

Global Predicate Detection and Event Ordering. Our Problem. To compute predicates over the state of a distributed application. Model. Message passing No failures Two possible timing assumptions: Synchronous System Asynchronous System No upper bound on message delivery time - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Global Predicate Detection  and Event Ordering

Global Predicate Detection

and Event Ordering

Page 2: Global Predicate Detection  and Event Ordering

Our Problem

To compute predicatesover the state of

a distributed application

Page 3: Global Predicate Detection  and Event Ordering

Model

Message passing

No failures

Two possible timing assumptions:

Synchronous System

Asynchronous System

No upper bound on message delivery time

No bound on relative process speeds

No centralized clock

Page 4: Global Predicate Detection  and Event Ordering

Asynchronous systems

Weakest possible assumptions

Weak assumptions ´ less vulnerabilities

Asynchronous slow

“Interesting” model w.r.t. failures

Page 5: Global Predicate Detection  and Event Ordering

Client-Server

•Processes exchange messages using •Remote Procedure Call (RPC)

A client requests a service by sending the server a

message. The client blocks while waiting for a response

sc

Page 6: Global Predicate Detection  and Event Ordering

Client-Server

• Processes exchange messages using • Remote Procedure Call (RPC)

The server computes the response (possibly asking

other servers) and returns it to the client

A client requests a service by sending the server a

message. The client blocks while waiting for a response

s

#!?%!

c

Page 7: Global Predicate Detection  and Event Ordering

Deadlock!

Page 8: Global Predicate Detection  and Event Ordering

Goal

•Design a protocol by which a processor can determine whether a global predicate (say, deadlock) holds

Page 9: Global Predicate Detection  and Event Ordering

Draw arrow from pi to pj if pj has received a request but has not responded yet

Wait-For Graphs

Page 10: Global Predicate Detection  and Event Ordering

Draw arrow from pi to pj if pj has received a request but has not responded yet

Cycle in WFG ) deadlock

Deadlock ) ¦ cycle in WFG

Wait-For Graphs

Page 11: Global Predicate Detection  and Event Ordering

The protocol

p0 sends a message to p1 p3

On receipt of p0 ‘s message, pi replies with its state and wait-for info

Page 12: Global Predicate Detection  and Event Ordering

An execution

Page 13: Global Predicate Detection  and Event Ordering

An execution

Page 14: Global Predicate Detection  and Event Ordering

An execution

Ghost Deadlock!

Page 15: Global Predicate Detection  and Event Ordering

We have a problem...

Asynchronous system

no centralized clock, etc. etc.

Synchrony useful to

coordinate actions

order events

Page 16: Global Predicate Detection  and Event Ordering

Events and HistoriesProcesses execute sequences of events

Events can be of 3 types: local, send, and receive

epi is the i-th event of process p

The local history hp of process p is the sequence of events executed by process

hpk : prefix that contains first k events

hp0 : initial, empty sequence

The history H is the set hp0 [ hp1

[ … hpn-1NOTE: In H, local histories are interpreted as sets, rather than sequences, of events

Page 17: Global Predicate Detection  and Event Ordering

Ordering events

Observation 1:

Events in a local history are totally ordered

time

Page 18: Global Predicate Detection  and Event Ordering

Ordering events

Observation 1:

Events in a local history are totally ordered

Observation 2:

For every message m, send(m) precedes receive(m)

time

time

time

Page 19: Global Predicate Detection  and Event Ordering

Happened-before(Lamport[1978])

•A binary relation defined over events

1. if eik,ei

l2hi and k<l , then eik !ei

l

2. if ei=send (m) and ej=receive(m), then ei! ej

3. if e!e’ and e’! e‘’, then e! e‘’

Page 20: Global Predicate Detection  and Event Ordering

Space-Time diagrams

•A graphic representation of a distributed execution

time

Page 21: Global Predicate Detection  and Event Ordering

Space-Time diagrams

•A graphic representation of a distributed execution

time

Page 22: Global Predicate Detection  and Event Ordering

Space-Time diagrams

•A graphic representation of a distributed execution

time

Page 23: Global Predicate Detection  and Event Ordering

Space-Time diagrams

•A graphic representation of a distributed execution

time

Page 24: Global Predicate Detection  and Event Ordering

Space-Time diagrams

•A graphic representation of a distributed execution

time

H and impose a partial order

Page 25: Global Predicate Detection  and Event Ordering

Space-Time diagrams

•A graphic representation of a distributed execution

time

H and impose a partial order

Page 26: Global Predicate Detection  and Event Ordering

Space-Time diagrams

•A graphic representation of a distributed execution

time

H and impose a partial order

Page 27: Global Predicate Detection  and Event Ordering

Space-Time diagrams

•A graphic representation of a distributed execution

time

H and impose a partial order

Page 28: Global Predicate Detection  and Event Ordering

Runs andConsistent Runs

A run is a total ordering of the events in H that is consistent with the local histories of the processors

Ex: h1,h2, … ,hn is a run

A run is consistent if the total order imposed in the run is an extension of the partial order induced by!

A single distributed computation may correspond to several consistent runs!

Page 29: Global Predicate Detection  and Event Ordering

Cuts

•A cut C is a subset of the global history of H

Page 30: Global Predicate Detection  and Event Ordering

•A cut C is a subset of the global history of H

•The frontier of C is the set of events

Cuts

Page 31: Global Predicate Detection  and Event Ordering

Global states and cuts

The global state of a distributed computation is an tuple of n local states

= (1 ... n )

To each cut (1c1, ... n

cn) corresponds a global

state

Page 32: Global Predicate Detection  and Event Ordering

Consistent cuts and consistent global states

A cut is consistent if

A consistent global state is one corresponding to a consistent cut

Page 33: Global Predicate Detection  and Event Ordering

What sees

Page 34: Global Predicate Detection  and Event Ordering

What sees

•Not a consistent global state: the cut contains the event corresponding to the receipt of the last message by p3 but not the corresponding send event

Page 35: Global Predicate Detection  and Event Ordering

Our task

Develop a protocol by which a processor can build a consistent global state

Informally, we want to be able to take a snapshot of the computation

Not obvious in an asynchronous system...

Page 36: Global Predicate Detection  and Event Ordering

Our approach

Develop a simple synchronous protocol

Refine protocol as we relax assumptions

Record:processor stateschannel states

Assumptions:FIFO channelsEach m timestamped with with T(send(m))

Page 37: Global Predicate Detection  and Event Ordering

Snapshot I

• 1. p0 selects tss

• 2. p0 sends “take a snapshot at tss” to all processes

• 3. when clock of pi reads tss then a. records its local state i

b. starts recording messages received on each of incoming channels

• stops recording a channel when it receives first message with timestamp greater than or equal to tss

Page 38: Global Predicate Detection  and Event Ordering

Snapshot I

• 1. p0 selects tss

• 2. p0 sends “take a snapshot at tss” to all processes

• 3. when clock of pi reads tss then a. records its local state i

b. sends an empty message along its outgoing channelsc. starts recording messages received on each of

incoming channelsd. stops recording a channel when it receives first

message with timestamp greater than or equal to tss

Page 39: Global Predicate Detection  and Event Ordering

Correctness

Theorem: Snapshot I produces a consistent cut

< Assumption >

< Assumption >

< 0 and 1>

Proof: Need to prove

< Definition >

< Property of real time>

< 2 and 4>

< 5 and 3>

< Definition >

Page 40: Global Predicate Detection  and Event Ordering

Clock Condition

< Property of real time>

Can the Clock Condition be implemented some other way?

Page 41: Global Predicate Detection  and Event Ordering

Lamport Clocks

•Each process maintains a local variable LC•LC(e) = value of LC for event e

Page 42: Global Predicate Detection  and Event Ordering

Increment Rules

Timestamp m with

Page 43: Global Predicate Detection  and Event Ordering

Space-Time Diagrams and Logical

Clocks2

1

3

4 5 6

6

7

7

8

8

9

Page 44: Global Predicate Detection  and Event Ordering

A subtle problem

• when LC=t do S

• doesn’t make sense for Lamport clocks!

• there is no guarantee that LC will ever be t• S is anyway executed after

• Fixes: • If e is internal/send and LC = t-2

• execute e and then S• If e = receive(m) Æ (TS(m) ¸ t) Æ (LC · t-1)

• put message back in channel• re-enable e; set LC=t-1; execute S

Page 45: Global Predicate Detection  and Event Ordering

An obvious problem

No tss !

Choose large enough that it cannot be reached by applying the update rules of logical clocks

Page 46: Global Predicate Detection  and Event Ordering

An obvious problem

No tss!

Choose large enough that it cannot be reached by applying the update rules of logical clocks

Doing so assumes

upper bound on message delivery time

upper bound relative process speeds

Better relax it

Page 47: Global Predicate Detection  and Event Ordering

Snapshot II

p0 selects

p0 sends “take a snapshot at tss” to all processes; it waits for all of them to reply and then sets its logical clock to

when clock of pi reads then pi

records its local state i

sends an empty message along its outgoing channelsstarts recording messages received on each incoming channelstops recording a channel when receives first message with timestamp greater than or equal to

Page 48: Global Predicate Detection  and Event Ordering

Relaxing synchrony

Process does nothing for the protocol during this time!

take a snapshot at

empty message:

monitorschannels records

local state

sends empty message:

Use empty message to announce snapshot!

Page 49: Global Predicate Detection  and Event Ordering

Snapshot III

Processor p0 sends itself “take a snapshot “

when pi receives “take a snapshot” for the first time from pj:

records its local state i

sends “take a snapshot” along its outgoing channels

sets channel from pj to empty

starts recording messages received over each of its other incoming channels

when receives “take a snapshot” beyond the first time from pk:

pi stops recording channel from pk

when pi has received “take a snapshot” on all channels, it sends collected state to p0 and stops.

Page 50: Global Predicate Detection  and Event Ordering

Snapshots: a perspective

The global state s saved by the snapshot protocol is a consistent global state

Page 51: Global Predicate Detection  and Event Ordering

Snapshots: a perspective

The global state s saved by the snapshot protocol is a consistent global stateBut did it ever occur during the computation?

a distributed computation provides only a partial order of eventsmany total orders (runs) are compatible with that partial orderall we know is that s could have occurred

Page 52: Global Predicate Detection  and Event Ordering

Snapshots: a perspective

The global state s saved by the snapshot protocol is a consistent global stateBut did it ever occur during the computation?

a distributed computation provides only a partial order of eventsmany total orders (runs) are compatible with that partial orderall we know is that s could have occurred

We are evaluating predicates on states that may have never occurred!

Page 53: Global Predicate Detection  and Event Ordering

An Execution and its Lattice

Page 54: Global Predicate Detection  and Event Ordering

An Execution and its Lattice

Page 55: Global Predicate Detection  and Event Ordering

An Execution and its Lattice

Page 56: Global Predicate Detection  and Event Ordering

An Execution and its Lattice

Page 57: Global Predicate Detection  and Event Ordering

An Execution and its Lattice

Page 58: Global Predicate Detection  and Event Ordering

An Execution and its Lattice

Page 59: Global Predicate Detection  and Event Ordering

An Execution and its Lattice

Page 60: Global Predicate Detection  and Event Ordering

An Execution and its Lattice

Page 61: Global Predicate Detection  and Event Ordering

An Execution and its Lattice

Page 62: Global Predicate Detection  and Event Ordering

An Execution and its Lattice

Page 63: Global Predicate Detection  and Event Ordering

An Execution and its Lattice

Page 64: Global Predicate Detection  and Event Ordering

An Execution and its Lattice

Page 65: Global Predicate Detection  and Event Ordering

An Execution and its Lattice

Page 66: Global Predicate Detection  and Event Ordering

An Execution and its Lattice

Page 67: Global Predicate Detection  and Event Ordering

Reachability

• kl is reachable from ij if there is a path from kl to ij in the lattice

Page 68: Global Predicate Detection  and Event Ordering

Reachability

• kl is reachable from ij if there is a path from kl to ij in the lattice

Page 69: Global Predicate Detection  and Event Ordering

Reachability

• kl is reachable from ij if there is a path from kl to ij in the lattice

Page 70: Global Predicate Detection  and Event Ordering

Reachability

• kl is reachable from ij if there is a path from kl to ij in the lattice

Page 71: Global Predicate Detection  and Event Ordering

So, why do we care about s again?

Deadlock is a stable property

Deadlock Deadlock

If a run R of the snapshot protocol starts in i and terminates in f, then

Page 72: Global Predicate Detection  and Event Ordering

So, why do we care about s again?

Deadlock is a stable property

Deadlock Deadlock

If a run R of the snapshot protocol starts in i and terminates in f, then

Deadlock in s implies deadlock in f

No deadlock in s implies no deadlock in i

Page 73: Global Predicate Detection  and Event Ordering

Same problem, different approach

Monitor process does not query explicitly

Instead, it passively collects information and uses it to build an observation.

(reactive architectures, Harel and Pnueli [1985])

An observation is an ordering of event of the distributed computation based on the order in which the receiver is notified of the events.

Page 74: Global Predicate Detection  and Event Ordering

Observations: a few observationsAn observation puts no constraint on the order in which the monitor receives notifications

Page 75: Global Predicate Detection  and Event Ordering

Observations: a few observationsAn observation puts no constraint on the order in which the monitor receives notifications

Page 76: Global Predicate Detection  and Event Ordering

Observations: a few observationsAn observation puts no constraint on the order in which the monitor receives notifications

Page 77: Global Predicate Detection  and Event Ordering

Causal delivery

•FIFO delivery guarantees:

Page 78: Global Predicate Detection  and Event Ordering

Causal delivery

•FIFO delivery guarantees:

•Causal delivery generalizes FIFO:

Page 79: Global Predicate Detection  and Event Ordering

Causal delivery

•FIFO delivery guarantees:

•Causal delivery generalizes FIFO:

send event

receive event

deliver event

Page 80: Global Predicate Detection  and Event Ordering

Causal delivery

•FIFO delivery guarantees:

•Causal delivery generalizes FIFO:

• send event

receive event

deliver event

Page 81: Global Predicate Detection  and Event Ordering

Causal delivery

•FIFO delivery guarantees:

•Causal delivery generalizes FIFO:

send event

receive event

deliver event

Page 82: Global Predicate Detection  and Event Ordering

Causal delivery

•FIFO delivery guarantees:

•Causal delivery generalizes FIFO:

send event

receive event

deliver event

1

Page 83: Global Predicate Detection  and Event Ordering

Causal delivery

•FIFO delivery guarantees:

•Causal delivery generalizes FIFO:

send event

receive event

deliver event

1 2

Page 84: Global Predicate Detection  and Event Ordering

Causal Deliveryin Synchronous Systems

•We use the upper bound on message delivery time

Page 85: Global Predicate Detection  and Event Ordering

Causal Deliveryin Synchronous Systems

•We use the upper bound on message delivery time

•DR1: At time t , p0 delivers all messages it received with timestamp up to t- in increasing timestamp order

Page 86: Global Predicate Detection  and Event Ordering

Causal Deliverywith Lamport Clocks

• DR1.1: Deliver all received messages in increasing (logical clock) timestamp order.

Page 87: Global Predicate Detection  and Event Ordering

Causal Deliverywith Lamport Clocks

• DR1.1: Deliver all received messages in increasing (logical clock) timestamp order.

1

Page 88: Global Predicate Detection  and Event Ordering

Causal Deliverywith Lamport Clocks

• DR1.1: Deliver all received messages in increasing (logical clock) timestamp order.

1 4

Should p0 deliver?

Page 89: Global Predicate Detection  and Event Ordering

Causal Deliverywith Lamport Clocks

• DR1.1: Deliver all received messages in increasing (logical clock) timestamp order.

• Problem: Lamport Clocks don’t provide gap detection

1 4

Should p0 deliver?

Given two events e and e’ and their clock values LC(e) and LC(e’) — where LC(e) < LC(e’), determine whether some e’’ event

exists s.t. LC(e) < LC(e’’) < LC(e’)

Page 90: Global Predicate Detection  and Event Ordering

Stability

•DR2: Deliver all received stable messages in increasing (logical clock) timestamp order.

•A message m received by p is stable at p if p will never receive a future message m s.t. TS(m’) < TS(m)

Page 91: Global Predicate Detection  and Event Ordering

Implementing Stability

Real-time clocks

wait for time units

Page 92: Global Predicate Detection  and Event Ordering

Implementing Stability

Real-time clocks

wait for time units

Lamport clocks

wait on each channel for m s.t. TS(m) > LC(e)

Design better clocks!

Page 93: Global Predicate Detection  and Event Ordering

Clocks and STRONG Clocks

Lamport clocks implement the clock condition:

We want new clocks that implement the strong clock condition:

Page 94: Global Predicate Detection  and Event Ordering

Causal Histories

The causal history of an event e in (H,!) is the set

Page 95: Global Predicate Detection  and Event Ordering

Causal Histories

The causal history of an event e in (H,!) is the set

Page 96: Global Predicate Detection  and Event Ordering

Causal Histories

The causal history of an event e in (H,!) is the set

Page 97: Global Predicate Detection  and Event Ordering

How to build

•Each process : pi

initializes = 0

if eik is an internal or send event, then

• if eik is a receive event for message m,

then

Page 98: Global Predicate Detection  and Event Ordering

Pruning causal histories

Prune segments of history that are known to all processes (Peterson, Bucholz and Schlichting)

Use a more clever way to encode (e)

Page 99: Global Predicate Detection  and Event Ordering

Vector Clocks

Consider i(e), the projection of (e) on pi

i(e) is a prefix of hi : i(e) = hiki – it can be

encoded using ki

(e) = 1(e) [ 2(e) [ . . . [ n(e) can be encoded using

Represent using an n-vector VC such that

Page 100: Global Predicate Detection  and Event Ordering

Update rules

Message m is timestamped with

Page 101: Global Predicate Detection  and Event Ordering

Example

[1,0,0]

[0,1,0]

[2,1,0]

[1,0,1] [1,0,2] [1,0,3]

[3,1,2]

[1,2,3]

[4,1,2] [5,1,2]

[4,3,3]

[5,1,4]

Page 102: Global Predicate Detection  and Event Ordering

Operational interpretation

•=

•=

[1,0,0]

[0,1,0]

[2,1,0]

[1,0,1] [1,0,2] [1,0,3]

[3,1,2]

[1,2,3]

[4,1,2] [5,1,2]

[4,3,3]

[5,1,4]

Page 103: Global Predicate Detection  and Event Ordering

Operational interpretation

´ no. of events executed pi by up to and including ei

´

[1,0,0]

[0,1,0]

[2,1,0]

[1,0,1] [1,0,2] [1,0,3]

[3,1,2]

[1,2,3]

[4,1,2] [5,1,2]

[4,3,3]

[5,1,4]

Page 104: Global Predicate Detection  and Event Ordering

Operational interpretation

´ no. of events executed pi by up to and including ei

´ no. of events executed by pj that happen before ei of pi

[1,0,0]

[0,1,0]

[2,1,0]

[1,0,1] [1,0,2] [1,0,3]

[3,1,2]

[1,2,3]

[4,1,2] [5,1,2]

[4,3,3]

[5,1,4]

Page 105: Global Predicate Detection  and Event Ordering

VC properties:event ordering

1. Given two vectors V and V+, less than is defined as: V < V+ ´ (V V+) Æ (8 k : 1· k· n : V[k] · V+[k])

Strong Clock Condition:

Simple Strong Clock Condition: Given ei of pi and ej of pj, where i j

1. Concurrency: Given ei of pi and ej of pj, where i j

Page 106: Global Predicate Detection  and Event Ordering

VC properties: consistency

Pairwise inconsistency

Events ei of pi and ej of pj (i j) are pairwise inconsistent (i.e. can’t be on the frontier of the same consistent cut) if and only if

Consistent Cut

A cut defined by (c1, . . ., cn) is consistent if and only if

Page 107: Global Predicate Detection  and Event Ordering

VC properties:weak gap detection

Weak gap detection

Given ei of pi and ej of pj, if VC(ei)[k] < VC(ej)[k] for some k j, then there exists ek s.t

[2,2,2]

[2,0,1]

[0,0,2]

Page 108: Global Predicate Detection  and Event Ordering

VC properties:weak gap detection

Weak gap detection

Given ei of pi and ej of pj, if VC(ei)[k] < VC(ej)[k] for some k j, then there exists ek s.t

[2,2,2]

[2,0,1]

[0,0,2]

[2,1,1]

[0,0,1]

[1,0,1]

Page 109: Global Predicate Detection  and Event Ordering

VC properties:strong gap detection

Weak gap detection

Given ei of pi and ej of pj, if VC(ei)[k] < VC(ej)[k] for some k j, then there exists ek s.t

Strong gap detection

Given ei of pi and ej of pj, if VC(ei)[i] < VC(ej)[i] for some k j, then there exists ei

’ s.t

Page 110: Global Predicate Detection  and Event Ordering

VCs for Causal Delivery

Each process increments the local component of its VC only for events that are notified to the monitor

Each message notifying event e is timestamped with VC(e)

The monitor keeps all notification messages in a set M

Page 111: Global Predicate Detection  and Event Ordering

Stability

•Suppose p0 has received mj from pj.

•When is it safe for p0 to deliver mj ?

Page 112: Global Predicate Detection  and Event Ordering

Stability

•Suppose p0 has received mj from pj

•When is it safe for p0 to deliver mj ?

There is no earlier message in M

Page 113: Global Predicate Detection  and Event Ordering

Stability

•Suppose p0 has received mj from pj

•When is it safe for p0 to deliver mj ?

There is no earlier message in M

There is no earlier message from pj

no. of pj messages delivered by p0

Page 114: Global Predicate Detection  and Event Ordering

Stability

•Suppose p0 has received mj from pj

•When is it safe for p0 to deliver mj ?

There is no earlier message in M

There is no earlier message from pj

There is no earlier message mk’’ from pk (k j) …

?

no. of pj messages delivered by p0

Page 115: Global Predicate Detection  and Event Ordering

Checking for .

Let mk’ be the last message p0 delivered

from pk

By strong gap detection, mk’’ exists only if

Hence, deliver mj as soon as

Page 116: Global Predicate Detection  and Event Ordering

The protocol

p0 maintains an array D[1, . . ., n] of counters

D[i] = TS(mi)[i] where mi is the last message delivered from pi

• DR3: Deliver m from pj as soon as both of the following conditions are satisfied:

1.

2.