mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 10:37:23 +01:00
Completes the T4a-5.0 §8C.3 Discovery Bridge resolution (Option
P-refined, landed per architect + QA round-19). Extends the
AssignmentFact wire with master-minted peer set + monotonic
generation, adds a separate host-only decode path that does NOT
touch AssignmentInfo (preserves the TestNoOtherAssignment
InfoConstruction AST fence), and wires Host.streamOnce to drive
ReplicationVolume.UpdateReplicaSet after every self-replica
AssignmentFact.
Guardrails (all four from round-19) honored:
1. decodeAssignmentFact unchanged; AST fence stays green.
2. decodeReplicaTargets is SEPARATE and produces replication.
ReplicaTarget + generation, never AssignmentInfo. Adapter +
engine packages: zero changes.
3. Peer set is master-minted only. Host does NOT accumulate or
derive from other-replica facts (option R rejected).
4. peer_set_generation mandatory on the wire; monotonic guard in
ReplicationVolume.UpdateReplicaSet.
Changes:
core/rpc/proto/control.proto
NEW message ReplicaDescriptor{replica_id, epoch, endpoint_
version, data_addr, ctrl_addr}. AssignmentFact gains
`repeated ReplicaDescriptor peers = 7` (excludes self) and
`uint64 peer_set_generation = 8` (monotonic, master-minted).
core/rpc/control/control.pb.go + control_grpc.pb.go
Regenerated via scripts/genproto.sh.
core/host/master/services.go
SubscribeAssignments fills fact.Peers via new collectPeers
helper (reads Publisher.LastPublished for each non-self slot
in the volume's accepted topology). Generation derived as
`(info.Epoch << 32) | info.EndpointVersion` — monotonic
because publisher's lex-dedupe upstream guarantees strictly-
increasing (Epoch, EV) pairs and Epoch/EV are durable authority
facts (survives master restart).
core/host/volume/subscribe.go
NEW decodeReplicaTargets(fact) ([]replication.ReplicaTarget,
uint64) — strict field-copy, same discipline as decode
AssignmentFact. Produces a different output type so the
AST fence TestNoOtherAssignmentInfoConstruction continues to
pass.
core/host/volume/host.go
Config gains `ReplicationVolume *replication.ReplicationVolume`
(nil = T0/observer-only; non-nil = T4a-5 production wire).
streamOnce self-replica branch calls UpdateReplicaSet(gen,
targets) AFTER adapter.OnAssignment. Non-blocking log on
error (best-effort; failure does not stop the assignment
stream).
core/replication/volume.go
UpdateReplicaSet signature break (QA option (a), no shim):
Before: UpdateReplicaSet(targets []ReplicaTarget) error
After: UpdateReplicaSet(generation uint64, targets []ReplicaTarget) error
Three-way generation rule (T4a-5.0 §9.4, QA corrected sw's
original MaxUint64 sentinel which would have one-way-poisoned
the monotonic guard):
- gen == 0: unversioned apply; peer map mutated;
lastAppliedGeneration NOT advanced. Test/fake-master only.
- gen > 0 && gen > lastApplied: apply + advance.
- gen > 0 && gen <= lastApplied: stale; peer map NOT mutated;
replayedGens counter increments; debug log emits peer-ID-
set delta (Q2 binding — IDs only, not full target structs).
Returns nil (idempotent replay is success).
Empty peer set (N → 0) flows through the same teardown path as
any N → M-1 removal. No special branch (Q3 binding).
New state: lastAppliedGeneration uint64 (mu-guarded);
replayedGens atomic.Uint64 (stats counter, private; public
Stats() deferred to T4-end observability pass).
New helpers (internal): peerIDSet, targetIDSet,
stringSetEqual, formatIDSet (deterministic brace-form
rendering of peer-ID sets for log diffs).
core/replication/volume_test.go
All 8 existing tests migrated to new signature with gen=0
(unversioned apply preserves previous functional semantics).
3 new tests (Q1/Q2/Q3 pins):
9. UpdateReplicaSet_Generation_MonotonicGuard — advance
through gens 1, 2, 3; stale replays at gen=2 and gen=3
(equal is stale); verify replayedGens counter; forward
progress at gen=4 works. Exercises Q2 differing-peers
path via the gen=2 replay with original r1+r2 set.
10. UpdateReplicaSet_GenerationZero_DoesNotAdvanceGuard —
gen=5 applied, gen=0 applied (peers mutated, last
Applied stays at 5), gen=3 rejected as stale. Pins the
correctness of the gen=0 rule vs. the original
MaxUint64 sentinel which would have failed this test.
11. UpdateReplicaSet_EmptyPeerSet_AppliesWithTeardown — Q3
binding three assertions: PeerCount=0 after empty
apply, all former peers' executor sessions invalidated,
next OnLocalWrite succeeds as zero-fanout no-op.
Verification: full 20-package repo suite green (core/host: 124s
including supersede_integration_test; core/host/volume: 31ms
confirming AST fence TestNoOtherAssignmentInfoConstruction still
passes; core/replication: all 17 tests green). G-2 tri-line godoc
on every new public surface.
Closes T4a-5.0 §8C.3 Discovery Bridge. Next: T4a-6 L2 subprocess
integration test.
86 lines
3.5 KiB
Go
86 lines
3.5 KiB
Go
// Package volume implements the block volume host: the volume-side
|
|
// product daemon composition that connects to a block master, ingests
|
|
// local slot facts into periodic heartbeat RPCs, subscribes to
|
|
// the master's assignment stream, and feeds delivered assignments
|
|
// into a VolumeReplicaAdapter.
|
|
//
|
|
// T0 scope (v3-phase-15-t0-sketch.md):
|
|
//
|
|
// - Drives control-plane route only (G0 + G1).
|
|
// - NO data path, NO real runtime executor: uses a noop executor
|
|
// stub (noop_executor.go). Adapter projection reflects the
|
|
// assigned lineage; ModeHealthy is NOT claimed.
|
|
// - Single volume per process for T0 simplicity.
|
|
//
|
|
// Boundary (sketch §3 + §3.1 + §6.4):
|
|
//
|
|
// - volume host imports core/rpc (wire types) + core/adapter
|
|
// (consumer API). It MUST NOT import core/authority mint
|
|
// symbols (Publisher.apply, SubmitObservedState, AssignmentAsk).
|
|
// - The ONLY adapter.AssignmentInfo composite literal allowed
|
|
// in this package sits in decodeAssignmentFact below.
|
|
// TestNoOtherAssignmentInfoConstruction (L0) enforces this
|
|
// as a static guard.
|
|
package volume
|
|
|
|
import (
|
|
"github.com/seaweedfs/seaweed-block/core/adapter"
|
|
"github.com/seaweedfs/seaweed-block/core/replication"
|
|
control "github.com/seaweedfs/seaweed-block/core/rpc/control"
|
|
)
|
|
|
|
// decodeAssignmentFact is the SOLE permitted translator from a
|
|
// master-minted wire fact into the adapter's ingress type. It is
|
|
// a strict field-copy: every field in the output comes directly
|
|
// from the input's corresponding field. No mutation, no local
|
|
// defaults, no fields from any other source.
|
|
//
|
|
// This is the round-3 architect-pinned boundary (T0 sketch §3.1).
|
|
// If a second AssignmentInfo composite literal appears anywhere
|
|
// in core/host/volume/ the AST guard in
|
|
// TestNoOtherAssignmentInfoConstruction fails.
|
|
func decodeAssignmentFact(f *control.AssignmentFact) adapter.AssignmentInfo {
|
|
return adapter.AssignmentInfo{
|
|
VolumeID: f.VolumeId,
|
|
ReplicaID: f.ReplicaId,
|
|
Epoch: f.Epoch,
|
|
EndpointVersion: f.EndpointVersion,
|
|
DataAddr: f.DataAddr,
|
|
CtrlAddr: f.CtrlAddr,
|
|
}
|
|
}
|
|
|
|
// decodeReplicaTargets is the T4a-5 peer-set decode path. Parallel
|
|
// to decodeAssignmentFact but produces replication.ReplicaTarget
|
|
// values + the monotonic peer_set_generation — NOT adapter.Assignment
|
|
// Info. This preserves the T0 boundary (decodeAssignmentFact
|
|
// remains the sole AssignmentInfo constructor; AST fence
|
|
// TestNoOtherAssignmentInfoConstruction continues to pass) while
|
|
// unlocking primary-side replication fan-out via
|
|
// ReplicationVolume.UpdateReplicaSet(generation, targets).
|
|
//
|
|
// Field-copy only, same discipline as decodeAssignmentFact: no
|
|
// derivation, no accumulation, no cache — the peer-set authority
|
|
// is master-minted (T4a-5.0 discovery §9.1 guardrail #3).
|
|
//
|
|
// Master-side contract (v3-phase-15-t4a-5-0-host-callback-discovery
|
|
// doc §9.1): f.Peers already excludes the self-replica; no
|
|
// further filter is needed here. Callers feed the returned
|
|
// targets slice + generation directly into UpdateReplicaSet.
|
|
func decodeReplicaTargets(f *control.AssignmentFact) ([]replication.ReplicaTarget, uint64) {
|
|
if len(f.Peers) == 0 {
|
|
return nil, f.PeerSetGeneration
|
|
}
|
|
out := make([]replication.ReplicaTarget, 0, len(f.Peers))
|
|
for _, p := range f.Peers {
|
|
out = append(out, replication.ReplicaTarget{
|
|
ReplicaID: p.ReplicaId,
|
|
DataAddr: p.DataAddr,
|
|
ControlAddr: p.CtrlAddr,
|
|
Epoch: p.Epoch,
|
|
EndpointVersion: p.EndpointVersion,
|
|
})
|
|
}
|
|
return out, f.PeerSetGeneration
|
|
}
|