Skip to content

Commit

Permalink
Merge pull request cockroachdb#1168 from nvanbenschoten/nvanbenschote…
Browse files Browse the repository at this point in the history
…n/teeEventListener

Export TeeEventListener
  • Loading branch information
nvanbenschoten authored Jun 22, 2021
2 parents 311cdb5 + 523e9e4 commit 4fcf409
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 66 deletions.
70 changes: 4 additions & 66 deletions cmd/pebble/compact.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
},
}
}
64 changes: 64 additions & 0 deletions event.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
},
}
}

0 comments on commit 4fcf409

Please sign in to comment.