Skip to content

About

This is a fault-tolerant distributed file storage system implemented in Python. The system demonstrates four key characteristics: fault tolerance, data replication and consistency, time synchronization, and a consensus algorithm.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

Distributed File Storage System

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:

  1. Fault Tolerance: The system can continue operating even if one or more servers fail.
  2. Data Replication and Consistency: Data is replicated across multiple nodes with strong consistency guarantees.
  3. Time Synchronization: All nodes maintain synchronized clocks using an NTP-like protocol.
  4. Consensus Algorithm: The Raft consensus algorithm is used to ensure all nodes agree on the system state.

Team Members

  1. IT23226814 - Vakesh Ranganathan
  2. IT23372344 - Moksha Mudalige
  3. IT23161610 - Jayamini Herath
  4. IT23162600 - Nayantha Nethsara

Features

  • 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.

Requirements

  • Python 3.7+

System Architecture

The system consists of multiple components:

  1. RaftNode: Implements the Raft consensus algorithm for leader election and log replication.
  2. TimeSync: Synchronizes time across nodes using an NTP-like protocol.
  3. FaultDetector: Detects node failures and handles recovery.
  4. DistributedStorageClient: Client interface for the system.
  5. DistributedStorageSystem: Main class that integrates all components.

How to Run

Demo Mode

The easiest way to see the system in action is to run the demo:

python main.py --mode demo

This will start a 5-node system, demonstrate basic file operations, simulate node failures and recovery, and show concurrent operations.

Running as a Server

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 8000

Running as a Client

To 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 9000

Demonstrating Key Characteristics

1. Fault Tolerance

The 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:

  1. Start the system in demo mode (python main.py --mode demo)
  2. Observe how the system continues to function after a node failure
  3. Note that data written after the failure is still accessible
  4. Watch as the recovered node catches up with missed updates

2. Data Replication and Consistency

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:

  1. Write data to the system using the client
  2. Observe that the data is accessible from any node
  3. Check the logs to see replication messages between nodes

3. Time Synchronization

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:

  1. Observe the synchronized times in the log output
  2. The system adds artificial clock skew to showcase synchronization
  3. Note that even with skew, operations maintain correct order

4. Consensus Algorithm (Raft)

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:

  1. Observe leader election messages in the logs
  2. Watch log replication happening after writes
  3. Kill the leader node and observe a new election
  4. Verify that the system maintains consistency throughout

Client Commands

When using the client mode, you have access to these commands:

  • write <filename> - Write content to a file
  • read <filename> - Read content from a file
  • delete <filename> - Delete a file
  • mkdir <dirname> - Create a directory
  • list [dirname] - List contents of a directory (defaults to root)
  • rename <old_name> <new_name> - Rename a file
  • exit - Exit the client

Understanding the Code

Key Classes

  • TimeSync: Handles time synchronization between nodes
  • LogEntry: Represents an entry in the Raft log
  • RaftNode: Implements the Raft consensus algorithm
  • FaultDetector: Detects and handles node failures
  • DistributedStorageClient: Client interface for the distributed storage
  • DistributedStorageSystem: Main system class that integrates all components

About

This is a fault-tolerant distributed file storage system implemented in Python. The system demonstrates four key characteristics: fault tolerance, data replication and consistency, time synchronization, and a consensus algorithm.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages