Files
seaweedfs/seaweed-block/core/host/volume/subscribe.go
T
pingqiuandClaude Opus 5.5 5bf6e17ab1 replication, master, volume: count a peer only with the master-recorded store
A peer counts toward write ACKs only while its barrier store equals the
store the master recorded for it from a primary's attestation, carried in
the replica descriptor; empty never matches, and the peer's own word never
changes it. A record change re-sends the assignment at the same
generation and the primary updates expected stores in place.

A volume's first bind records its initial replicas: until each has an
attested store the fact carries the awaited count, the primary serves no
frontend I/O and reports "creating: waiting for replica attestations
(n of N)"; the primary learns new peers' stores with a barrier at LSN 0.
Replica rows show store_attested/store_id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 06:43:45 -08:00

117 lines
4.6 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).
// - adapter.AssignmentInfo composite literals are allowed only
// in named decode/identity boundary functions.
// 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"
"github.com/seaweedfs/seaweed-block/core/storage"
control "github.com/seaweedfs/seaweed-block/core/rpc/control"
)
// decodeAssignmentFact is the primary 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).
// Additional supporting-replica decode sites must be named and AST-pinned by
// TestNoOtherAssignmentInfoConstruction.
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,
}
}
// decodeSelfPeerAssignment extracts this host's supporting-replica lineage from
// a master-minted primary AssignmentFact. It is deliberately parallel to
// decodeAssignmentFact and still field-copy only: the peer descriptor is the
// master's statement that this replica belongs to the current volume lineage.
func decodeSelfPeerAssignment(f *control.AssignmentFact, selfReplicaID string) (adapter.AssignmentInfo, bool) {
var zero adapter.AssignmentInfo
for _, p := range f.Peers {
if p.GetReplicaId() != selfReplicaID {
continue
}
if p.GetEpoch() == 0 ||
p.GetEndpointVersion() == 0 ||
p.GetEpoch() != f.GetEpoch() ||
p.GetEndpointVersion() != f.GetEndpointVersion() ||
p.GetDataAddr() == "" ||
p.GetCtrlAddr() == "" {
return zero, false
}
return adapter.AssignmentInfo{
VolumeID: f.VolumeId,
ReplicaID: p.ReplicaId,
Epoch: p.Epoch,
EndpointVersion: p.EndpointVersion,
DataAddr: p.DataAddr,
CtrlAddr: p.CtrlAddr,
}, true
}
return zero, false
}
// 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,
StoreID: storage.StoreIDFromBytes(p.StoreId),
})
}
return out, f.PeerSetGeneration
}