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.
- 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
Each node maintains connections to:
- Next node
- Next-next node (for topology repair)
- Previous node
- REST API on port N+1 for external control
- RPC on port N for inter-node communication
- Binary protocol using tarpc for RPC
- Rust toolchain
- Cargo
cargo build --release
./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
A bash script (control.sh
) is provided to interact with the system:
chmod +x control.sh
./control.sh
Available commands:
g <idx>
- Get node healths <idx>
- Get node statusj <from_idx> <to_idx>
- Join nodesl <idx>
- Node leavesk <idx>
- Kill noder <idx>
- Revive nodeacq <idx> <resource>
- Acquire resourcerel <idx> <resource>
- Release resourcedet <idx>
- Start deadlock detectionwait <idx> <target_idx>
- Wait for messageactive <idx>
- Set node activepassive <idx>
- Set passivedelay <idx> <ms>
- Set delay
# 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
- 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
- Implements Chandy-Misra-Haas algorithm
- Uses probe messages for cycle detection
- Supports active/passive state transitions
- Detection can be initiated from any node
- Self-healing ring topology
- Node failure detection
- Topology repair mechanism
- Resource state recovery
This project is licensed under the MIT License - see the LICENSE.md file for details.