This is a fault-tolerant distributed file storage system implemented in Python. The system demonstrates four key characteristics of distributed systems as per the assignment requirements:
- Fault Tolerance: The system can continue operating even if one or more servers fail.
- Data Replication and Consistency: Data is replicated across multiple nodes with strong consistency guarantees.
- Time Synchronization: All nodes maintain synchronized clocks using an NTP-like protocol.
- Consensus Algorithm: The Raft consensus algorithm is used to ensure all nodes agree on the system state.
- IT23226814 - Vakesh Ranganathan
- IT23372344 - Moksha Mudalige
- IT23161610 - Jayamini Herath
- IT23162600 - Nayantha Nethsara
- Fault-tolerant Architecture: The system continues to function when nodes fail and automatically integrates recovered nodes.
- Strong Consistency: Uses Raft to ensure all nodes have the same view of data.
- Distributed File Operations: Supports basic file operations (read, write, delete, list, etc.) across the distributed system.
- Time Synchronization: NTP-like time synchronization keeps node clocks aligned.
- Failure Detection: Automatically detects node failures and handles recovery.
- Client Interface: Simple client interface for interacting with the system.
- Python 3.7+
The system consists of multiple components:
- RaftNode: Implements the Raft consensus algorithm for leader election and log replication.
- TimeSync: Synchronizes time across nodes using an NTP-like protocol.
- FaultDetector: Detects node failures and handles recovery.
- DistributedStorageClient: Client interface for the system.
- DistributedStorageSystem: Main class that integrates all components.
The easiest way to see the system in action is to run the demo:
python main.py --mode demoThis will start a 5-node system, demonstrate basic file operations, simulate node failures and recovery, and show concurrent operations.
To run a specific node in the system:
python main.py --mode server --node-id <node_id> --nodes <total_nodes> --base-port <base_port> --time-port <time_port>Example:
python main.py --mode server --node-id 0 --nodes 5 --base-port 9000 --time-port 8000To use the interactive client:
python main.py --mode client --nodes <total_nodes> --base-port <base_port>Example:
python main.py --mode client --nodes 5 --base-port 9000The system demonstrates fault tolerance through:
- Replication of data across multiple nodes
- Automatic leader election when the current leader fails
- Continued operation when minority nodes fail
- Recovery of failed nodes and bringing them back in sync
To demonstrate:
- Start the system in demo mode (
python main.py --mode demo) - Observe how the system continues to function after a node failure
- Note that data written after the failure is still accessible
- Watch as the recovered node catches up with missed updates
The system implements a replicated state machine with strong consistency:
- All writes go through the leader
- The Raft consensus protocol ensures all replicas have identical logs
- Log entries are only committed when replicated to a majority of nodes
Demonstration:
- Write data to the system using the client
- Observe that the data is accessible from any node
- Check the logs to see replication messages between nodes
The system uses an NTP-like protocol for time synchronization:
- A central time server provides the reference time
- Each node periodically syncs with the time server
- Clock skew is detected and corrected
- Operations are timestamped with synchronized time
To demonstrate:
- Observe the synchronized times in the log output
- The system adds artificial clock skew to showcase synchronization
- Note that even with skew, operations maintain correct order
The Raft consensus algorithm ensures agreement among nodes:
- Leader election ensures only one node accepts writes
- Log replication keeps all nodes in sync
- Term numbers and voting process prevent split-brain scenarios
- Committed entries are guaranteed to be durable
Demonstration:
- Observe leader election messages in the logs
- Watch log replication happening after writes
- Kill the leader node and observe a new election
- Verify that the system maintains consistency throughout
When using the client mode, you have access to these commands:
write <filename>- Write content to a fileread <filename>- Read content from a filedelete <filename>- Delete a filemkdir <dirname>- Create a directorylist [dirname]- List contents of a directory (defaults to root)rename <old_name> <new_name>- Rename a fileexit- Exit the client
TimeSync: Handles time synchronization between nodesLogEntry: Represents an entry in the Raft logRaftNode: Implements the Raft consensus algorithmFaultDetector: Detects and handles node failuresDistributedStorageClient: Client interface for the distributed storageDistributedStorageSystem: Main system class that integrates all components