企业版集群
无限扩展。MynaDB 企业版将单机数据库转变为分布式、水平可扩展的集群,实现计算存储分离架构。按需添加节点, 扩展至 PB 级别,借助基于 S3 的存储实现 11 个 9 的数据持久性。
架构概览
Clients (HTTP / Flight / MySQL)
│
▼
┌───────────────────┐
│ Load Balancer │
└─────────┬─────────┘
│
┌─────────────────────────┼─────────────────────────┐
│ │ │
▼ ▼ ▼
┌────────────────┐ ┌────────────────┐ ┌────────────────┐
│ Router Node 1 │ │ Router Node 2 │ │ Router Node N │
│ HTTP:7000 │ │ (Stateless) │ │ (Stateless) │
│ Flight:7001 │ │ ShardCache │ │ ShardCache │
│ MySQL:7002 │ │ QueryCoord │ │ QueryCoord │
└──────┬─────────┘ └──────┬─────────┘ └──────┬─────────┘
│ Arrow Flight │ │
├────────────────────────┼────────────────────────┘
│ │
▼ ▼
┌────────────────┐ ┌────────────────┐
│ Data Node 1 │ │ Data Node N │ ┌────────────────┐
│ HTTP:5000 │ │ (Scaled-out) │ │ Admin Console │
│ Flight:5001 │ │ DataCache │ │ HTTP:18080 │
│ DataCache │ │ WAL + Parquet │ │ Cluster Mgmt │
│ WAL + Parquet │ │ Compaction │ │ SQL Editor │
└──────┬─────────┘ └──────┬─────────┘ └──────┬─────────┘
│ │ │
└────────────┬───────────┘ │
▼ │
┌──────────────────────────────────────────────────┐ │
│ SHARED OBJECT STORAGE │ │
│ (S3 / MinIO / OSS) │ │
└──────────────────────────────────────────────────┘ │
│
┌──────────────────────────────────────────────────┐ │
│ META SERVICE (Raft Consensus) │◄──────┘
│ ┌────────┐ ┌────────┐ ┌────────┐ │
│ │ Meta 1 │ │ Meta 2 │ │ Meta 3 │ │
│ │ Leader │ │Follower│ │Follower│ │
│ │ :6000 │ │ :6100 │ │ :6200 │ │
│ └────────┘ └────────┘ └────────┘ │
│ Metadata • Table Routing • Locks • Events │
└──────────────────────────────────────────────────┘
核心优势
自动扩缩容
无需数据迁移即可增减计算节点。从 3 个节点无缝扩展到 100+ 个节点。
11 个 9 的持久性
S3 对象存储提供 99.999999999% 的数据持久性。您的数据安全无忧。
成本高效
数据仅存储一份于低成本对象存储中,无需副本复制开销。
即时故障转移
无状态节点意味着即时恢复,无需等待领导者选举。
节点类型
Meta 节点
基于 Raft 的共识服务(OpenRaft 0.9)。管理元数据、表路由、分布式锁、领导者选举和事件流。部署 3 或 5 个节点。
端口:HTTP 6000,gRPC 6001
Router 节点
无状态请求路由器,通过 ShardCache 实现表级路由。面向客户端提供 HTTP、Arrow Flight 和 MySQL 线协议。支持扇出查询协调。
端口:HTTP 7000,Flight 7001,MySQL 7002
Data 节点
存储和查询执行引擎。将写入数据缓存到 DataCache,刷新为 Parquet 文件到 S3,运行 LSM 压缩合并,并通过 DataFusion 在本地执行 SQL 查询。
端口:HTTP 5000,Flight 5001
Admin 控制台
可选的 Web 管理界面。连接 Meta 进行节点发现,提供 SQL 编辑器、存储浏览器和集群监控仪表盘。
端口:HTTP 18080
工作原理
表级路由
MynaDB 使用表级路由来优化时序数据工作负载的性能。每个表由特定的 Data 节点拥有, 所有权信息在 Meta 服务中跟踪。与文件级路由相比,元数据条目减少 600 倍,同时保持出色的缓存局部性。
写入路径
1. Client → POST /write/:db (to Router)
2. Router parses line protocol, extracts table name
3. Router looks up table owner in ShardCache
4. Router sends RecordBatch to Data node via Arrow Flight
5. Data node inserts into DataCache (in-memory)
6. Data node registers table with Meta (if new)
7. Background: DataCache flushes to Parquet on S3 every 60s
8. Background: Compactor merges Parquet files (L0 → L1 → L2)
查询路径
1. Client → GET /query/:db?sql=... (to Router)
2. Router parses SQL, extracts table references
3. Router determines target Data nodes from ShardCache
4. Router fans out query to Data nodes in parallel (Arrow Flight)
5. Each Data node executes locally:
- Check DataCache for hot data
- Read matching Parquet files from S3
- Apply partition pruning + predicate pushdown
6. Router aggregates partial results
7. Return combined result to client
故障恢复
Data 节点每 5 秒发送一次心跳,租约 TTL 为 15 秒。当节点崩溃时,Meta 领导者检测到过期的租约, 将节点标记为 Inactive,并触发恢复管理器。孤立的表会被重新分配给健康的节点,Router 的 ShardCache 通过事件流进行更新。可选的冷备节点可在故障转移前将未持久化的数据刷新到 S3。
配置
[cluster]
enabled = true
node_id = "" # Auto-generated if empty
advertise_addr = "0.0.0.0:7000"
role = "hybrid" # "compute", "compactor", "hybrid"
[cluster.coordinator]
type = "etcd"
endpoints = ["etcd-1:2379", "etcd-2:2379", "etcd-3:2379"]
lock_prefix = "/mynadb/locks/"
lock_ttl_secs = 30
heartbeat_interval_secs = 5
[cluster.cache]
invalidation_channel = "/mynadb/cache/invalidate"
[cluster.compaction]
leader_only = true
election_key = "/mynadb/leader/compactor"
[cluster.health]
check_interval_secs = 10
unhealthy_threshold = 3
集群 API
| 端点 | 方法 | 描述 |
|---|---|---|
/cluster/status |
GET | 集群整体状态和当前节点信息 |
/cluster/nodes |
GET | 列出所有已注册的节点 |
/cluster/leader |
GET | 当前领导者信息 |
/cluster/health |
GET | 集群健康检查 |
/cluster/drain?node_id=xxx |
POST | 排空节点(准备移除) |
/cluster/remove?node_id=xxx |
DELETE | 从集群中移除节点 |
示例:集群状态
curl http://localhost:7000/cluster/status
{
"enabled": true,
"node_id": "mynadb-1",
"role": "hybrid",
"state": "active",
"is_leader": true,
"leader_id": "mynadb-1",
"total_nodes": 3,
"healthy_nodes": 3,
"coordinator_type": "etcd",
"coordinator_connected": true
}
部署
Kubernetes
# Create namespace
kubectl create namespace mynadb
# Apply manifests
kubectl apply -f deploy/kubernetes/configmap.yaml
kubectl apply -f deploy/kubernetes/service.yaml
kubectl apply -f deploy/kubernetes/deployment.yaml
kubectl apply -f deploy/kubernetes/hpa.yaml
# Check status
kubectl get pods -n mynadb
kubectl get svc -n mynadb
Docker Compose
# Start cluster with etcd and MinIO
docker-compose -f deploy/docker-compose.cluster.yaml up -d
# Verify nodes
curl http://localhost:7000/cluster/nodes
# Write to node 1
curl -X POST http://localhost:7000/write/testdb \
-d "cpu,host=a value=1"
# Query from node 2 (port 7010)
curl http://localhost:7010/query/testdb \
-d "SELECT * FROM cpu"
# Check HAProxy stats
open http://localhost:8404/stats
指标监控
Prometheus 指标可通过 /metrics 端点获取:
| 指标 | 类型 | 描述 |
|---|---|---|
mynadb_cluster_nodes_total |
Gauge | 节点总数 |
mynadb_cluster_nodes_healthy |
Gauge | 健康节点数 |
mynadb_cluster_is_leader |
Gauge | 当前节点是否为领导者(1 表示是) |
mynadb_cluster_lock_acquisitions_total |
Counter | 锁获取次数 |
mynadb_cluster_cache_invalidations_total |
Counter | 缓存失效发送次数 |
性能
| 指标 | 单机模式 | 集群模式(缓存命中) | 集群模式(缓存未命中) |
|---|---|---|---|
| 写入延迟(p50) | 5-10ms | 10-30ms | 50-100ms |
| 写入延迟(p99) | 20-50ms | 50-100ms | 150-300ms |
| 查询延迟(p50) | 10-50ms | 10-50ms | 100-300ms |
| 写入吞吐量 | 100K 点/秒 | 100K 点/秒/节点 | - |
方案对比
| 特性 | MynaDB 集群 | Shared-Nothing(Raft) | 主从模式 |
|---|---|---|---|
| 复杂度 | 中等 | 非常高 | 低 |
| 自动扩缩容 | 优秀 | 困难(需要重平衡) | 不支持 |
| 持久性 | S3(11 个 9) | Raft 多数派 | 复制延迟 |
| 故障转移时间 | 即时 | 10-15 秒 | 10-30 秒 |
| 最适场景 | 云端、弹性扩展 | 私有化部署、强一致性 | 简单高可用 |