docs: raft cluster status, plans closed, CHANGELOG/README/monitoring
- Add raft-cluster-status overview (C3a/C3b/post-C3b shipped on main) - Mark C3a/C3b design+plans done; refresh operator docs en/bg - CHANGELOG 1.2.0 Raft section; README cluster example and status line - monitoring.md health/metrics match real HTTP port+440 and raft series
This commit is contained in:
+30
-1
@@ -5,9 +5,11 @@ BaraDB supports distributed deployment with Raft consensus, sharding, and replic
|
||||
> ⚠️ **Multi-Database Limitation**
|
||||
> The distributed modules (Raft, sharding, and replication) are currently wired to the **`default`** database only. If you use multiple databases (`CREATE DATABASE`, `USE DATABASE`), distributed features do not yet span across them. Each database would need its own cluster setup.
|
||||
|
||||
> **Status (2026-07-30):** Raft C3a (network election), C3b (SQL writes), DDL replication, leader forwarding, log compaction, and metrics are **shipped on `main`**. Design/history: `docs/superpowers/specs/2026-07-30-raft-cluster-status.md`.
|
||||
|
||||
## Raft Consensus
|
||||
|
||||
Leader election and log replication over TCP. Enable with:
|
||||
Leader election and log replication over TCP; SQL DML/DDL on the default DB go through the raft log. Enable with:
|
||||
|
||||
| Env | Meaning |
|
||||
|-----|---------|
|
||||
@@ -25,6 +27,26 @@ When Raft is enabled, SQL DML (`INSERT`/`UPDATE`/`DELETE`/`MERGE` and transactio
|
||||
|
||||
**Metrics:** with raft enabled, `GET /metrics` (HTTP port = `BARADB_PORT + 440`) includes Prometheus lines such as `baradb_raft_is_leader`, `baradb_raft_term`, `baradb_raft_log_entries`, `baradb_raft_apply_lag`, `baradb_raft_commit_wait_ms_total`, `baradb_raft_elections_total`, `baradb_raft_forwards_total`, and `baradb_raft_compactions_total`. `GET /health` embeds a `raft` object (`role`, `term`, `leader_id`, `commit_index`, `apply_lag`, …).
|
||||
|
||||
### Minimal 3-node example
|
||||
|
||||
```bash
|
||||
# Shared peers (raft ports) and client peers (SQL ports)
|
||||
export BARADB_RAFT_ENABLED=true
|
||||
export BARADB_RAFT_PEERS=n1@127.0.0.1:46101,n2@127.0.0.1:46102,n3@127.0.0.1:46103
|
||||
export BARADB_RAFT_CLIENT_PEERS=n1@127.0.0.1:46010,n2@127.0.0.1:46020,n3@127.0.0.1:46030
|
||||
|
||||
# Terminal 1
|
||||
BARADB_PORT=46010 BARADB_RAFT_PORT=46101 BARADB_RAFT_NODE_ID=n1 \
|
||||
BARADB_DATA_DIR=./data/n1 ./build/baradadb
|
||||
|
||||
# Terminal 2 / 3 — n2@46020/46102, n3@46030/46103 similarly
|
||||
|
||||
# After a leader appears (check logs for "became leader"):
|
||||
# curl http://127.0.0.1:46450/health # n1 HTTP = 46010+440
|
||||
```
|
||||
|
||||
### In-process API (tests / embedding)
|
||||
|
||||
```nim
|
||||
import barabadb/core/raft
|
||||
|
||||
@@ -39,6 +61,13 @@ n1.becomeLeader()
|
||||
let entry = n1.appendLog("SET key1 value1")
|
||||
```
|
||||
|
||||
### E2E tests
|
||||
|
||||
| Test | What it proves |
|
||||
|------|----------------|
|
||||
| `tests/raft_e2e_test.nim` | 3 real processes; election + kill-leader failover |
|
||||
| `tests/raft_writes_e2e_test.nim` | DDL/DML via raft, follower forward, index SELECT, failover writes |
|
||||
|
||||
## Sharding
|
||||
|
||||
Distribute data across nodes:
|
||||
|
||||
+56
-10
@@ -4,21 +4,39 @@
|
||||
|
||||
### HTTP Health Endpoint
|
||||
|
||||
HTTP listens on **TCP port + 440** (e.g. `BARADB_PORT=9472` → health on `9912`).
|
||||
|
||||
```bash
|
||||
curl http://localhost:9470/health
|
||||
curl http://localhost:9912/health
|
||||
```
|
||||
|
||||
Response:
|
||||
Response (raft disabled):
|
||||
|
||||
```json
|
||||
{
|
||||
"status": "healthy",
|
||||
"version": "0.1.0",
|
||||
"uptime_seconds": 86400,
|
||||
"checks": {
|
||||
"storage": "ok",
|
||||
"memory": "ok",
|
||||
"connections": "ok"
|
||||
"status": "ok",
|
||||
"version": "1.1.6",
|
||||
"raft": { "enabled": false }
|
||||
}
|
||||
```
|
||||
|
||||
With `BARADB_RAFT_ENABLED=true`, a `raft` object is included:
|
||||
|
||||
```json
|
||||
{
|
||||
"status": "ok",
|
||||
"version": "1.1.6",
|
||||
"raft": {
|
||||
"enabled": true,
|
||||
"node_id": "n1",
|
||||
"role": "leader",
|
||||
"term": 2,
|
||||
"leader_id": "n1",
|
||||
"commit_index": 42,
|
||||
"last_applied": 42,
|
||||
"apply_lag": 0,
|
||||
"log_entries": 12,
|
||||
"snapshot_index": 30
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -35,10 +53,38 @@ Returns `200 OK` when the server is ready to accept traffic, `503` during startu
|
||||
|
||||
### Prometheus-Compatible Metrics
|
||||
|
||||
Same HTTP base port as health (`BARADB_PORT + 440`). When auth is enabled, send a Bearer token.
|
||||
|
||||
```bash
|
||||
curl http://localhost:9470/metrics
|
||||
curl http://localhost:9912/metrics
|
||||
```
|
||||
|
||||
Always present:
|
||||
|
||||
| Metric | Meaning |
|
||||
|--------|---------|
|
||||
| `baradb_queries_total` | HTTP queries handled |
|
||||
| `baradb_query_errors_total` | Failed HTTP queries |
|
||||
| `baradb_inserts_total` / `baradb_selects_total` | Statement class counts |
|
||||
| `baradb_connections_active` | Active connections |
|
||||
|
||||
With raft enabled, additional series (labels include `node="…"`):
|
||||
|
||||
| Metric | Meaning |
|
||||
|--------|---------|
|
||||
| `baradb_raft_is_leader` | 1 if this process is leader |
|
||||
| `baradb_raft_term` | Current term |
|
||||
| `baradb_raft_log_entries` | In-memory log length |
|
||||
| `baradb_raft_commit_index` / `baradb_raft_last_applied` | Raft indices |
|
||||
| `baradb_raft_apply_lag` | commit − applied |
|
||||
| `baradb_raft_snapshot_index` | Compacted log base |
|
||||
| `baradb_raft_elections_total` | Times this node became leader |
|
||||
| `baradb_raft_commit_wait_ms_total` / `_avg` | Wait-for-commit latency |
|
||||
| `baradb_raft_forwards_total` | Follower→leader SQL forwards |
|
||||
| `baradb_raft_compactions_total` | Log prefix compactions |
|
||||
|
||||
See also [distributed.md](distributed.md) for cluster env vars and ops notes.
|
||||
|
||||
Example output:
|
||||
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user