Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storage/disk: don't error in absence of collected states #139079

Merged
merged 1 commit into from
Jan 15, 2025
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
4 changes: 1 addition & 3 deletions pkg/storage/disk/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,7 @@ type Monitor struct {

// CumulativeStats returns the most-recent stats observed.
func (m *Monitor) CumulativeStats() (Stats, error) {
if event, err := m.tracer.Latest(); err != nil {
return Stats{}, err
} else if event.err != nil {
if event := m.tracer.Latest(); event.err != nil {
return Stats{}, event.err
} else {
return event.stats, nil
Expand Down
11 changes: 5 additions & 6 deletions pkg/storage/disk/monitor_tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"time"

"github.com/cockroachdb/cockroach/pkg/util/syncutil"
"github.com/cockroachdb/errors"
)

type traceEvent struct {
Expand Down Expand Up @@ -87,16 +86,16 @@ func (m *monitorTracer) RecordEvent(event traceEvent) {
}
}

// Latest retrieves the last traceEvent that was queued. If the trace is empty
// we throw an error.
func (m *monitorTracer) Latest() (traceEvent, error) {
// Latest retrieves the last traceEvent that was queued. Returns a zero-valued
// traceEvent if none exists.
func (m *monitorTracer) Latest() traceEvent {
m.mu.Lock()
defer m.mu.Unlock()
if m.sizeLocked() == 0 {
return traceEvent{}, errors.Errorf("trace is empty")
return traceEvent{}
}
latestIdx := (m.mu.end - 1) % m.capacity
return m.mu.trace[latestIdx], nil
return m.mu.trace[latestIdx]
}

// RollingWindow retrieves all traceEvents that occurred after the specified
Expand Down
8 changes: 2 additions & 6 deletions pkg/storage/disk/monitor_tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,9 @@ func TestMonitorTracer(t *testing.T) {
}
return ""
case "latest":
event, err := tracer.Latest()
event := tracer.Latest()
buf.Reset()
if err != nil {
fmt.Fprint(&buf, err.Error())
} else {
fmt.Fprintf(&buf, "%q", event)
}
fmt.Fprintf(&buf, "%q", event)
return buf.String()
case "trace":
buf.Reset()
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/disk/testdata/tracer
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ rolling-window time=2024-03-27T12:00:00.5Z

latest
----
trace is empty
"0001-01-01T00:00:00Z\t\t0\t0\t0\t0s\t0\t0\t0\t0s\t0\t0s\t0s\t0\t0\t0\t0s\t0\t0s\tnil"

trace
----
Expand Down
Loading