A distributed file system implementation in Go that demonstrates distributed systems concepts including consensus protocols, distributed locking, and fault-tolerant storage.
- File Operations: Create, read, write, delete files and directories
- Distributed Coordination: Paxos consensus algorithm for replication
- Distributed Locking: Concurrent access control across nodes
- Caching: Local caching for improved performance
- Fault Tolerance: Replication and consensus protocols
The system consists of several microservices:
- DFS Service: Main file system interface
- Extent Service: Handles file data storage
- Lock Service: Manages distributed locking
- Paxos Service: Implements consensus protocol
- Management Service: Node health monitoring
- Bounds Checking: Fixed potential panics when accessing empty strings
- Variable Shadowing: Resolved variable redeclaration bugs
- Error Handling: Improved error propagation and handling throughout
- gRPC Connections: Fixed incorrect
grpc.NewClientusage togrpc.Dial - Resource Management: Better connection cleanup and error handling
- Input Validation: Added proper validation for all inputs
- Error Messages: More descriptive error messages with context
- Logging: Improved logging with structured information
- Code Structure: Refactored long functions into smaller, focused ones
- Documentation: Added comprehensive comments and documentation
- Configuration: Centralized configuration management
- Read-Write Mutex: Upgraded to RWMutex for better concurrent access
- Context Management: Proper context cancellation and timeouts
- Connection Pooling: Better connection management
./scripts/setup-dev.sh
# Or manually
make deps
make all./scripts/start-services.sh start
### 3. Monitor Services
```bash
# Check status
./scripts/start-services.sh status
# View logs
./scripts/start-services.sh logs
# Stop services
./scripts/start-services.sh stopComprehensive service management script with the following commands:
start- Start all DFS services in the correct orderstop- Stop all services gracefullyrestart- Restart all servicesstatus- Show status of all serviceslogs- View service logsclean- Clean up log files and PID files
Usage Examples:
# Start with default configuration
./scripts/start-services.sh start
# Start with custom ports
./scripts/start-services.sh start -p 3001 -e 3002 -l 2001
# Check service status
./scripts/start-services.sh status
# View logs for a specific service
./scripts/start-services.sh logs dfsSets up the complete development environment:
- Checks and installs required tools (Go, protoc, etc.)
- Sets up Go modules and dependencies
- Generates protocol buffer code
- Builds the project
- Creates development configuration
- Sets up Git hooks
Usage:
# Full setup
./scripts/setup-dev.sh
# Skip optional steps
./scripts/setup-dev.sh --skip
# Force setup (overwrite existing)
./scripts/setup-dev.sh --forceThe system can be configured via environment variables:
# Service ports
export DFS_PORT=2001
export EXTENT_PORT=2002
export LOCK_PORT=1001
# Service addresses
export EXTENT_SERVICE=127.0.0.1:2002
export LOCK_SERVICE=127.0.0.1:1001
# Development settings
export DFS_DEBUG=true
export DFS_LOG_LEVEL=debugA .env file is created during setup with default values:
# DFS Development Environment Configuration
DFS_PORT=2001
EXTENT_PORT=2002
LOCK_PORT=1001
REPLICA_LOCK_PORT=1002
EXTENT_SERVICE=127.0.0.1:2002
LOCK_SERVICE=127.0.0.1:1001
# Development settings
DFS_DEBUG=true
DFS_LOG_LEVEL=debug
DFS_MAX_CACHE_SIZE=1000
DFS_CACHE_TTL=300- Go 1.23.1 or later
- Protocol Buffers compiler (protoc)
- Make (optional, for build automation)
# Build all services
make all
# Build specific service
make dfsService
make extentService
make lockService
# Build with race detection
make race
# Build with debug symbols
make debug
# Clean build artifacts
make clean# Start all services using the script (recommended)
./scripts/start-services.sh start
# Or manually
./bin/extentService &
./bin/lockService &
./bin/dfsService -extentService=127.0.0.1:2002 -lockService=127.0.0.1:1001 &The system exposes gRPC services for:
- DFS Service: File operations (get, put, delete, mkdir, rmdir, dir)
- Extent Service: Raw file data storage
- Lock Service: Distributed locking (acquire, release)
- Paxos Service: Consensus protocol (prepare, accept, decide)
dfs/
├── cmd/ # Service executables
│ ├── dfsService/ # Main DFS service
│ ├── extentService/ # File storage service
│ └── lockService/ # Distributed locking service
├── pkg/ # Shared packages
│ ├── core/ # Core utilities and config
│ ├── paxos/ # Paxos consensus implementation
│ └── *Proto/ # Protocol buffer definitions
├── scripts/ # Build and deployment scripts
│ ├── start-services.sh # Service management (Linux/macOS)
│ ├── start-services.ps1 # Service management (Windows)
│ ├── setup-dev.sh # Development environment setup
│ └── test-client.sh # Test client
└── logs/ # Service logs (created at runtime)
- Setup Environment:
./scripts/setup-dev.sh - Make Changes: Edit code as needed
- Build:
make all - Test:
./scripts/test-client.sh test - Run:
./scripts/start-services.sh start - Monitor:
./scripts/start-services.sh logs - Stop:
./scripts/start-services.sh stop
The project follows Go best practices:
- Proper error handling and propagation
- Input validation and sanitization
- Comprehensive logging
- Clean separation of concerns
- Proper resource management
A pre-commit hook is automatically installed that:
- Formats Go code using
go fmt - Ensures all code is properly formatted before commits
-
Port Already in Use
# Check what's using the port lsof -i :2001 # Kill the process kill -9 <PID>
-
Service Won't Start
# Check logs ./scripts/start-services.sh logs dfs # Check if dependencies are running ./scripts/start-services.sh status
-
Build Failures
# Clean and rebuild make clean make all # Check Go version go version
-
Protocol Buffer Issues
# Regenerate protobuf code make proto # Or use the setup script ./scripts/setup-dev.sh
Logs are stored in the logs/ directory:
dfs.log- DFS service logsextent.log- Extent service logslock.log- Lock service logs
Check service status with:
./scripts/start-services.sh status- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
This is a hobby project for educational purposes.
- Built with Go and gRPC
- Implements Paxos consensus algorithm
- Demonstrates distributed systems concepts