26
Distributed Snapshot

Distributed Snapshot. One-dollar bank Let a $1 coin circulate in a network of a million banks. How can someone count the total $ in circulation? If not

Embed Size (px)

Citation preview

Page 1: Distributed Snapshot. One-dollar bank Let a $1 coin circulate in a network of a million banks. How can someone count the total $ in circulation? If not

Distributed Snapshot

Page 2: Distributed Snapshot. One-dollar bank Let a $1 coin circulate in a network of a million banks. How can someone count the total $ in circulation? If not

One-dollar bank

01

2

(0,1)

(1,2)(2,0)

Let a $1 coin circulate in a network of a million banks.

How can someone count the total $ in circulation? If

not counted “properly,” then one may think the total $

in circulation to be one million.

Page 3: Distributed Snapshot. One-dollar bank Let a $1 coin circulate in a network of a million banks. How can someone count the total $ in circulation? If not

Importance of snapshots

Major uses in

- deadlock detection

- termination detection

- rollback recovery

- global predicate computation

Page 4: Distributed Snapshot. One-dollar bank Let a $1 coin circulate in a network of a million banks. How can someone count the total $ in circulation? If not

Example 1

• Suppose you want to take a picture of a scenic view– Your camera cannot fit the entire scene in

one picture

– Take several pictures– Combine them to get overall picture

Page 5: Distributed Snapshot. One-dollar bank Let a $1 coin circulate in a network of a million banks. How can someone count the total $ in circulation? If not

Example 2

• Suppose you want to take a picture of basketball game– Your camera cannot fit the entire scene in

one picture

– Take several pictures– Combine them to get overall picture

• Care needs to be taken to ensure that the several pictures you took are consistent

– E.g., the same player cannot be in two places

Page 6: Distributed Snapshot. One-dollar bank Let a $1 coin circulate in a network of a million banks. How can someone count the total $ in circulation? If not

Example: Distributed Systems

• You want to take a picture (global snapshot) of the distributed system– You can take a picture (local snapshot) of

one process at a time– Need to combine these local snapshots– Need for consistency

Page 7: Distributed Snapshot. One-dollar bank Let a $1 coin circulate in a network of a million banks. How can someone count the total $ in circulation? If not

Example: Distributed Systems

• Local snapshot– Can be viewed in terms of the last event on

the process• When we combine such snapshots, we call it a

global snapshot

– Can be viewed in terms of the last event and all preceding events on a process

• When we combine such snapshots, we call it a (global) cut

Page 8: Distributed Snapshot. One-dollar bank Let a $1 coin circulate in a network of a million banks. How can someone count the total $ in circulation? If not

Consistent cut

(a consistent cut C) (b happened before a) b C

a b c d g

m e f

k i h jCut 1 Cut 2

A cut is a set of events.

(Not consistent)(Consistent)

P1

P2

P3

Page 9: Distributed Snapshot. One-dollar bank Let a $1 coin circulate in a network of a million banks. How can someone count the total $ in circulation? If not

Consistent snapshot

The set of states immediately following a

consistent cut forms a consistent snapshot

of a distributed system.

• A snapshot that is of practical interest is the

most recent one. Let C1 and C2 be two

consistent cuts and C1 C2. Then C2 is more

recent than C1.

• Assumption: The cut lines do not go through

any event

Page 10: Distributed Snapshot. One-dollar bank Let a $1 coin circulate in a network of a million banks. How can someone count the total $ in circulation? If not

Consistent snapshot

How to record a consistent snapshot? Note that

1. The recording must be non-invasive

2. Recording must be done on-the-fly.

You cannot stop the system.

Page 11: Distributed Snapshot. One-dollar bank Let a $1 coin circulate in a network of a million banks. How can someone count the total $ in circulation? If not

Chandy-Lamport Algorithm

Works on a

(1) strongly connected graph

(2) each channel is FIFO.

An initiator initiates the

algorithm by sending out

a marker ( )

Page 12: Distributed Snapshot. One-dollar bank Let a $1 coin circulate in a network of a million banks. How can someone count the total $ in circulation? If not

White and red processes

Initially every process is white. When a

process receives a marker, it turns

red if it has not already done so.

Every action by a process, and every

message sent by a process gets the

color of that process.

Page 13: Distributed Snapshot. One-dollar bank Let a $1 coin circulate in a network of a million banks. How can someone count the total $ in circulation? If not

Two steps

Step 1. In one atomic action, the initiator (a) Turns red (b) Records its own state (c) sends a marker along all outgoing channels

Step 2. Every other process, upon receiving a marker for the first time (and before doing anything else) (a) Turns red (b) Records its own state (c) sends markers along all outgoing channels

