Marmot: A distributed SQLite replicator built on a gossip-based protocol

2 min read Original article ↗

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-v2 binary built and available.
  • MySQL Client: mysql CLI 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 2

Open a second terminal tab/window and join the cluster:

Node 3

Open a third terminal tab/window and join the cluster:

Note: 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:

Run the following SQL:

Connect to Node 2

In a new terminal tab (or exit the previous mysql session):

Verify data replication:

Make changes on Node 2:

Connect to Node 3

Check Node 3:

Verify all changes:

Step 3: Test Fault Tolerance

Let's simulate a node failure.

  1. Kill Node 2: Go to the terminal running Node 2 and press Ctrl+C.
  2. Write to Node 1:
  3. Restart Node 2: Run the same command to start Node 2 again.
  4. Verify Recovery: Connect to Node 2 and check if it caught up.

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:

Reference