Skip to content

A distributed system featuring REST API and tarpc for inter node communication.

License

Notifications You must be signed in to change notification settings

levitvas/tarpc-distributed-system

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Distributed System with Ring Topology

A distributed system implementation featuring a ring topology with resource management and deadlock detection capabilities. The system uses both REST API and RPC for inter-node communication.

Features

  • Ring topology with self-healing capabilities
  • Distributed resource management
  • Chandy-Misra-Haas deadlock detection algorithm
  • REST API for external control
  • RPC for inter-node communication

Architecture

Node Structure

Each node maintains connections to:

  • Next node
  • Next-next node (for topology repair)
  • Previous node

Communication

  • REST API on port N+1 for external control
  • RPC on port N for inter-node communication
  • Binary protocol using tarpc for RPC

Building and Running

Prerequisites

  • Rust toolchain
  • Cargo

Building

cargo build --release

Running a Node

./target/release/distributed_system <ip> <port> <resource_name>

Example:

./target/release/distributed_system 127.0.0.1 2010 A
./target/release/distributed_system 127.0.0.1 2020 B
./target/release/distributed_system 127.0.0.1 2030 C

Control Script

A bash script (control.sh) is provided to interact with the system:

chmod +x control.sh
./control.sh

Available commands:

  • g <idx> - Get node health
  • s <idx> - Get node status
  • j <from_idx> <to_idx> - Join nodes
  • l <idx> - Node leaves
  • k <idx> - Kill node
  • r <idx> - Revive node
  • acq <idx> <resource> - Acquire resource
  • rel <idx> <resource> - Release resource
  • det <idx> - Start deadlock detection
  • wait <idx> <target_idx> - Wait for message
  • active <idx> - Set node active
  • passive <idx> - Set passive
  • delay <idx> <ms> - Set delay

Example Usage

Creating a Ring Topology

# Start 3 nodes in separate terminals
./target/release/distributed_system 127.0.0.1 2010 A
./target/release/distributed_system 127.0.0.1 2020 B
./target/release/distributed_system 127.0.0.1 2030 C

# In control script:
j 1 0  # Join node 0 to 1
j 2 1  # Join node 1 to 2

Implementation Details

Resource Management

  • Resources are uniquely identified by strings
  • Each resource has one owner
  • Resource requests are queued when busy
  • Resource state includes current user and request queue

Deadlock Detection

  • Implements Chandy-Misra-Haas algorithm
  • Uses probe messages for cycle detection
  • Supports active/passive state transitions
  • Detection can be initiated from any node

Fault Tolerance

  • Self-healing ring topology
  • Node failure detection
  • Topology repair mechanism
  • Resource state recovery

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

About

A distributed system featuring REST API and tarpc for inter node communication.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published