From 523e9e4652fba3ea2379b60ece7f65259b60a14d Mon Sep 17 00:00:00 2001 From: Nathan VanBenschoten Date: Thu, 17 Jun 2021 23:52:01 -0400 Subject: [PATCH] Export TeeEventListener I plan to use this is CockroachDB to tee events to a new `pebbleMetricListener` object that will listen to and expose metrics on write stalls. This will give us better visibility into these events. --- cmd/pebble/compact.go | 70 +++---------------------------------------- event.go | 64 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 66 deletions(-) diff --git a/cmd/pebble/compact.go b/cmd/pebble/compact.go index 1dcb87d4d9..d1f78fe392 100644 --- a/cmd/pebble/compact.go +++ b/cmd/pebble/compact.go @@ -114,8 +114,10 @@ func open(dir string, listener pebble.EventListener) (*replay.DB, error) { opts.EventListener = listener if verbose { - opts.EventListener = teeEventListener(opts.EventListener, - pebble.MakeLoggingEventListener(nil)) + opts.EventListener = pebble.TeeEventListener( + opts.EventListener, + pebble.MakeLoggingEventListener(nil), + ) } rd, err := replay.Open(dir, opts) return rd, err @@ -422,67 +424,3 @@ func removeAll(dir string) { log.Fatal(err) } } - -// teeEventListener wraps two event listeners, forwarding all events to both. -func teeEventListener(a, b pebble.EventListener) pebble.EventListener { - a.EnsureDefaults(nil) - b.EnsureDefaults(nil) - return pebble.EventListener{ - BackgroundError: func(err error) { - a.BackgroundError(err) - b.BackgroundError(err) - }, - CompactionBegin: func(info pebble.CompactionInfo) { - a.CompactionBegin(info) - b.CompactionBegin(info) - }, - CompactionEnd: func(info pebble.CompactionInfo) { - a.CompactionEnd(info) - b.CompactionEnd(info) - }, - FlushBegin: func(info pebble.FlushInfo) { - a.FlushBegin(info) - b.FlushBegin(info) - }, - FlushEnd: func(info pebble.FlushInfo) { - a.FlushEnd(info) - b.FlushEnd(info) - }, - ManifestCreated: func(info pebble.ManifestCreateInfo) { - a.ManifestCreated(info) - b.ManifestCreated(info) - }, - ManifestDeleted: func(info pebble.ManifestDeleteInfo) { - a.ManifestDeleted(info) - b.ManifestDeleted(info) - }, - TableCreated: func(info pebble.TableCreateInfo) { - a.TableCreated(info) - b.TableCreated(info) - }, - TableDeleted: func(info pebble.TableDeleteInfo) { - a.TableDeleted(info) - b.TableDeleted(info) - }, - TableIngested: func(info pebble.TableIngestInfo) { - a.TableIngested(info) - b.TableIngested(info) - }, - WALCreated: func(info pebble.WALCreateInfo) { - a.WALCreated(info) - b.WALCreated(info) - }, - WALDeleted: func(info pebble.WALDeleteInfo) { - a.WALDeleted(info) - b.WALDeleted(info) - }, - WriteStallBegin: func(info pebble.WriteStallBeginInfo) { - a.WriteStallBegin(info) - b.WriteStallBegin(info) - }, - WriteStallEnd: func() { - a.WriteStallEnd() - b.WriteStallEnd() - }, - } -} diff --git a/event.go b/event.go index 00a6ff3032..b57801a2d6 100644 --- a/event.go +++ b/event.go @@ -559,3 +559,67 @@ func MakeLoggingEventListener(logger Logger) EventListener { }, } } + +// TeeEventListener wraps two EventListeners, forwarding all events to both. +func TeeEventListener(a, b EventListener) EventListener { + a.EnsureDefaults(nil) + b.EnsureDefaults(nil) + return EventListener{ + BackgroundError: func(err error) { + a.BackgroundError(err) + b.BackgroundError(err) + }, + CompactionBegin: func(info CompactionInfo) { + a.CompactionBegin(info) + b.CompactionBegin(info) + }, + CompactionEnd: func(info CompactionInfo) { + a.CompactionEnd(info) + b.CompactionEnd(info) + }, + FlushBegin: func(info FlushInfo) { + a.FlushBegin(info) + b.FlushBegin(info) + }, + FlushEnd: func(info FlushInfo) { + a.FlushEnd(info) + b.FlushEnd(info) + }, + ManifestCreated: func(info ManifestCreateInfo) { + a.ManifestCreated(info) + b.ManifestCreated(info) + }, + ManifestDeleted: func(info ManifestDeleteInfo) { + a.ManifestDeleted(info) + b.ManifestDeleted(info) + }, + TableCreated: func(info TableCreateInfo) { + a.TableCreated(info) + b.TableCreated(info) + }, + TableDeleted: func(info TableDeleteInfo) { + a.TableDeleted(info) + b.TableDeleted(info) + }, + TableIngested: func(info TableIngestInfo) { + a.TableIngested(info) + b.TableIngested(info) + }, + WALCreated: func(info WALCreateInfo) { + a.WALCreated(info) + b.WALCreated(info) + }, + WALDeleted: func(info WALDeleteInfo) { + a.WALDeleted(info) + b.WALDeleted(info) + }, + WriteStallBegin: func(info WriteStallBeginInfo) { + a.WriteStallBegin(info) + b.WriteStallBegin(info) + }, + WriteStallEnd: func() { + a.WriteStallEnd() + b.WriteStallEnd() + }, + } +}