mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
feat: /status MasterWait for a workspace primary without a grant
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d16a30eca4
commit
232a74e73e
3 files changed
+54
No files matched your search
@@ -630,6 +630,7 @@ func runVolume(f flags, exits *processExit) int {
|
||||
var status *volume.StatusServer
|
||||
if f.statusAddr != "" {
|
||||
status = volume.NewStatusServer(h.ProjectionView())
|
||||
status.SetMasterWait(h.MasterWaitStatus)
|
||||
if f.nvmeListen != "" {
|
||||
status.SetNVMeListenerReady(false)
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/engine"
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/durable"
|
||||
control "github.com/seaweedfs/seaweed-block/core/rpc/control"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
@@ -161,3 +163,24 @@ func TestLeaseGuardSleepsUntilTheBarrier(t *testing.T) {
|
||||
t.Fatal("Run did not stop during the barrier sleep")
|
||||
}
|
||||
}
|
||||
|
||||
// /status shows MasterWait (reason, since, until) only while a workspace
|
||||
// primary holds no granted lease.
|
||||
func TestStatusShowsTheMasterWait(t *testing.T) {
|
||||
p := stubProjector{p: engine.ReplicaProjection{Mode: engine.ModeHealthy, Epoch: 1, EndpointVersion: 1}}
|
||||
view := NewAdapterProjectionView(p, "v1", "r1", nil)
|
||||
view.workspaceRequired = true
|
||||
s := NewStatusServer(view)
|
||||
s.SetDurableStatusSource(stubDurableStatusSource{vols: []durable.VolumeStatus{{VolumeID: "v1", Operational: true}}})
|
||||
since, until := time.Unix(1000, 0), time.Unix(1045, 0)
|
||||
s.SetMasterWait(func() *MasterWait { return &MasterWait{Reason: "barrier", Since: since, Until: until} })
|
||||
got := s.statusProjection()
|
||||
if got.NotReadyReason != NotReadyLeaseNotHeld || got.MasterWait == nil ||
|
||||
*got.MasterWait != (MasterWaitStatus{Reason: "barrier", SinceMs: since.UnixMilli(), UntilMs: until.UnixMilli()}) {
|
||||
t.Fatalf("status %q MasterWait %+v; want barrier since/until", got.NotReadyReason, got.MasterWait)
|
||||
}
|
||||
view.workspaceRequired = false
|
||||
if got := s.statusProjection(); got.MasterWait != nil {
|
||||
t.Fatalf("MasterWait %+v shown without a lease wait", got.MasterWait)
|
||||
}
|
||||
}
|
||||
@@ -64,6 +64,7 @@ type StatusServer struct {
|
||||
allowExternal bool
|
||||
peerSource peerStatusSource
|
||||
durableSource durableStatusSource
|
||||
masterWait func() *MasterWait // why a workspace primary holds no grant; nil: not wired
|
||||
nvmeSource nvmeStatusSource
|
||||
ublkSource ublkStatusSource
|
||||
runtimeSource runtimeRecoverySource
|
||||
@@ -218,6 +219,26 @@ type StatusProjection struct {
|
||||
// wal_hole_suspected, issue #51). Visible, not an alert: they do not
|
||||
// change Healthy or the frontend's readiness.
|
||||
Warnings []string `json:",omitempty"`
|
||||
// MasterWait is why a workspace primary holds no granted lease, present
|
||||
// only while NotReadyReason is lease_not_held: Reason (unreachable,
|
||||
// credentials, barrier, no_assignment, refused, moved, deleted), since
|
||||
// when, and the wait's bound or the master's barrier time (UntilMs,
|
||||
// absent while there is no bound).
|
||||
MasterWait *MasterWaitStatus `json:",omitempty"`
|
||||
}
|
||||
|
||||
// MasterWaitStatus is MasterWait on /status (unix milliseconds).
|
||||
type MasterWaitStatus struct {
|
||||
Reason string
|
||||
SinceMs int64
|
||||
UntilMs int64 `json:",omitempty"`
|
||||
}
|
||||
|
||||
// SetMasterWait wires the host's master-wait reason into /status.
|
||||
func (s *StatusServer) SetMasterWait(f func() *MasterWait) {
|
||||
s.mu.Lock()
|
||||
s.masterWait = f
|
||||
s.mu.Unlock()
|
||||
}
|
||||
|
||||
// CatchUpStatus is a supporting replica's catch-up state.
|
||||
@@ -506,6 +527,7 @@ func (s *StatusServer) statusProjection() StatusProjection {
|
||||
p.Healthy = p.Healthy && !nvmePending
|
||||
p.FrontendPrimaryReady = p.FrontendPrimaryReady && !nvmePending
|
||||
src := s.durableSource
|
||||
masterWait := s.masterWait
|
||||
s.mu.Unlock()
|
||||
// INV-FE-PRIMARY-READY-OPERATIONAL-001: not FrontendPrimaryReady while the
|
||||
// local backend admits no I/O (before the storage claim of a chunk volume,
|
||||
@@ -534,6 +556,14 @@ func (s *StatusServer) statusProjection() StatusProjection {
|
||||
switch {
|
||||
case leaseNotHeld:
|
||||
p.NotReadyReason = NotReadyLeaseNotHeld
|
||||
if masterWait != nil {
|
||||
if w := masterWait(); w != nil {
|
||||
p.MasterWait = &MasterWaitStatus{Reason: w.Reason, SinceMs: w.Since.UnixMilli()}
|
||||
if !w.Until.IsZero() {
|
||||
p.MasterWait.UntilMs = w.Until.UnixMilli()
|
||||
}
|
||||
}
|
||||
}
|
||||
case backendReason != "":
|
||||
p.NotReadyReason = backendReason
|
||||
case nvmePending:
|
||||
|
||||
Reference in new issue
Block a user