mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
* V3 mini engine: Phase 01 + 02 + 03 initial implementation Phase 01 — Semantic Core (engine/): - 5 truth domains, 11 events, 6 commands, deterministic Apply() - Stale rejection, terminal truth, wrong-replica guard - 17 conformance tests Phase 02 — Reference Runtime (schema/ + runtime/ + conformance/): - YAML case loader with strict validation - Replay runner with expectation checker - 7 cases, 7 determinism proofs, 5 loader tests Phase 03 — Adapter (adapter/): - Single route: observation -> engine -> command -> executor - CommandExecutor with SetOnSessionClose callback - Command dispatch outside lock, session ID owned by adapter - 8 constraint tests (C8/C9/C10/C12 + callback + full route) 44 tests total, all passing. * Phase 04: runnable block sparrow with real TCP transport First public runnable slice of seaweed-block. Demonstrates three recovery paths end-to-end through a deterministic semantic engine: 1. Healthy: replica caught up (R >= H), no recovery needed 2. Catch-up: short gap (R >= S, R < H), ship blocks via TCP 3. Rebuild: long gap (R < S), full base copy via TCP Package structure (renamed v3mini/ -> core/): core/engine - deterministic Apply(state, event) reducer core/adapter - single-route adapter with async callback wiring core/schema - YAML conformance case loading (strict fields) core/runtime - replay runner for conformance oracle core/conformance - 7 YAML cases + determinism + loader tests core/storage - in-memory block store with LSN tracking core/transport - TCP protocol, replica listener, block executor cmd/sparrow - runnable demo binary 51 tests, all passing. Sparrow runs via: go run ./cmd/sparrow Key design rules enforced: - Engine decides, executor executes (C12) - Same facts produce same decision (C8) - Timer only triggers probe, never recovery (C9) - No transport state in engine (C10, recursive reflect guard) - Terminal truth only from SessionClosedCompleted - Executor honors engine-issued targetLSN exactly - Session close callback wired from executor to adapter to engine - Command dispatch outside adapter mutex (no deadlock risk) - Rebuild uses AdvanceFrontier (no LBA 0 corruption) - Catch-up reports barrier-confirmed achievedLSN, not intent * fix: address CodeRabbit/Gemini review findings 1. Max payload limit in ReadMsg (16MB cap, prevents memory exhaustion) 2. Session ID race fix: capture IDs under lock in buildSessionEvents, pass via map to executeCommand — no re-locking needed 3. Barrier response error handling in replica listener 4. Demo 1 uses waitForMode polling instead of fixed sleep 5. ApplyEntry validates data size matches blockSize 6. Rebuild test timing: small delay for replica Sync after MsgRebuildDone
58 lines
1.4 KiB
Go
58 lines
1.4 KiB
Go
package schema
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"os"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
// LoadCaseSuite loads a conformance case suite from a YAML file.
|
|
func LoadCaseSuite(path string) (*CaseSuite, error) {
|
|
data, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("schema: read %s: %w", path, err)
|
|
}
|
|
return ParseCaseSuite(data)
|
|
}
|
|
|
|
// ParseCaseSuite parses a conformance case suite from YAML bytes.
|
|
// Uses strict decoding: unknown fields are rejected to prevent typos
|
|
// from silently weakening conformance expectations.
|
|
func ParseCaseSuite(data []byte) (*CaseSuite, error) {
|
|
var suite CaseSuite
|
|
dec := yaml.NewDecoder(bytes.NewReader(data))
|
|
dec.KnownFields(true) // reject unknown fields
|
|
if err := dec.Decode(&suite); err != nil {
|
|
return nil, fmt.Errorf("schema: parse: %w", err)
|
|
}
|
|
if err := validateSuite(&suite); err != nil {
|
|
return nil, err
|
|
}
|
|
return &suite, nil
|
|
}
|
|
|
|
func validateSuite(suite *CaseSuite) error {
|
|
if suite.Version == "" {
|
|
return fmt.Errorf("schema: missing version")
|
|
}
|
|
if len(suite.Cases) == 0 {
|
|
return fmt.Errorf("schema: no cases defined")
|
|
}
|
|
for i, c := range suite.Cases {
|
|
if c.Name == "" {
|
|
return fmt.Errorf("schema: case %d missing name", i)
|
|
}
|
|
if len(c.Events) == 0 {
|
|
return fmt.Errorf("schema: case %q has no events", c.Name)
|
|
}
|
|
for j, ev := range c.Events {
|
|
if ev.Kind == "" {
|
|
return fmt.Errorf("schema: case %q event %d missing kind", c.Name, j)
|
|
}
|
|
}
|
|
}
|
|
return nil
|
|
}
|