Local Cluster Demo
This guide will walk you through setting up a local 3-node Marmot cluster and testing replication capabilities.
Prerequisites
- Marmot Binary: Ensure you have the
marmot-v2binary built and available. - MySQL Client:
mysqlCLI or any GUI client (DBeaver, etc.). - Terminal: A terminal with bash/zsh.
Step 1: Start the Cluster
We will start 3 nodes on your local machine.
Node 1 (Seed Node)
Open a new terminal tab/window and run:
# Node 1: HTTP 8081, MySQL 3307
./marmot-v2 -config cfg/config.toml -cluster-addr :8081 -mysql-port 3307 -node-id 1Node 2
Open a second terminal tab/window and join the cluster:
# Node 2: HTTP 8082, MySQL 3308
./marmot-v2 -config cfg/config.toml -cluster-addr :8082 -mysql-port 3308 -node-id 2 -seeds localhost:8081Node 3
Open a third terminal tab/window and join the cluster:
# Node 3: HTTP 8083, MySQL 3309
./marmot-v2 -config cfg/config.toml -cluster-addr :8083 -mysql-port 3309 -node-id 3 -seeds localhost:8081Note: You should see logs indicating that nodes have joined the cluster and established connections.
Step 2: Test Replication
Now let's verify that data replicates across the cluster.
Connect to Node 1
Open a fourth terminal tab/window:
mysql -h 127.0.0.1 -P 3307 -u rootRun the following SQL:
-- Create a database and table
CREATE DATABASE demo;
USE demo;
CREATE TABLE users (id INT PRIMARY KEY, name VARCHAR(50));
-- Insert some data
INSERT INTO users VALUES (1, 'Alice'), (2, 'Bob');Connect to Node 2
In a new terminal tab (or exit the previous mysql session):
mysql -h 127.0.0.1 -P 3308 -u rootVerify data replication:
USE demo;
SELECT * FROM users;
-- Should show Alice and BobMake changes on Node 2:
-- Update a record
UPDATE users SET name = 'Bobby' WHERE id = 2;
-- Insert a new record
INSERT INTO users VALUES (3, 'Charlie');Connect to Node 3
Check Node 3:
mysql -h 127.0.0.1 -P 3309 -u rootVerify all changes:
USE demo;
SELECT * FROM users;
-- Should show:
-- 1 | Alice
-- 2 | Bobby
-- 3 | CharlieStep 3: Test Fault Tolerance
Let's simulate a node failure.
- Kill Node 2: Go to the terminal running Node 2 and press
Ctrl+C. - Write to Node 1:
INSERT INTO users VALUES (4, 'Dave'); - Restart Node 2: Run the same command to start Node 2 again.
- Verify Recovery: Connect to Node 2 and check if it caught up.
SELECT * FROM users WHERE id = 4; -- Should show Dave
Marmot's anti-entropy mechanism ensures that Node 2 automatically fetches missing data from peers upon rejoining.
Cleanup
To stop all nodes, simply Ctrl+C in each terminal window. To clean up the data directories:
rm -rf ./marmot-data*