DayuanTan / DistributedOS-ClocksSync-MulticastOrdering-MutualExclusion-COMMIT

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DistributedOS-ClocksSync-MulticastOrdering-MutualExclusion-COMMIT

Environments:

All tests are on Ubuntu 16.04 LTS, g++ (Ubuntu 5.4.0-6ubuntu1~16.04.12) 5.4.0 20160609. -std=c++11

1. Proj2 Clocks Synchronization, Multicast Ordering, and Mutual Exclusion, COMMIT - Requirement

In this programming project, you will develop an n-node distributed system that provides a causally ordered multicasting service and a distributed locking scheme. The distributed system uses logical clock to timestamp messages sent/received between nodes. To start the distributed system, each node should synchronize their logical clocks to the same initial value, based on which the ordering of events can be determined among the machines. For causal ordered multicasting you can use the algorithm discussed in class.

Additionally, suppose the distributed nodes have read and write access to a shared file. The last task is to implement a distributed locking scheme that prevents concurrent accesses to the shared file (this is an extra credit bonus assignment). You can use the centralized, decentralized, or the distributed algorithm to realize mutual exclusive access to the file. To simplify the design and testing, the distributed system will be emulated using multiple processes on a single machine. Each process represents a machine and has a unique port number for communication.

1.1 Assignment-1 (60pts)

Suppose the logical clock on each machine represents the number of messages have been sent and received by this machine. It is actually a counter used by the process (or the machine emulator) to count events. Randomly initialize the logical clock of individual processes and use Berkeley’s algorithm to synchronize these clocks to the average clock. You can select any process as the time daemon to initiate the clock synchronization. After the synchronization, each process prints out its logical clock to check the result of synchronization.

1.2 Assignment-2 (40pts)

Implement the causal ordered multicasting for the distributed system. Create two threads for each process, one for sending the multicast message to other nodes and one for listening to its communication port. Use vector clocks to enforce the order of messages. Once a process delivers a received message to a user, it prints out the message on screen. You can assume that the number of processes (machines) is fixed (equal to or larger than 3) and processes will not fail, join, or leave the distributed system. Implement two versions of this program, one without causally ordered multicasting and one with this feature. Compare the results of the two programs.

1.3 Bonus assignment (20pts)

Add the feature of distributed locking to your program to protect a shared file. The file only contains a counter that can be read and updated by processes. Implement two operations: acquire and release on a lock variable to protect the file. At the beginning, each process opens the file and tries to update the counter in the file and verifies the update. Thus, the critical section includes the following operations: (1) point the file offset to the counter; (2) update the counter; (3) read and print out the counter value. You can use any of the mutual exclusion algorithm learned in class to implement the locking. The expected result is that the read of the counter value always matches the updated value by a process if locking is enabled.

2. Phase 1 - Assignment 1 Clock Synchronization, Berkeley Algorithm

The Background Knowledge Review and my Implementation for this part is at this repo "berkeley-algorithm-implementation".

3. Phase 2 - Assignment 2 Multicast Programming

The Background Knowledge Review and my Implementation for this part is at this repo "Multicast Programming and Multicast Ordering Implementation".

  1. Phase 2.0, Firstly I Implemented multicast programming for 1 sender and multiple receivers using sender.cpp and receiver.cpp files.
  2. Phase 2.1, Secondly I merged them into one process with 2 threads. One for sending messages while another one for continuously receiving messages from multicast group. This is required in assignment 2. Phase 3.0 implementation is based on the Phase 2.1 version.

4. Phase 3 - Assignment 2 Multicast Ordering

The Background Knowledge Review and my Implementation for this part is at this repo "Multicast Programming and Multicast Ordering Implementation".

  1. Phase 3.0, Thridly I implemented multicasting with messages processing but no ordering, which will be a base for multicast ordering versions. I added lots of helper functions to deal with message processing.
  2. Phase 3.1, is my implementation of FIFO ordering, based on phase 3.0 version. I added sending and receiving rules based on FIFO ordering algorithm.
  3. Phase 3.2, is my implementation of Causal ordering, based on phase 3.1 version. The adjustments are mainly message sending and receiving parts for Causal ordering algorithm.

5. Phase 4 - Assignment 3 Mutual Exlcusion

(Didn't implement. Mutual Exlcusion are very similar to proj1. Can add that part into here easily. )

Mutual exclusion

  • Mutual exclusion: is a concurrency control property which is introduced to prevent race conditions.
  • Critical section: code only one thread/process can execute at a time
  • Lock: mechanism for mutual exclusion. Lock entering critical section, accessing shared data. Unlock when complete. Wait if locked.

For single machine, we can use shared variable (like semaphores) to share the status of shared-resources and user, because these data are all in memory or shared memory.

For DS, no shared memory are avaiable, message passing is the sole means for implementing distributed mutual exclusion [1].

Three basic approaches for distributed mutual exclusion:

  1. Token based approach
  2. Non-token based approach (like Lamport's algorithm)
  3. Quorum based approach

More algorithm introduction about above three types of approaches refer to [2].

Lamport's algorithm

The algorithm discussed in requirement of bonus assignment and in prof's slide is Lamport's algorithm.

(These images credit to Prof. Ajay Kshemkalyani.)

Reference:

  1. multi-process fork()
  2. Multicast
  3. Multicast Sockets - Programming Tips
  4. NETWORK PROGRAMMING LINUX SOCKET PART 13: MULTICAST (I feel this one most useful)
  5. Oracle Using Multicast - send, receive IPv4 Multicast Datagrams
  6. Linux man7 socket(7) - Linux socket interface, overview, SOL_SOCKET socket options list
  7. Linux man7 IPv4 protocol implementation, protocol options list
  8. Linux man7 getsockopt, setsockopt - get and set options on sockets
  9. Linux man7 socket(2) - create an endpoint for communication
  10. POSIX man7 setsockopt — set the socket options

About

License:GNU General Public License v3.0