Files
seaweedfs/seaweed-block/core/authority/queue.go
T
wzcheng99andClaude Opus 4.7 60c5ff5db4 P14 S4: observation institution + multi-volume topology controller
Lands two related pieces that make late-Phase-14 observation-to-
authority truth system-owned:

1. Multi-volume TopologyController (accepted P14 topology set:
   per-volume three-slot on distinct servers). This was the
   "consumer baseline" staged earlier as full-topology
   scaffolding and is committed here as the foundation S4 feeds.

2. Observation institution: heartbeat / inventory -> stable
   ClusterSnapshot producer, per the S4 assignment
   (sw-block/design/v3-phase-14-s4-assignment.md and
   v3-phase-14-s4-sketch.md).

Load-bearing boundary held across both pieces:

  * observation institution may withhold supportability, but it
    may NOT mint authority (sketch §3)
  * Publisher stays the sole minter of Epoch/EndpointVersion
  * adapter.OnAssignment stays the one and only consumer ingress
  * no new engine event, command, or projection field

Observation-side deliverables (core/authority/):

  * observation_types.go — Observation, ServerFact, SlotFact,
    LocalRoleClaim, FreshnessConfig, Supportability enum
    (pending / supported / unsupported kept VISIBLY distinct per
    architect execution note), AcceptedTopology, six reason
    constants.
  * observation_store.go — push-ingest latest-wins per ServerID,
    derived ServerFreshness (never-observed / bootstrapping /
    missing / fresh / expired), immutable storeSnapshot for
    builder input, configurable GC.
  * observation_wire.go — V2 heartbeat wire shape port
    (block_heartbeat / block_heartbeat_proto /
    block_heartbeat_loop analogues) as mechanism only.
    HeartbeatToObservation is a pure field-shape copy.
  * unsupported_evidence.go — per-volume VolumeUnsupportedEvidence
    (latest-wins per VolumeID), separate VolumePendingStatus,
    SupportabilityReport with Pending + Unsupported as distinct
    maps, BuildResult.
  * snapshot_builder.go — pure BuildSnapshot(store, topology,
    reader) -> BuildResult. Reads publisher's current per-volume
    line via the read-only AuthorityBasisReader and stamps it in
    VolumeTopologySnapshot.Authority for supported volumes, so
    the controller's stale-resistance check can match on
    subsequent feeds. Observation never mints authority.
  * observation_host.go — owns store lifecycle, push-ingest
    entry points, reactive rebuild (build-on-change + coalescing
    wake), GC sweep honoring configured retain window,
    ControllerSink atomic submission (snapshot + report
    together so supportability transitions propagate even when
    supported volumes drop to zero).

Controller-side intake (core/authority/controller.go):

  * SubmitClusterSnapshot kept as the test-scaffolding entry.
  * NEW SubmitObservedState(snap, report) — the observation-fed
    intake. Mirrors SubmitClusterSnapshot's convergence
    discipline line-for-line (stale-basis preserves desired,
    no-emit clears desired, same-ask dedupe prevents authority
    churn) and adds pending/unsupported transition handling.
    Under this intake, the controller hears every supportability
    transition, including "zero supported volumes now", which
    clears stale desired state.

V2 muscles ported (mechanism only):

  * block_heartbeat / block_heartbeat_proto field layout
    (observation_wire.go)
  * block_heartbeat_loop shape concept (host owns the loop)

Explicitly NOT ported (per assignment denylist):

  * weed/storage/blockvol/promotion.go
  * old HandleAssignment / promote / demote ownership
  * master_block_plan / master_block_failover / master_block_registry /
    master_block_assignment_queue (reference only for S5/S6)
  * any V2 path where heartbeat timing or local status becomes
    failover truth

Proof matrix (observation_test.go — 35 tests covering all sketch
§16 rows + architect-round regressions):

  Authoring:
    - PartialInventory_PendingThenUnsupported
    - MissingServerObservation_NeverOrdinaryIneligible
    - EndToEnd_SystemFedSnapshotReachesController
    - ConflictingPrimaryClaim_Unsupported
    - ConflictingPrimaryClaim_NoWinnerEverChosen
    - ExpiredFact_SemanticallyIneligible
    - ExpiredDoesNotReachController
    - BadVolumeDoesNotBlockHealthyVolume_Isolation
    - VolumeUnsupportedEvidence_IsolatedPerVolume
    - DuplicateServerTopology_UnsupportedAndEvidenceRecorded
    - DuplicateServerTopology_NotControllerInput

  Host-level:
    - IngestMutation_TriggersSnapshotRebuild
    - FreshnessWindowHonored_NotTickMultiples
    - GCRetainWindow_Honored

  Boundary (AST-based, sketch §16a):
    - NeverMintsAuthority_BoundaryGuard
    - SupportabilityDoesNotReadClusterSnapshotOutput

  Architect round-2 regressions:
    - BuilderStampsAuthorityFromReader
    - SupportabilityCollapsePropagatesToController
    - SupportabilityCollapseClearsControllerDesired
    - UnknownObservedVolume_ProducesUnsupportedEvidence

  Architect round-3 regressions:
    - IdenticalSupportedSnapshots_NoDuplicateAsks
    - VolumeRecovers_ClearsStaleDesired

No changes to engine, adapter, transport, ops, storage, or
sparrow. 91 authority tests pass. Full module: 12 packages pass.

Design docs in sw-block/design/ external repo:
  * v3-phase-14-s4-assignment.md
  * v3-phase-14-s4-observation-institution.md
  * v3-phase-14-s4-sketch.md
  * v3-phase-14-s4-closure-gaps.md (architect-round boundary notes)
  * v3-phase-14-full-topology-design.md
  * v3-phase-14-placement-rebalance-policy.md

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-19 16:36:17 -07:00

68 lines
1.4 KiB
Go

package authority
import (
"context"
"sync"
)
// assignmentQueue is the bounded "latest desired state per volume"
// publication queue. It is intentionally not a history-preserving
// log: the convergence package cares about the latest desired
// authority move per volume, not every intermediate planning thought.
type assignmentQueue struct {
mu sync.Mutex
items map[string]AssignmentAsk
order []string
wake chan struct{}
}
func newAssignmentQueue() *assignmentQueue {
return &assignmentQueue{
items: make(map[string]AssignmentAsk),
wake: make(chan struct{}, 1),
}
}
func (q *assignmentQueue) enqueue(ask AssignmentAsk) {
q.mu.Lock()
defer q.mu.Unlock()
if _, exists := q.items[ask.VolumeID]; !exists {
q.order = append(q.order, ask.VolumeID)
}
q.items[ask.VolumeID] = ask
select {
case q.wake <- struct{}{}:
default:
}
}
func (q *assignmentQueue) discard(volumeID string) {
q.mu.Lock()
defer q.mu.Unlock()
delete(q.items, volumeID)
}
func (q *assignmentQueue) next(ctx context.Context) (AssignmentAsk, error) {
for {
q.mu.Lock()
if len(q.order) > 0 {
vid := q.order[0]
q.order = q.order[1:]
ask, ok := q.items[vid]
if !ok {
q.mu.Unlock()
continue
}
delete(q.items, vid)
q.mu.Unlock()
return ask, nil
}
q.mu.Unlock()
select {
case <-q.wake:
case <-ctx.Done():
return AssignmentAsk{}, ctx.Err()
}
}
}