fix: one server id names one host; portal and primary from the line server

INV-ASSIGNMENT-HOLDER-IDENTITY-001.
- ReportHeartbeat refuses (FailedPrecondition) a heartbeat whose slot addresses are
  on a host other than the one registered for its server id. Only the host part is
  compared; several server ids on one host stay allowed; an unregistered id has
  nothing to contradict.
- QueryVolumeStatus lists the primary's frontends from the server on the authority
  line (workspaceSourceHost), never a fresher same-replica claim from another server.
- ClusterStatus primary node is the line's server (issued holder), not placement, and
  the primary replica's evidence and publish target come only from that server.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Opus 5.5 committed 2026-11-22 04:44:21 -08:00
1 parent 6ff7a6a2b7
commit 5c912694b1
3 files changed
+98 -4

No files matched your search

@@ -122,7 +122,8 @@ func (h *Host) observationVolume(volumeID string, rec lifecycle.VolumeRecord, pl
volume.Replicas = replicas
volume.ObservedReplicas = countObservedReplicas(replicas)
if volume.PrimaryReplica != "" {
volume.PrimaryNode = serverForReplica(placement, volume.PrimaryReplica)
// the server on the authority line (issued holder), not placement (INV-ASSIGNMENT-HOLDER-IDENTITY-001)
volume.PrimaryNode = h.workspaceSourceHost(volumeID, line.ReplicaID, line.Epoch)
volume.PublishTarget = publishTargetForReplica(replicas, volume.PrimaryReplica)
}
@@ -230,7 +231,12 @@ func (h *Host) observationReplicas(volumeID string, placement lifecycle.Placemen
replica.Role = "primary"
replica.ReplicationRole = "primary"
}
if fact, ok := h.ObservationHost().Store().SlotFact(volumeID, replicaID); ok {
fact, ok := h.ObservationHost().Store().SlotFact(volumeID, replicaID)
if hasLine && line.Assigned && replicaID == line.ReplicaID {
// the primary's evidence comes only from the line's server (INV-ASSIGNMENT-HOLDER-IDENTITY-001)
_, fact, ok = h.holderSlotFact(volumeID, replicaID, line.Epoch)
}
if ok {
replica.Observed = true
replica.CandidateReady = fact.ReadyForPrimary
replica.CandidateReadyReason = candidateReason(fact.ReadyForPrimary)
@@ -0,0 +1,67 @@
package master
import (
"fmt"
"net"
"strings"
"github.com/seaweedfs/seaweed-block/core/authority"
"github.com/seaweedfs/seaweed-block/core/rpc/control"
)
// addrHost is the host part of a host:port (or bare host) address.
func addrHost(addr string) string {
if h, _, err := net.SplitHostPort(addr); err == nil {
return h
}
return strings.TrimSpace(addr)
}
// refuseServerIDFromOtherHost implements the host half of INV-ASSIGNMENT-HOLDER-IDENTITY-001. OSS has no host
// authentication, so a server id names a host only if every address a heartbeat reports under that id is on the host
// registered for it. A second process started with the same --server-id elsewhere (a copied config) is refused before
// its slots reach the observations. Only the host part is compared (each volume process listens on its own ports);
// several server ids on one host stay allowed; an id with no registry record has nothing to contradict.
func (h *Host) refuseServerIDFromOtherHost(r *control.HeartbeatReport) error {
if h.lifecycle == nil || h.lifecycle.Nodes == nil {
return nil
}
reg, ok := h.lifecycle.Nodes.GetNode(r.ServerId)
if !ok {
return nil
}
hosts := map[string]bool{}
for _, a := range []string{reg.DataAddr, reg.CtrlAddr, reg.Addr} {
if a != "" {
hosts[addrHost(a)] = true
}
}
if len(hosts) == 0 {
return nil
}
registered := addrHost(reg.DataAddr)
if registered == "" {
registered = addrHost(reg.Addr)
}
for _, s := range r.Slots {
for _, a := range []string{s.DataAddr, s.CtrlAddr} {
if a != "" && !hosts[addrHost(a)] {
return fmt.Errorf("heartbeat: server id %s is registered on host %s; refused from %s (volume %s replica %s): one server id names one host",
r.ServerId, registered, addrHost(a), s.VolumeId, s.ReplicaId)
}
}
}
return nil
}
// holderSlotFact is the slot fact of replica on the server the authority line names (workspaceSourceHost); a
// same-replica claim from any other server, however fresh, is never used (INV-ASSIGNMENT-HOLDER-IDENTITY-001).
// No resolvable holder: no fact (fail closed).
func (h *Host) holderSlotFact(volumeID, replicaID string, epoch uint64) (string, authority.SlotFact, bool) {
holder := h.workspaceSourceHost(volumeID, replicaID, epoch)
if holder == "" || h.obs == nil {
return holder, authority.SlotFact{}, false
}
fact, ok := h.obs.Store().SlotFactOnServer(holder, volumeID, replicaID)
return holder, fact, ok
}
+23 -2
View File
@@ -292,6 +292,10 @@ func (s *services) ReportHeartbeat(ctx context.Context, r *control.HeartbeatRepo
if err := s.host.refuseColocatedHeartbeat(r.ServerId, storeident.Identity{MachineID: r.GetMachineId(), Dev: r.GetDurableRootDev(), FSID: r.GetDurableRootFsid()}); err != nil {
return nil, status.Error(codes.FailedPrecondition, err.Error())
}
// INV-ASSIGNMENT-HOLDER-IDENTITY-001: one server id names one host.
if err := s.host.refuseServerIDFromOtherHost(r); err != nil {
return nil, status.Error(codes.FailedPrecondition, err.Error())
}
msg := heartbeatFromWire(r)
if err := s.host.ingestHeartbeatRecordingHealth(msg); err != nil {
return nil, fmt.Errorf("ingest: %w", err)
@@ -509,7 +513,15 @@ func (s *services) QueryVolumeStatus(ctx context.Context, req *control.StatusReq
replicaIDs = []string{line.ReplicaID}
}
replicaIDs = primaryFirstReplicaIDs(replicaIDs, line.ReplicaID)
resp.Frontends = statusFrontendsForAssignedVolume(s.host.obs, req.VolumeId, replicaIDs, line.Assigned)
// the primary's portal comes from the server on the line, never a fresher same-replica claim elsewhere
// (INV-ASSIGNMENT-HOLDER-IDENTITY-001)
resp.Frontends = statusFrontendsFor(s.host.obs, req.VolumeId, replicaIDs, line.Assigned, func(replicaID string) (authority.SlotFact, bool) {
if replicaID == line.ReplicaID {
_, fact, ok := s.host.holderSlotFact(req.VolumeId, replicaID, line.Epoch)
return fact, ok
}
return s.host.obs.Store().SlotFact(req.VolumeId, replicaID)
})
resp.UnhealthyReplicas = statusUnhealthyReplicas(s.host.obs, req.VolumeId, replicaIDs)
}
if ev, ok := ctrl.LastUnsupported(req.VolumeId); ok {
@@ -553,16 +565,25 @@ func primaryFirstReplicaIDs(replicaIDs []string, primaryReplicaID string) []stri
}
func statusFrontendsForAssignedVolume(obs *authority.ObservationHost, volumeID string, replicaIDs []string, assigned bool) []*control.FrontendTarget {
return statusFrontendsFor(obs, volumeID, replicaIDs, assigned, nil)
}
// statusFrontendsFor lists the frontends of replicaIDs in order; slotOf selects each replica's slot fact (nil: the
// freshest claim for that replica).
func statusFrontendsFor(obs *authority.ObservationHost, volumeID string, replicaIDs []string, assigned bool, slotOf func(replicaID string) (authority.SlotFact, bool)) []*control.FrontendTarget {
if !assigned || obs == nil {
return nil
}
if slotOf == nil {
slotOf = func(replicaID string) (authority.SlotFact, bool) { return obs.Store().SlotFact(volumeID, replicaID) }
}
out := make([]*control.FrontendTarget, 0, len(replicaIDs))
seen := map[string]struct{}{}
for _, replicaID := range replicaIDs {
if replicaID == "" {
continue
}
slot, ok := obs.Store().SlotFact(volumeID, replicaID)
slot, ok := slotOf(replicaID)
if !ok {
continue
}