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
66 lines
2.2 KiB
Go
66 lines
2.2 KiB
Go
// Package schema defines the conformance case format for the V3 mini engine.
|
|
// Cases are declarative: an ordered list of events and the expected outcomes.
|
|
package schema
|
|
|
|
// ConformanceCase is one replay scenario for the mini engine.
|
|
// It describes an ordered event stream and what the engine should produce.
|
|
type ConformanceCase struct {
|
|
Name string `yaml:"name"`
|
|
Description string `yaml:"description,omitempty"`
|
|
Events []EventInput `yaml:"events"`
|
|
Expect Expectation `yaml:"expect"`
|
|
}
|
|
|
|
// EventInput is one event in a conformance case.
|
|
// The Kind field selects the event type; the remaining fields
|
|
// are populated based on kind.
|
|
type EventInput struct {
|
|
Kind string `yaml:"kind"`
|
|
|
|
// Identity
|
|
VolumeID string `yaml:"volume_id,omitempty"`
|
|
ReplicaID string `yaml:"replica_id,omitempty"`
|
|
Epoch uint64 `yaml:"epoch,omitempty"`
|
|
EndpointVersion uint64 `yaml:"endpoint_version,omitempty"`
|
|
DataAddr string `yaml:"data_addr,omitempty"`
|
|
CtrlAddr string `yaml:"ctrl_addr,omitempty"`
|
|
|
|
// Recovery facts
|
|
R uint64 `yaml:"r,omitempty"`
|
|
S uint64 `yaml:"s,omitempty"`
|
|
H uint64 `yaml:"h,omitempty"`
|
|
|
|
// Session
|
|
SessionID uint64 `yaml:"session_id,omitempty"`
|
|
SessionKind string `yaml:"session_kind,omitempty"`
|
|
TargetLSN uint64 `yaml:"target_lsn,omitempty"`
|
|
AchievedLSN uint64 `yaml:"achieved_lsn,omitempty"`
|
|
|
|
// Failure
|
|
Reason string `yaml:"reason,omitempty"`
|
|
TransportEpoch uint64 `yaml:"transport_epoch,omitempty"`
|
|
}
|
|
|
|
// Expectation defines what the engine should produce after all events.
|
|
type Expectation struct {
|
|
// Final projection fields.
|
|
Mode string `yaml:"mode,omitempty"`
|
|
RecoveryDecision string `yaml:"recovery_decision,omitempty"`
|
|
SessionPhase string `yaml:"session_phase,omitempty"`
|
|
|
|
// Commands that must appear (by kind name).
|
|
MustEmitCommands []string `yaml:"must_emit_commands,omitempty"`
|
|
|
|
// Commands that must NOT appear.
|
|
MustNotEmitCommands []string `yaml:"must_not_emit_commands,omitempty"`
|
|
|
|
// Trace steps that must appear.
|
|
MustHaveTraceSteps []string `yaml:"must_have_trace_steps,omitempty"`
|
|
}
|
|
|
|
// CaseSuite is a collection of conformance cases.
|
|
type CaseSuite struct {
|
|
Version string `yaml:"version"`
|
|
Cases []ConformanceCase `yaml:"cases"`
|
|
}
|