Files
seaweedfs/seaweed-block/core/host/volume/subscribe.go
T
Ping Qiu 5c4f995c55 v0.2 alpha: Day-1 activation and first-volume loop (#48)
Package the Kubernetes alpha into a script-based Day-1 activation loop: activate the stack, create the first PVC-backed volume, verify writer/reader data, collect product-owned observation evidence, render a local read-only report, and clean up.

Includes multi-node-safe activation defaults, first-volume example automation, read-only ops report output, README/quickstart/release note updates, and review-driven hardening for fail-fast configuration, promotion evidence, inventory fail-closed behavior, and test guards.

Validated by Day-1 activation run 20260517-205252-04e9 and read-only report run 20260517-212358-bfba. Local targeted tests passed.
2026-05-18 16:43:35 -07:00

115 lines
4.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).
// - 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"
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,
})
}
return out, f.PeerSetGeneration
}