diff --git a/seaweed-block/cmd/blockvolume/main.go b/seaweed-block/cmd/blockvolume/main.go index 6ae1f22433..b5f037a042 100644 --- a/seaweed-block/cmd/blockvolume/main.go +++ b/seaweed-block/cmd/blockvolume/main.go @@ -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) } diff --git a/seaweed-block/core/host/volume/master_wait_test.go b/seaweed-block/core/host/volume/master_wait_test.go index bb33d18d77..ced1c0af6a 100644 --- a/seaweed-block/core/host/volume/master_wait_test.go +++ b/seaweed-block/core/host/volume/master_wait_test.go @@ -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) + } +} diff --git a/seaweed-block/core/host/volume/status_server.go b/seaweed-block/core/host/volume/status_server.go index 456b46f1e3..0202686b8e 100644 --- a/seaweed-block/core/host/volume/status_server.go +++ b/seaweed-block/core/host/volume/status_server.go @@ -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: