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: Make logging event listener async for DiskSlow #96021

Merged
merged 1 commit into from
Jan 27, 2023
Merged
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
33 changes: 28 additions & 5 deletions pkg/storage/pebble.go
Original file line number Diff line number Diff line change
Expand Up @@ -987,12 +987,29 @@ func NewPebble(ctx context.Context, cfg PebbleConfig) (p *Pebble, err error) {
// disk is stalled. While the logging subsystem should also be robust to
// stalls and crash the process if unable to write logs, there's less risk
// to sequencing the crashing listener first.
//
// For the same reason, make the logging call asynchronous for DiskSlow events.
// This prevents slow logging calls during a disk slow/stall event from holding
// up Pebble's internal disk health checking, and better obeys the
// EventListener contract for not having any functions block or take a while to
// run. Creating goroutines is acceptable given their low cost, and the low
// write concurrency to Pebble's FS (Pebble compactions + flushes + SQL
// spilling to disk). If the maximum concurrency of DiskSlow events increases
// significantly in the future, we can improve the logic here by queueing up
// most of the logging work (except for the Fatalf call), and have it be done
// by a single goroutine.
lel := pebble.MakeLoggingEventListener(pebbleLogger{
ctx: logCtx,
depth: 2, // skip over the EventListener stack frame
})
oldDiskSlow := lel.DiskSlow
lel.DiskSlow = func(info pebble.DiskSlowInfo) {
// Run oldDiskSlow asynchronously.
go oldDiskSlow(info)
}
el := pebble.TeeEventListener(
p.makeMetricEtcEventListener(ctx),
pebble.MakeLoggingEventListener(pebbleLogger{
ctx: logCtx,
depth: 2, // skip over the EventListener stack frame
}),
lel,
)

p.eventListener = &el
Expand Down Expand Up @@ -1071,10 +1088,16 @@ func (p *Pebble) makeMetricEtcEventListener(ctx context.Context) pebble.EventLis
atomic.AddInt64(&p.diskStallCount, 1)
// Note that the below log messages go to the main cockroach log, not
// the pebble-specific log.
//
// Run non-fatal log.* calls in separate goroutines as they could block
// if the logging device is also slow/stalling, preventing pebble's disk
// health checking from functioning correctly. See the comment in
// pebble.EventListener on why it's important for this method to return
// quickly.
if fatalOnExceeded {
log.Fatalf(ctx, "file write stall detected: %s", info)
} else {
log.Errorf(ctx, "file write stall detected: %s", info)
go log.Errorf(ctx, "file write stall detected: %s", info)
}
return
}
Expand Down