Cluster Getting Started

Get a fully functional MynaDB cluster running on your local machine in minutes. This guide walks you through building the project from source, understanding the four node types, configuring each component, starting a development cluster with a single command, and verifying that data flows correctly end-to-end.

Tip: If you are new to MynaDB clustering, start here. Once your local cluster is running, move on to Cluster Architecture for a deeper understanding and Cluster Scaling for production deployment guidance.

Prerequisites

Before you begin, make sure you have the following installed on your system:

Build from Source

MynaDB is written in Rust. You need a recent stable Rust toolchain to compile the project. Install it via rustup.rs if you do not already have it.

bash
# Install Rust (if not already installed)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# Clone and build
git clone https://github.com/panbooks/mynadb.git
cd mynadb
cargo build --release

The compiled binary will be located at ./target/release/mynadb. All cluster node types (meta, router, data, admin) are served by this single binary with different configuration files and subcommands.

Install goreman

goreman is a process manager for Procfile-based applications. It starts all cluster processes with a single command and provides color-coded log output.

bash
# Install via Go (requires Go toolchain)
go install github.com/mattn/goreman@latest

# Or download a prebuilt binary from the releases page
# https://github.com/mattn/goreman/releases

MinIO (Optional)

MinIO is only required if you want to test the cluster with S3-compatible shared object storage. The default local-storage cluster profile stores data on the local filesystem and does not need MinIO. If you want to test the S3 backend:

bash
# Run MinIO with Docker
docker run -d --name minio \
  -p 9000:9000 -p 9001:9001 \
  -e MINIO_ROOT_USER=minioadmin \
  -e MINIO_ROOT_PASSWORD=minioadmin \
  minio/minio server /data --console-address ":9001"

# Create a bucket for MynaDB
mc alias set local http://localhost:9000 minioadmin minioadmin
mc mb local/mynadb

Understanding Node Types

A MynaDB cluster consists of four distinct node types, each with a dedicated responsibility. Understanding these roles is essential before deploying your first cluster.

⚖

Meta Nodes

The brain of the cluster. Meta nodes form a Raft consensus group that stores all cluster metadata: node registrations, table schemas, partition assignments, and leader election state. They provide service discovery so routers and data nodes can find each other.

Deploy: 3 or 5 nodes (odd number required for Raft quorum)
Ports: HTTP 6000, gRPC 6001
Stateful: Yes (Raft log + snapshots persisted to disk)

⇄

Router Nodes

The gateway for all client connections. Routers are completely stateless and expose HTTP (InfluxDB line protocol + SQL), Apache Arrow Flight (gRPC), and MySQL wire protocol. They discover data nodes via meta and route writes to the correct data node, and coordinate distributed queries across multiple data nodes.

Deploy: 1+ (load-balance with HAProxy or Nginx for HA)
Ports: HTTP 7000, Flight 7001, MySQL 7002
Stateful: No (can be killed and restarted freely)

🗃

Data Nodes

The workhorses of the cluster. Data nodes store time series data in Parquet format, execute queries locally using Apache DataFusion, run background compaction jobs, and manage retention policies. Each data node registers with the meta cluster and receives write assignments based on partition ownership.

Deploy: 2+ (scale horizontally for more throughput and storage)
Ports: HTTP 5000, Flight 5001
Stateful: Yes (Parquet files + WAL on local or shared storage)

🖥

Admin Node

An optional web-based management console that provides a unified view of the entire cluster. The admin node connects to meta for node discovery and forwards API requests to individual data nodes. It offers a query console, storage browser, cluster monitoring dashboard, and event log.

Deploy: 0 or 1 (optional, for operational convenience)
Ports: HTTP 18080
Stateful: No (all state is derived from meta + data nodes)

Node Type Role Default Ports Recommended Count
Meta Raft consensus, metadata storage, service discovery, cluster coordination HTTP: 6000, gRPC: 6001 3 (odd number required for Raft quorum)
Router Stateless request routing, client-facing protocols (HTTP, Arrow Flight, MySQL wire) HTTP: 7000, Flight: 7001, MySQL: 7002 1+ (load-balance for HA)
Data Data storage, query execution, compaction, and background jobs HTTP: 5000, Flight: 5001 2+ (scale horizontally)
Admin Web-based management console for monitoring, queries, and cluster administration HTTP: 18080 0–1 (optional)
Startup order matters: Meta nodes must start first and complete Raft leader election before any other node type can register. Router and data nodes connect to the meta cluster for service discovery, and the admin node connects to meta for cluster-wide visibility.

Configuration

Each node type has its own TOML configuration file. Below are annotated examples for each node in a local development cluster. In production, you would adjust ports, addresses, and storage paths to match your infrastructure.

Meta Node Configuration (meta1.toml)

