Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 28 additions & 16 deletions csi-driver/internal/mds/agent/nfsd_watchdog.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,10 @@ type NFSDWatchdog struct {
inEpisode bool
episodeAt time.Time
lastDump time.Time
// stuckSince is episodeAt while an episode lasts, nil otherwise, for
// readers beside Tick.
stuckSince atomic.Pointer[time.Time]
// stalledSince is when nfsd stopped completing requests, nil while it
// completes them, for readers beside Tick. A thread on one wait starts an
// episode but not a stall: under load it serves many requests there.
stalledSince atomic.Pointer[time.Time]
}

func (w *NFSDWatchdog) now() time.Time {
Expand Down Expand Up @@ -264,16 +265,16 @@ func (w *NFSDWatchdog) Tick() {

stuck := w.trackWaits(threads)
calls, haveCalls := readRPCCalls(root)
notDraining := running && w.trackPool(pool, calls, haveCalls)
notDraining, flat := w.trackPool(pool, calls, haveCalls)
notDraining = running && notDraining
w.trackStall(notDraining || (len(stuck) > 0 && (!haveCalls || flat)))
if running && w.ticks%summaryEvery == 0 {
w.summarize(threads, pool)
}

switch {
case (len(stuck) > 0 || notDraining) && !w.inEpisode:
w.inEpisode, w.episodeAt = true, w.now()
at := w.episodeAt
w.stuckSince.Store(&at)
w.Log.Warningf("nfsd watchdog: nfsd looks stuck: %s", describeEpisode(stuck, notDraining))
w.dumpStacks(root, threads)
case (len(stuck) > 0 || notDraining) && w.now().Sub(w.lastDump) >= stackDumpEvery:
Expand All @@ -282,7 +283,6 @@ func (w *NFSDWatchdog) Tick() {
w.dumpStacks(root, threads)
case len(stuck) == 0 && !notDraining && w.inEpisode:
w.inEpisode = false
w.stuckSince.Store(nil)
w.Log.Infof("nfsd watchdog: episode ended after %s", w.now().Sub(w.episodeAt).Round(time.Second))
}
}
Expand All @@ -309,13 +309,24 @@ func (w *NFSDWatchdog) trackWaits(threads []nfsdThread) []nfsdThread {
return stuck
}

// trackStall starts or ends the stall StuckFor reports.
func (w *NFSDWatchdog) trackStall(stalled bool) {
switch {
case stalled && w.stalledSince.Load() == nil:
at := w.now()
w.stalledSince.Store(&at)
case !stalled:
w.stalledSince.Store(nil)
}
}

// trackPool reports whether work arrived over the last stuckTicks ticks while
// nfsd processed no request. Without the RPC statistics it does not judge:
// there is no progress to compare the arrivals with.
func (w *NFSDWatchdog) trackPool(pool poolStats, calls uint64, haveCalls bool) bool {
// nfsd processed no request, and whether it processed none at all. Without the
// RPC statistics it does not judge: there is no progress to compare with.
func (w *NFSDWatchdog) trackPool(pool poolStats, calls uint64, haveCalls bool) (notDraining, flat bool) {
if !haveCalls {
w.pools, w.calls = nil, nil
return false
return false, false
}
w.pools = append(w.pools, pool)
w.calls = append(w.calls, calls)
Expand All @@ -324,10 +335,11 @@ func (w *NFSDWatchdog) trackPool(pool poolStats, calls uint64, haveCalls bool) b
w.calls = w.calls[len(w.calls)-stuckTicks-1:]
}
if len(w.pools) <= stuckTicks {
return false
return false, false
}
moved := pool.minus(w.pools[0])
return (moved.Arrived > 0 || moved.Enqueued > 0) && calls == w.calls[0]
flat = calls == w.calls[0]
return (moved.Arrived > 0 || moved.Enqueued > 0) && flat, flat
}

// summarize logs one line: threads by state, the wchans they wait in, and the
Expand Down Expand Up @@ -412,10 +424,10 @@ func RunNFSDWatchdog(ctx context.Context, w *NFSDWatchdog, interval time.Duratio
}
}

// StuckFor reports how long the current stuck episode has lasted, zero outside
// one. Safe to call beside Tick.
// StuckFor reports how long nfsd has completed no request while it had work,
// zero while it completes them. Safe to call beside Tick.
func (w *NFSDWatchdog) StuckFor() time.Duration {
since := w.stuckSince.Load()
since := w.stalledSince.Load()
if since == nil {
return 0
}
Expand Down
38 changes: 38 additions & 0 deletions csi-driver/internal/mds/agent/nfsd_watchdog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,3 +387,41 @@ func TestTheWatchdogReportsHowLongNFSDHasBeenStuck(t *testing.T) {
t.Errorf("StuckFor = %v after the episode ended, want 0", got)
}
}

// Regression: SFAM-2857. Under heavy writes every request a thread serves can
// block on the same wchan, so the thread looks stuck while requests complete.
// That is load, not a stall, and must not count toward the guest's health.
func TestAThreadOnOneWaitWhileRequestsCompleteIsNotStuckForHealth(t *testing.T) {
p := newFakeProc(t)
p.thread(101, "nfsd", "D", "xlog_wait_on_iclog")
now := time.Unix(0, 0)
w := newWatchdog(p, &recorder{}, &now)
for i := range 20 {
p.pool(10+100*i, 10+100*i, 10+100*i)
p.rpcCalls(500 + 100*i)
w.Tick()
now = now.Add(15 * time.Second)
}
if got := w.StuckFor(); got != 0 {
t.Errorf("StuckFor = %v while requests keep completing, want 0", got)
}
}

// The same wait with no request completing is a real stall: a disk that died
// under nfsd while clients stopped sending.
func TestAThreadOnOneWaitWithNoRequestCompletingIsStuckForHealth(t *testing.T) {
p := newFakeProc(t)
p.pool(10, 10, 10)
p.rpcCalls(500)
p.thread(101, "nfsd", "D", "submit_bio_wait")
now := time.Unix(0, 0)
w := newWatchdog(p, &recorder{}, &now)
for range 4 {
w.Tick()
}
now = now.Add(4 * time.Minute)
w.Tick()
if got := w.StuckFor(); got != 4*time.Minute {
t.Errorf("StuckFor = %v with no request completing, want 4m", got)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,13 @@ spec:
type: string
type: object
type: array
unhealthyDeadline:
description: |-
UnhealthyDeadline is how long a booted guest may stay unhealthy before
the pod restarts. The metadata server is a singleton in the data path of
every pNFS volume, so a restart pauses all of them. 0s never restarts it.
Unset keeps the runner's default of 90s.
type: string
type: object
type: object
sidecarImages:
Expand Down
7 changes: 7 additions & 0 deletions operator/api/v1alpha2/simplyblockdriver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,13 @@ type DriverPNFSMDS struct {
// server.
// +optional
DataNetwork *DriverPNFSDataNetwork `json:"dataNetwork,omitempty"`

// UnhealthyDeadline is how long a booted guest may stay unhealthy before
// the pod restarts. The metadata server is a singleton in the data path of
// every pNFS volume, so a restart pauses all of them. 0s never restarts it.
// Unset keeps the runner's default of 90s.
// +optional
UnhealthyDeadline *metav1.Duration `json:"unhealthyDeadline,omitempty"`
}

// DriverPNFSDataNetwork is the storage data network the metadata server is
Expand Down
5 changes: 5 additions & 0 deletions operator/api/v1alpha2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,13 @@ spec:
type: string
type: object
type: array
unhealthyDeadline:
description: |-
UnhealthyDeadline is how long a booted guest may stay unhealthy before
the pod restarts. The metadata server is a singleton in the data path of
every pNFS volume, so a restart pauses all of them. 0s never restarts it.
Unset keeps the runner's default of 90s.
type: string
type: object
type: object
sidecarImages:
Expand Down
7 changes: 7 additions & 0 deletions operator/dist/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6760,6 +6760,13 @@ spec:
type: string
type: object
type: array
unhealthyDeadline:
description: |-
UnhealthyDeadline is how long a booted guest may stay unhealthy before
the pod restarts. The metadata server is a singleton in the data path of
every pNFS volume, so a restart pauses all of them. 0s never restarts it.
Unset keeps the runner's default of 90s.
type: string
type: object
type: object
sidecarImages:
Expand Down
3 changes: 3 additions & 0 deletions operator/internal/controllers/driver/mds.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,9 @@ func mdsRunnerContainer(
// The guest's traffic to the data network leaves through it.
args = append(args, "--data-interface="+MDSDataInterface)
}
if spec.UnhealthyDeadline != nil {
args = append(args, "--unhealthy-deadline="+spec.UnhealthyDeadline.Duration.String())
}
return corev1.Container{
Name: MDSContainerName,
Image: image,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Tests that SimplyblockDriver.spec.pnfs.mds.unhealthyDeadline reaches the
// runner, the only lever short of pinning an image (SFAM-2857).

package driver

import (
"slices"
"strings"
"testing"
"time"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func TestMDSRunnerTakesTheUnhealthyDeadline(t *testing.T) {
d := withMDS(testDriver("simplyblock"))
d.Spec.PNFS.MDS.UnhealthyDeadline = &metav1.Duration{Duration: 0}
_, sts, err := MDSObjects(d, testClusterID, "simplyblock-state", nil)
if err != nil {
t.Fatalf("MDSObjects: %v", err)
}
if args := runnerContainer(t, sts).Args; !slices.Contains(args, "--unhealthy-deadline=0s") {
t.Errorf("runner args = %v, want --unhealthy-deadline=0s", args)
}

d.Spec.PNFS.MDS.UnhealthyDeadline = &metav1.Duration{Duration: 10 * time.Minute}
_, sts, _ = MDSObjects(d, testClusterID, "simplyblock-state", nil)
if args := runnerContainer(t, sts).Args; !slices.Contains(args, "--unhealthy-deadline=10m0s") {
t.Errorf("runner args = %v, want --unhealthy-deadline=10m0s", args)
}
}

// Unset leaves the runner's own default in force.
func TestMDSRunnerWithoutAnUnhealthyDeadlineKeepsItsDefault(t *testing.T) {
_, sts, err := MDSObjects(withMDS(testDriver("simplyblock")), testClusterID, "simplyblock-state", nil)
if err != nil {
t.Fatalf("MDSObjects: %v", err)
}
for _, arg := range runnerContainer(t, sts).Args {
if strings.HasPrefix(arg, "--unhealthy-deadline") {
t.Errorf("runner args carry %q with the field unset", arg)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,13 @@ spec:
type: string
type: object
type: array
unhealthyDeadline:
description: |-
UnhealthyDeadline is how long a booted guest may stay unhealthy before
the pod restarts. The metadata server is a singleton in the data path of
every pNFS volume, so a restart pauses all of them. 0s never restarts it.
Unset keeps the runner's default of 90s.
type: string
type: object
type: object
sidecarImages:
Expand Down
Loading