Cluster Scaling
MynaDB clusters are designed for elastic scaling. Add data nodes to increase write throughput and query parallelism, or remove nodes to reduce cost during low-traffic periods. Because all persistent data lives in shared object storage (S3, MinIO, or OSS), scaling operations never require data migration or rebalancing. This page covers the complete node lifecycle, scale-out and scale-in procedures, failure detection, cold standby replication, and operational best practices.
Node Lifecycle
Every data node in a MynaDB cluster progresses through a well-defined set of states. Understanding these states is essential for planning maintenance windows, executing scale-in operations, and reasoning about failure recovery. The Meta cluster tracks the current state of every registered node and publishes state transitions as events to all Routers and Admin consoles.
Node Lifecycle State Machine
============================
+-----------+ RegisterNode +----------+
| Starting | --------------------> | Active | <----- heartbeat refreshes lease
| (1) | (auto on boot) | (2) |
+-----------+ +----+-----+
|
+------------------+------------------+
| |
drain request heartbeat timeout
| (3 missed)
v |
+-----------+ v
| Draining | +------------+
| (3) | | Inactive |
+-----+-----+ | (4) |
| +------------+
scale-in plan (detected by Meta leader;
assigns tables triggers recovery manager)
to other nodes
|
v
+-----------+ flush complete +-----------+
| Retiring | ---------------------> | Drained |
| (5) | memtable flushed, | (6) |
+-----------+ tables reassigned +-----------+
(safe to terminate)
The following table describes each state in detail, including the conditions that trigger transitions and the operational implications of each state.
| State | ID | Description | Accepts Writes | Serves Queries |
|---|---|---|---|---|
| Starting | 1 | Node is initializing: loading configuration, connecting to Meta, replaying WAL. Not yet visible to Routers and not ready for traffic. | No | No |
| Active | 2 | Healthy and fully operational. Actively heartbeating to Meta, serving read and write traffic, and running background jobs if elected leader. | Yes | Yes |
| Draining | 3 | Maintenance mode. No new writes are accepted. Existing in-flight requests are allowed to complete. Active connections drain over a configurable timeout (default 30s). | No | Yes (existing only) |
| Inactive | 4 | Node is dead or unreachable, detected when the Meta leader observes 3 consecutive missed heartbeats (15s with default 5s interval). Triggers the recovery manager. | No | No |
| Retiring | 5 | Scale-in in progress. The node is flushing its in-memory DataCache to object storage and its table ownership is being reassigned to other active nodes by the Meta leader. | No | Yes (read-only) |
| Drained | 6 | Scale-in complete. All cached data has been flushed to S3 and all table ownership has been transferred. The node can be safely terminated or decommissioned. | No | No |
Scale-Out (Adding Nodes)
Scaling out a MynaDB cluster is straightforward: start a new node with the correct configuration pointing to the Meta cluster, and it will automatically register itself and begin serving traffic. No data migration is needed because all nodes share the same object storage backend.
Adding Data Nodes
When a new data node starts, the following sequence occurs automatically:
- The data node loads its configuration and connects to the Meta cluster via gRPC.
- It calls
RegisterNodeon the Meta leader, providing its node ID, advertise address, HTTP port, Flight port, and capabilities. - The Meta leader persists the registration in the Raft log and transitions the node to Active state.
- A
NodeRegisteredevent is published to all subscribers (Routers, Admin consoles). - Each Router receives the event and updates its
ShardCacheto include the new node in the routing table. - New writes for tables not yet owned by any node may be routed to the new node (least-loaded selection).
- The new node can immediately serve queries against historical data in shared object storage.
Configure and start a new data node:
# dev/configs/cluster-local/data3.toml
[data]
node_id = "data-3"
http_port = 5200
flight_port = 5201
advertise_addr = "127.0.0.1:5201"
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/data3"
[cache]
flush_interval_secs = 60
max_size_mb = 1024
[wal]
enabled = true
sync_on_write = false
rotate_size_mb = 128
# Start the new data node
./target/release/mynadb -c dev/configs/cluster-local/data3.toml data start
# Verify registration (should show 3 data nodes)
curl -s http://localhost:7000/cluster/nodes | jq '.nodes[] | {node_id, state, http_addr}'
Adding Router Nodes
Router nodes are completely stateless. They discover data nodes through the Meta cluster and maintain an
in-memory routing table (ShardCache) that is refreshed via Meta event subscriptions. Adding a
new Router requires no coordination with existing Routers.
- Start the Router with Meta endpoints configured.
- The Router connects to Meta and subscribes to cluster events.
- It builds its
ShardCachefrom the current node registry. - The Router is immediately ready to serve traffic on HTTP, Arrow Flight, and MySQL wire protocols.
- Place the new Router behind your existing load balancer (HAProxy, NGINX, ALB, etc.).
# dev/configs/cluster/router2.toml
[router]
node_id = "router-2"
http_port = 7010
flight_port = 7011
mysql_port = 7012
[router.meta]
endpoints = ["127.0.0.1:6001", "127.0.0.1:6101", "127.0.0.1:6201"]
connect_timeout_ms = 5000
request_timeout_ms = 30000
[router.routing]
cache_refresh_interval_ms = 1000
data_node_pool_size = 10
# Start the second router
./target/release/mynadb -c dev/configs/cluster/router2.toml router start
# Add to HAProxy backend (example)
# server router2 127.0.0.1:7010 check inter 5s fall 3 rise 2
# Verify the new router can serve queries
curl "http://localhost:7010/query/testdb" -d "SELECT * FROM cpu LIMIT 5"
Table Ownership Assignment
MynaDB uses a table-level ownership model to coordinate writes. When a write arrives for a table that is not yet owned by any data node, the Router assigns ownership to the least-loaded active data node. The assignment is recorded in the Meta cluster and maintained with a TTL-based lease.
Table Ownership Assignment Flow
================================
Client Router Meta Data Node
| | | |
| POST /write/mydb | | |
| cpu,host=a value=1 | | |
|-------------------------->| | |
| | | |
| | LookupOwner("mydb", | |
| | "default", "cpu") | |
| |------------------------>| |
| | | |
| | owner = None | |
| |<------------------------| |
| | | |
| | RegisterTable("mydb", | |
| | "default", "cpu", | |
| | node_id="data-3", | |
| | ttl=600) | |
| |------------------------>| |
| | | TableRegistered |
| | | event published |
| | | |
| | Forward write to | |
| | data-3 | |
| |------------------------------------------------>|
| | | |
| | | 204 OK
| |<------------------------------------------------|
| 204 OK | | |
|<--------------------------| | |
Scale-In (Removing Nodes)
Removing nodes from a MynaDB cluster requires careful orchestration to prevent data loss. The scale-in process ensures that all in-memory data is flushed to object storage and all table ownership is transferred to remaining nodes before a node is terminated. MynaDB provides both a planning (dry-run) API and an execution API for safe scale-in operations.
Graceful Scale-In Process
A graceful scale-in operation proceeds through four distinct phases:
| Phase | Action | Description |
|---|---|---|
| 1. Plan | Determine target nodes | Select which data nodes to retire based on the chosen strategy (least_loaded or most_idle). Validate that enough active nodes remain to serve the cluster. A dry-run mode shows the plan without executing it. |
| 2. Migration | Reassign table ownership | For each table owned by a retiring node, the Meta leader calls ReassignTable to transfer ownership to a healthy active node. Routers receive TableReassigned events and update their ShardCache. |
| 3. Draining | Flush and drain | The retiring node is marked as Retiring (state 5). It stops accepting new writes, flushes its entire DataCache to object storage, completes any in-flight write operations, and publishes cache invalidation events for all flushed files. |
| 4. Drained | Safe to terminate | Once all data is flushed and all tables are reassigned, the node transitions to Drained (state 6). It can now be safely terminated, and its resources can be released. |
Graceful Scale-In Flow
=======================
Admin/Operator Meta Leader Retiring Node Remaining Nodes Router
| | | | |
| POST scale-in/plan | | | |
| (dry_run: true) | | | |
|--------------------->| | | |
| plan: retire data-2 | | | |
|<---------------------| | | |
| | | | |
| POST scale-in/ | | | |
| execute-plan | | | |
|--------------------->| | | |
| | | | |
| | ReassignTable | | |
| | (cpu -> data-1) | | |
| |-------------------------------------------->| |
| | | | TableReassigned |
| |------------------------------------------------------------>|
| | | | |
| | SetState(Retiring) | | |
| |-------------------->| | |
| | | | |
| | | flush DataCache | |
| | | to S3 | |
| | |--> (writes parquet) | |
| | | | |
| | | cache invalidation | |
| | |-------------------->| |
| | | | |
| | SetState(Drained) | | |
| |<--------------------| | |
| | | | |
| scale-in complete | | | |
|<---------------------| | | |
| | | | |
| (safe to terminate data-2) | | |
Scale-In API
The scale-in API is available on the Router (which forwards to the Meta leader). Always start with a dry-run to review the plan before executing.
Step 1: Plan (Dry Run)
# Preview which nodes will be retired and which tables will be reassigned
curl -s -X POST http://localhost:7000/cluster/scale-in/plan \
-H "Content-Type: application/json" \
-d '{
"reduce_primaries": 2,
"strategy": "least_loaded",
"dry_run": true
}' | jq .
{
"plan": {
"nodes_to_retire": ["data-4", "data-5"],
"tables_to_reassign": [
{
"catalog": "mydb",
"schema": "default",
"table": "cpu",
"current_owner": "data-4",
"new_owner": "data-1"
},
{
"catalog": "mydb",
"schema": "default",
"table": "memory",
"current_owner": "data-4",
"new_owner": "data-2"
},
{
"catalog": "mydb",
"schema": "service_1",
"table": "disk",
"current_owner": "data-5",
"new_owner": "data-3"
}
],
"remaining_active_nodes": 3,
"estimated_flush_size_mb": 512.4
},
"dry_run": true,
"strategy": "least_loaded"
}
The strategy parameter determines how nodes are selected for retirement:
| Strategy | Selection Criteria | Best For |
|---|---|---|
least_loaded |
Retires nodes with the fewest owned tables and smallest in-memory cache size | Minimizing flush time and reassignment overhead |
most_idle |
Retires nodes with the lowest recent write/query throughput | Cost optimization during low-traffic periods |
Step 2: Execute
# Execute the scale-in plan (removes dry_run flag)
curl -s -X POST http://localhost:7000/cluster/scale-in/execute-plan \
-H "Content-Type: application/json" \
-d '{
"reduce_primaries": 2,
"strategy": "least_loaded"
}' | jq .
{
"status": "in_progress",
"nodes_retiring": ["data-4", "data-5"],
"tables_reassigned": 3,
"estimated_completion_secs": 45,
"tracking_id": "scale-in-2026-02-13T10:30:00Z"
}
Step 3: Monitor Progress
# Check progress of an active scale-in operation
curl -s http://localhost:7000/cluster/scale-in/status | jq .
# Poll until all retiring nodes reach Drained state
watch -n 5 'curl -s http://localhost:7000/cluster/nodes | \
jq ".nodes[] | select(.state == \"Retiring\" or .state == \"Drained\") | {node_id, state}"'
Table Reassignment
When a node is retiring, the Meta leader orchestrates the transfer of table ownership. This is the critical path of the scale-in operation and proceeds as follows:
- The Meta leader iterates over all tables owned by the retiring node.
- For each table, it selects the best target node using a load-balancing heuristic (fewest owned tables, most available memory).
Meta.ReassignTableatomically transfers ownership in the Raft log.- A
TableReassignedevent is published. All Routers update theirShardCache. - New writes for the reassigned table are immediately routed to the new owner.
- The old (retiring) node flushes any remaining cached data for that table to object storage.
- Once all tables are reassigned and flushed, the node transitions to Drained.
# Manually reassign a single table (advanced usage)
curl -s -X POST http://localhost:7000/cluster/reassign-table \
-H "Content-Type: application/json" \
-d '{
"catalog": "mydb",
"schema": "default",
"table": "cpu",
"from_node": "data-2",
"to_node": "data-1"
}' | jq .
Failure Detection & Recovery
MynaDB uses a heartbeat and lease-based system to detect node failures. When a data node becomes unreachable, the Meta leader automatically triggers a recovery workflow that preserves data integrity and restores cluster health without operator intervention.
Heartbeat & Lease System
Every active data node sends a heartbeat to the Meta leader at a configurable interval (default: every 5 seconds). Each heartbeat renews the node's lease, which has a TTL of 15 seconds (3x the heartbeat interval). If a node fails to heartbeat before its lease expires, the Meta leader marks it as Inactive.
| Parameter | Default | Description |
|---|---|---|
heartbeat_interval_secs |
5 | How often each data node sends a heartbeat to the Meta leader |
lease_ttl_secs |
15 | Time after the last heartbeat before the lease expires (should be 3x heartbeat interval) |
expire_check_interval_secs |
5 | How often the Meta leader scans for expired leases |
max_missed_heartbeats |
3 | Number of missed heartbeats before a node is considered dead (informational; actual detection is lease-based) |
# Data node heartbeat configuration
[data.heartbeat]
interval_secs = 5 # Send heartbeat every 5 seconds
lease_ttl_secs = 15 # Lease expires after 15 seconds of silence
# Meta leader lease expiration settings
[meta.leases]
expire_check_interval_secs = 5
recovery_delay_secs = 3 # Wait 3s after expiry before triggering recovery
# (prevents false positives during brief network blips)
Crash Recovery Flow
When the Meta leader detects an expired lease, the following recovery sequence is triggered automatically:
- Lease expiration detected: The Meta leader's periodic
ExpireLeasestask discovers a stale lease for the failed node. - Node marked Inactive: The Meta leader updates the node's state to Inactive (state 4) in the Raft log. A
NodeStateChangedevent is published. - Recovery manager triggered: After the configurable
recovery_delay_secs(default 3s), the recovery manager begins processing the failed node. - Standby flush (if configured): If the failed node has a configured cold standby (backing standby), the standby node flushes its replicated DataCache to object storage, preserving any in-flight data that had not yet been flushed by the primary.
- Orphaned tables reassigned: All tables previously owned by the failed node are reassigned to healthy active nodes using the same load-balancing heuristic as scale-in.
- Router notification: Routers receive
NodeStateChangedandTableReassignedevents, updating theirShardCacheto exclude the failed node and route writes to new owners. - Writes automatically reroute: Subsequent writes for affected tables are transparently directed to the new owner nodes. Clients experience a brief latency spike but no errors (Routers retry on transient failures).
Crash Recovery Timeline
========================
Time (seconds)
0s 5s 10s 15s 18s 20s 25s
|---------|---------|---------|---------|---------|---------|
^ ^ ^ ^ ^ ^
| | | | | |
Node Last Missed Lease Recovery Tables
crashes heartbeat heartbeat expires manager reassigned;
received #3 (Meta triggers writes
detected marks rerouted
Inactive)
|<-- heartbeat_interval -->|
|<-- lease_ttl (15s) -->|
|<-3s->|
delay |<-- ~5s -->|
recovery traffic
processing restored
Total recovery time: ~20-25 seconds (worst case)
Cold Standby Replication
For workloads that require minimal data loss during node failures, MynaDB supports a cold standby replication model. Each primary data node can have one standby node that asynchronously replicates the primary's in-memory DataCache. If the primary fails, the standby can flush the replicated cache to object storage before table ownership is reassigned, preserving data that had not yet been persisted.
Primary/Standby Model
Data nodes operate in one of two modes, determined by the DataNodeMode configuration:
| Mode | Accepts Writes | Serves Queries | Replicates | Description |
|---|---|---|---|---|
| Primary | Yes | Yes | Sends to Standby | The active write owner for assigned tables. Asynchronously replicates cached data to its configured standby node via Arrow Flight. |
| Standby | No (replication only) | Yes (read-only) | Receives from Primary | Maintains a replica of the primary's DataCache. Can serve read queries to offload the primary. Automatically flushes cache if the primary fails. |
Configuration
# Primary data node configuration (data1.toml)
[data]
node_id = "data-1"
mode = "primary"
http_port = 5000
flight_port = 5001
advertise_addr = "10.0.1.10:5001"
meta_endpoints = ["10.0.1.1:6001", "10.0.1.2:6001", "10.0.1.3:6001"]
# Configure the standby that will receive replication data
[data.replication]
backing_standby = "data-1-standby" # Node ID of the standby
replication_mode = "async" # "async" (default) or "sync"
batch_size = 1000 # Records per replication batch
max_lag_secs = 30 # Alert if standby falls behind
# Standby data node configuration (data1-standby.toml)
[data]
node_id = "data-1-standby"
mode = "standby"
http_port = 5010
flight_port = 5011
advertise_addr = "10.0.1.11:5011"
meta_endpoints = ["10.0.1.1:6001", "10.0.1.2:6001", "10.0.1.3:6001"]
# Configure the primary this standby replicates from
[data.replication]
replication_source = "data-1" # Node ID of the primary
flight_endpoint = "10.0.1.10:5001" # Primary's Flight address for receiving data
Write Replication Flow
Write Replication Flow (Async Mode)
====================================
Client Router Primary (data-1) Standby (data-1-standby) S3
| | | | |
| POST /write | | | |
|-------------->| | | |
| | forward write | | |
| |----------------->| | |
| | | | |
| | | 1. Write to WAL | |
| | | 2. Buffer in DataCache | |
| | | 3. Return 204 | |
| |<-----------------| | |
| 204 OK | | | |
|<--------------| | | |
| | | | |
| | | (async, batched) | |
| | | Replicate via Flight | |
| | |----------------------->| |
| | | | Buffer in local |
| | | | DataCache replica |
| | | | |
| | | (periodic flush) | |
| | |--------------------------------------------->|
| | | Flush to Parquet on S3 | |
| | | | |
Primary Failure with Standby
When a primary node with a configured standby fails, the recovery flow is enhanced:
- Meta leader detects the primary's expired lease and marks it Inactive.
- Recovery manager identifies the configured backing standby (
data-1-standby). - The standby is instructed to flush its replicated DataCache to object storage. This preserves writes that the primary had accepted but not yet flushed.
- After the standby flush completes, orphaned tables are reassigned to healthy primary nodes.
- The standby resumes its standby role for whichever primary is assigned its tables (or can be promoted to primary if configured).
max_lag_secs (default 30s). Writes accepted by the primary but not yet replicated to the standby
will be lost if the primary crashes. For zero data loss, use replication_mode = "sync" at the cost
of higher write latency.
Table Ownership TTL
Table ownership in MynaDB is maintained through a TTL (Time-To-Live) based lease mechanism. This design prevents stale ownership records from persisting indefinitely when nodes crash or are removed without a graceful scale-in. Active data nodes must periodically refresh their ownership leases to maintain write access to their tables.
How TTL-Based Ownership Works
- When a table is first assigned to a data node (via
RegisterTable), an ownership record is created in the Meta Raft log with a default TTL of 600 seconds (10 minutes). - The owning data node calls
RefreshOwnerTTLperiodically (typically every 60 seconds) to reset the TTL timer. - If the owning node crashes or becomes unreachable, the TTL counts down. After 600 seconds without a refresh, the ownership record expires.
- The Meta leader's periodic cleanup task detects expired ownership records and removes them.
- The table becomes unowned and can be claimed by the next node that receives a write for it.
# Ownership lifecycle for table "mydb.default.cpu"
t=0s RegisterTable(mydb, default, cpu, owner=data-1, ttl=600s)
ownership.expires_at = now + 600s
t=60s RefreshOwnerTTL(mydb, default, cpu, owner=data-1)
ownership.expires_at = now + 600s # reset
t=120s RefreshOwnerTTL(mydb, default, cpu, owner=data-1)
ownership.expires_at = now + 600s # reset
t=180s [data-1 crashes]
(no more RefreshOwnerTTL calls)
t=195s Meta detects expired lease, marks data-1 as Inactive
Recovery manager reassigns tables immediately
(does NOT wait for TTL expiry in crash recovery)
# TTL expiry is a safety net for edge cases:
# - Meta was temporarily partitioned and missed the crash
# - Node was removed from cluster without graceful scale-in
# - Stale ownership from a previous cluster incarnation
t=780s If not already cleaned up: TTL expires
Meta removes stale ownership record
Table becomes unowned, available for new assignment
# Table ownership TTL configuration
[data.ownership]
ttl_secs = 600 # Ownership expires after 10 minutes without refresh
refresh_interval_secs = 60 # Refresh every 60 seconds (should be << ttl_secs)
cleanup_interval_secs = 120 # Meta checks for expired ownership every 2 minutes
Monitoring Cluster Health
Effective monitoring is essential for operating a scaled MynaDB cluster. MynaDB exposes health endpoints, Prometheus metrics, and structured log events that provide visibility into node states, ownership distribution, heartbeat status, and scaling operations.
Health Endpoints
# Basic health check (returns 200 if healthy, 503 if degraded)
curl -s http://localhost:7000/health | jq .
# Detailed cluster status (node count, leader info, coordinator state)
curl -s http://localhost:7000/cluster/status | jq .
# List all registered nodes with their states
curl -s http://localhost:7000/cluster/nodes | jq .
{
"nodes": [
{
"node_id": "data-1",
"state": "Active",
"http_addr": "10.0.1.10:5000",
"flight_addr": "10.0.1.10:5001",
"mode": "primary",
"tables_owned": 12,
"cache_size_mb": 256.3,
"last_heartbeat": "2026-02-13T10:30:05Z",
"uptime_secs": 86400
},
{
"node_id": "data-2",
"state": "Active",
"http_addr": "10.0.1.20:5000",
"flight_addr": "10.0.1.20:5001",
"mode": "primary",
"tables_owned": 10,
"cache_size_mb": 198.7,
"last_heartbeat": "2026-02-13T10:30:04Z",
"uptime_secs": 86400
},
{
"node_id": "data-1-standby",
"state": "Active",
"http_addr": "10.0.1.11:5010",
"flight_addr": "10.0.1.11:5011",
"mode": "standby",
"replication_source": "data-1",
"replication_lag_secs": 2,
"last_heartbeat": "2026-02-13T10:30:03Z",
"uptime_secs": 86400
}
],
"total": 3,
"healthy": 3,
"active": 2,
"standbys": 1
}
Prometheus Metrics
The following Prometheus metrics are exposed at /metrics on every node and are particularly
useful for monitoring scaling operations and cluster health:
| Metric | Type | Description |
|---|---|---|
mynadb_cluster_nodes_total |
Gauge | Total number of registered nodes (all states) |
mynadb_cluster_nodes_healthy |
Gauge | Number of nodes in Active state with a valid lease |
mynadb_cluster_nodes_by_state |
Gauge (labeled) | Node count per state: state="active|draining|retiring|inactive|drained" |
mynadb_cluster_lock_acquisitions_total |
Counter | Total number of distributed lock acquisitions (partition-level write locks) |
mynadb_cluster_lock_wait_seconds |
Histogram | Time spent waiting to acquire distributed locks |
mynadb_cluster_heartbeat_latency_seconds |
Histogram | Round-trip time for heartbeat RPCs from data nodes to Meta |
mynadb_cluster_tables_owned |
Gauge | Number of tables owned by this node |
mynadb_cluster_replication_lag_seconds |
Gauge | Standby replication lag behind primary (standby nodes only) |
mynadb_cluster_scale_in_operations_total |
Counter | Total number of scale-in operations executed |
mynadb_cluster_table_reassignments_total |
Counter | Total number of table ownership reassignments |
Grafana Alerting Rules
The following alerting rules are recommended for production deployments. Import them into Grafana or configure them in your Prometheus alerting rules file:
groups:
- name: mynadb_cluster_health
interval: 15s
rules:
# Alert if any node has been inactive for more than 2 minutes
- alert: MynaDBNodeInactive
expr: mynadb_cluster_nodes_by_state{state="inactive"} > 0
for: 2m
labels:
severity: critical
annotations:
summary: "MynaDB node is inactive"
description: "{{ $value }} node(s) have been in Inactive state for over 2 minutes. Check Meta logs for recovery status."
# Alert if healthy node count drops below minimum
- alert: MynaDBClusterDegraded
expr: mynadb_cluster_nodes_healthy < 2
for: 1m
labels:
severity: critical
annotations:
summary: "MynaDB cluster has fewer than 2 healthy nodes"
description: "Only {{ $value }} healthy data node(s) remaining. Cluster may be unable to handle write load."
# Alert if heartbeat latency is elevated
- alert: MynaDBHeartbeatSlow
expr: histogram_quantile(0.99, rate(mynadb_cluster_heartbeat_latency_seconds_bucket[5m])) > 5
for: 3m
labels:
severity: warning
annotations:
summary: "MynaDB heartbeat latency is high"
description: "p99 heartbeat latency is {{ $value }}s. Network issues may cause false failure detection."
# Alert if standby replication lag exceeds threshold
- alert: MynaDBReplicationLag
expr: mynadb_cluster_replication_lag_seconds > 60
for: 5m
labels:
severity: warning
annotations:
summary: "MynaDB standby replication lag is high"
description: "Standby replication lag is {{ $value }}s. Data loss window in case of primary failure."
# Alert if a scale-in operation is stuck
- alert: MynaDBScaleInStuck
expr: mynadb_cluster_nodes_by_state{state="retiring"} > 0
for: 15m
labels:
severity: warning
annotations:
summary: "MynaDB scale-in operation appears stuck"
description: "{{ $value }} node(s) have been in Retiring state for over 15 minutes. Check for flush errors."
Best Practices
Meta Cluster
- Always run 3 or 5 meta nodes. Raft requires a majority quorum (2 of 3, or 3 of 5) to function. An even number of meta nodes provides no benefit and wastes resources.
- Place meta nodes in different availability zones. Distribute meta nodes across at least 2 (ideally 3) AZs to survive a single AZ failure.
- Use dedicated instances for meta nodes. Meta nodes are lightweight but latency-sensitive. Co-locating them with data nodes can cause election timeouts under heavy write load.
Router Layer
- Use separate router and data nodes in production. While a "hybrid" node mode exists, separating concerns improves resource isolation and simplifies scaling.
- Place routers behind a load balancer. Use HAProxy, NGINX, or a cloud ALB. Configure health checks against
/health. - Scale routers independently of data nodes. Routers are stateless and can be scaled based on query/write request rate, while data nodes scale based on storage and compute needs.
Scaling Operations
- Always test scale-in with
dry_run: truefirst. Review the plan output to understand which tables will be reassigned and estimate the flush duration. - Scale in during low-traffic periods. While MynaDB handles scale-in gracefully, performing it during off-peak hours minimizes the impact on write latency during table reassignment.
- Monitor the scale-in progress. Watch the
/cluster/scale-in/statusendpoint and verify that nodes reach the Drained state before terminating them. - Do not terminate nodes in Retiring state. Killing a node before it finishes flushing its DataCache will result in data loss for unflushed writes. Wait for the Drained state.
High Availability
- Keep standby nodes for critical workloads. Cold standby replication significantly reduces the data loss window during primary failures. The cost is one additional node per primary.
- Monitor heartbeat and lease metrics. Elevated heartbeat latency can indicate network issues that may lead to false failure detection. Tune
lease_ttl_secsif you operate in a high-latency network environment. - Maintain at least N+1 data nodes. Always have one more data node than strictly necessary so the cluster can absorb a node failure without becoming overloaded.
- Use
replication_mode = "sync"for zero-RPO workloads. Synchronous replication guarantees zero data loss at the cost of higher write latency (the primary waits for the standby to acknowledge each batch).
Configuration Tuning
- Set
flush_interval_secsbased on acceptable data loss. A shorter interval means less data in the DataCache at any given time, reducing the flush duration during scale-in and the data loss window during crashes. - Size
max_size_mbto avoid OOM. The DataCache holds all writes between flushes. If the write rate exceeds the flush rate, the cache grows unbounded. Set a conservative limit and monitor/memory. - Tune
ownership.ttl_secsfor your environment. In stable environments, the default 600s is fine. In environments with frequent scaling, consider reducing it to 300s for faster cleanup of stale ownership.