mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
docs: prune historical notes from public docs
This commit is contained in:
1 parent
c5b02f1924
commit
66351dff8e
16 files changed
+13
-2172
No files matched your search
@@ -4,9 +4,9 @@
|
||||
// authoritative AssignmentInfo values to subscribers keyed by
|
||||
// (VolumeID, ReplicaID).
|
||||
//
|
||||
// The design note is docs/p14-s2-design.md. Three boundaries hold:
|
||||
// 1. S2 owns publication of authority truth.
|
||||
// 2. S2 does NOT own failover policy.
|
||||
// Three boundaries hold:
|
||||
// 1. The authority package owns publication of assignment truth.
|
||||
// 2. The authority package does NOT own failover policy.
|
||||
// 3. Engine and adapter remain consumers, not producers, of
|
||||
// assignment truth.
|
||||
package authority
|
||||
@@ -20,8 +20,8 @@ import (
|
||||
|
||||
// AskIntent is the only control knob a Directive has. The publisher
|
||||
// uses it to decide which authoritative field to advance and by how
|
||||
// much. S2 supports exactly three intents. Retirement is deferred
|
||||
// (see docs/p14-s2-design.md "What we are NOT building").
|
||||
// much. The current publisher supports exactly three intents.
|
||||
// Retirement is deliberately not part of this input surface yet.
|
||||
type AskIntent int
|
||||
|
||||
const (
|
||||
|
||||
@@ -360,10 +360,10 @@ func (h *Host) Close() error {
|
||||
|
||||
// runHeartbeat sends a HeartbeatReport every HeartbeatInterval.
|
||||
// Send failures are logged with bounded backoff but do NOT panic
|
||||
// or hang the volume process (per sketch §8.2.1 test 4).
|
||||
// or hang the volume process.
|
||||
//
|
||||
// The loop shape is ported from weed/server/block_heartbeat_loop.go
|
||||
// — see docs/t0-port-audit.md §2.
|
||||
// The loop shape is intentionally simple: immediate first report,
|
||||
// then periodic reports until the host context is cancelled.
|
||||
func (h *Host) runHeartbeat(ctx context.Context) {
|
||||
defer h.wg.Done()
|
||||
tick := time.NewTicker(h.cfg.HeartbeatInterval)
|
||||
|
||||
@@ -1,157 +0,0 @@
|
||||
# Bootstrap and Validation
|
||||
|
||||
This doc is the reference for the sparrow CLI flags, HTTP endpoints,
|
||||
and exit codes. For the product-shape view of the single-node surface
|
||||
(scope statement, workflow, honesty rules, carry-forward), see
|
||||
[docs/single-node-surface.md](single-node-surface.md).
|
||||
|
||||
This binary is NOT a production operator CLI — the production
|
||||
interface is `weed shell` after integration.
|
||||
|
||||
## Supported
|
||||
|
||||
| Action | How |
|
||||
|---|---|
|
||||
| Run the three canonical demos (default) | `go run ./cmd/sparrow` |
|
||||
| Print scope statement (supported / unsupported) | `go run ./cmd/sparrow --help` |
|
||||
| Print version | `go run ./cmd/sparrow --version` |
|
||||
| Repeatable validation | `go run ./cmd/sparrow --runs 10 --json` |
|
||||
| Machine-readable output for CI | `go run ./cmd/sparrow --json` |
|
||||
| Optional read-only HTTP inspection | `go run ./cmd/sparrow --http :9090` |
|
||||
| Phase 06 calibration pass | `go run ./cmd/sparrow --calibrate` |
|
||||
| Calibration report as JSON (for tester review) | `go run ./cmd/sparrow --calibrate --json` |
|
||||
| Phase 07 single-node persistence demo | `go run ./cmd/sparrow --persist-demo --persist-dir DIR` |
|
||||
| Persistence demo as JSON | `go run ./cmd/sparrow --persist-demo --persist-dir DIR --json` |
|
||||
|
||||
## Not supported
|
||||
|
||||
These will either not exist or will return an explicit error:
|
||||
|
||||
- crash consistency from process kill or power loss (Phase 07 proves clean stop+restart only)
|
||||
- distributed durability across nodes
|
||||
- master service or dynamic assignment
|
||||
- any mutation via the HTTP ops surface — POST/PUT/PATCH/DELETE return 501
|
||||
- RF3 or multi-replica flows
|
||||
- frontend protocols (iSCSI, NVMe-oF)
|
||||
- concurrent writer during replication
|
||||
- a real operator CLI — `weed shell` is the eventual interface
|
||||
- SmartWAL semantics (future implementation behind the same `LogicalStorage` interface)
|
||||
|
||||
## Default run
|
||||
|
||||
```bash
|
||||
go run ./cmd/sparrow
|
||||
```
|
||||
|
||||
Exercises the three canonical recovery paths in one process:
|
||||
|
||||
1. **Healthy** — replica already caught up (R ≥ H), no recovery needed
|
||||
2. **Catch-up** — replica within retained WAL window (R ≥ S, R < H)
|
||||
3. **Rebuild** — replica beyond retained WAL window (R < S)
|
||||
|
||||
Exit code 0 when all three reach `healthy`; 1 otherwise.
|
||||
|
||||
Default output is human-readable text.
|
||||
|
||||
## Machine-readable output
|
||||
|
||||
```bash
|
||||
go run ./cmd/sparrow --json
|
||||
```
|
||||
|
||||
Emits one JSON summary object covering all runs:
|
||||
|
||||
```json
|
||||
{
|
||||
"version": "0.5.0-phase05",
|
||||
"runs": 1,
|
||||
"total": 3,
|
||||
"passed": 3,
|
||||
"failed": 0,
|
||||
"all_passed": true,
|
||||
"results": [
|
||||
{ "run": 1, "name": "healthy", "pass": true, "mode": "healthy", "R": 10, "S": 1, "H": 10 },
|
||||
{ "run": 1, "name": "catch-up", "pass": true, "mode": "healthy", "R": 20, "S": 1, "H": 20 },
|
||||
{ "run": 1, "name": "rebuild", "pass": true, "mode": "healthy", "R": 20, "S": 21, "H": 20 }
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
Failing results carry a `reason` field. Exit code reflects pass/fail.
|
||||
|
||||
## Repeatable validation
|
||||
|
||||
```bash
|
||||
go run ./cmd/sparrow --json --runs 10
|
||||
```
|
||||
|
||||
Repeats the full three-demo sequence N times. A single FAIL in any
|
||||
iteration flips `all_passed` to false and sets a non-zero exit code.
|
||||
|
||||
This is the CI-friendly form: one command, deterministic outcome,
|
||||
machine-readable, exit code tells you if something broke.
|
||||
|
||||
## Read-only HTTP inspection
|
||||
|
||||
```bash
|
||||
go run ./cmd/sparrow --http :9090
|
||||
```
|
||||
|
||||
Starts an HTTP server alongside the demo run. The sparrow runs its
|
||||
three demos first (so there is state to inspect), then keeps the
|
||||
HTTP server alive until `Ctrl+C`.
|
||||
|
||||
| Endpoint | Method | Returns |
|
||||
|---|---|---|
|
||||
| `/` | GET | surface map: scope + list of endpoints + read-only note |
|
||||
| `/status` | GET | version, uptime, scope statement, current demo label |
|
||||
| `/projection` | GET | latest adapter `ReplicaProjection` as JSON |
|
||||
| `/trace` | GET | latest adapter trace as JSON array |
|
||||
| `/watchdog` | GET | latest adapter watchdog lifecycle evidence as JSON array |
|
||||
| `/diagnose` | GET | bounded single-node diagnosis summary over projection / trace / watchdog |
|
||||
| any path | POST/PUT/PATCH/DELETE | 501 Not Implemented + read-only ops-surface body |
|
||||
| unknown path | GET | 404 with a `hint` field pointing to `/` |
|
||||
|
||||
### Example
|
||||
|
||||
```bash
|
||||
# In one shell:
|
||||
go run ./cmd/sparrow --http :9090 &
|
||||
|
||||
# In another:
|
||||
curl -s localhost:9090/ | jq # surface map — start here
|
||||
curl -s localhost:9090/status | jq
|
||||
curl -s localhost:9090/projection | jq
|
||||
curl -s localhost:9090/trace | jq
|
||||
curl -s localhost:9090/watchdog | jq
|
||||
curl -s localhost:9090/diagnose | jq
|
||||
```
|
||||
|
||||
### Invariants enforced at the HTTP layer
|
||||
|
||||
- Every mutation verb returns 501 with a structured body.
|
||||
- No handler calls `engine.Apply` directly; the ops package only reads
|
||||
through `adapter.Projection()` and `adapter.Trace()`.
|
||||
- No handler can choose recovery semantics or redefine `targetLSN`.
|
||||
- The scope statement in `/status` matches the `--help` output exactly.
|
||||
|
||||
## Exit codes
|
||||
|
||||
| Code | Meaning |
|
||||
|---|---|
|
||||
| 0 | All demos / scenarios / persistence checks passed |
|
||||
| 1 | One or more demos failed, or persisted data did not survive restart |
|
||||
| 2 | Usage or flag error |
|
||||
| 3 | Runtime setup failure (e.g. `--http` bind failed; persistence file open / fsync failed) |
|
||||
|
||||
## What the interface is NOT
|
||||
|
||||
- Not a volume manager. There is no `create`, `delete`, `list`, `resize`.
|
||||
- Not a master. Assignment is hardcoded in the sparrow for demo purposes.
|
||||
- Not a frontend. There is no iSCSI / NVMe-oF here.
|
||||
- Not a persistence layer. Everything is in memory; killing the process
|
||||
loses all state, by design.
|
||||
|
||||
Each of these is deliberately out of Phase 05 scope. The eventual
|
||||
production operator experience is `weed shell block.*` per
|
||||
`sw-block/design/v3-operations-design.md` §1.3.
|
||||
@@ -1,101 +0,0 @@
|
||||
# Code Comment Alignment Checklist
|
||||
|
||||
This checklist is for cleaning code comments, script output, and public-facing
|
||||
strings so they match the alpha documentation.
|
||||
|
||||
The goal is not to erase development history. The goal is to avoid confusing
|
||||
external contributors with internal phase names, old gate labels, or comments
|
||||
that imply stale semantics.
|
||||
|
||||
## Scope
|
||||
|
||||
Check these areas first:
|
||||
|
||||
- `cmd/blockmaster`
|
||||
- `cmd/blockvolume`
|
||||
- `cmd/blockcsi`
|
||||
- `core/lifecycle`
|
||||
- `core/authority`
|
||||
- `core/host`
|
||||
- `core/recovery`
|
||||
- `core/replication`
|
||||
- `core/frontend/iscsi`
|
||||
- `deploy/k8s/alpha`
|
||||
- `scripts/run-k8s-alpha.sh`
|
||||
|
||||
## Public-Facing Rule
|
||||
|
||||
Public-facing docs, manifests, CLI help, and alpha scripts should use product
|
||||
language:
|
||||
|
||||
- alpha
|
||||
- blockmaster
|
||||
- blockvolume
|
||||
- blockcsi
|
||||
- lifecycle
|
||||
- authority
|
||||
- recovery
|
||||
- iSCSI
|
||||
- Kubernetes
|
||||
- dynamic PVC
|
||||
|
||||
They should avoid internal planning labels such as gate names, phase numbers, or
|
||||
temporary branch names.
|
||||
|
||||
## Internal Comment Rule
|
||||
|
||||
Internal comments may mention historical test gates only when the reference is
|
||||
needed to explain a pinned invariant. Otherwise prefer the product concept.
|
||||
|
||||
Examples:
|
||||
|
||||
| Prefer | Avoid |
|
||||
|---|---|
|
||||
| dual-lane recovery | G7-redo path |
|
||||
| recovery-aware WAL feeding | hardware-fix path |
|
||||
| alpha Kubernetes smoke path | dynamic-gate path |
|
||||
| authority publisher | product-loop gate |
|
||||
| old-primary fail-closed | stale-fence gate |
|
||||
|
||||
## Semantic Checks
|
||||
|
||||
When updating comments, preserve these design facts:
|
||||
|
||||
- placement intent is not authority
|
||||
- verified placement is not assignment
|
||||
- authority moved is not data continuity proven
|
||||
- frontend fact is not storage readiness
|
||||
- recovery close is not target-LSN crossing
|
||||
- one peer has one WAL-feeding decision owner
|
||||
- old primary must fail closed after supersede
|
||||
- CSI alpha path is iSCSI-first, not NVMe-oF yet
|
||||
- current alpha storage uses `walstore`
|
||||
|
||||
Do not simplify comments in a way that loses these boundaries.
|
||||
|
||||
## Suggested Grep Pass
|
||||
|
||||
Run:
|
||||
|
||||
```bash
|
||||
rg "P15|G15|G9|G8|G7|Phase 15|g7-debug|targetLSN|target LSN" README.md docs deploy scripts cmd core
|
||||
```
|
||||
|
||||
Classify each hit:
|
||||
|
||||
- public-facing leak: fix now
|
||||
- internal invariant reference: keep or rewrite to product language
|
||||
- old debug log: put behind a flag or rename when touching that module
|
||||
- stale semantic wording: fix with a small test if behavior is affected
|
||||
|
||||
## Done Criteria
|
||||
|
||||
This cleanup is done when:
|
||||
|
||||
- `README.md`, `docs/architecture.md`, `docs/roadmap.md`, and
|
||||
`deploy/k8s/alpha/README.md` contain no internal gate names
|
||||
- alpha script output does not require internal history to understand
|
||||
- code comments near lifecycle/authority/recovery use current vocabulary
|
||||
- any kept internal references have a clear reason
|
||||
- tests still pass for the touched packages
|
||||
|
||||
@@ -1,111 +0,0 @@
|
||||
# Data Sync Institution
|
||||
|
||||
The data-sync institution is the bounded layer that moves bytes
|
||||
between primary and replica during catch-up and rebuild. It owns
|
||||
the wire protocol, the lineage gate, and the achieved-frontier
|
||||
report. It does not own recovery classification, session lifecycle
|
||||
policy, failover decisions, or operator-facing publication.
|
||||
|
||||
This doc names what the institution owns, what it does not, and
|
||||
what is explicitly carried forward to later phases.
|
||||
|
||||
## Files
|
||||
|
||||
| File | Role |
|
||||
|---|---|
|
||||
| `core/transport/protocol.go` | Wire format: message types, `RecoveryLineage`, `ShipEntry`, `ProbeResponse`, encoders / decoders |
|
||||
| `core/transport/barrier.go` | Typed `BarrierResponse{AchievedLSN}`, `sendBarrierReq`, `recvBarrierResp` |
|
||||
| `core/transport/executor.go` | Session lifecycle (register / attach conn / invalidate / finish), probe path |
|
||||
| `core/transport/catchup_sender.go` | Primary-side catch-up byte movement |
|
||||
| `core/transport/rebuild_sender.go` | Primary-side rebuild byte movement |
|
||||
| `core/transport/replica.go` | Replica-side per-message-type handlers, lineage gate |
|
||||
|
||||
The split is deliberate: each sender owns its own ship loop so the
|
||||
two protocols stay distinct on the page, even though their inner
|
||||
loops look similar today.
|
||||
|
||||
## What the Institution Owns
|
||||
|
||||
1. **Byte movement** — sending blocks from primary store to replica
|
||||
store, in deterministic LBA order.
|
||||
2. **Wire protocol** — frame types, encoders, decoders, length
|
||||
prefixes, lineage tuple serialization.
|
||||
3. **Lineage gate** — `acceptMutationLineage` rejects any mutating
|
||||
frame whose lineage is less authoritative than the currently
|
||||
active one, or whose required fields are zero.
|
||||
4. **Achieved-frontier report** — every barrier exchange returns a
|
||||
typed `BarrierResponse{AchievedLSN}`. The replica reports what
|
||||
`Sync()` actually returned; the primary returns that value
|
||||
verbatim to the engine.
|
||||
5. **Per-conn deadlines** — every recovery write and read sets a
|
||||
bounded deadline so a silent peer cannot park the sender.
|
||||
6. **Cancel / invalidation** — `InvalidateSession` closes the conn
|
||||
directly so a parked `ReadMsg` unblocks immediately rather than
|
||||
waiting for TCP timeout.
|
||||
7. **Probe** — observation-only request/response that returns the
|
||||
replica's R/S/H boundaries. Carries no lineage, never mutates.
|
||||
|
||||
## What the Institution Does NOT Own
|
||||
|
||||
The following belong to later phases. The data-sync institution
|
||||
must not silently absorb them:
|
||||
|
||||
| Concern | Owner | Why not here |
|
||||
|---|---|---|
|
||||
| Choosing catch-up vs rebuild | engine (P9 inherits) | semantic policy, not byte movement |
|
||||
| Session start / cancel / complete lifecycle as semantic events | P10 | execution lifecycle, not data plane |
|
||||
| Timeout / retry policy across sessions | P10 | lifecycle decision, not per-write deadline |
|
||||
| Live WAL streaming during rebuild | P10 / P12 | requires lifecycle states the data plane has no business knowing |
|
||||
| Resumable rebuild with bitmap progress | P10 / P12 | progress state outlives a single byte-movement run |
|
||||
| Fan-out to N replicas (RF≥3) | P12 | replicated topology, not single-replica byte movement |
|
||||
| Promotion / demotion / failover selection | P14 | topology authority |
|
||||
| Epoch minting | P14 | topology authority — engine consumes, P14 produces |
|
||||
| Operator-facing health publication | P15 | governance surface |
|
||||
|
||||
## Fail-Closed Contract
|
||||
|
||||
The institution's fail-closed contract — proven in
|
||||
`core/transport/failclosed_test.go`:
|
||||
|
||||
| Scenario | Property proven |
|
||||
|---|---|
|
||||
| Overlapping sessions | A higher-lineage session bumps `activeLineage`; subsequent frames from the older session are rejected at the data plane |
|
||||
| Primary crash mid-rebuild | A subsequent higher-lineage session converges; achieved frontier reflects the new session, data matches the new primary |
|
||||
| Replica disconnects before BarrierResp | Primary surfaces `Success=false` with `AchievedLSN=0`; never fabricates a frontier |
|
||||
| Stale Ship after newer Rebuild | Cross-message-type lineage check rejects the stale Ship even though Rebuild was the lineage source |
|
||||
| Probe during rebuild | Probe is observation only; does not disturb `activeLineage`; subsequent rebuild frames continue to be accepted |
|
||||
|
||||
The barrier wire contract — proven in
|
||||
`core/transport/barrier_test.go`:
|
||||
|
||||
- `BarrierResponse` roundtrip preserves `AchievedLSN` exactly.
|
||||
- A short barrier payload returns an error; the primary cannot
|
||||
fabricate a frontier on a malformed reply.
|
||||
|
||||
## Reading Order
|
||||
|
||||
For someone new to this institution:
|
||||
|
||||
1. `core/transport/protocol.go` — wire shapes
|
||||
2. `core/transport/barrier.go` — the typed achieved-frontier seam
|
||||
3. `core/transport/replica.go` — `acceptMutationLineage` and the
|
||||
per-message handlers
|
||||
4. `core/transport/catchup_sender.go` and
|
||||
`core/transport/rebuild_sender.go` — primary-side flows
|
||||
5. `core/transport/failclosed_test.go` — the institution's
|
||||
negative-space proof
|
||||
|
||||
## Carry-Forward
|
||||
|
||||
Items the data-sync institution leaves explicitly to later phases:
|
||||
|
||||
- **P10 (recovery execution lifecycle)** — multi-attempt retries,
|
||||
per-session timeout policy, structured session phases
|
||||
(accepted / running / completed / failed) beyond what the wire
|
||||
needs, live-WAL-during-rebuild orchestration.
|
||||
- **P12 (bounded replicated failover contract)** — fan-out to N
|
||||
replicas, rejoin contract, bitmap-based resumable rebuild.
|
||||
- **P14 (topology / failover policy)** — epoch authority, who
|
||||
promotes, when to fail over, replica placement.
|
||||
- **P15 (operator-facing governance surface)** — operator commands
|
||||
for retire / repair / rebalance.
|
||||
@@ -1,136 +0,0 @@
|
||||
# Local Data Process
|
||||
|
||||
The local data process is the bounded execution institution that
|
||||
owns one node's read, write, flush, checkpoint, and recovery
|
||||
mechanics. It lives behind the `LogicalStorage` seam and serves the
|
||||
semantic engine through that seam — without holding any semantic
|
||||
authority itself.
|
||||
|
||||
This doc names what the institution IS, what it owns, what it does
|
||||
NOT own, and what crash model is actually proven against it.
|
||||
|
||||
## What it owns
|
||||
|
||||
| Responsibility | Where it lives | Notes |
|
||||
|---|---|---|
|
||||
| Local read | `WALStore.Read`, `BlockStore.Read`, `smartwal.Store.Read` | Returns current bytes for an LBA. Reads check the dirty map first, fall back to the extent for any LBA the flusher has already drained. |
|
||||
| Local write | `Write` on each implementation | Allocates next LSN, appends to WAL, updates dirty map. NOT durable until Sync returns. |
|
||||
| Local sync | `Sync` on each implementation | Forces the underlying file to disk. The durability boundary. Group-committed across concurrent callers. |
|
||||
| Local flush | `core/storage/flusher.go` | Background goroutine: snapshots dirty map → writes data into extent → fsyncs → advances on-disk checkpoint LSN → drops the flushed entries from the dirty map. |
|
||||
| Local checkpoint | `WALStore.persistCheckpoint` + `superblock.WALCheckpointLSN` | Pinned by the flusher. Recovery skips records whose LSN ≤ checkpoint. |
|
||||
| Local recover | `WALStore.Recover` + `core/storage/recovery.go` | Replays WAL records past the checkpoint into the dirty map. Defensive past-head scan picks up writes that landed after the last superblock update. Idempotent. |
|
||||
|
||||
## What it does NOT own
|
||||
|
||||
The institution is execution, not authority. It must never:
|
||||
|
||||
- decide recovery class (`catch_up` vs `rebuild`) — that's the engine
|
||||
- decide mode transitions (`healthy` / `recovering` / `degraded`) — that's the engine
|
||||
- emit engine commands or interpret events
|
||||
- read engine projection as control input
|
||||
- redefine `targetLSN` — the engine sets it, storage honors it
|
||||
|
||||
Specifically: the local data process exposes `Boundaries() (R, S, H)`
|
||||
so the engine can reason about durability/retention/head, but the
|
||||
**interpretation** of those numbers belongs to the engine. The
|
||||
storage just reports them.
|
||||
|
||||
## Crash model — what is actually proven
|
||||
|
||||
The institution is proven against the following abrupt-termination
|
||||
windows. "Abrupt termination" means the file handle is dropped
|
||||
without going through `Close()` — no implicit fsync, no superblock
|
||||
update, no graceful flusher drain.
|
||||
|
||||
### `WALStore` (regular WAL+extent backend)
|
||||
|
||||
| Crash window | Tested by | What survives |
|
||||
|---|---|---|
|
||||
| Pre-Sync (writes returned, Sync not called) | `TestCrashFamily_AbruptKillAtMultipleWindows/kill_pre_sync` | Nothing required. Acked = none. |
|
||||
| Post-Sync, pre-flush | `kill_post_sync_pre_flush` | All Sync'd writes (recovered from WAL on Recover) |
|
||||
| Post-flush (data in extent, checkpoint advanced) | `kill_post_flush` | All flushed writes (extent direct on read; recovery skips checkpointed records) |
|
||||
| Post-flush + further unacked writes | `kill_post_flush_then_more_unacked_writes` | Flushed writes always; further unacked writes may or may not survive but never corrupt acked data |
|
||||
|
||||
### `smartwal.Store` (extent-direct backend)
|
||||
|
||||
SmartWAL has fewer windows because there is no separate flush step
|
||||
— writes go directly to extent, and one fsync per Sync covers both
|
||||
the extent and the metadata ring.
|
||||
|
||||
| Crash window | Tested by | What survives |
|
||||
|---|---|---|
|
||||
| Pre-Sync (writes returned, Sync not called) | `TestSmartWAL_CrashFamily_AbruptKillAtMultipleWindows/kill_pre_sync` | Nothing required. Reads return either the written bytes (if extent pwrite reached disk) or zeros. |
|
||||
| Post-Sync (writes + Sync, then kill) | `kill_post_sync` | All Sync'd writes |
|
||||
| Acked + later unacked overwrite of the same LBA | `kill_after_acked_then_unacked_overwrite` | LBA reads either the acked bytes (A) or the unacked-overwrite bytes (B) — never garbage, never another LBA's data. **Failure-atomicity claim verified.** |
|
||||
|
||||
For every window:
|
||||
|
||||
- **Acked writes survive.** A write whose enclosing `Sync()` returned
|
||||
with no error is recoverable.
|
||||
- **Unacked writes never corrupt acked data.** A pre-Sync write that
|
||||
survives the crash returns its written bytes; a pre-Sync write that
|
||||
doesn't survive returns the LBA's prior bytes (zeros if never
|
||||
written before). Never garbage, never another LBA's bytes.
|
||||
- **Recovery is deterministic.** Two Reopen+Recover cycles on the
|
||||
same on-disk state produce identical results. Verified by
|
||||
`TestRecovery_DeterministicAcrossMultipleOpens`.
|
||||
|
||||
## Crash model — what is NOT proven
|
||||
|
||||
These are intentional boundary choices. None are implied by the
|
||||
"acked writes survive" claim:
|
||||
|
||||
- **Power loss with disabled write cache.** We rely on `fsync`
|
||||
semantics holding at the OS+device boundary. If the device has a
|
||||
volatile write cache and `fsync` doesn't flush it (cache-lying
|
||||
device or misconfigured controller), acked writes can still be
|
||||
lost. Mitigation lives at the device-management layer
|
||||
(write-cache disable / FUA), not in this code.
|
||||
- **Distributed durability.** Single-node only. Replication and
|
||||
cross-node ack live in `core/transport`; this doc and these
|
||||
tests do not cover them.
|
||||
- **Bit rot / silent data corruption from the device.** We CRC each
|
||||
WAL record but do not CRC the extent itself. A surface-level
|
||||
bit flip in the extent goes undetected at this layer.
|
||||
- **Network partition / shared-storage races.** Out of scope.
|
||||
|
||||
## Carry-forward
|
||||
|
||||
| Item | Where it'd land |
|
||||
|---|---|
|
||||
| Extent-side per-block CRC | inside the local data process; would let recovery detect bit rot in the extent |
|
||||
| Compaction (rewrite extent + truncate WAL) | inside the local data process; bounded WAL today via circular buffer + checkpoint + tail advance, but no actual compaction yet |
|
||||
| Raw block device backing | small additive change, see `docs/persistence.md` Backing-store options |
|
||||
| `O_DIRECT` + FUA writes | larger change, brings device-managed durability into our contract |
|
||||
| SmartWAL as a swappable backend | already exists in `core/storage/smartwal/`; adopting it as default would be a separate decision |
|
||||
|
||||
## Interaction with peer institutions (carry-forward)
|
||||
|
||||
The local data process is one of four named execution institutions
|
||||
the architect identifies. The others are deliberately deferred to
|
||||
later phases:
|
||||
|
||||
| Institution | What it would own | Currently lives as |
|
||||
|---|---|---|
|
||||
| **DataCommunicator** | replication + rebuild data movement | informally in `core/transport` |
|
||||
| **RecoveryExecutor** | command execution lifecycle (StartCatchUp / StartRebuild / session close handling) | `core/adapter` (`VolumeReplicaAdapter`) |
|
||||
| **ProgressFeed** | typed progress/trace surface separate from `engine.TraceEntry` | every consumer reads `adapter.Trace()` ad hoc |
|
||||
|
||||
Naming and tightening these is future work. The local data process
|
||||
is bounded today and the seam (`LogicalStorage`) is correct, so the
|
||||
others can be carved out independently when their phase arrives.
|
||||
|
||||
## How to read the surface from outside
|
||||
|
||||
Anything a caller wants from the local data process goes through
|
||||
`LogicalStorage`. The compile-time assertion `var _ LogicalStorage =
|
||||
(*WALStore)(nil)` (and analogous ones for `BlockStore` and
|
||||
`smartwal.Store`) is the source of truth: a backend either satisfies
|
||||
the seam or does not. There is no other way in.
|
||||
|
||||
Specifically: the flusher is an **internal** detail of the
|
||||
implementation. Callers do not invoke it, do not configure it, do
|
||||
not see it. It runs because the institution needs to keep its WAL
|
||||
bounded and its checkpoint current. Diagnostic accessors like
|
||||
`WALStore.CheckpointLSN()` and `WALStore.FlushCount()` exist for
|
||||
tests and observability but are not part of `LogicalStorage`.
|
||||
@@ -10,18 +10,14 @@ This directory contains public and technical documentation.
|
||||
| `developer-architecture.md` | Deeper module-by-module architecture for contributors. |
|
||||
| `runtime-state-machines.md` | Mermaid state-machine and loop overview. |
|
||||
| `roadmap.md` | Alpha roadmap and non-claims. |
|
||||
| `qa-alpha-developer-test.md` | QA task for testing the public alpha as a new developer. |
|
||||
| `comment-alignment-checklist.md` | Checklist for keeping comments and public strings aligned with current vocabulary. |
|
||||
|
||||
## Historical / Design Notes
|
||||
## Calibration Evidence
|
||||
|
||||
Older files in this directory capture earlier design stages, audits, and
|
||||
calibration notes. They are useful for archaeology, but new contributors should
|
||||
start with the public/contributor docs above.
|
||||
`calibration/` contains evidence documents still referenced by calibration code.
|
||||
Keep them here until those references move to the shared design archive.
|
||||
|
||||
## Documentation Rule
|
||||
|
||||
If a document is meant for external users, avoid internal phase or gate labels.
|
||||
If a document is historical, keep the history but do not link it as the primary
|
||||
onboarding path.
|
||||
|
||||
Historical design notes should live in `sw-block/design/`, not in this public
|
||||
docs entry path.
|
||||
@@ -1,134 +0,0 @@
|
||||
# P14 S2 — Scoped Audit (Authority Path)
|
||||
|
||||
This is the audit note for P14 S2. It is pure observation of the V3
|
||||
repo at the time of writing. No design here, no code. The design note
|
||||
is `p14-s2-design.md`.
|
||||
|
||||
The audit answers five questions about how `assignment` / `epoch` /
|
||||
`endpointVersion` travel through the system today, plus a sixth about
|
||||
which V2 pieces are mechanically portable to V3.
|
||||
|
||||
## Sharpened constraints honored in the audit
|
||||
|
||||
1. S2 is *authoritative publication*, not policy source. Findings are
|
||||
tagged mechanism vs policy-shaped.
|
||||
2. Authority must be a system-owned route. Findings explicitly flag
|
||||
hidden-operator-path smells (renamed test helper, CLI/admin manual
|
||||
entry, volume-local convenience path).
|
||||
3. The architect's owner-placement bias is thin-control-plane layer
|
||||
outside the volume body — NOT inside adapter or volume server.
|
||||
4. V2 port inventory splits `portable-mechanism` vs `policy-tangled`.
|
||||
|
||||
## Q1 — Producers of `assignment` / `epoch` / `endpointVersion`
|
||||
|
||||
**Real-system code.** None today. There is no production path in V3
|
||||
that mints or observes an assignment from outside the process.
|
||||
|
||||
- `engine.applyAssignment` mutates identity at `core/engine/apply.go:171-174`
|
||||
but only after the adapter has already normalized an `AssignmentInfo`
|
||||
coming from *some* caller. Today, the callers are all tests.
|
||||
- `engine.applyProbeSucceeded` binds observed endpoint/transport epoch
|
||||
at `core/engine/apply.go:258-259`. This observes what the transport
|
||||
reports, not a minted truth.
|
||||
- `engine.applyFenceCompleted` bumps internal `FencedEpoch` at
|
||||
`core/engine/apply.go:509`. Internal gate, not authority.
|
||||
|
||||
**Test / scenario code.**
|
||||
|
||||
- `harness.assign(epoch, endpointVersion)` in
|
||||
`core/calibration/harness.go:87-92`.
|
||||
- Scenario driver in `core/calibration/scenarios.go:64`.
|
||||
- Declarative conformance via `core/conformance/cases.yaml`, decoded
|
||||
by `core/schema/convert.go:13-20`.
|
||||
- Adapter unit tests at `core/adapter/adapter_test.go` (many call
|
||||
sites) construct `AssignmentInfo` inline.
|
||||
|
||||
**Hidden-operator-path candidates.** None. The ops HTTP surface is
|
||||
read-only: mutation verbs rejected at `core/ops/server.go:46-63`. There
|
||||
is no CLI flag, admin endpoint, or debug hook in `cmd/sparrow/main.go`
|
||||
that mints or modifies epoch / assignment.
|
||||
|
||||
## Q2 — Publishers
|
||||
|
||||
No multi-subscriber publisher exists. Every site calls
|
||||
`VolumeReplicaAdapter.OnAssignment(...)` directly
|
||||
(`core/adapter/adapter.go:103-105`). No registry, bus, store, or
|
||||
watcher. This is greenfield for the publication path.
|
||||
|
||||
## Q3 — Consumers beyond the adapter
|
||||
|
||||
- Transport executor embeds epoch in outbound `RecoveryLineage`:
|
||||
`core/transport/executor.go:75-86`.
|
||||
- Transport replica validates lineage epoch on inbound:
|
||||
`core/transport/replica.go:186`.
|
||||
- Ops `/projection` surfaces epoch / endpointVersion read-only:
|
||||
`core/ops/handlers.go:45-48`, `core/engine/projection.go:20-26`.
|
||||
- Storage does NOT embed assignment in persisted state. (V2
|
||||
`weed/storage/blockvol/blockvol.go:71-72` persists epoch for fencing;
|
||||
V3 does not.)
|
||||
|
||||
No policy-adjacent reader exists.
|
||||
|
||||
## Q4 — Test-injection / manual-driving inventory
|
||||
|
||||
All three recognized paths:
|
||||
|
||||
- Calibration scenarios (`harness.assign`).
|
||||
- Conformance YAML cases.
|
||||
- Adapter and mock tests.
|
||||
|
||||
Hidden-operator-path screen: clean.
|
||||
|
||||
- No test helper wears a production name.
|
||||
- No CLI / admin API accepts an `AssignmentInfo`.
|
||||
- No `vol.SetEpoch()` convenience shortcut exists inside the adapter
|
||||
or engine that bypasses the assignment ingress.
|
||||
|
||||
Because there is no hidden-operator-path today, S2 does *not* have a
|
||||
demotion problem. It has a **build-the-real-route** problem.
|
||||
|
||||
## Q5 — Existing authority-adjacent surfaces
|
||||
|
||||
None in V3. The categorization below applies the owner-placement bias:
|
||||
|
||||
| Existing surface | Category | Why |
|
||||
|---|---|---|
|
||||
| `engine` | Not an authority | Pure reducer. Accepts events. Not a decision owner. |
|
||||
| `adapter` | Volume-local-shaped affordance | Sits inside sparrow volume body; owns local ingress. Using it as the authority owner would conflate topology authority with replica-local execution — explicitly NOT preferred. |
|
||||
| `ops` (read-only) | Read-only inspection | Rejects mutations. Not a control path. |
|
||||
| (new thin control-plane layer) | Control-plane-shaped gap | Preferred S2 landing spot. Greenfield. |
|
||||
|
||||
S2 must create a new thin layer outside the volume body.
|
||||
|
||||
## Q6 — V2 port inventory
|
||||
|
||||
Source: `C:\work\seaweedfs`.
|
||||
|
||||
| V2 piece | File | Category | Note |
|
||||
|---|---|---|---|
|
||||
| `BlockVolumeHeartbeatCollector` | `weed/server/block_heartbeat_loop.go:16-34` | portable-mechanism | Status aggregation + assignment fetch loop. No policy. |
|
||||
| `SetAssignmentSource()` | `weed/server/block_heartbeat_loop.go:67-71` | portable-mechanism | Callback wire-up. Pure mechanism. |
|
||||
| `ProcessBlockVolumeAssignments()` | `weed/storage/store_blockvol.go:129-145` | portable-mechanism | Per-volume apply. Mechanism only. |
|
||||
| `BlockVolumeAssignment` struct | `weed/storage/blockvol/block_heartbeat.go:49-61` | portable-mechanism | Data shape (epoch, role, replica addrs). |
|
||||
| `BlockVolumeInfoMessage` struct | `weed/storage/blockvol/block_heartbeat.go:10-38` | portable-mechanism | Heartbeat message shape. |
|
||||
| `vol.SetEpoch()` / `vol.SetRole()` | `weed/storage/blockvol/blockvol.go:71-74` | portable-mechanism | Low-level bind. Mechanism only if authority is outside. |
|
||||
| `HandleAssignment()` | `weed/storage/blockvol/promotion.go:19-69` | policy-tangled | Inline promotion/demotion decision, shipper stop, lease revoke. Volume-local convenience ownership. **Do not port.** |
|
||||
| `promote()` / `demote()` | `weed/storage/blockvol/promotion.go:71-137` | policy-tangled | Role state machine with drain semantics. **Do not port.** |
|
||||
|
||||
## Summary
|
||||
|
||||
- **V3 is additive-greenfield for authority.** No pre-existing path to
|
||||
dismantle, no hidden operator surface to demote.
|
||||
- **Publication is also greenfield.** S2 must invent a real
|
||||
publication route — a system-owned layer that calls
|
||||
`adapter.OnAssignment(...)` on subscribers, replacing today's
|
||||
test-only call sites with a genuine producer.
|
||||
- **V2 port scope is limited to shapes and low-level bind
|
||||
machinery.** The V2 promotion/demotion state machine is
|
||||
policy-tangled and does not belong in S2.
|
||||
- **Owner lands outside the volume body.** The architect's bias maps
|
||||
cleanly onto the greenfield shape.
|
||||
|
||||
S2 builds exactly one new thing and does not disturb any existing
|
||||
path: a thin authority publisher that adapters subscribe to and
|
||||
consume via the existing `OnAssignment` ingress.
|
||||
@@ -1,197 +0,0 @@
|
||||
# P14 S2 — Closure (what S2 closed, what belongs to S3)
|
||||
|
||||
This note records exactly what landed in S2, exactly what stayed out,
|
||||
and where the boundary with S3 sits. It is intended to be stable:
|
||||
future phases must not quietly widen S2's scope after the fact.
|
||||
|
||||
The audit note is `p14-s2-audit.md`. The design note is
|
||||
`p14-s2-design.md`. They are unchanged by this closure.
|
||||
|
||||
## What S2 closed
|
||||
|
||||
1. **A system-owned publication route for assignment truth.** The
|
||||
new package `core/authority/` hosts a `Publisher` that authors
|
||||
`adapter.AssignmentInfo` values and fans them out to subscribers
|
||||
keyed by `(VolumeID, ReplicaID)`. The publisher is the only
|
||||
production code in V3 that constructs an `AssignmentInfo` with a
|
||||
non-zero `Epoch`.
|
||||
|
||||
2. **Ack-gated authorship of `Epoch` and `EndpointVersion`.** The
|
||||
only input to the publisher is a narrow `AssignmentAsk`
|
||||
(`VolumeID`, `ReplicaID`, `DataAddr`, `CtrlAddr`, `Intent`).
|
||||
Epoch and EndpointVersion are *output*, not input. Directives
|
||||
cannot hand the publisher a preformed epoch.
|
||||
|
||||
3. **Three explicit authoring intents.** `Bind`, `RefreshEndpoint`,
|
||||
`Reassign`. Each has a pinned, table-specified publisher
|
||||
action. Rejected and no-op cases are explicit. Retirement
|
||||
(`Remove`) is deliberately deferred.
|
||||
|
||||
4. **A Directive seam for S3.** `Directive.Next(ctx) AssignmentAsk`
|
||||
is the single upstream interface. The trivial `StaticDirective`
|
||||
ships in S2. S3's failover policy will plug in behind the same
|
||||
interface when it arrives — it will not need to reach into the
|
||||
publisher.
|
||||
|
||||
5. **A Bridge that forwards publisher output to the adapter.** The
|
||||
`Bridge` helper subscribes to a `(VolumeID, ReplicaID)` stream
|
||||
via `Subscribe` (which returns a per-subscription cancel) and
|
||||
forwards each `AssignmentInfo` to the adapter's existing
|
||||
`OnAssignment` ingress. The adapter remains the one and only
|
||||
consumer entry point; no second mutation ingress was added.
|
||||
Per-subscription cancel ensures one Bridge exiting never
|
||||
disconnects other consumers on the same stream.
|
||||
|
||||
5a. **Lossless-for-current-fact delivery.** Per-subscription
|
||||
channels have capacity 1 with overwrite-latest semantics: if a
|
||||
new publication arrives before the subscriber drains the prior
|
||||
one, the publisher replaces the pending stale value with the
|
||||
latest. The subscriber therefore never silently loses the
|
||||
current authoritative state. Intermediate states may be
|
||||
coalesced; for authority truth that is correct (the engine
|
||||
cares about current identity, not interstitial history).
|
||||
|
||||
6. **Closure target met.** The integration test
|
||||
`TestClosureTarget_SparrowReachesHealthyViaAuthorityRoute` in
|
||||
`core/authority/authority_test.go` boots a `Publisher` with a
|
||||
`StaticDirective`, wires a `Bridge` into a real
|
||||
`VolumeReplicaAdapter`, and reaches `Mode == ModeHealthy`
|
||||
without any `harness.assign(...)` call.
|
||||
|
||||
7. **Non-forgeability is enforced by AST-based structural test.**
|
||||
`TestNonForgeability_NoAssignmentInfoMintingOutsideAuthority`
|
||||
parses every production `.go` file in the whole repo (NOT just
|
||||
`core/` — also covers `cmd/` and any future production
|
||||
packages) using `go/ast`. It fails if a file outside the
|
||||
allowlist either (a) constructs `AssignmentInfo` via composite
|
||||
literal with a non-zero `Epoch` or `EndpointVersion` field, or
|
||||
(b) declares a local variable of type `AssignmentInfo` (the
|
||||
classic bypass shape: `var x AssignmentInfo; x.Epoch = input`).
|
||||
Allowlist: `core/authority/`, `core/calibration/`,
|
||||
`core/conformance/`, `core/schema/`. Adding a new package to
|
||||
the allowlist is an explicit, reviewable change.
|
||||
|
||||
8. **Sparrow demos migrated to authority route.** The three
|
||||
pre-existing demos in `cmd/sparrow/main.go` (healthy / catch_up
|
||||
/ rebuild) previously minted `AssignmentInfo` with hard-coded
|
||||
epochs directly. After S2 they all route assignment truth
|
||||
through a shared `authority.Publisher`: the `healthy` demo
|
||||
issues an `IntentBind`, the `catch_up` and `rebuild` demos
|
||||
issue `IntentReassign`. No demo code in `cmd/sparrow/main.go`
|
||||
constructs `AssignmentInfo` directly — the non-forgeability
|
||||
test enforces this.
|
||||
|
||||
## What S2 did NOT close
|
||||
|
||||
Explicit non-goals, to avoid future scope drift:
|
||||
|
||||
- **No failover policy.** S2 does not decide who becomes primary,
|
||||
when to promote, when to reassign, or under what conditions.
|
||||
Those are S3.
|
||||
- **No eligibility rules.** S2 does not reason about which replicas
|
||||
are allowed to serve at an epoch.
|
||||
- **No placement or rebalance.** S2 does not choose where replicas
|
||||
go or move them.
|
||||
- **No retirement intent.** `Remove` is deferred. Neither of the
|
||||
possible retirement delivery shapes (channel close vs. a new
|
||||
adapter mutation ingress) fit the S2 boundary.
|
||||
- **No external control API.** There is no HTTP or CLI endpoint
|
||||
that accepts an `AssignmentInfo` or an `AssignmentAsk`. That
|
||||
surface belongs to P15.
|
||||
- **No V2 port of policy-tangled units.** `HandleAssignment()`,
|
||||
`promote()`, `demote()` are NOT imported and will not be ported
|
||||
as copies in any future V3 phase.
|
||||
- **No new engine fact, no new engine command, no new truth
|
||||
domain.** The engine is untouched by S2.
|
||||
- **No new mutation ingress on the adapter.** `OnAssignment` stays
|
||||
the sole consumer entry point.
|
||||
|
||||
## S2 / S3 boundary (table)
|
||||
|
||||
| Question | Owned by | Notes |
|
||||
|---|---|---|
|
||||
| Who publishes assignment truth? | S2 (`authority.Publisher`) | |
|
||||
| How does the adapter receive it? | S2 (`Bridge` → `OnAssignment`) | |
|
||||
| Who *authors* `Epoch` / `EndpointVersion`? | S2 (`Publisher` mints from `Intent`) | Never accepts preformed values. |
|
||||
| When should epoch bump? | S3 | S2's `Directive` is the seam. |
|
||||
| Who is eligible to be primary? | S3 | |
|
||||
| What triggers a failover? | S3 | |
|
||||
| How should replicas be placed or rebalanced? | S3 | |
|
||||
| What retirement looks like on the wire? | S3 / P15 | Deferred. |
|
||||
| What is the external control API? | P15 | |
|
||||
|
||||
## Files added / changed in S2
|
||||
|
||||
Added:
|
||||
|
||||
- `core/authority/directive.go` — `AskIntent`, `AssignmentAsk`,
|
||||
`Directive`, `StaticDirective`, validation errors.
|
||||
- `core/authority/authority.go` — `Publisher`, `Subscribe` (returns
|
||||
per-subscription cancel func), `LastPublished`, `Run`, `Bridge`,
|
||||
`AssignmentConsumer`. No key-wide unsubscribe verb — per-
|
||||
subscription cancel is the only teardown path.
|
||||
- `core/authority/authority_test.go` — 26 tests covering intent
|
||||
semantics, fan-out keyed by `(VolumeID, ReplicaID)`,
|
||||
**independent-unsubscribe**, **lossless-for-current-fact
|
||||
delivery**, **cancel-vs-delivery race (stress test)**,
|
||||
**late-subscriber-under-concurrent-publish ordering**,
|
||||
late-subscriber catch-up, `Run` loop,
|
||||
`RunClosesLiveSubscriptionsOnExit`, `Bridge`, closure target,
|
||||
AST-based non-forgeability including direct bypass-coverage
|
||||
tests for `var x AssignmentInfo`,
|
||||
`x := adapter.AssignmentInfo{}`, and the pointer-form variants
|
||||
`var x = &adapter.AssignmentInfo{}` and
|
||||
`x := &adapter.AssignmentInfo{}`.
|
||||
- `docs/p14-s2-audit.md`, `docs/p14-s2-design.md`, this file.
|
||||
|
||||
Changed:
|
||||
- `cmd/sparrow/main.go`: the three demo sites (healthy / catch_up
|
||||
/ rebuild) migrated from direct `adpt.OnAssignment(...)` to the
|
||||
authority route via a shared `Publisher` + per-demo `Bridge`.
|
||||
This surfaced and fixed the pre-existing "hidden operator path"
|
||||
smell where sparrow was minting epochs outside authority. The
|
||||
non-forgeability test now passes on `cmd/sparrow/main.go`.
|
||||
|
||||
Engine, adapter, transport, ops, and storage are unchanged.
|
||||
|
||||
## How to verify S2 is still closed in a future session
|
||||
|
||||
Run these tests. All must pass. All must continue to pass:
|
||||
|
||||
```
|
||||
go test ./core/authority/ -count=1
|
||||
```
|
||||
|
||||
Specifically:
|
||||
|
||||
- `TestPublisher_Bind_MintsEpochAndEndpointVersion`
|
||||
- `TestPublisher_Bind_RejectsDoubleBind`
|
||||
- `TestPublisher_RefreshEndpoint_BumpsOnlyEndpointVersion`
|
||||
- `TestPublisher_RefreshEndpoint_IdempotentOnSameAddrs`
|
||||
- `TestPublisher_RefreshEndpoint_RejectsUnboundKey`
|
||||
- `TestPublisher_Reassign_BumpsEpochAndResetsEndpointVersion`
|
||||
- `TestPublisher_Reassign_RejectsUnboundKey`
|
||||
- `TestPublisher_Validate_RejectsMissingFields` (six sub-cases)
|
||||
- `TestPublisher_FanOut_TwoSubscribersOnSameKey`
|
||||
- `TestPublisher_IndependentUnsubscribe_OtherPeersUnaffected`
|
||||
- `TestPublisher_FanOut_SubscriberOnOtherVolumeDoesNotReceive`
|
||||
- `TestPublisher_LateSubscriber_ReceivesLastPublished`
|
||||
- `TestPublisher_Cancel_ClosesOnlyThisSubscription`
|
||||
- `TestPublisher_DeliveryConvergesToLatestOnSlowConsumer`
|
||||
- `TestPublisher_CancelDuringDeliveryDoesNotPanic`
|
||||
- `TestPublisher_LateSubscriberReceivesLatestUnderConcurrentPublish`
|
||||
- `TestPublisher_RunClosesLiveSubscriptionsOnExit`
|
||||
- `TestPublisher_Run_DrivesDirectiveUntilCtxCancel`
|
||||
- `TestPublisher_Run_LogsAndContinuesOnRejectedAsk`
|
||||
- `TestBridge_ForwardsToConsumer`
|
||||
- `TestClosureTarget_SparrowReachesHealthyViaAuthorityRoute`
|
||||
- `TestNonForgeability_NoAssignmentInfoMintingOutsideAuthority`
|
||||
- `TestNonForgeability_CatchesShortDeclBypass`
|
||||
- `TestNonForgeability_CatchesVarDeclBypass`
|
||||
- `TestNonForgeability_CatchesPointerShortDeclBypass`
|
||||
- `TestNonForgeability_CatchesPointerVarDeclBypass`
|
||||
|
||||
If the non-forgeability test starts failing because some new
|
||||
production package wants to construct `AssignmentInfo{Epoch: ...}`,
|
||||
the correct response is to route that new site through the
|
||||
authority publisher, not to add a path to the allowlist by reflex.
|
||||
@@ -1,336 +0,0 @@
|
||||
# P14 S2 — Bounded Authority Path (Design Note)
|
||||
|
||||
This is the design note for P14 S2. Scope is deliberately narrow:
|
||||
publish `assignment` / `epoch` / `endpointVersion` through a
|
||||
system-owned route, consumed by the existing adapter ingress. Nothing
|
||||
more.
|
||||
|
||||
The audit note is `p14-s2-audit.md`. Read it first for the factual
|
||||
baseline. This note proceeds on that baseline and commits to a shape.
|
||||
|
||||
## Load-bearing boundaries (do not blur)
|
||||
|
||||
These three statements are the contract of S2. Every piece of code in
|
||||
this phase must be reducible to them.
|
||||
|
||||
1. **S2 owns publication of authority truth.** The package introduced
|
||||
here is *the* place where `assignment` / `epoch` / `endpointVersion`
|
||||
become visible to the rest of the system.
|
||||
2. **S2 does NOT own failover policy.** *Who* becomes primary, *when*
|
||||
to promote, *where* to place replicas, and *how* to rebalance are
|
||||
explicitly NOT in S2. They belong to P14 S3.
|
||||
3. **Engine and adapter remain consumers, not producers, of
|
||||
assignment truth.** Nothing in this phase adds a new engine fact,
|
||||
a new policy ownership inside the engine, or a new mutation ingress
|
||||
inside the adapter. The adapter's `OnAssignment(...)` stays the
|
||||
one and only consumer entry point.
|
||||
|
||||
If a change seems to need more than these three statements, it is not
|
||||
S2.
|
||||
|
||||
## Closure target
|
||||
|
||||
> After S2, sparrow must reach Healthy through a genuine
|
||||
> `authority.Publisher -> adapter.OnAssignment(...)` route, not only
|
||||
> through harness injection.
|
||||
|
||||
That sentence is the acceptance test. Everything else serves it.
|
||||
|
||||
## Package layout
|
||||
|
||||
New package: `core/authority/`.
|
||||
|
||||
Rationale:
|
||||
|
||||
- Outside `cmd/sparrow` and outside `core/adapter` — it is *not* the
|
||||
volume body.
|
||||
- Outside `core/engine` — authority is not a reducer fact.
|
||||
- Sibling to `core/transport`, `core/ops`, `core/storage`. Adapter is
|
||||
the sole connection point.
|
||||
|
||||
Files:
|
||||
|
||||
- `authority.go` — `Publisher` type, subscriber bookkeeping, publish
|
||||
semantics.
|
||||
- `directive.go` — `Directive` input interface + a trivial
|
||||
`StaticDirective` implementation (bounded producer policy source,
|
||||
see below).
|
||||
- `authority_test.go` — unit tests for publication and consumption.
|
||||
|
||||
## Input type — narrower than `AssignmentInfo`
|
||||
|
||||
A `Directive` does NOT hand the publisher an `AssignmentInfo`. It
|
||||
hands the publisher an `AssignmentAsk` — a request for the publisher
|
||||
to perform authorship. Epoch and EndpointVersion are deliberately
|
||||
absent; they are not input, they are output.
|
||||
|
||||
```
|
||||
type AssignmentAsk struct {
|
||||
VolumeID string // required
|
||||
ReplicaID string // required
|
||||
DataAddr string // required (may change to request an endpoint bump)
|
||||
CtrlAddr string // required
|
||||
Intent AskIntent // Bind | RefreshEndpoint | Reassign
|
||||
}
|
||||
|
||||
type AskIntent int // see "Authoring rules" below
|
||||
```
|
||||
|
||||
S2 ships exactly three intents: `Bind`, `RefreshEndpoint`, `Reassign`.
|
||||
A fourth obvious intent — `Remove` / retirement — is intentionally
|
||||
omitted. Retirement would need a second delivery shape (either a
|
||||
channel close that the subscriber must interpret, or a new
|
||||
`adapter.OnRemoval`-style mutation ingress), and both options expand
|
||||
the S2 boundary: the first makes the subscription contract carry
|
||||
semantics beyond "the next fact", the second opens a second
|
||||
authority-to-adapter mutation path in violation of boundary #3
|
||||
(the adapter's `OnAssignment(...)` is the one and only consumer
|
||||
entry point). The S2 closure target — sparrow reaches Healthy via
|
||||
the real publication route — does not require retirement, so S2
|
||||
ships without it. Retirement is a later-phase concern and will be
|
||||
designed alongside the S3 policy seam.
|
||||
|
||||
`Intent` is the only control knob the directive has. The publisher
|
||||
then decides which authoritative field to advance and by how much.
|
||||
This is the seam by which S3 will later ask the publisher to bump
|
||||
epoch without S3 ever constructing the epoch itself.
|
||||
|
||||
## Authoring rules — the publisher is the minter
|
||||
|
||||
The publisher owns a monotonic counter keyed by `(VolumeID,
|
||||
ReplicaID)`. Given an `AssignmentAsk` it decides as follows:
|
||||
|
||||
| `Intent` | Precondition | Publisher action | Emitted `AssignmentInfo` |
|
||||
|---|---|---|---|
|
||||
| `Bind` | No prior publish for this `(vid, rid)` | mint `Epoch=1`, `EndpointVersion=1` | fresh |
|
||||
| `Bind` | Prior publish exists | reject (directive bug) | none |
|
||||
| `RefreshEndpoint` | Prior publish exists; addrs differ | keep `Epoch`, bump `EndpointVersion` | same epoch, new EV |
|
||||
| `RefreshEndpoint` | Prior publish exists; addrs identical | no-op (idempotent) | none |
|
||||
| `Reassign` | Prior publish exists | bump `Epoch`, reset `EndpointVersion=1` | new epoch |
|
||||
|
||||
Rejected or no-op directives do not mutate state and do not fan out.
|
||||
|
||||
The publisher NEVER accepts a preformed epoch or endpointVersion from
|
||||
any caller. The only knob is `Intent`. This is what makes the publisher
|
||||
a real author rather than a relay.
|
||||
|
||||
## Who can construct an `AssignmentInfo`
|
||||
|
||||
Only `core/authority/` may construct an `AssignmentInfo` with
|
||||
`Epoch > 0` in a production path. Enforcement is twofold:
|
||||
|
||||
1. `AssignmentInfo` stays in `core/adapter` as it is today (it is
|
||||
the adapter's ingress shape). The authority package is the only
|
||||
production package that constructs one.
|
||||
2. A package-level test in `core/authority/` audits every
|
||||
production `.go` file in the whole repo (not just `core/`)
|
||||
using `go/ast`. It fails if a file outside the allowlist either
|
||||
(a) constructs `adapter.AssignmentInfo` via composite literal
|
||||
with a non-zero `Epoch` or `EndpointVersion`, or (b) declares a
|
||||
local variable — `var x`, `var x = X{...}`, or `x := X{...}`,
|
||||
including pointer forms (`&X{...}`) — whose declared or
|
||||
inferred type is `AssignmentInfo`. Case (b) closes the
|
||||
deferred-mutation bypass (`var x AssignmentInfo; x.Epoch = v`).
|
||||
Test helpers (`_test.go` files) are exempt, and the
|
||||
test-infrastructure packages `core/calibration/`,
|
||||
`core/conformance/`, `core/schema/` are explicitly allowlisted.
|
||||
|
||||
## Publication API — no public write verb
|
||||
|
||||
The publisher exposes three verbs, none of which accept an
|
||||
`AssignmentInfo`:
|
||||
|
||||
- `Subscribe(volumeID, replicaID string) (<-chan AssignmentInfo, func())`
|
||||
— a consumer registers interest in authoritative assignments for
|
||||
a specific `(VolumeID, ReplicaID)`. Returns a receive channel and
|
||||
a **per-subscription** cancel function. Each cancel closes only
|
||||
its own subscription's channel; other live subscriptions on the
|
||||
same `(vid, rid)` are untouched. Cancel is idempotent.
|
||||
- `LastPublished(volumeID, replicaID string) (AssignmentInfo, bool)`
|
||||
— read-only inspection of the last emitted fact for a key.
|
||||
- `Run(ctx)` — drive the publisher: consume `AssignmentAsk` values
|
||||
from the directive, apply the authoring rules above, fan out to
|
||||
subscribers. One goroutine. Stops on ctx cancel. On exit, every
|
||||
live subscription channel is closed so Bridges observe end of
|
||||
stream.
|
||||
|
||||
What the publisher will NOT expose:
|
||||
|
||||
- No `PublishAssignment(AssignmentInfo)`. Removed. Its earlier
|
||||
presence let callers forge authoritative truth.
|
||||
- No key-wide `Unsubscribe(vid, rid)`. Removed. A key-wide teardown
|
||||
would let one Bridge exiting silently disconnect other live
|
||||
consumers on the same stream — the architect caught this;
|
||||
per-subscription cancel is the fix.
|
||||
- No `SetEpoch(...)`, no `ForcePromote(...)`, no per-replica
|
||||
health reads, no placement hints, no rebalance verbs.
|
||||
|
||||
### Delivery semantics — lossless for the current fact
|
||||
|
||||
Per-subscription channels have capacity 1. When the publisher
|
||||
authors a new `AssignmentInfo` and a subscriber has not yet drained
|
||||
the previous one, the publisher **overwrites** the pending stale
|
||||
value with the latest. The subscriber therefore always reads the
|
||||
LATEST authoritative state on its next drain — never silently loses
|
||||
the current fact.
|
||||
|
||||
Intermediate states between two consumer drains may be coalesced.
|
||||
For authority truth this is the correct semantic: the engine cares
|
||||
about current identity, not interstitial history. A subscriber that
|
||||
cares about state transitions should use `LastPublished` plus its
|
||||
own change-detection — but for driving the adapter's
|
||||
`OnAssignment`, the latest fact is sufficient (monotonic guards in
|
||||
the engine accept it).
|
||||
|
||||
This replaces the earlier "drop on full with only a log line"
|
||||
delivery, which could leave a subscriber on stale truth until an
|
||||
unrelated later ask happened.
|
||||
|
||||
## Directive interface
|
||||
|
||||
```
|
||||
type Directive interface {
|
||||
Next(ctx context.Context) (AssignmentAsk, error)
|
||||
}
|
||||
```
|
||||
|
||||
The trivial S2 implementation is `StaticDirective` — a pre-wired
|
||||
sequence of `AssignmentAsk` values set by process configuration,
|
||||
typically one `Bind` per replica at startup for the closure target.
|
||||
|
||||
What is explicitly NOT in scope for any `Directive` implementation
|
||||
in S2:
|
||||
|
||||
- No eligibility rules ("is replica X allowed to be primary").
|
||||
- No promotion triggers ("promote when primary fails").
|
||||
- No failover orchestration ("advance everyone's epoch on quorum
|
||||
loss").
|
||||
- No placement or rebalance ("pick the least-loaded node").
|
||||
|
||||
All four belong to S3. The `Directive` + `AssignmentAsk.Intent`
|
||||
pair is the seam where S3 will plug in real policy. S2 ships only
|
||||
`StaticDirective`.
|
||||
|
||||
## Subscriber model
|
||||
|
||||
Adapters subscribe by `(VolumeID, ReplicaID)` at construction. The
|
||||
sparrow main loop wires the adapter to the publisher:
|
||||
|
||||
```
|
||||
pub := authority.NewPublisher(dir)
|
||||
a := adapter.NewVolumeReplicaAdapter(exec)
|
||||
go authority.Bridge(ctx, pub, a, "vol1", "r1")
|
||||
// receives on Subscribe("vol1", "r1"),
|
||||
// calls a.OnAssignment(info)
|
||||
```
|
||||
|
||||
`Bridge` is a thin for-loop: receive, forward, repeat. It has no
|
||||
decision logic. Its only state is "am I still the live subscriber".
|
||||
|
||||
Identity is uniformly `(VolumeID, ReplicaID)` across subscription,
|
||||
authoring, and fanout — fixing the narrow-key bug where same-named
|
||||
replicas across different volumes would have been multiplexed.
|
||||
|
||||
Stale rejection continues to live where it already lives — in
|
||||
`engine.applyAssignment`. The publisher does NOT replicate that logic;
|
||||
it only enforces its own output monotonicity (per authoring rules
|
||||
above) and lets the engine's existing guards handle the rest.
|
||||
|
||||
## V2 port plan (what this commits to)
|
||||
|
||||
From the audit, the V2 portable-mechanism items are:
|
||||
|
||||
- `BlockVolumeAssignment` — useful as a wire *shape* reference. V3
|
||||
`AssignmentInfo` already exists; we may adopt field names from V2
|
||||
for consistency but do not import.
|
||||
- `BlockVolumeInfoMessage` — same. Shape only.
|
||||
- `BlockVolumeHeartbeatCollector` — NOT imported in S2. Its role
|
||||
(periodic status collection) is orthogonal to publication. It may
|
||||
become a subscriber in a later phase.
|
||||
- `ProcessBlockVolumeAssignments` — NOT imported. It is the *volume
|
||||
side* consumer in V2; in V3 that job is the adapter's.
|
||||
|
||||
Policy-tangled items (`HandleAssignment`, `promote`, `demote`) are
|
||||
NOT ported in S2 and will NOT be ported in any subsequent V3 phase as
|
||||
a copy — their behavior, if still needed, will be re-derived from
|
||||
engine commands.
|
||||
|
||||
## What S2 closes vs what stays open
|
||||
|
||||
| Question | S2 answers | S2 does NOT answer |
|
||||
|---|---|---|
|
||||
| Who publishes assignment truth? | `authority.Publisher` | — |
|
||||
| How does the adapter receive it? | via `Subscribe(vid,rid)` → `Bridge` → `OnAssignment` | — |
|
||||
| Who *authors* epoch / endpointVersion? | `Publisher` (mints from `Intent`; never accepts preformed values) | — |
|
||||
| When should epoch bump? | — | S3 |
|
||||
| Who is eligible to be primary? | — | S3 |
|
||||
| What triggers a failover? | — | S3 |
|
||||
| How should replicas be placed or rebalanced? | — | S3 |
|
||||
| What is the external control API? | — | P15 |
|
||||
|
||||
## Test plan (sketch — full tests land in code step)
|
||||
|
||||
- **Publisher is the minter**: a directive issues only `AssignmentAsk`
|
||||
values (no epoch/endpointVersion). After `Run(ctx)` processes them,
|
||||
subscribers observe `AssignmentInfo` with monotonically increasing
|
||||
`Epoch` / `EndpointVersion` authored by the publisher.
|
||||
- **Non-forgeability**: an AST-based structural test parses EVERY
|
||||
production `.go` file across the whole repo (not just `core/`)
|
||||
and fails if a file outside the allowlist either (a) constructs
|
||||
`adapter.AssignmentInfo` via composite literal with non-zero
|
||||
`Epoch` / `EndpointVersion`, or (b) declares a local variable
|
||||
of type `AssignmentInfo` / `*AssignmentInfo` / `[]AssignmentInfo`
|
||||
(the classic bypass shape for deferred mutation). Allowlist:
|
||||
`core/authority/` (minter) and the test-infrastructure packages
|
||||
`core/calibration/`, `core/conformance/`, `core/schema/`. The
|
||||
adapter package itself is NOT in the allowlist — it only names
|
||||
the type in signatures and never declares a local variable of
|
||||
it.
|
||||
- **Fan-out keyed by (VolumeID, ReplicaID)**: two subscribers on the
|
||||
same `(vol1, r1)` both receive. A subscriber on `(vol2, r1)` does
|
||||
NOT receive `vol1`-keyed assignments (regression for the
|
||||
narrow-key bug).
|
||||
- **Intent semantics**: `Bind` on fresh key mints `Epoch=1, EV=1`;
|
||||
`RefreshEndpoint` with changed addrs keeps epoch, bumps EV;
|
||||
`RefreshEndpoint` with unchanged addrs is a no-op; `Reassign`
|
||||
bumps epoch and resets EV to 1; `Bind` on an existing key is
|
||||
rejected.
|
||||
- **Bridge → adapter → engine**: end-to-end assertion that publisher
|
||||
output reaches `ReplicaState.Identity` via the existing ingress,
|
||||
with no additional event type added to the engine.
|
||||
- **Stale rejection unchanged**: engine rejects an older-epoch fact
|
||||
via its existing guard. The publisher does NOT duplicate the
|
||||
check (regression: no silent second rejector).
|
||||
- **Closure target**: a sparrow integration test boots with a
|
||||
`StaticDirective` and reaches `Mode == ModeHealthy` without a
|
||||
single `harness.assign(...)` call.
|
||||
|
||||
## What we are NOT building
|
||||
|
||||
- No admin or CLI mutation surface for assignments.
|
||||
- No V2 heartbeat or V2 HandleAssignment port.
|
||||
- No new engine events, commands, or truth domains.
|
||||
- No promotion / demotion state machine.
|
||||
- No eligibility or placement computation.
|
||||
- No retirement / `Remove` intent. Adding retirement requires a
|
||||
second delivery shape that would either overload subscriptions
|
||||
with lifecycle semantics or open a second mutation ingress on
|
||||
the adapter. Neither fits the S2 boundary. Deferred.
|
||||
|
||||
## Acceptance
|
||||
|
||||
S2 is architect-clean when:
|
||||
|
||||
1. The three load-bearing boundary statements are enforced by the
|
||||
code (no backdoor mutation, no engine/adapter-side production of
|
||||
authority, Directive is the only policy seam).
|
||||
2. The publisher is the minter, not a relay. `Directive.Next`
|
||||
returns `AssignmentAsk` (no epoch / no endpointVersion). No
|
||||
public verb accepts a preformed `AssignmentInfo`. The
|
||||
non-forgeability structural test passes.
|
||||
3. Identity is `(VolumeID, ReplicaID)` uniformly — subscription,
|
||||
authoring state, and fan-out all key by the same unit. The
|
||||
multi-volume fan-out test passes.
|
||||
4. The closure target integration test passes.
|
||||
5. The V2 policy-tangled items listed in the audit remain
|
||||
unimported.
|
||||
@@ -1,301 +0,0 @@
|
||||
# Persistence
|
||||
|
||||
This doc describes the single-node persistence backend in
|
||||
`core/storage/`. It is one implementation behind the `LogicalStorage`
|
||||
interface; the in-memory `BlockStore` is the other. Both satisfy the
|
||||
same contract; tests run against both via a shared factory table so a
|
||||
new backend slots in without test duplication.
|
||||
|
||||
For the broader institutional view of read / write / flush /
|
||||
checkpoint / recover as one bounded execution institution with an
|
||||
explicit crash model and named carry-forward boundaries, see
|
||||
[docs/local-data-process.md](local-data-process.md).
|
||||
|
||||
## What this proves
|
||||
|
||||
1. **Acked writes survive crash.** A write whose enclosing `Sync()`
|
||||
returned with no error is recoverable after a process kill or
|
||||
clean stop. Verified by `TestWALStore_AckedWritesSurviveSimulatedCrash`
|
||||
which simulates a kill by dropping the file handle without going
|
||||
through `Close()`.
|
||||
2. **Recovery is deterministic.** Calling `Recover()` twice on the
|
||||
same on-disk state yields identical results. Verified by
|
||||
`TestWALStore_RecoverIsIdempotent`.
|
||||
3. **Pre-Sync writes can be lost but never corrupted.** A write that
|
||||
completed but was not followed by a successful `Sync()` may or
|
||||
may not be present after recovery. If absent, the LBA reads as
|
||||
zeros. If present, it reads as the bytes that were written —
|
||||
never some other LBA's bytes, never garbage.
|
||||
4. **Boundaries report current truth.** `Boundaries()` returns the
|
||||
live `(R, S, H)` triple — synced LSN, retained-window tail, and
|
||||
newest written LSN — so the engine can classify recovery without
|
||||
the storage taking a position on what those numbers mean.
|
||||
|
||||
## What this does NOT prove
|
||||
|
||||
These are intentional scope choices. The scope statement
|
||||
(`sparrow --help`) lists them as not supported:
|
||||
|
||||
- Distributed durability across nodes. This backend is single-node.
|
||||
- Replicated persistence. The `core/transport` primary→replica path
|
||||
still operates on in-memory stores in the demos and calibration;
|
||||
WAL persistence is admitted as a backend, not adopted as the
|
||||
default everywhere.
|
||||
- SmartWAL semantics. SmartWAL is a future implementation behind the
|
||||
same interface; not part of this slice.
|
||||
- Compaction. The WAL is bounded by configured size, but there is
|
||||
no background defragger that rewrites old extents.
|
||||
- Concurrent writer per LBA. The interface assumes serialized writes
|
||||
per LBA.
|
||||
|
||||
## The interface
|
||||
|
||||
```go
|
||||
type LogicalStorage interface {
|
||||
Write(lba uint32, data []byte) (lsn uint64, err error)
|
||||
Read(lba uint32) ([]byte, error)
|
||||
Sync() (stableLSN uint64, err error)
|
||||
Recover() (recoveredLSN uint64, err error)
|
||||
Boundaries() (R, S, H uint64)
|
||||
NextLSN() uint64
|
||||
NumBlocks() uint32
|
||||
BlockSize() int
|
||||
AdvanceFrontier(lsn uint64)
|
||||
AdvanceWALTail(newTail uint64)
|
||||
ApplyEntry(lba uint32, data []byte, lsn uint64) error
|
||||
AllBlocks() map[uint32][]byte
|
||||
Close() error
|
||||
}
|
||||
```
|
||||
|
||||
Two implementations satisfy it today:
|
||||
|
||||
| Impl | File | Notes |
|
||||
|---|---|---|
|
||||
| `BlockStore` | `core/storage/store.go` | in-memory; default for runnable slice and calibration |
|
||||
| `WALStore` | `core/storage/walstore.go` | WAL+extent, crash-safe; backs `--persist-demo` |
|
||||
|
||||
Adding a third implementation: provide a constructor and add it to
|
||||
`implementations()` in `contract_test.go`. Every contract test runs
|
||||
against it automatically.
|
||||
|
||||
## Execution-layer scope decision
|
||||
|
||||
`LogicalStorage` is the **accepted persistence seam** for this slice.
|
||||
The direction is correct and the contract is honored by both
|
||||
implementations behind it (in-memory `BlockStore` and crash-safe
|
||||
`WALStore`, plus the experimental `smartwal.Store` subpackage). The
|
||||
seam describes what storage IS, not what storage DECIDES.
|
||||
|
||||
Three other named execution institutions are **deliberately deferred**
|
||||
to later phases — not built, not implied as done:
|
||||
|
||||
| Institution | What it would own | Why deferred |
|
||||
|---|---|---|
|
||||
| `DataCommunicator` | replication + rebuild data movement | currently lives informally in `core/transport`; promoting to a named interface needs its own scope |
|
||||
| `RecoveryExecutor` | command execution lifecycle (StartCatchUp / StartRebuild / session close handling) | currently lives in `core/adapter` as `VolumeReplicaAdapter`; the boundary is the right shape but the interface name and method set deserve a dedicated phase |
|
||||
| `ProgressFeed` | a structured progress/trace surface separate from `engine.TraceEntry` | currently every consumer reads `adapter.Trace()` ad hoc; a typed feed would tighten this |
|
||||
|
||||
Recording these here so later phases can pick them up explicitly,
|
||||
not silently inherit "we did this already". The decision matches
|
||||
the architect-defined V3 execution-layer pattern in
|
||||
`v3-phase-development-model.md` §16; this slice closes the storage
|
||||
slot of that pattern only.
|
||||
|
||||
Some `LogicalStorage` methods are **replication-facing today** —
|
||||
`ApplyEntry`, `AllBlocks`, `AdvanceFrontier`, `AdvanceWALTail` — and
|
||||
exist on the seam because the current `core/transport` rebuild
|
||||
path needs them somewhere. When the future `DataCommunicator` seam
|
||||
is named, splitting those methods into a sibling interface
|
||||
(`ReplicationSink` or similar) is a clean follow-up. They satisfy
|
||||
contract tests against both backends today, which is enough for
|
||||
this slice.
|
||||
|
||||
## Storage is not authority
|
||||
|
||||
`LogicalStorage` is execution machinery. It must not:
|
||||
|
||||
- decide recovery class (`catch_up` vs `rebuild`)
|
||||
- decide mode transitions (`healthy` / `recovering` / `degraded`)
|
||||
- emit engine commands or interpret events
|
||||
- read engine projection as control input
|
||||
|
||||
Specifically: `WALStore` exposes `Boundaries() (R, S, H)`, but
|
||||
**interpreting** those boundaries to choose recovery is the engine's
|
||||
job. The engine reads R/S/H via the adapter and classifies; storage
|
||||
just reports them.
|
||||
|
||||
`Recover()` recovers data, not policy. After `Recover()` returns,
|
||||
the engine still has no opinion until an `AssignmentObserved` event
|
||||
lands and the normal route runs.
|
||||
|
||||
## On-disk layout (`WALStore`)
|
||||
|
||||
A `WALStore` is one preallocated file with three regions:
|
||||
|
||||
```
|
||||
[0 .. 4096) superblock
|
||||
[4096 .. 4096+walSize) circular WAL region
|
||||
[4096+walSize .. 4096+walSize+volumeSize) block-indexed extent
|
||||
```
|
||||
|
||||
The superblock records geometry (block size, volume size, WAL size)
|
||||
and a UUID. The WAL is a circular buffer; head/tail are
|
||||
monotonically-increasing logical counters so head==tail unambiguously
|
||||
means empty. The extent is preallocated to hold every addressable
|
||||
block at its natural offset.
|
||||
|
||||
### WAL record format
|
||||
|
||||
Each record is variable-size:
|
||||
|
||||
```
|
||||
prefix (30 bytes):
|
||||
LSN(8) Reserved(8) Type(1) Flags(1) LBA(8) Length(4)
|
||||
data (Length bytes for Write, 0 for Trim/Barrier)
|
||||
trailer (8 bytes):
|
||||
CRC32(4) EntrySize(4)
|
||||
```
|
||||
|
||||
CRC covers prefix + data. The trailer's `EntrySize` lets a torn-write
|
||||
scanner detect mid-record truncation independently of the CRC. The
|
||||
recovery scanner walks the WAL region, validating CRC and
|
||||
`EntrySize`; the first invalid record marks the end of useful data.
|
||||
|
||||
### Read path
|
||||
|
||||
A `Read(lba)`:
|
||||
|
||||
1. Looks up `lba` in the dirty map (sharded for low contention).
|
||||
2. If present: fetches the record from the WAL at the recorded
|
||||
offset and returns the data section.
|
||||
3. If absent: fetches the block from the extent at
|
||||
`extentBase + lba * blockSize`.
|
||||
|
||||
### Write path
|
||||
|
||||
A `Write(lba, data)`:
|
||||
|
||||
1. Allocates the next LSN.
|
||||
2. Encodes a WAL record with that LSN.
|
||||
3. Appends to the circular WAL (the writer handles wrap-around with
|
||||
padding records).
|
||||
4. Updates the dirty map so subsequent reads see the new bytes.
|
||||
5. Returns the LSN — **not** durable yet.
|
||||
|
||||
### Durability
|
||||
|
||||
`Sync()` enqueues an fsync request through the group committer.
|
||||
Concurrent `Sync()` callers are batched into one fsync per
|
||||
millisecond (default), so write throughput scales with concurrency
|
||||
not fsync count. When `Sync()` returns nil, every Write whose LSN is
|
||||
≤ the returned `stableLSN` is on durable media.
|
||||
|
||||
### Recovery
|
||||
|
||||
`Recover()` rebuilds the dirty map from the WAL. It:
|
||||
|
||||
1. Reads the superblock for WAL geometry and head/tail hints.
|
||||
2. Scans the known head→tail range, replaying records past the
|
||||
checkpoint LSN into the dirty map.
|
||||
3. Continues scanning past the recorded head, in case writes landed
|
||||
after the last superblock update — the first invalid CRC stops
|
||||
the extension.
|
||||
|
||||
`Recover()` is idempotent.
|
||||
|
||||
## How to run the demo
|
||||
|
||||
```bash
|
||||
mkdir -p /tmp/sparrow-persist
|
||||
go run ./cmd/sparrow --persist-demo --persist-dir /tmp/sparrow-persist
|
||||
```
|
||||
|
||||
Expected output ends with `result: PASS — all blocks survived restart`.
|
||||
|
||||
For machine-readable evidence:
|
||||
|
||||
```bash
|
||||
go run ./cmd/sparrow --persist-demo --persist-dir /tmp/sparrow-persist --json
|
||||
```
|
||||
|
||||
```json
|
||||
{
|
||||
"path": "/tmp/sparrow-persist/sparrow-persist.dat",
|
||||
"num_blocks": 16,
|
||||
"block_size": 4096,
|
||||
"n_writes": 4,
|
||||
"synced_before_close": 4,
|
||||
"recovered_after_open": 4,
|
||||
"all_matched": true
|
||||
}
|
||||
```
|
||||
|
||||
Exit codes:
|
||||
|
||||
| Code | Meaning |
|
||||
|---|---|
|
||||
| 0 | All blocks round-tripped intact through Sync + Close + Recover |
|
||||
| 1 | One or more blocks did not survive restart |
|
||||
| 2 | Usage / flag error (e.g. missing `--persist-dir`) |
|
||||
| 3 | Runtime error (file create / open / read / write / fsync failed) |
|
||||
|
||||
## Backing-store options (carry-forward)
|
||||
|
||||
The current `WALStore` and `smartwal.Store` both take a `path string`
|
||||
and treat it as a regular file: `Truncate` for preallocation,
|
||||
`O_CREATE|O_EXCL` for create-fresh, kernel page cache for buffering,
|
||||
`fsync` for the durability boundary.
|
||||
|
||||
The `*os.File` API preserves the option of pointing at a raw block
|
||||
device (`/dev/sdb`, `/dev/nvme0n1`, `\\.\PhysicalDriveN` on Windows)
|
||||
without an interface change. Going there is **not** in the current
|
||||
implementation but is **not blocked** by the design. Adding it is a
|
||||
progression of independent steps, each useful on its own.
|
||||
|
||||
| Step | Effort | Net benefit (rough order) |
|
||||
|---|---|---|
|
||||
| File-or-device branch in Create/Open: skip `Truncate`, query device size via seek-to-end / `BLKGETSIZE64` | ~2 h | Works on `/dev/sdb`; still page-cached, still fsync-bound. ~3-5x perf vs filesystem |
|
||||
| Add `O_DIRECT` mode + sector-align WAL records | ~6-8 h | Bypass page cache; predictable latency; ~10x perf |
|
||||
| Use FUA (Force Unit Access) on writes; drop the group committer | ~4-6 h on top of O_DIRECT | Per-write durability without separate fsync; concurrent writers scale linearly; ~20-50x perf |
|
||||
| User-space NVMe (SPDK / vfio-user style) | weeks/months | Dedicated CPU, polling queues; ~100-500x perf; different operational model (pinned cores, hugepages) |
|
||||
|
||||
These are perf-scale changes only — they do not alter the
|
||||
`LogicalStorage` contract. A consumer of `LogicalStorage` cannot
|
||||
tell which backing-store option was chosen, only that the contract
|
||||
is satisfied.
|
||||
|
||||
### NVMe controller features worth tracking
|
||||
|
||||
Modern NVMe devices expose hardware features that simplify and
|
||||
speed up our design once we go device-direct:
|
||||
|
||||
| Feature | What it enables |
|
||||
|---|---|
|
||||
| FUA (Force Unit Access) bit per write | Drop the group committer; per-write durability with no extra syscall |
|
||||
| NVM Atomic Write Unit (often 16KB) | Drop per-record CRC for blocks that fit; hardware guarantees torn-free writes |
|
||||
| T10 PI (8-byte protection info per sector) | End-to-end CRC the device verifies; replaces our application-level CRC for raw devices |
|
||||
| ZNS (Zoned Namespaces) | Append-only zones with GC-aware semantics; perfect substrate for the WAL region |
|
||||
| Multiple submission/completion queues | Lock-free per-writer parallelism |
|
||||
| SR-IOV | Per-volume queue isolation; no noisy-neighbor on hot writers |
|
||||
|
||||
None of these are required for Phase 07 closure. They define the
|
||||
trajectory if and when V3 needs production-class storage performance.
|
||||
|
||||
## Future work behind this seam
|
||||
|
||||
- **Background flusher.** Currently the WAL is the active storage
|
||||
for any LBA that has ever been written; the extent is preallocated
|
||||
but unused except as the fallback for never-written LBAs. A
|
||||
background flusher that drains dirty entries to extent and
|
||||
advances the checkpoint LSN keeps WAL space bounded. The hooks
|
||||
(dirty map, group committer, checkpoint LSN field in the
|
||||
superblock) are already in place.
|
||||
- **SmartWAL backend.** A second `LogicalStorage` implementation
|
||||
with a denser metadata-only WAL record and extent-first writes.
|
||||
No interface change; old data files cannot be read by SmartWAL
|
||||
and vice versa.
|
||||
- **Snapshots.** Out of scope.
|
||||
- **Replicated persistence.** The transport already replicates
|
||||
in-memory; switching the replica side to `WALStore` is a small
|
||||
follow-up.
|
||||
@@ -1,132 +0,0 @@
|
||||
# Alpha Developer QA Test
|
||||
|
||||
This is a QA task for testing the project as if QA were a new external
|
||||
developer. The goal is not to prove every recovery/failover case. The goal is to
|
||||
verify that the public alpha instructions are runnable, understandable, and
|
||||
honest.
|
||||
|
||||
## Test Persona
|
||||
|
||||
Act like a developer who found the repository today and wants to try the
|
||||
Kubernetes alpha.
|
||||
|
||||
Assumptions:
|
||||
|
||||
- no private design docs
|
||||
- no internal gate names
|
||||
- no prior knowledge of the project's history
|
||||
- access to a Linux host or VM with Kubernetes, Docker, and iSCSI tooling
|
||||
|
||||
## Documents Under Test
|
||||
|
||||
Read only these first:
|
||||
|
||||
1. `README.md`
|
||||
2. `deploy/k8s/alpha/README.md`
|
||||
3. `docs/architecture.md`
|
||||
4. `docs/roadmap.md`
|
||||
|
||||
Only open source files or scripts when the public docs tell you to.
|
||||
|
||||
## Primary Run
|
||||
|
||||
From the repository root:
|
||||
|
||||
```bash
|
||||
bash scripts/run-k8s-alpha.sh
|
||||
```
|
||||
|
||||
Expected high-level result:
|
||||
|
||||
- images build or the docs clearly explain how to build/import them
|
||||
- Kubernetes manifests apply cleanly
|
||||
- dynamic PVC is created
|
||||
- pod reaches `Succeeded`
|
||||
- pod log includes `/data/payload.bin: OK`
|
||||
- cleanup leaves no active iSCSI session for the test target
|
||||
- artifact path is printed
|
||||
|
||||
## Required Evidence
|
||||
|
||||
Capture these in the QA report:
|
||||
|
||||
- repository commit SHA
|
||||
- host OS and Kubernetes distribution/version
|
||||
- command run
|
||||
- wall-clock duration
|
||||
- pod final phase
|
||||
- pod log checksum line
|
||||
- blockmaster log path
|
||||
- blockvolume log path
|
||||
- blockcsi log path
|
||||
- `iscsiadm -m session` before and after
|
||||
- cleanup result
|
||||
|
||||
If the command fails, the report must include:
|
||||
|
||||
- first failing command or timeout point
|
||||
- relevant pod describe output
|
||||
- daemon logs if available
|
||||
- whether the failure is documentation, host environment, manifest, or product
|
||||
behavior
|
||||
|
||||
## Usability Checks
|
||||
|
||||
Answer these questions directly:
|
||||
|
||||
- Could a new developer identify prerequisites without asking us?
|
||||
- Did any command expose internal gate names or old branch names?
|
||||
- Did any script output confuse alpha users with internal labels?
|
||||
- Did the README overclaim production readiness?
|
||||
- Did the docs explain iSCSI vs future NVMe-oF clearly?
|
||||
- Did the docs explain current storage durability limits clearly?
|
||||
- Was cleanup clear and safe?
|
||||
|
||||
## Pass Criteria
|
||||
|
||||
The developer-facing alpha path passes when:
|
||||
|
||||
- the public docs are enough to run the smoke test
|
||||
- the run produces a checksum-verified pod write/read
|
||||
- the system cleans up test resources
|
||||
- failures, if any, are actionable without internal context
|
||||
- the documentation does not claim production readiness
|
||||
|
||||
## Non-Claims
|
||||
|
||||
This QA task does not prove:
|
||||
|
||||
- multi-node durability
|
||||
- failover while a pod remains mounted
|
||||
- RF=3 quorum behavior
|
||||
- production security
|
||||
- performance
|
||||
- snapshot/resize/clone support
|
||||
- NVMe-oF integration
|
||||
|
||||
Those need separate tests.
|
||||
|
||||
## Suggested Report Format
|
||||
|
||||
```text
|
||||
Alpha developer test: PASS/FAIL
|
||||
Commit:
|
||||
Host:
|
||||
Kubernetes:
|
||||
Command:
|
||||
Duration:
|
||||
Pod result:
|
||||
Checksum evidence:
|
||||
Artifacts:
|
||||
Cleanup:
|
||||
|
||||
Usability notes:
|
||||
- ...
|
||||
|
||||
Blocking issues:
|
||||
- ...
|
||||
|
||||
Non-blocking polish:
|
||||
- ...
|
||||
```
|
||||
|
||||
@@ -1,121 +0,0 @@
|
||||
# Bounded Replicated Durable Slice
|
||||
|
||||
The replicated-durable-slice institution is the first bounded
|
||||
product capability above single-node operation. It proves one
|
||||
old-primary → new-primary → rejoin path that converges, rejects
|
||||
stale lineage at every layer, and leaves the replica consistent
|
||||
with the new primary's data.
|
||||
|
||||
This is mechanism, not policy. P12 does not decide who should be
|
||||
the new primary or when failover should trigger — it proves the
|
||||
handoff works when those decisions arrive from above.
|
||||
|
||||
## The bounded route
|
||||
|
||||
One statement:
|
||||
|
||||
> Given an external reassignment `(replicaID, epoch+1, new addresses)`,
|
||||
> the engine clears any in-flight session, invalidates stale lineage,
|
||||
> re-probes the replica, decides catch-up or rebuild based on R/S/H
|
||||
> facts, and converges to healthy. When recovery is needed (R < H),
|
||||
> the new primary's mutating traffic establishes the new epoch on the
|
||||
> replica, and the old primary's stale execution is rejected by the
|
||||
> lineage gate. When the replica is already caught up (R ≥ H), no
|
||||
> mutating traffic is sent and the replica's lineage gate is NOT
|
||||
> advanced — see "Known limitation" below.
|
||||
|
||||
### Steps
|
||||
|
||||
| Step | What happens | Who acts |
|
||||
|---|---|---|
|
||||
| 1. Master reassigns | sends `AssignmentObserved(epoch+1)` to the new primary's adapter | external authority (P14 scope) |
|
||||
| 2. Old primary demoted | receives explicit `ReplicaRemoved` from external authority | external authority |
|
||||
| 3. Engine clears | epoch bump → `InvalidateSession` + clear session/reachability/recovery | engine (deterministic) |
|
||||
| 4. Probe | new primary probes replica to discover R/S/H | executor (data-sync institution) |
|
||||
| 5. Decide | engine's `decide()` classifies catch-up or rebuild | engine (semantic authority) |
|
||||
| 6. Execute | catch-up or rebuild ships blocks at new epoch | executor (recovery-execution institution) |
|
||||
| 7. Converge | session completes, replica in-sync with new primary | all layers |
|
||||
|
||||
### Authority boundary
|
||||
|
||||
| Decision | Owner | Notes |
|
||||
|---|---|---|
|
||||
| Who becomes new primary | **P14** (not this phase) | P12 consumes `(replicaID, epoch+1)` as input |
|
||||
| When to trigger failover | **P14** (not this phase) | P12 executes, doesn't decide |
|
||||
| What recovery class to use | **engine** | R/S/H → catch-up or rebuild |
|
||||
| How to move bytes | **data-sync institution** | lineage-gated, barrier-verified |
|
||||
| How to manage session lifecycle | **recovery-execution institution** | prepared/start/timeout/close |
|
||||
| How to reject stale old-primary traffic | **lineage gate** (transport layer) | epoch comparison at replica ingress |
|
||||
|
||||
## What this proves
|
||||
|
||||
Four handoff tests in `core/adapter/handoff_test.go`:
|
||||
|
||||
| Test | What it proves |
|
||||
|---|---|
|
||||
| `TestHandoff_OldPrimaryToNewPrimary_Converges` | Full route: A (epoch=1) reaches healthy; B (epoch=2) probes, recovers, converges. Replica data matches B. |
|
||||
| `TestHandoff_StaleOldPrimaryTraffic_Rejected` | After B's epoch=2 **recovery traffic** establishes lineage on the replica, stale epoch=1 frames are rejected at the data plane. Requires B to have sent at least one mutating message — does NOT cover the R≥H (no-recovery) branch. |
|
||||
| `TestHandoff_RejoinAfterNewPrimary_DataConsistent` | After handoff, every LBA the new primary wrote is byte-identical on the replica. |
|
||||
| `TestHandoff_OldPrimaryDemoted_NoResurrection` | During an active session, `ReplicaRemoved` clears the session; late `OnSessionStart` and `OnSessionClose` callbacks from the old executor cannot resurrect a healthy projection or re-enter a running phase. |
|
||||
|
||||
These tests use two real adapters + two real transport executors
|
||||
sharing one replica listener — no mocks. They prove the lower
|
||||
institutions (lineage gate, session lifecycle, data sync) compose
|
||||
into a working handoff at the product level.
|
||||
|
||||
## Durability claim
|
||||
|
||||
**Bounded:** all writes that the new primary successfully replicates
|
||||
(barrier ack'd by the replica after catch-up or rebuild) are durable
|
||||
on the replica's store. The replica converges to the new primary's
|
||||
complete data set.
|
||||
|
||||
**Not claimed:** writes that were in-flight on the old primary at the
|
||||
moment of reassignment and had not yet been barrier-ack'd by the
|
||||
replica may be lost. The new primary's truth is authoritative after
|
||||
handoff.
|
||||
|
||||
## Known limitation
|
||||
|
||||
**If the new primary's probe finds the replica already caught up
|
||||
(R ≥ H), no mutating traffic is sent.** The replica's lineage gate
|
||||
stays at the old epoch because probes are lineage-free. Stale
|
||||
old-epoch traffic with a higher sessionID could still land.
|
||||
|
||||
In practice this is low risk because:
|
||||
- The old primary's adapter has been demoted (removal clears sessions)
|
||||
- SessionIDs are monotonic within one process, so a truly "old" session
|
||||
has a lower sessionID than anything the new primary would mint
|
||||
- The scenario requires a delayed old-epoch frame arriving AFTER the
|
||||
old primary has been told to stop but BEFORE the new primary sends
|
||||
any mutating traffic — a narrow window
|
||||
|
||||
If this becomes a real concern (e.g., in a multi-replica or
|
||||
cross-datacenter topology), the fix is straightforward: have the
|
||||
new primary emit a no-op barrier at its epoch even when no recovery
|
||||
is needed, so the replica's lineage gate advances proactively.
|
||||
This is deferred as a P14 concern because it requires knowing when
|
||||
to fence beyond identity-driven invalidation.
|
||||
|
||||
## What this does NOT prove
|
||||
|
||||
| Concern | Owner | Why not here |
|
||||
|---|---|---|
|
||||
| Who decides to reassign | P14 | topology authority |
|
||||
| When failover should trigger | P14 | failover policy |
|
||||
| Epoch minting / authority governance | P14 | topology authority |
|
||||
| Multi-replica (RF ≥ 3) coordination | P14 | broader topology |
|
||||
| Launch readiness / release criteria | P13 | production hardening |
|
||||
| Operator controls (retire / repair / rebalance) | P15 | governance surface |
|
||||
|
||||
## Carry-forward
|
||||
|
||||
- **P13 (production hardening)** — release criteria for the
|
||||
replicated slice: timeout tuning, error-budget gates, operator
|
||||
runbook for manual failover.
|
||||
- **P14 (topology / failover policy)** — epoch authority, automated
|
||||
failover trigger, proactive lineage fence on caught-up probe,
|
||||
placement/rebalance decisions, multi-replica coordination.
|
||||
- **P15 (operator-facing governance surface)** — operator commands
|
||||
for failover, rejoin, retire, repair; production observability
|
||||
beyond what the single-node surface provides.
|
||||
@@ -1,122 +0,0 @@
|
||||
# Single-Node Product Surface
|
||||
|
||||
The single-node product surface is the bounded operator-facing
|
||||
layer above the accepted lower institutions (local data process,
|
||||
data sync, recovery execution). It makes one repeatable workflow —
|
||||
start, inspect, validate, diagnose — explicit and testable without
|
||||
claiming any cluster-shaped authority.
|
||||
|
||||
This doc names what the surface owns, what it does not, and what
|
||||
each endpoint is for.
|
||||
|
||||
## One-sentence scope
|
||||
|
||||
**One bounded single-node operator surface — start / inspect /
|
||||
validate / diagnose — exposed as six read-only HTTP endpoints plus
|
||||
a small CLI, mirroring accepted lower-institution truth without
|
||||
cluster-shaped wording or mutation authority.**
|
||||
|
||||
## Repeatable workflow
|
||||
|
||||
| Step | Command | What it proves |
|
||||
|---|---|---|
|
||||
| start | `go run ./cmd/sparrow` | The three canonical recovery paths (healthy, catch-up, rebuild) complete end-to-end on one node |
|
||||
| inspect | `go run ./cmd/sparrow --http :9090` then `curl /` | The surface is self-describing; every endpoint names what it owns |
|
||||
| validate | `go run ./cmd/sparrow --runs N --json` | Repeatable, deterministic outcome suitable for CI; exit code reflects pass/fail |
|
||||
| diagnose | `curl /diagnose`, `/trace`, `/watchdog` | Bounded local evidence sufficient to answer "what is this node doing and why" without inventing new authority |
|
||||
|
||||
Optional extensions that stay inside the single-node boundary:
|
||||
|
||||
| Command | What it adds |
|
||||
|---|---|
|
||||
| `--calibrate` | Drives a wider scenario set through the accepted route; still single-node |
|
||||
| `--persist-demo --persist-dir DIR` | Demonstrates the local data process through one clean stop-and-restart cycle |
|
||||
|
||||
## HTTP endpoints
|
||||
|
||||
| Path | Owns |
|
||||
|---|---|
|
||||
| `GET /` | Self-describing surface map: the scope statement, every sub-endpoint, and a note that the surface is read-only |
|
||||
| `GET /status` | Version, uptime, scope, current demo label |
|
||||
| `GET /projection` | The adapter's current `ReplicaProjection` (semantic truth derived from lower institutions) |
|
||||
| `GET /trace` | The engine's decision trace for the current demo — full fidelity, untransformed |
|
||||
| `GET /watchdog` | The adapter's start-timeout watchdog lifecycle evidence (arm / clear / supersede / fire / fire_noop) |
|
||||
| `GET /diagnose` | A bounded summary over projection + last trace step + watchdog counters — useful for "is this node healthy, and if not, why" at a glance |
|
||||
|
||||
Every path responds with 501 to any non-GET/HEAD/OPTIONS method.
|
||||
Unknown paths return 404 with a hint to `/`.
|
||||
|
||||
## What this surface owns
|
||||
|
||||
1. **Self-description** — one endpoint (`GET /`) lists every other
|
||||
endpoint; an operator can discover the capability without reading
|
||||
source or design docs.
|
||||
2. **Bounded diagnosis** — `/diagnose` collapses projection + trace
|
||||
tail + watchdog counters into one small structured view. The full
|
||||
evidence stays at the dedicated endpoints.
|
||||
3. **Honest empty states** — every endpoint returns a valid JSON
|
||||
response even before any demo has run. Empty arrays, not `null`;
|
||||
zero values, not fabricated fields.
|
||||
4. **Mutation-closed enforcement** — the read-only boundary is
|
||||
enforced at the HTTP layer, not by omitting handlers.
|
||||
|
||||
## What this surface does NOT own
|
||||
|
||||
The following belong to later phases. P11's surface must not absorb
|
||||
them:
|
||||
|
||||
| Concern | Owner | Why not here |
|
||||
|---|---|---|
|
||||
| Choosing `catch_up` vs `rebuild` | engine | semantic policy |
|
||||
| Deciding to fail over or promote | P14 | topology authority |
|
||||
| Epoch authority / endpoint minting | P14 | produced above the executor |
|
||||
| Multi-replica coordination | P12 | replicated slice, not one node |
|
||||
| Operator mutations (retire / repair / rebalance) | P15 | governance surface, needs P14 truth first |
|
||||
| A cluster shell / CLI that implies collective control | P15 | weed shell, post-integration |
|
||||
|
||||
The surface is explicitly **read-only**. Any HTTP verb other than
|
||||
GET / HEAD / OPTIONS returns 501. The CLI admits local workflow
|
||||
actions (`--runs`, `--calibrate`, `--persist-demo`) which are
|
||||
operator-initiated workflow invocations, not arbitrary mutations
|
||||
against a running server.
|
||||
|
||||
## Honesty rules (tested)
|
||||
|
||||
These rules are enforced by `core/ops/surface_test.go`:
|
||||
|
||||
| Rule | Proof |
|
||||
|---|---|
|
||||
| Surface index lists exactly the endpoints wired into the mux | `TestSurfaceIndex_SelfDescribing` |
|
||||
| Surface index declares itself single-node | `TestSurfaceIndex_WordingIsSingleNode` |
|
||||
| Surface index contains no cluster-shaped vocabulary ("cluster", "failover", "promotion", "topology authority", "rf3") | `TestSurfaceIndex_WordingIsSingleNode` |
|
||||
| `/diagnose` returns honest empty values when no demo has run | `TestDiagnose_EmptyStateIsHonest` |
|
||||
| `/diagnose` exposes only fields derivable from lower truth | `TestDiagnose_OnlyReadsLowerTruth` |
|
||||
| `/` and `/diagnose` reject every mutation verb | `TestSurfaceMutations_IncludesRootAndDiagnose` |
|
||||
| Every read endpoint returns a valid empty-safe JSON response | existing `*_EmptyWhenNoDemo` tests |
|
||||
|
||||
## Reading order
|
||||
|
||||
For someone new to this surface:
|
||||
|
||||
1. `GET /` — the surface map (run the sparrow, hit the root)
|
||||
2. `core/ops/server.go` — endpoint wiring
|
||||
3. `core/ops/handlers.go` — handler bodies, state snapshot reads
|
||||
4. `core/ops/state.go` — the read-only mirror over adapter state
|
||||
5. `core/ops/surface_test.go` — honesty proofs
|
||||
|
||||
## Carry-forward
|
||||
|
||||
Items the single-node surface leaves explicitly to later phases:
|
||||
|
||||
- **P12 (bounded replicated durable slice)** — multi-replica status
|
||||
aggregation, rejoin visibility, multi-peer inspection.
|
||||
- **P14 (topology / failover policy)** — any surface that exposes
|
||||
or accepts promotion / placement / epoch decisions.
|
||||
- **P15 (operator-facing governance surface)** — a cluster-shaped
|
||||
shell (`weed shell block.*`), operator mutation verbs,
|
||||
production-grade authentication, and operator-visible retry /
|
||||
repair / rebalance actions.
|
||||
|
||||
P13 (hardening gate) will define the release criteria that this
|
||||
surface must meet before P14 widens it into a replicated control
|
||||
surface.
|
||||
@@ -1,201 +0,0 @@
|
||||
# Engine Surface
|
||||
|
||||
This doc is a taxonomy reference for the semantic core. It names every
|
||||
event, command, and state domain the engine currently exposes, so that
|
||||
reviewers and contributors can see the full surface without re-reading
|
||||
the code.
|
||||
|
||||
It deliberately does NOT try to draw one unified state diagram. The
|
||||
reason is in [Why No Single Diagram](#why-no-single-diagram).
|
||||
|
||||
## Surface Summary
|
||||
|
||||
| Dimension | Count | Values |
|
||||
|---|---|---|
|
||||
| Events | 12 | `AssignmentObserved`, `EndpointObserved`, `ReplicaRemoved`, `ProbeSucceeded`, `ProbeFailed`, `RecoveryFactsObserved`, `SessionPrepared`, `SessionStarted`, `SessionProgressObserved`, `SessionClosedCompleted`, `SessionClosedFailed`, `SessionInvalidated` |
|
||||
| Commands | 6 | `ProbeReplica`, `StartCatchUp`, `StartRebuild`, `InvalidateSession`, `PublishHealthy`, `PublishDegraded` |
|
||||
| Truth domains | 5 | `Identity`, `Reachability`, `Recovery`, `Session`, `Publication` |
|
||||
| Operator `Mode` | 4 | `healthy`, `degraded`, `recovering`, `idle` |
|
||||
| `RecoveryDecision` | 4 | `unknown`, `none`, `catch_up`, `rebuild` |
|
||||
| `SessionKind` | 3 | `""` (none), `catch_up`, `rebuild` |
|
||||
| `SessionPhase` | 5 | `""` (none), `starting`, `running`, `completed`, `failed` |
|
||||
| `ProbeStatus` | 4 | `unknown`, `probing`, `reachable`, `unreachable` |
|
||||
| `ContactKind` | 5 | `none`, `ship`, `barrier`, `probe`, `ctrl_ack` |
|
||||
|
||||
Source files:
|
||||
- Events: `core/engine/events.go`
|
||||
- Commands: `core/engine/commands.go`
|
||||
- Truth domains and enums: `core/engine/state.go`
|
||||
- Operator projection and `Mode`: `core/engine/projection.go`
|
||||
|
||||
## Runtime Layer (not part of engine surface)
|
||||
|
||||
The engine is deliberately free of transport and runtime state. The
|
||||
current `seaweedfs/V2` runtime that will eventually sit beneath this
|
||||
engine has its own orthogonal state machine — included here for
|
||||
context, NOT because it is part of the engine contract:
|
||||
|
||||
| Layer | State machine | Values |
|
||||
|---|---|---|
|
||||
| V2 runtime shipper | `ReplicaState` | `Connecting`, `InSync`, `CatchingUp`, `Degraded`, `NeedsRebuild`, `Rebuilding`, `Disconnected` |
|
||||
|
||||
The engine does not read these, does not decide based on them, and
|
||||
does not return to them. They are runtime execution state. If a future
|
||||
V3 runtime is written, it will have its own analogous states, and the
|
||||
engine will stay unaware of them.
|
||||
|
||||
## Recovery Command Lineage
|
||||
|
||||
The engine still emits partial-state recovery intent:
|
||||
|
||||
- `StartCatchUp`
|
||||
- `StartRebuild`
|
||||
|
||||
But in the deliver code those commands are NOT executed as lineage-free
|
||||
requests.
|
||||
|
||||
The accepted execution contract is:
|
||||
|
||||
1. the engine chooses recovery class and freezes `targetLSN`
|
||||
2. the adapter assigns a fresh `sessionID`
|
||||
3. the execution surface binds recovery work to
|
||||
`sessionID + epoch + endpointVersion + targetLSN`
|
||||
4. the transport layer carries that lineage on mutating recovery traffic
|
||||
5. stale or superseded lineage is rejected or ignored rather than
|
||||
allowed to redefine live truth
|
||||
|
||||
This means:
|
||||
|
||||
- the semantic command is still partial state
|
||||
- the execution route is not
|
||||
- delayed callbacks, old sessions, and stale primary traffic must be
|
||||
fenced by lineage before they can affect current truth
|
||||
|
||||
Files:
|
||||
|
||||
- `core/adapter/adapter.go`
|
||||
- `core/adapter/executor.go`
|
||||
- `core/transport/protocol.go`
|
||||
- `core/transport/executor.go`
|
||||
- `core/transport/replica.go`
|
||||
|
||||
## Semantic Death Rule In Deliver Code
|
||||
|
||||
The short form from the design docs is now implemented concretely:
|
||||
|
||||
**old process may still run, but it must already be semantically dead.**
|
||||
|
||||
In the deliver code that means:
|
||||
|
||||
1. identity advance clears engine session truth immediately and emits
|
||||
`InvalidateSession`
|
||||
2. the executor actively cancels invalidated sessions instead of only
|
||||
logging them
|
||||
3. late close callbacks from invalidated sessions are dropped
|
||||
4. the replica listener rejects stale mutation lineage on ship/rebuild
|
||||
traffic
|
||||
|
||||
So execution lag is tolerated only as cleanup latency. It is not
|
||||
allowed to continue mutating accepted semantic or storage truth.
|
||||
|
||||
## Why No Single Diagram
|
||||
|
||||
A "one big state diagram" view does not fit, and should not be drawn:
|
||||
|
||||
1. **Combinatorics.** The full reachable system state is the product of
|
||||
5 truth domains. Even if each domain has only 4–5 distinguishable
|
||||
values, the Cartesian product is in the hundreds. Most of those
|
||||
combinations are unreachable by construction, but they're not
|
||||
unreachable by any explicit rule — they're unreachable because the
|
||||
reducer never produces them from legal event sequences.
|
||||
|
||||
2. **It invites anti-patterns.** Historically in the V2 lineage,
|
||||
attempts to draw one unified diagram led to two bad habits:
|
||||
- treating the diagram as the source of truth and adding code to
|
||||
"fix" mismatches, rather than fixing the diagram — this is how
|
||||
transport mechanics leak into semantics (A7)
|
||||
- using timer/ordering tricks to force desired transitions that
|
||||
the diagram showed but the reducer didn't naturally produce —
|
||||
this is how timer firings become semantic authority (A1) and
|
||||
ordering becomes policy (A4)
|
||||
|
||||
3. **The engine is a reducer, not an FSM.** `Apply(state, event) →
|
||||
(state, commands, projection)` is a pure function. The legal state
|
||||
space is the set of states reachable from the zero value through
|
||||
any sequence of legal events. That set is defined by the reducer,
|
||||
not by a diagram.
|
||||
|
||||
## What Replaces The Diagram
|
||||
|
||||
Small per-domain diagrams are fine and do fit — they live in review
|
||||
comments and local sketches when needed. The durable source of truth
|
||||
for "what states can this system be in" is not a diagram. It is:
|
||||
|
||||
1. **The reducer itself** — `core/engine/apply.go` is the full
|
||||
specification of legal transitions. If a state is unreachable, it
|
||||
is unreachable because no event sequence produces it, and that's
|
||||
visible in the code.
|
||||
|
||||
2. **Invariants** — constraint tests live beside the code:
|
||||
- `C8` same facts → same decision
|
||||
- `C9` timers only trigger observation, never decisions
|
||||
- `C10` engine state contains no transport/runtime types
|
||||
- `C12` executors cannot return decisions to the engine
|
||||
- Same-observation batch rule: multi-fact observations enter
|
||||
through `applyBatchAndExecute` atomically
|
||||
(see `core/adapter/adapter.go` ingress header)
|
||||
- stale session callbacks and stale mutation lineage are rejected
|
||||
by ID/epoch/endpoint fencing
|
||||
- recovery facts arriving before probe success still converge once
|
||||
reachability becomes current
|
||||
|
||||
3. **Conformance cases** — YAML event sequences with expected
|
||||
projections under `core/conformance/`. Each case pins one
|
||||
legal trajectory.
|
||||
|
||||
Those cases now include:
|
||||
|
||||
- stale probe failure with old transport epoch is rejected
|
||||
- recovery facts arriving before probe success still converge to the
|
||||
same catch-up decision
|
||||
|
||||
4. **Trace output** — every `Apply` emits a trace entry per decision
|
||||
step. For any concrete run, the trace is the diagram for that run.
|
||||
|
||||
## Sub-Diagrams That Do Fit
|
||||
|
||||
When a local view helps review, these per-dimension diagrams fit on
|
||||
one page and are welcome:
|
||||
|
||||
- `Mode` transitions (4 nodes)
|
||||
- `SessionPhase` lifecycle (linear: `none` → `starting` → `running` → `completed`/`failed`)
|
||||
- `ProbeStatus` transitions (4 nodes)
|
||||
- `RecoveryDecision` flowchart (R/S/H → one of 4 decisions)
|
||||
- Event → command trigger matrix (12 × 6)
|
||||
|
||||
If you draw one of these for a review, drop it in a PR comment or an
|
||||
adjacent short `.md` near the code. Don't try to extend it into the
|
||||
full system — the full system belongs to the reducer.
|
||||
|
||||
## Extending The Surface
|
||||
|
||||
When adding an event, command, enum value, or truth domain:
|
||||
|
||||
1. Update the type in the corresponding `core/engine/*.go` file.
|
||||
2. Update the count in the table above.
|
||||
3. Update the reducer in `core/engine/apply.go`.
|
||||
4. Add a conformance case covering the new transition.
|
||||
5. If the new ingress produces multiple same-observation facts, route
|
||||
them through `applyBatchAndExecute` and add a contention test
|
||||
(see the adapter ingress rule).
|
||||
|
||||
Do not add a type without a reducer path. Do not add a reducer path
|
||||
without a conformance case. The surface grows only when all three
|
||||
move together.
|
||||
|
||||
If the new surface can outlive reassignment, restart, or handoff, also
|
||||
answer these before accepting it:
|
||||
|
||||
1. what is the minimum execution lineage
|
||||
2. where is stale lineage rejected
|
||||
3. how do we prove old callbacks cannot become new truth
|
||||
@@ -1,106 +0,0 @@
|
||||
# T0 Port Audit
|
||||
|
||||
Date: 2026-04-20
|
||||
Status: tracked; updated with every T0 patch that touches a V2 file
|
||||
Purpose: satisfy PG4 (`v3-phase-15-qa-system.md`) — every V2 file referenced by T0 must have explicit ported-function vs rejected-function lists
|
||||
|
||||
## 1. Rule
|
||||
|
||||
For every V2 source file that the T0 patch touches, consults, or claims to port, this doc lists:
|
||||
|
||||
1. **Ported functions** — V2 functions whose structure is copied (as mechanism) into the target file.
|
||||
2. **Consulted functions** — V2 functions read for shape/idea but NOT copied.
|
||||
3. **Rejected functions** — V2 functions explicitly NOT ported; the rejection reason must name a boundary rule.
|
||||
|
||||
If a V2 file appears in T0 commit diffs (even indirectly referenced) and is not listed here, T0 close fails PG4.
|
||||
|
||||
## 2. `weed/server/block_heartbeat_loop.go` (177 LOC)
|
||||
|
||||
Target: port loop shape into `core/host/volume/heartbeat_loop.go`.
|
||||
|
||||
**Ported**:
|
||||
- `BlockHeartbeatLoop.Run` outer cadence (ticker-driven periodic collection + send).
|
||||
- `BlockHeartbeatLoop.collectAndSend` shape (gather local slot facts, translate to wire, send unary).
|
||||
|
||||
**Consulted (not copied)**:
|
||||
- Shutdown/context-cancellation pattern.
|
||||
- Backoff-on-error shape.
|
||||
|
||||
**Rejected**:
|
||||
- Any V2 path that writes back authority / role / assignment from the heartbeat-ack side. heartbeats carry observation only (sketch §3 load-bearing).
|
||||
- V2's coupled "heartbeat timing → failover" shortcuts.
|
||||
|
||||
## 3. `weed/storage/blockvol/block_heartbeat.go`
|
||||
|
||||
Target: port local-collector shape into `core/host/volume/collect.go`.
|
||||
|
||||
**Ported**:
|
||||
- Replica-inventory walk → per-slot `HeartbeatSlot` fill pattern.
|
||||
|
||||
**Consulted (not copied)**:
|
||||
- V2 `LocalRoleClaim` populating convention (the block system preserves the field but the `LocalRolePrimary` value NEVER writes authority — already enforced at the observation-layer `ReasonConflictingPrimaryClaim` rule from P14 S4).
|
||||
|
||||
**Rejected**:
|
||||
- V2 paths that consult local role state to DECIDE primary. the block system consults local role state only to REPORT it raw (observation fact, never authority).
|
||||
|
||||
## 4. `weed/storage/blockvol/block_heartbeat_proto.go`
|
||||
|
||||
Target: cross-check that `authority.HeartbeatMessage` field set matches V2 proto.
|
||||
|
||||
**Ported**:
|
||||
- Field names + types already ported into `core/authority/observation_wire.go` in P14 S4. T0 adds no new fields; T0 only serializes the existing `HeartbeatMessage` over the T0 HTTP/JSON transport.
|
||||
|
||||
**Rejected**:
|
||||
- V2 extension fields that carry role-as-authority semantics. None of those fields exist in `authority.HeartbeatMessage` — already filtered at S4 port time.
|
||||
|
||||
## 5. `weed/server/master_grpc_server_block.go` (600 LOC)
|
||||
|
||||
Target: port the heartbeat-ingress RPC handler SHAPE into `core/host/master/observation_handler.go`.
|
||||
|
||||
**Ported**:
|
||||
- Handler pattern: parse request → translate to `authority.HeartbeatMessage` → call `ObservationHost.Ingest` → return ack.
|
||||
|
||||
**Consulted (not copied)**:
|
||||
- Sender-verification pattern (matches expected `ServerID`). T0 ships a minimal form; full authn is T4.
|
||||
|
||||
**Rejected**:
|
||||
- V2's `HandleAssignment` endpoint — NEVER ported. The block master never receives an assignment-mutation RPC; the one-way flow is observation in, assignment out.
|
||||
- V2 `reportBlockVolume` paths that invoke `promote` / `demote` / local-role-based failover.
|
||||
- Any RPC endpoint that accepts `Epoch` / `EndpointVersion` from a volume-side caller.
|
||||
|
||||
## 6. `weed/server/master_block_observability.go` / `master_block_evidence.go`
|
||||
|
||||
Target: consulted for `EvidenceService.QueryVolumeStatus` response shape.
|
||||
|
||||
**Ported**:
|
||||
- Projection-fact + evidence-reason response shape (read-only).
|
||||
|
||||
**Rejected**:
|
||||
- V2 fields that reference V2 role semantics (`Primary`, `Candidate`, promotion timers). Evidence is adapter projection + controller unsupported-evidence + convergence-stuck — all P14-era shapes only.
|
||||
|
||||
## 7. Files NOT ported in T0 first patch
|
||||
|
||||
Listed per assignment §4 denylist + sketch §7.3. None of these enter the T0 diff:
|
||||
|
||||
- `weed/storage/blockvol/promotion.go`
|
||||
- V2 master paths implementing `HandleAssignment` / `promote` / `demote`
|
||||
- V2 paths where heartbeat timing writes authority
|
||||
- V2 paths where a volume-local role claim becomes authority
|
||||
|
||||
## 8. V2 files referenced by T0 design docs but NOT ported at all
|
||||
|
||||
These appear in the T0 sketch §7.1–7.2 or this audit's cross-refs but carry no ported functions. Listing for traceability:
|
||||
|
||||
- `weed/server/volume_server_block.go` (1891 LOC) — consulted only as reference for volume-side state machine shape; no functions ported in the first T0 patch. A later T0-follow-up may port specific subsets if L2/L3 tests surface a gap.
|
||||
- `weed/server/volume_grpc_block.go` (207 LOC) — consulted only as reference for volume-side RPC client conventions.
|
||||
|
||||
## 9. Audit change log
|
||||
|
||||
| Date | V2 file | Action | T0 target |
|
||||
|---|---|---|---|
|
||||
| 2026-04-20 | `weed/server/block_heartbeat_loop.go` | loop-shape ported | `core/host/volume/heartbeat_loop.go` |
|
||||
| 2026-04-20 | `weed/storage/blockvol/block_heartbeat.go` | collector shape ported | `core/host/volume/collect.go` |
|
||||
| 2026-04-20 | `weed/server/master_grpc_server_block.go` | handler shape ported (heartbeat only) | `core/host/master/observation_handler.go` |
|
||||
| 2026-04-20 | all others in §7 denylist | REJECTED | — |
|
||||
|
||||
Future T0 follow-ups update this table before the patch lands.
|
||||
Reference in new issue
Block a user