The algorithm terminates when (1) every process turns red, and (2) Every process has received a marker through each incoming channel.

Page 14: Distributed Snapshot. One-dollar bank Let a $1 coin circulate in a network of a million banks. How can someone count the total $ in circulation? If not

Why does it work?

Lemma 1. No red message is received in a white action.

Page 15: Distributed Snapshot. One-dollar bank Let a $1 coin circulate in a network of a million banks. How can someone count the total $ in circulation? If not

Why does it work?

Theorem. The global state recorded by Chandy-Lamport algorithm is equivalent to the ideal snapshot state SSS.

Hint. A pair of actions (a, b) can be scheduled in any order, if there is no causal order between them, so (a; b) is equivalent to (b; a)

SSSEasy conceptualization of the snapshot state

All white All red

Page 16: Distributed Snapshot. One-dollar bank Let a $1 coin circulate in a network of a million banks. How can someone count the total $ in circulation? If not

Why does it work?

Let an observer observe the following actions:

w[i] w[k] r[k] w[j] r[i] w[l] r[j] r[l] … w[i] w[k] w[j] r[k] r[i] w[l] r[j] r[l] … [Lemma 1]w[i] w[k] w[j] r[k] w[l] r[i] r[j] r[l] … [Lemma 1]w[i] w[k] w[j] w[l] r[k] r[i] r[j] r[l] … [done!]

Recorded state

Page 17: Distributed Snapshot. One-dollar bank Let a $1 coin circulate in a network of a million banks. How can someone count the total $ in circulation? If not

Understanding snapshot

The observed state is a feasible state that is reachable

from the initial configuration. It may not actually be visited

during a specific execution.

The final state of the original computation is always

reachable from the observed state.

Page 18: Distributed Snapshot. One-dollar bank Let a $1 coin circulate in a network of a million banks. How can someone count the total $ in circulation? If not

Discussions

What good is a snapshot if that state has never been visited by the system?

- It is relevant for the detection of stable predicates.

- Useful for checkpointing.

Page 19: Distributed Snapshot. One-dollar bank Let a $1 coin circulate in a network of a million banks. How can someone count the total $ in circulation? If not

Discussions

What if the channels are not FIFO?

Study how Lai-Yang algorithm works. It does not use any marker

LY1. The initiator records its own state. When it needs to send a

message m to another process, it sends a message (m, red).

LY2. When a process receives a message (m, red), it records its state

if it has not already done so, and then accepts the message m.

Question 1. Why will it work?

Question 1 Are there any limitations of this approach?

Page 20: Distributed Snapshot. One-dollar bank Let a $1 coin circulate in a network of a million banks. How can someone count the total $ in circulation? If not

Another related problem

Distributed snapshot = distributed read.

Distributed reset = distributed write

Page 21: Distributed Snapshot. One-dollar bank Let a $1 coin circulate in a network of a million banks. How can someone count the total $ in circulation? If not

Global state collection

Some applications

- computing network topology

- termination detection

- deadlock detection

Chandy Lamport algorithm does a partial job. Each process collects a

fragment of the global state, but these pieces have to be stitched together to

form a global state.

All to all broadcast can be achieved via computation similar to

diffusing computation

Page 22: Distributed Snapshot. One-dollar bank Let a $1 coin circulate in a network of a million banks. How can someone count the total $ in circulation? If not

Recall: Global State

• The global state of a system consists of – One local state for each process

• Contains all the messages sent and received upto a point in computation

• A local state could be specified by the `last’ event on the respective process

Page 23: Distributed Snapshot. One-dollar bank Let a $1 coin circulate in a network of a million banks. How can someone count the total $ in circulation? If not

Consistency in Global State

• Consistent iff– If reception of any message is recorded in

the global state then the corresponding send is also recorded

• If global snapshot is consistent then what is the causal relation between the `last’ events of respective processes?

Page 24: Distributed Snapshot. One-dollar bank Let a $1 coin circulate in a network of a million banks. How can someone count the total $ in circulation? If not

Revisit Dijkstra Safra Termination Detection Algorithm• Note that the token is collecting a global

snapshot of the system– Can we see if it is consistent?

Page 25: Distributed Snapshot. One-dollar bank Let a $1 coin circulate in a network of a million banks. How can someone count the total $ in circulation? If not

2 Phase Termination Detection

• Maintain c.j similar to Dijkstra-Safra Termination Detection– But no color variable maintained

Page 26: Distributed Snapshot. One-dollar bank Let a $1 coin circulate in a network of a million banks. How can someone count the total $ in circulation? If not

Application of Global State Detection

• Termination detection

• Checkpointing and recovery