Chapter 12 Message Ordering Causal Ordering n n

  • Slides: 19
Download presentation
Chapter 12 Message Ordering

Chapter 12 Message Ordering

Causal Ordering n n n A single message should not be overtaken by a

Causal Ordering n n n A single message should not be overtaken by a sequence of messages Stronger than FIFO Example of FIFO but not causal

Causal and FIFO ordering n FIFO: q n Any two messages from a process

Causal and FIFO ordering n FIFO: q n Any two messages from a process Pi to Pj are received Causal: q If r 1 , r 2 are the receive events on some process and s 1, s 2 are the corresponding send events :

Algorithm for causal ordering n n Maintain a matrix M[1. . N, 1. .

Algorithm for causal ordering n n Maintain a matrix M[1. . N, 1. . N] at each process When Pi sends a message to Pj q q n M[i, j] = M[i, j] + 1 Piggyback M with the message When Pi receives a message with matrix W from Pj q If Then receive message else block M = max (M, W)

Algorithm for causal ordering n n The entry M[k, j] at process i ,

Algorithm for causal ordering n n The entry M[k, j] at process i , records the number of messages sent by j to process k as known by process I If a process i receives a message from j with the matrix W then q If W[k, i] >M[k, i] then j knows of a message k has sent to i , though i has not received the message till then. Hence process i blocks the message from j.

Algorithm

Algorithm

Applications n Causal chat – Figure 12. 5 q q Uses Causal Linker Figure

Applications n Causal chat – Figure 12. 5 q q Uses Causal Linker Figure 12. 4 P 0 P 1 § q q P 0 P 1 P 2 If P 0 sends a message to P 1 and P 2 and P 1 sends a reply to both P 0 and P 2 then causal linker gives the guarantee that P 1’s reply cannot reach P 2 before the original query

Synchronous Ordering n n n Equivalent to a computation in which all messages are

Synchronous Ordering n n n Equivalent to a computation in which all messages are logically instantaneous Stronger than Causal and FIFO ordering Formally, let be the set of all external events. Then, a computation is synchronous iff there exists a mapping T from to the set of natural numbers such that and

Examples Synchronous Non-Synchronous

Examples Synchronous Non-Synchronous

Synchronous order : Algorithm n n n The algorithm cannot be totally symmetric (if

Synchronous order : Algorithm n n n The algorithm cannot be totally symmetric (if two processes wish to simultaneously send messages to each other) Use process numbers to order all processes Use control messages to enforce synchronous ordering

Synchronous order : Algorithm n Messages: q q n n Big : sent by

Synchronous order : Algorithm n Messages: q q n n Big : sent by a bigger process to smaller process Small: sent by a smaller process to bigger process All processes are initially active An active process can send a big message q q After sending turn passive till an ack is received Passive process cannot send or receive any message (except, of course, the ack )

Synchronous order : Algorithm n Small messages: q q q Request permission from the

Synchronous order : Algorithm n Small messages: q q q Request permission from the bigger process before sending Permission can be granted by an active process. The bigger process turns passive after granting the permission Once the message is received the bigger process can turn active

Algorithm

Algorithm

Total order for multicast messages n n n If process Pi sends messages x,

Total order for multicast messages n n n If process Pi sends messages x, y to processes Pj, Pk , . . then all the processes Pj, Pk … receive the messages in the same order (x, y or y, x) Observe that this does not imply causal or even FIFO ordering Algorithms: q q Similar to the mutex problem Assume FIFO channels

Centralized and Lamport Algorithms n Assume FIFO channels q q q Broadcast a message

Centralized and Lamport Algorithms n Assume FIFO channels q q q Broadcast a message request. CS Centralized: Coordinator multicasts the message instead of sending the lock Lamport: n n The broadcast is stored in a queue by all processes and a timestamped ack is sent back A process can deliver (act on) a message with timestamp t in its request queue if it has received a message with timestamp greater than t from all other processes ( Entering the CS in Lamport’s mutex algorithm)

Skeen’s Algorithm n n Lamport’s Algorithm is wasteful if messages are multicast (the other

Skeen’s Algorithm n n Lamport’s Algorithm is wasteful if messages are multicast (the other processes simple ignore the messages) Skeen’s algorithm results in # of messages proportional to the number of recipients of the message

Skeen’s Algorithm n n n Send a timestamped message to all the destination processes

Skeen’s Algorithm n n n Send a timestamped message to all the destination processes On receiving a message, a process marks it as undeliverable and sends the value of the logical clock as the proposed timestamp to the initiator Set the max of all proposals as the final timestamp and send to all destinations On receiving the final timestamp of a message, it is marked as deliverable. A deliverable message is delivered if it has the smallest timestamp in the message queue.

0 1 2 n n n Process 0 multicasts msg to 1 and 2

0 1 2 n n n Process 0 multicasts msg to 1 and 2 On receiving 1 and 2 they mark it undeliverable and send propose with values 2 and 4 respectively If 1 receives another message from a lower priority process (say with id 3), then it ignores the message till it has received final from 0 Process 0 takes the max of the proposed timestamps and send out final 4 to processes 1 and 2 Processes 1 and 2 mark msg as deliverable and deliver it if it has the smallest timestamp

Application n Replicated State Machine q q q Provide fault tolerant service using multiple

Application n Replicated State Machine q q q Provide fault tolerant service using multiple servers All machines should process all requests in the same order Use total ordering of messages