Meta nodes use Raft consensus to maintain a consistent, replicated metadata store. The peers list must include the gRPC addresses of all other meta nodes in the cluster (not the node's own address).

toml — dev/configs/cluster/meta1.toml
[meta]
node_id = 1                              # Unique integer ID for this meta node
http_port = 6000                         # HTTP API for management and health checks
bind_addr = "0.0.0.0:6001"              # gRPC listen address (Raft + client RPCs)
advertise_addr = "127.0.0.1:6001"       # Address other nodes use to reach this node
data_dir = "./dev/data/cluster/meta1"   # Persistent storage for Raft log and snapshots
peers = ["127.0.0.1:6101", "127.0.0.1:6201"]  # gRPC addresses of OTHER meta nodes

[meta.raft]
heartbeat_interval_ms = 150              # Raft heartbeat frequency
election_timeout_min_ms = 300            # Minimum election timeout
election_timeout_max_ms = 500            # Maximum election timeout (randomized)
snapshot_threshold = 10000               # Compact Raft log after this many entries

For the second and third meta nodes, change node_id, ports, data_dir, and peers accordingly:

toml — dev/configs/cluster/meta2.toml
[meta]
node_id = 2
http_port = 6100
bind_addr = "0.0.0.0:6101"
advertise_addr = "127.0.0.1:6101"
data_dir = "./dev/data/cluster/meta2"
peers = ["127.0.0.1:6001", "127.0.0.1:6201"]

[meta.raft]
heartbeat_interval_ms = 150
election_timeout_min_ms = 300
election_timeout_max_ms = 500
snapshot_threshold = 10000
toml — dev/configs/cluster/meta3.toml
[meta]
node_id = 3
http_port = 6200
bind_addr = "0.0.0.0:6201"
advertise_addr = "127.0.0.1:6201"
data_dir = "./dev/data/cluster/meta3"
peers = ["127.0.0.1:6001", "127.0.0.1:6101"]

[meta.raft]
heartbeat_interval_ms = 150
election_timeout_min_ms = 300
election_timeout_max_ms = 500
snapshot_threshold = 10000

Router Node Configuration (router1.toml)

Routers are stateless and handle all client-facing protocols. They discover data nodes through the meta cluster and route write and query requests accordingly. You can run multiple routers behind a load balancer.

toml — dev/configs/cluster/router1.toml
[router]
node_id = "router-1"                    # Unique string ID for this router
http_port = 7000                         # HTTP API (write/query endpoints)
flight_port = 7001                       # Apache Arrow Flight gRPC port
mysql_port = 7002                        # MySQL wire protocol port

[router.meta]
endpoints = [                            # All meta node gRPC addresses
  "127.0.0.1:6001",
  "127.0.0.1:6101",
  "127.0.0.1:6201"
]
connect_timeout_ms = 5000               # Timeout for connecting to meta nodes
request_timeout_ms = 30000              # Timeout for meta RPC requests

[router.routing]
cache_refresh_interval_ms = 1000        # How often to refresh the routing table
data_node_pool_size = 10                # HTTP connection pool size per data node

Data Node Configuration (data1.toml)

Data nodes store Parquet files, execute queries using Apache DataFusion, and run background jobs like compaction and retention. In local-storage mode, each node writes to a separate directory on the local filesystem. For production S3 deployments, all nodes share the same bucket.

toml — dev/configs/cluster-local/data1.toml
[data]
node_id = "data-1"                       # Unique string ID for this data node
http_port = 5000                          # HTTP API for direct access and health checks
advertise_addr = "127.0.0.1:5001"        # Address the router uses to reach this node
meta_endpoints = [                        # All meta node gRPC addresses
  "127.0.0.1:6001",
  "127.0.0.1:6101",
  "127.0.0.1:6201"
]

[storage]
backend = "local"                         # Storage backend: "local", "s3", "minio", "oss"
data_dir = "./dev/data/cluster/data1"    # Local data directory for Parquet files

[cache]
flush_interval_secs = 60                 # Flush write cache to Parquet every 60 seconds
max_size_mb = 1024                       # Maximum in-memory write cache size

[wal]
enabled = true                            # Enable write-ahead log for durability
sync_on_write = false                     # true = durable but slower, false = faster
rotate_size_mb = 128                      # Rotate WAL file at this size

[compaction]
min_files = 5                             # Minimum L0 files before triggering compaction
max_level = 5                             # Maximum compaction level
max_concurrent_compactions = 4            # Parallel compaction jobs

[retention]
enabled = true                            # Enable automatic partition cleanup
default_days = 7                          # Delete partitions older than N days
interval_secs = 3600                      # Check every hour

For the second data node, change node_id, http_port, advertise_addr, and data_dir:

toml — dev/configs/cluster-local/data2.toml
[data]
node_id = "data-2"
http_port = 5100
advertise_addr = "127.0.0.1:5101"
meta_endpoints = [
  "127.0.0.1:6001",
  "127.0.0.1:6101",
  "127.0.0.1:6201"
]

[storage]
backend = "local"
data_dir = "./dev/data/cluster/data2"

[cache]
flush_interval_secs = 60
max_size_mb = 1024

[wal]
enabled = true
sync_on_write = false
rotate_size_mb = 128

[compaction]
min_files = 5
max_level = 5
max_concurrent_compactions = 4

[retention]
enabled = true
default_days = 7
interval_secs = 3600

Admin Node Configuration (admin.toml)

The admin node connects to the meta cluster to discover all other nodes and provides a web-based management interface with a query console, storage browser, and cluster dashboard.

toml — dev/configs/cluster/admin.toml
[admin]
enabled = true                           # Enable the admin console
port = 18080                             # HTTP port for the web UI and API
meta_endpoints = [                       # All meta node gRPC addresses
  "127.0.0.1:6001",
  "127.0.0.1:6101",
  "127.0.0.1:6201"
]

Starting a Local Cluster

Quick Start with goreman

The fastest way to start a complete cluster is with goreman using the included Procfile. This launches all node types with local-storage configuration (no MinIO required). The Procfile defines the startup order and delay between process groups:

Procfile — dev/Procfile.cluster-local
# Meta nodes start first (Raft consensus group)
meta1: ./target/release/mynadb -c dev/configs/cluster/meta1.toml meta start
meta2: ./target/release/mynadb -c dev/configs/cluster/meta2.toml meta start
meta3: ./target/release/mynadb -c dev/configs/cluster/meta3.toml meta start

# Router and data nodes start after 3s delay (meta must be ready)
router1: sleep 3 && ./target/release/mynadb -c dev/configs/cluster/router1.toml router start
data1: sleep 3 && ./target/release/mynadb -c dev/configs/cluster-local/data1.toml data start
data2: sleep 3 && ./target/release/mynadb -c dev/configs/cluster-local/data2.toml data start

# Admin starts after 5s delay (data nodes must be registered)
admin: sleep 5 && ./target/release/mynadb -c dev/configs/cluster/admin.toml admin start

Start the entire cluster with a single command:

bash
goreman -f dev/Procfile.cluster-local start

Startup Sequence

Understanding the startup sequence helps with debugging. Here is what happens when the cluster boots:

  1. Meta nodes start — All three meta nodes start simultaneously. They connect to each other via the peers list and begin the Raft leader election process. Within 300–500ms, one node is elected leader and begins accepting metadata writes.
  2. Router connects to meta (after ~3s) — The router connects to the meta cluster using the endpoints list. It fetches the routing table (which data nodes exist and which partitions they own) and starts accepting client connections on HTTP, Flight, and MySQL ports.
  3. Data nodes register with meta (after ~3s) — Each data node connects to the meta cluster, registers itself (advertising its HTTP and Flight addresses), and begins heartbeating. The meta leader updates the routing table so the router can discover the new data nodes.
  4. Admin discovers all nodes (after ~5s) — The admin node connects to meta, retrieves the full list of registered nodes, and starts the web UI. It periodically polls meta for changes and forwards requests to data nodes as needed.

This single command starts the following processes:

Process Description Ports Startup Delay
meta1 First meta node (initial Raft leader candidate) HTTP: 6000, gRPC: 6001 Immediate
meta2 Second meta node HTTP: 6100, gRPC: 6101 Immediate
meta3 Third meta node HTTP: 6200, gRPC: 6201 Immediate
router1 Router node (client entry point) HTTP: 7000, Flight: 7001, MySQL: 7002 3 seconds
data1 First data node HTTP: 5000, Flight: 5001 3 seconds
data2 Second data node HTTP: 5100, Flight: 5101 3 seconds
admin Admin web console HTTP: 18080 5 seconds

goreman handles process lifecycle and outputs color-coded logs to the terminal. Press Ctrl+C to stop all processes gracefully.

Manual Start (Step by Step)

If you prefer to start each node individually, or if you need to debug a specific node, follow these steps in order. Open a separate terminal for each command.

Step 1: Start the Meta Nodes

The three meta nodes form a Raft consensus group. They must all be started before other nodes can register. Start them in three separate terminals:

bash — Terminal 1
# Meta node 1
./target/release/mynadb -c dev/configs/cluster/meta1.toml meta start
bash — Terminal 2
# Meta node 2
./target/release/mynadb -c dev/configs/cluster/meta2.toml meta start
bash — Terminal 3
# Meta node 3
./target/release/mynadb -c dev/configs/cluster/meta3.toml meta start

Wait approximately 3 seconds for the Raft leader election to complete. You will see a log message like INFO raft: node 1 elected as leader for term 1 in one of the terminals.

Step 2: Start the Router Node

The router connects to the meta cluster for service discovery and begins accepting client requests on all three protocols.

bash — Terminal 4
# Router node
./target/release/mynadb -c dev/configs/cluster/router1.toml router start

Step 3: Start the Data Nodes

Data nodes register with the meta cluster and begin heartbeating. They are responsible for storing data, executing queries, and running compaction.

bash — Terminal 5
# Data node 1
./target/release/mynadb -c dev/configs/cluster-local/data1.toml data start
bash — Terminal 6
# Data node 2
./target/release/mynadb -c dev/configs/cluster-local/data2.toml data start

Step 4: Start the Admin Console (Optional)

The admin console provides a web-based UI for cluster monitoring and management. Wait a couple of seconds after the data nodes start so they have time to register with meta.

bash — Terminal 7
# Admin console
./target/release/mynadb -c dev/configs/cluster/admin.toml admin start

Verify the Cluster

Once all nodes are running, verify that the cluster is healthy and data flows correctly through the entire system.

Check Cluster Health

The router exposes a health endpoint that reports its connectivity to the meta cluster and data nodes:

bash
# Check cluster health via router
curl http://localhost:7000/health

Expected response:

json
{
  "status": "ok",
  "version": "0.3.0",
  "uptime_secs": 12
}

List Registered Nodes

Use the admin API to see all nodes that have registered with the meta cluster:

bash
# List all registered nodes via admin console API
curl http://localhost:18080/api/v1/nodes

Expected response (truncated):

json
{
  "success": true,
  "data": {
    "nodes": [
      {
        "node_id": "data-1",
        "role": "data",
        "http_addr": "127.0.0.1:5000",
        "status": "healthy"
      },
      {
        "node_id": "data-2",
        "role": "data",
        "http_addr": "127.0.0.1:5100",
        "status": "healthy"
      }
    ],
    "count": 2
  }
}

Write Test Data

Send time series data to the router using InfluxDB line protocol. The router will route the write to the appropriate data node:

bash
# Write a single point through the router
curl -X POST http://localhost:7000/write/testdb \
  -d "cpu,host=server1,region=us-east value=85.5"

# Write multiple points at once
curl -X POST http://localhost:7000/write/testdb \
  -d "cpu,host=server1,region=us-east value=85.5
cpu,host=server2,region=us-west value=72.3
cpu,host=server3,region=eu-west value=91.0
memory,host=server1,region=us-east used_percent=64.2
memory,host=server2,region=us-west used_percent=48.7
disk,host=server1,region=us-east used_gb=450,total_gb=1000"

A successful write returns HTTP 204 No Content with an empty body.

Query Data Back

Query the data through the router using SQL. The router coordinates the query across all data nodes and merges the results:

bash
# Query all CPU metrics
curl "http://localhost:7000/query/testdb" \
  -d "SELECT * FROM cpu ORDER BY time DESC LIMIT 10"

# Aggregate query
curl "http://localhost:7000/query/testdb" \
  -d "SELECT host, AVG(value) as avg_cpu FROM cpu GROUP BY host"

# Use the EXPLAIN endpoint to inspect query plans
curl "http://localhost:7000/explain/testdb?sql=SELECT+*+FROM+cpu+LIMIT+10"

Access the Admin Console

Open your browser and navigate to http://localhost:18080 to access the admin web console. From there you can:

Port Reference

The following table lists all default ports used by a local development cluster. When deploying to production, customize these in each node's configuration file.

Service Port Protocol Description
meta1 HTTP 6000 HTTP Meta node 1 management API and health checks
meta1 gRPC 6001 gRPC Meta node 1 Raft consensus and client RPCs
meta2 HTTP 6100 HTTP Meta node 2 management API and health checks
meta2 gRPC 6101 gRPC Meta node 2 Raft consensus and client RPCs
meta3 HTTP 6200 HTTP Meta node 3 management API and health checks
meta3 gRPC 6201 gRPC Meta node 3 Raft consensus and client RPCs
data1 HTTP 5000 HTTP Data node 1 direct access and health checks
data1 Flight 5001 gRPC Data node 1 Arrow Flight interface
data2 HTTP 5100 HTTP Data node 2 direct access and health checks
data2 Flight 5101 gRPC Data node 2 Arrow Flight interface
Router HTTP 7000 HTTP Client write and query API (InfluxDB line protocol, SQL)
Router Flight 7001 gRPC Apache Arrow Flight for high-throughput queries
Router MySQL 7002 MySQL wire MySQL wire protocol for BI tool compatibility
Admin 18080 HTTP Web-based management console and API
Port conflicts: If any of these ports are already in use on your machine, update the corresponding configuration file. Make sure to also update any peers, endpoints, or advertise_addr references that point to the changed port.

Next Steps

Now that your local cluster is running, explore these guides to deepen your understanding and prepare for production deployment: