Simple distributed KV store with consistent hashing and gossip protocol written in Rust for maximum efficiency.
The system uses consistent hashing to distribute keys across multiple nodes in the cluster. Each node is assigned a position on the hash ring, and keys are mapped to nodes based on their hash values. This allows for efficient key distribution and minimizes data movement when nodes are added or removed.
- PUT key value
- READ key
- DELETE key
- BATCHPUT key1 value1 key2 value2 ...
This command does not use consistent hashing and queries all keys in the local node only.
- RANGE start_key end_key
- In-memory storage with optional persistence (TODO)
- Pluggable storage backends (in-memory, file-based, etc.)
- Gossip protocol for node discovery and cluster membership
- Simple command-line interface for interacting with the KV store
- Basic error handling and logging
- Unit tests for core functionality
- Basic consistent hashing for key distribution
- Virtual nodes for better distribution
- Rust 1.70+
- Cargo
- Git
-
Clone the repository:
git clone https://github.com/codejitsu/KavaDB.git
-
Install Rust and Cargo if you haven't already. You can follow the instructions at rustup.rs.
-
Change into the project directory:
cd KavaDB/node -
Build the project:
cargo build
-
Run the project:
cargo run
The node will peak the the kava.conf file in the current directory for configuration by default.
To simulate a distributed environment, you can run multiple instances of the application with different configuration files.
Open multiple terminal windows and run the following commands:
# Terminal 1
cargo run -- kava.conf
# Terminal 2
cargo run -- kava2.conf
# Terminal 3
cargo run -- kava3.confNow you can interact with any of the nodes using the command-line interface. For example, in Terminal 1, you can run:
echo "PUT nickname codejitsu" | nc localhost 3001Now you can read the value from any node:
echo "READ nickname" | nc localhost 3002The application can be configured using the kava.conf file located in the project directory.
There are three config files provided for testing:
kava1.confkava2.confkava3.conf
Each config file represents a different node in the cluster. You can run multiple instances of the application with different config files to simulate a distributed environment.
To run the tests, use the following command:
cargo test