From 95ef57b067f10ba41bd2b200012857f7787b9a04 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Wed, 17 Jun 2026 16:39:22 -0700 Subject: [PATCH] docs: add core engineering wiki deep dives --- seaweed-block/docs/wiki/coverage-matrix.md | 15 ++- .../docs/wiki/deep-dives/csi-lifecycle.md | 93 ++++++++++++++++++ .../deep-dives/managed-volume-readiness.md | 86 ++++++++++++++++ .../wiki/deep-dives/operation-layer-v05.md | 90 +++++++++++++++++ .../wiki/deep-dives/smartwal-dirty-failure.md | 89 +++++++++++++++++ .../docs/wiki/deep-dives/testops-authoring.md | 97 +++++++++++++++++++ seaweed-block/internal/docs/current-plan.md | 8 +- seaweed-block/mkdocs.yml | 6 ++ 8 files changed, 472 insertions(+), 12 deletions(-) create mode 100644 seaweed-block/docs/wiki/deep-dives/csi-lifecycle.md create mode 100644 seaweed-block/docs/wiki/deep-dives/managed-volume-readiness.md create mode 100644 seaweed-block/docs/wiki/deep-dives/operation-layer-v05.md create mode 100644 seaweed-block/docs/wiki/deep-dives/smartwal-dirty-failure.md create mode 100644 seaweed-block/docs/wiki/deep-dives/testops-authoring.md diff --git a/seaweed-block/docs/wiki/coverage-matrix.md b/seaweed-block/docs/wiki/coverage-matrix.md index 06f8e63144..6c5753bd88 100644 --- a/seaweed-block/docs/wiki/coverage-matrix.md +++ b/seaweed-block/docs/wiki/coverage-matrix.md @@ -19,21 +19,21 @@ Coverage levels: |---|---|---|---|---| | Product positioning and claims | Prevents over-claiming and release confusion | `docs/releases/`, `docs/roadmap.md`, `docs/user-capabilities.md` | mapped | claim-boundary page by release | | Day-1 Kubernetes install and first PVC | User entry path and release smoke | Phase 20, 25, 40, 44 finished plans; quickstart | mapped | install flow diagram and troubleshooting | -| CSI lifecycle | PVC/PV path, CreateVolume/DeleteVolume, node stage/publish | `core/csi`, `docs/runtime-state-machines.md`, Phase 44 D2 | linked | deep dive needed | -| SwBlockVolume CR identity | Bridge from CSI to operation layer | Phase 44 D2 sign-off, `core/csi/kubernetes_metadata.go` | mapped | sequence diagram and field ownership | -| operator-status | CRD status, Events, node evidence, cleanup/delete-safety | Phases 35-40, `core/ops` | mapped | deep dive needed | -| lifecycle-owner | bounded finalizer add/release | Phases 41-44, lifecycle-owner refs | mapped | deep dive needed | +| CSI lifecycle | PVC/PV path, CreateVolume/DeleteVolume, node stage/publish | `core/csi`, `docs/runtime-state-machines.md`, Phase 44 D2 | deep | expand DeleteVolume details later | +| SwBlockVolume CR identity | Bridge from CSI to operation layer | Phase 44 D2 sign-off, `core/csi/kubernetes_metadata.go` | deep | add field-by-field CRD contract later | +| operator-status | CRD status, Events, node evidence, cleanup/delete-safety | Phases 35-40, `core/ops` | deep initial | add status writer/schema conformance page | +| lifecycle-owner | bounded finalizer add/release | Phases 41-44, lifecycle-owner refs | deep initial | add admission policy field matrix | | Admission/RBAC boundary | Prevents finalizer owner from becoming broad operator | Phase 42 sign-off, Helm templates | linked | VAP/RBAC decision diagram | | Delete-safety | Holds unsafe deletion, releases on clean evidence | Phase 39, 42, 44; finalizer-delete-safety contract | deep initial | field-by-field status contract | | Cleanup verifier | Zero-residue authority and safety evidence | cleanup scripts, Phase 29, 36, 44 | mapped | residue taxonomy | -| ManagedVolume readiness | Shared ready/blocked/unknown model | Phase 22, 32, 35-36 | linked | detailed priority diagram | +| ManagedVolume readiness | Shared ready/blocked/unknown model | Phase 22, 32, 35-36 | deep initial | add reason-code taxonomy | | Node readiness / CSI evidence | Avoids false node-ready status | Phase 37 | linked | detailed live evidence diagram | -| SmartWAL dirty failure | Proves dirty storage evidence cannot become false Ready | Phase 34 | linked | deep dive needed | +| SmartWAL dirty failure | Proves dirty storage evidence cannot become false Ready | Phase 34 | deep | add exact test log excerpts later | | Authority / epoch / promotion | One-primary, fencing, restart authority persistence | Phases 13-18, 31, invariant ledger | linked | authority protocol deep dive | | Returned-replica rebuild/reintegration | Next major storage lifecycle feature | recovery refs, roadmap | linked | readiness/gap analysis | | iSCSI frontend / ALUA / multipath | Current default frontend and transparent failover path | iSCSI refs, Phase 17, 27, 37 | linked | ALUA path-state diagram | | NVMe ANA parity | Planned protocol parity path | NVMe refs, roadmap | linked | future protocol page | -| TestOps runner and scenarios | Product evidence, not just tests | `testops/`, Phase 33-34 | mapped | authoring guide needed | +| TestOps runner and scenarios | Product evidence, not just tests | `testops/`, Phase 33-34 | deep initial | add runner action reference | | Support bundle/replay/report/dashboard | Cold-reader diagnosis and support path | Phases 23-24, 28, 32, 36 | mapped | bundle structure diagram | | Release engineering | Image/chart skew prevention | Phases 40, 44, release notes | mapped | release checklist page | | Docker volume plugin idea | Future non-K8s adapter | roadmap | linked | investigation page later | @@ -65,4 +65,3 @@ explicit non-claims These eight pages would cover most of the hard-earned knowledge from the last few months. The rest can remain linked until those are reviewed. - diff --git a/seaweed-block/docs/wiki/deep-dives/csi-lifecycle.md b/seaweed-block/docs/wiki/deep-dives/csi-lifecycle.md new file mode 100644 index 0000000000..aae74516e2 --- /dev/null +++ b/seaweed-block/docs/wiki/deep-dives/csi-lifecycle.md @@ -0,0 +1,93 @@ +# CSI Lifecycle And SwBlockVolume Identity + +This page explains the Kubernetes-facing path from PVC to Seaweed Block +operation-layer identity. + +## Problem + +Kubernetes users think in PVCs and pods. Seaweed Block internally needs a +volume identity, publish target, replica facts, delete-safety state, and +event/status surfaces. If those are not correlated, every tool can invent its +own answer about the same volume. + +The `SwBlockVolume` CR is the bridge: + +```text +PVC / StorageClass +-> CSI CreateVolume +-> Seaweed Block volume +-> SwBlockVolume identity CR +-> operator-status writes status +-> lifecycle-owner protects deletion +``` + +## Ownership + +| Owner | Writes | Must not write | +|---|---|---| +| CSI | `SwBlockVolume.metadata.name`, `.spec.pvcName`, `.spec.storageClass` | status, finalizers | +| operator-status | `SwBlockVolume.status`, Events | spec, finalizers | +| lifecycle-owner | Seaweed Block protection finalizer only | spec, status, labels, annotations, ownerReferences | + +This split is the product boundary. It is why Phase 44 matters: a normal PVC can +now create the CR identity object before the status and lifecycle layers act. + +## Sequence + +```mermaid +sequenceDiagram + participant K as Kubernetes + participant CSI as blockcsi + participant BM as blockmaster + participant CR as SwBlockVolume CR + participant OS as operator-status + participant LO as lifecycle-owner + + K->>CSI: CreateVolume(PVC, StorageClass) + CSI->>BM: create Seaweed Block volume + BM-->>CSI: volume id / publish facts + CSI->>CR: create or patch identity spec + LO->>CR: add protection finalizer + OS->>BM: read cluster evidence + OS->>CR: patch status + emit Events +``` + +## Main Code + +| Behavior | Entry point | +|---|---| +| In-cluster Kubernetes client | `core/csi/kubernetes_metadata.go` | +| Ensure `SwBlockVolume` identity CR | `InClusterSwBlockVolumeRegistrar.EnsureVolumeObject` | +| Create/patch spec on conflict | `patchVolumeSpec` | +| CSI wiring | `core/csi/controller.go`, `cmd/blockcsi/main.go` | +| Helm flag | `blockcsi --swblockvolume-cr-namespace` | +| CSI RBAC | `charts/seaweed-block/templates/*csi*rbac*` | + +## Important Detail + +The CR name is derived from the operator status identity: + +```text +SwBlockVolumeObjectName(ManagedVolumeOperatorStatus{ + VolumeID: ..., + PVCName: ..., +}) +``` + +That keeps Kubernetes object naming aligned with the operation-layer read model. + +## QA Evidence + +| Gate | What it proved | +|---|---| +| Phase 44 D2 | normal PVC creates exactly one `SwBlockVolume` CR; lifecycle-owner adds one protection finalizer; operator-status writes Ready status | +| Phase 44 D3/D4 | delete request drives delete-safety status and finalizer hold/release | +| Phase 44 D5/D6 | multi-volume delete state stays isolated | + +## Non-Claims + +- CSI does not own `SwBlockVolume.status`. +- CSI does not add or remove finalizers. +- CSI does not run cleanup. +- `SwBlockVolume` is not a replacement for PVC/PV lifecycle ownership. + diff --git a/seaweed-block/docs/wiki/deep-dives/managed-volume-readiness.md b/seaweed-block/docs/wiki/deep-dives/managed-volume-readiness.md new file mode 100644 index 0000000000..c8ee902264 --- /dev/null +++ b/seaweed-block/docs/wiki/deep-dives/managed-volume-readiness.md @@ -0,0 +1,86 @@ +# ManagedVolume Readiness + +`ManagedVolume` is the read-side product model for one PVC-backed Seaweed Block +volume. It correlates facts from Kubernetes, CSI, authority, replicas, frontend, +host path, cleanup, and support evidence. + +It does not own Kubernetes lifecycle or authority. + +## Why It Exists + +Without a shared read model, CLI, dashboard, QA scripts, and CRD status can +derive different answers from the same underlying state. The core invariant is: + +```text +User-facing PVC/volume explanations must be derived from ManagedVolume facts, +not independently recomposed by CLI, dashboard, TestOps, CSI logs, or shell grep. +``` + +## Readiness Priority + +```mermaid +flowchart TD + A[ManagedVolume facts] --> B{Evidence current?} + B -->|no| U[Ready=Unknown / EvidenceStale] + B -->|yes| C{Known blocker?} + C -->|yes| D[Ready=False / Blocked=True] + C -->|no| E{Recovery in progress?} + E -->|yes| R[Ready=False / Recovering=True] + E -->|no| F{Positive ready evidence?} + F -->|yes| G[Ready=True] + F -->|no| U +``` + +The important rule is not "green unless proven bad". It is: + +```text +Ready=True requires positive current evidence. +``` + +## Common Reason Codes + +| Situation | Projection | +|---|---| +| first volume verified | `Ready=True`, reason `first_volume_verified` | +| CSI image pull failed | `Ready=False`, `Blocked=True`, reason `csi_node_image_pull_failed` | +| status endpoint unreachable | `Ready=Unknown`, `EvidenceStale=True` | +| node NotReady | node `unknown/node_not_ready` | +| image missing on node | node `blocked/image_missing_on_node` | +| cleanup residue | `CleanupRequired=True`, delete-safety rejected | +| WAL integrity fault | not Ready; reason should remain diagnosable | + +## Surfaces + +The same projection feeds: + +- `sw-block ops report`, +- dashboard `/operator-snapshot.json`, +- `sw-block ops explain`, +- `SwBlockCluster.status`, +- `SwBlockVolume.status`, +- Kubernetes Events. + +## Main Code + +| Behavior | Entry point | +|---|---| +| ManagedVolume model/projection | `core/ops/managed_volume_*` | +| observation bundle replay | `core/ops/observation_bundle.go` | +| report/dashboard rendering | `cmd/sw-block/main.go`, `core/ops` report helpers | +| CRD status mapping | `core/ops/operator_status_controller.go` | + +## QA Evidence + +| Gate | What it proved | +|---|---| +| Phase 32 | healthy/blocked/restart/multi-volume/stale surfaces agree | +| Phase 34 | dirty SmartWAL evidence cannot become false Ready | +| Phase 35-36 | CRD status, Events, cleanup, support refs, node evidence align | +| Phase 37 | live node/CSI blockers no longer mask false node readiness | + +## Non-Claims + +- `ManagedVolume` does not choose a primary. +- `ManagedVolume` does not execute promotion, rebuild, failback, or cleanup. +- `ManagedVolume` is a read model and action contract, not a storage authority. + diff --git a/seaweed-block/docs/wiki/deep-dives/operation-layer-v05.md b/seaweed-block/docs/wiki/deep-dives/operation-layer-v05.md new file mode 100644 index 0000000000..b6e592cc19 --- /dev/null +++ b/seaweed-block/docs/wiki/deep-dives/operation-layer-v05.md @@ -0,0 +1,90 @@ +# Operation Layer v0.5 + +The v0.5 operation layer is the first bounded mutating lifecycle path. It is +not a broad operator. It exists to prove one controlled loop: + +```text +facts -> judgment -> status/action -> admission-confined mutation -> evidence +``` + +## Why It Exists + +Before this layer, Seaweed Block could observe many states but could not safely +own a Kubernetes lifecycle mutation. Phase 39 showed why: patching finalizers on +a CRD requires main-object patch permission, which is too broad unless an +admission boundary confines the write. + +v0.5 resolves that by separating three components: + +| Component | Role | +|---|---| +| CSI | create/update `SwBlockVolume` identity CR | +| operator-status | publish `.status` and Events only | +| lifecycle-owner | add/release only the Seaweed Block protection finalizer | + +## End-To-End Loop + +```mermaid +flowchart TD + A[Live facts: PVC, volume, cleanup evidence] --> B[operator-status judgment] + B --> C[SwBlockVolume.status deleteSafety] + C --> D{lifecycle-owner decision} + D -->|missing/stale/residue| E[hold finalizer] + D -->|allowed + releasable| F[patch finalizer list] + F --> G[VAP admits only protection finalizer shape] + G --> H[CR deletion completes] + E --> I[Warning Event + user-facing reason] + H --> J[Normal Event + zero residue gate] +``` + +## Delete-Safety Contract + +| Evidence | Decision | State | Finalizer | +|---|---|---|---| +| missing cleanup evidence | unknown | requested | held | +| stale cleanup evidence | unknown | requested | held | +| residue present | rejected | blocked | held | +| clean fresh evidence | allowed | releasable | released | + +The cleanup evidence is external. The lifecycle-owner does not execute cleanup. + +## Main Code + +| Behavior | Entry point | +|---|---| +| operator-status reconcile | `core/ops/operator_status_controller.go` | +| Kubernetes status writer | `core/ops/kubernetes_status_writer.go` | +| cleanup evidence parsing | `core/ops/cleanup_evidence.go` | +| delete-safety projection | `core/ops/observation_bundle.go` | +| lifecycle-owner reconcile | `core/ops/lifecycle_owner_controller.go` | +| action model | `core/ops/action_model.go` | + +## Admission Boundary + +The lifecycle-owner needs main-object patch because CRD finalizers are mutated +through the main object. Kubernetes RBAC alone cannot express "finalizers only" +for this CRD. The boundary is therefore: + +```text +RBAC permits lifecycle-owner main patch on SwBlockVolume +AND +ValidatingAdmissionPolicy denies any patch that changes spec, status, labels, +annotations, ownerReferences, foreign finalizers, or mixed fields +``` + +## QA Evidence + +| Phase | Evidence | +|---|---| +| 41 | lifecycle-owner foundation and dry-run decision model | +| 42 | real Kubernetes ValidatingAdmissionPolicy boundary | +| 43 | finalizer add/release as isolated gates | +| 44 | integrated PVC -> protected CR -> hold/release -> zero-residue path | + +## Non-Claims + +- No automatic cleanup execution. +- No PVC/PV/workload deletion by operator-status or lifecycle-owner. +- No rebuild, failback, backup, or upgrade execution. +- No production operator claim. + diff --git a/seaweed-block/docs/wiki/deep-dives/smartwal-dirty-failure.md b/seaweed-block/docs/wiki/deep-dives/smartwal-dirty-failure.md new file mode 100644 index 0000000000..77c2efd0f0 --- /dev/null +++ b/seaweed-block/docs/wiki/deep-dives/smartwal-dirty-failure.md @@ -0,0 +1,89 @@ +# SmartWAL Dirty-Failure Path + +The SmartWAL corruption gate is the best example of why live dirty-failure +tests matter. It found a real false-ready bug that unit tests and clean failure +tests missed. + +## Problem + +A corrupted WAL record is not the same as a missing pod or a clean restart. If +the product detects corruption but still reports `Ready=True`, users get a +false safety signal. + +The required behavior is: + +```text +detect integrity fault +-> fail closed +-> block local readiness +-> projection refuses Ready=True without positive readiness +``` + +## Failure Chain + +```mermaid +sequenceDiagram + participant QA as TestOps corrupt gate + participant WAL as SmartWAL + participant BV as blockvolume + participant BM as blockmaster + participant OPS as operator-status/report + + QA->>WAL: corrupt real WAL record + WAL-->>BV: recovery CRC mismatch / WAL integrity fault + BV->>BV: keep status endpoint diagnosable + BV->>BM: do not publish local primary readiness + BM->>OPS: evidence lacks positive primary readiness + OPS-->>QA: Ready is Unknown/Blocked, never Ready=True +``` + +## What The Gate Caught + +The gate forced fixes through multiple layers: + +1. Storage layer: do not skip mid-history CRC mismatch as a harmless torn tail. +2. blockvolume process: do not continue publishing healthy after durable + recovery fault. +3. blockmaster projection: heartbeat/reachability is not enough for Ready. + Primary readiness must be positively confirmed. + +This sequence matters because each local fix was necessary but insufficient +until the surface stopped claiming false readiness. + +## Main Code Areas + +| Layer | Code area | +|---|---| +| SmartWAL recovery | `core/storage/smartwal/` | +| durable frontend readiness | `core/frontend/durable/` | +| blockvolume process readiness | `cmd/blockvolume/main.go` | +| blockmaster projection | `core/host/master/observation_snapshot.go`, `core/host/volume/projection_bridge.go` | +| status projection | `core/ops` | + +## QA Evidence + +| Artifact | Purpose | +|---|---| +| `helm-smartwal-corrupt-restart-chain.yaml` | live dirty-failure scenario | +| Phase 34 D4 finding | proved false Ready after real WAL corruption | +| Phase 34 D4 verify reports | tracked storage fix, process fix, projection fix | +| Phase 34 D4 PASS | confirmed no false Ready after corruption | + +## Design Rule + +Do not let "process is reachable" imply "volume is ready". + +```text +reachable endpoint + assigned primary != positive readiness evidence +``` + +This same rule should be reused for returned-replica rebuild, partial recovery, +and future dirty shutdown scenarios. + +## Non-Claims + +- The gate does not prove all WAL corruption modes are recoverable. +- It does not prove no data loss under every power-loss pattern. +- It proves the product does not falsely report Ready when known dirty evidence + is present. + diff --git a/seaweed-block/docs/wiki/deep-dives/testops-authoring.md b/seaweed-block/docs/wiki/deep-dives/testops-authoring.md new file mode 100644 index 0000000000..6da768fb5f --- /dev/null +++ b/seaweed-block/docs/wiki/deep-dives/testops-authoring.md @@ -0,0 +1,97 @@ +# TestOps Authoring Guide + +TestOps scenarios are product evidence. They should not merely prove that a +helper script printed the expected text. + +## Realism Levels + +| Level | Pattern | Product value | +|---|---|---| +| L0 self-proof | helper writes `x=1`, scenario greps `x=1` | weak; avoid for claims | +| L1 replay | saved bundle is replayed through report/status logic | good for projection | +| L2 live injection | real failure is induced and observed | good for status/failure claims | +| L3 adversarial | live failure plus timing/concurrency/isolation | release-grade evidence | + +## Scenario Shape + +A good scenario has: + +```text +pre-run cleanup +-> install/provision +-> induce or observe product state +-> collect independent evidence +-> assert status/action/surface behavior +-> cleanup +-> residue verifier +``` + +## Anti-Pattern: Self-Proof + +Bad: + +```text +script echoes managed_volume_count=3 +scenario greps managed_volume_count=3 +``` + +Better: + +```text +script reports managed_volume_count=3 +scenario independently queries Kubernetes or operator-snapshot and compares +``` + +## Gate Design Checklist + +Before adding a scenario, answer: + +```text +What product claim does this gate defend? +What independent evidence source checks the helper output? +What false-positive would make this test dangerous? +What residue must be cleaned? +Does failure produce a cold-reader bundle? +Is the gate L1, L2, or L3? +``` + +## Evidence Surfaces + +Prefer gates that compare at least two surfaces: + +- CRD status, +- operator-snapshot.json, +- report summary, +- dashboard JSON, +- explain output, +- Kubernetes Events, +- host cleanup verifier, +- direct workload read/write. + +## Scenario Families + +| Family | Purpose | +|---|---| +| first-volume | user install and PVC loop | +| multi-volume RF=3 | identity isolation and frontend collision prevention | +| restart persistence | data/authority persistence after k3s restart | +| negative status | blocked/unknown reasons and no false Ready | +| dirty failure | WAL/status endpoint corruption-style failures | +| lifecycle-owner | admission and finalizer boundaries | +| cleanup | zero-residue and delete-safety evidence | + +## Main Files + +| Area | Path | +|---|---| +| scenario definitions | `testops/scenarios/` | +| suites | `testops/suites/` | +| runner contracts | `internal/docs/ref/testops-runner-binary-contract.md` | +| control/data contract | `internal/docs/ref/testops-control-data-contract.md` | +| QA sign-offs | `internal/docs/qa-assignments/` | + +## Release Rule + +Do not call a feature product-ready from unit tests alone. A release claim needs +at least one replay or live gate that exercises the user-visible surface. + diff --git a/seaweed-block/internal/docs/current-plan.md b/seaweed-block/internal/docs/current-plan.md index cee530bcd2..ae776df8f1 100644 --- a/seaweed-block/internal/docs/current-plan.md +++ b/seaweed-block/internal/docs/current-plan.md @@ -106,10 +106,10 @@ Acceptance: [x] major domains from the last several months are listed [x] each domain maps to source evidence and current wiki coverage [x] priority deep pages are ordered for review -[ ] operation-layer v0.5 deep dive -[ ] block engine / WAL dirty-failure deep dive -[ ] CSI + SwBlockVolume lifecycle deep dive -[ ] TestOps scenario authoring deep dive +[x] operation-layer v0.5 deep dive +[x] block engine / WAL dirty-failure deep dive +[x] CSI + SwBlockVolume lifecycle deep dive +[x] TestOps scenario authoring deep dive [ ] returned-replica rebuild readiness deep dive ``` diff --git a/seaweed-block/mkdocs.yml b/seaweed-block/mkdocs.yml index 25b2135076..86f94a7797 100644 --- a/seaweed-block/mkdocs.yml +++ b/seaweed-block/mkdocs.yml @@ -39,6 +39,12 @@ nav: - Protocol Catalog: wiki/protocol-catalog.md - Phase Map: wiki/phase-map.md - QA and TestOps Map: wiki/testops-map.md + - Deep Dives: + - CSI Lifecycle: wiki/deep-dives/csi-lifecycle.md + - Operation Layer v0.5: wiki/deep-dives/operation-layer-v05.md + - ManagedVolume Readiness: wiki/deep-dives/managed-volume-readiness.md + - SmartWAL Dirty Failure: wiki/deep-dives/smartwal-dirty-failure.md + - TestOps Authoring: wiki/deep-dives/testops-authoring.md - Product: - Overview: overview.md - User Capabilities: user-capabilities.md