Skip to content
Open
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: 44 additions & 0 deletions event.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/cockroachdb/pebble/objstorage"
"github.com/cockroachdb/pebble/objstorage/remote"
"github.com/cockroachdb/pebble/vfs"
"github.com/cockroachdb/pebble/wal"
"github.com/cockroachdb/redact"
)

Expand Down Expand Up @@ -97,6 +98,35 @@ func (i LevelInfo) SafeFormat(w redact.SafePrinter, _ rune) {
redact.Safe(i.Score))
}

// WALReplayInfo contains the info for the WAL replay information event.
type WALReplayInfo struct {
// WALs contains the list of WALs that were replayed.
WALs []WALFileInfo
}

// WALFileInfo contains information about a single WAL file. Multiple files can
// be part of the same logical WAL.
type WALFileInfo struct {
LogicalNum wal.NumWAL
Path string
}

func (i WALReplayInfo) String() string {
return redact.StringWithoutMarkers(i)
}

// SafeFormat implements redact.SafeFormatter.
func (i WALReplayInfo) SafeFormat(w redact.SafePrinter, _ rune) {
w.Printf("Replayed WALs:")
if len(i.WALs) == 0 {
w.Printf(" none")
return
}
for _, wal := range i.WALs {
w.Printf(" %s:%s", redact.Safe(wal.LogicalNum), redact.Safe(wal.Path))
}
}

// BlobFileCreateInfo contains the info for a blob file creation event.
type BlobFileCreateInfo struct {
JobID int
Expand Down Expand Up @@ -874,6 +904,10 @@ type EventListener struct {
// operation such as flush or compaction.
BackgroundError func(error)

// WALReplayed is emitted once during Open; it contains information about WAL
// replay.
WALReplayed func(WALReplayInfo)

// BlobFileCreated is invoked after a blob file has been created.
BlobFileCreated func(BlobFileCreateInfo)

Expand Down Expand Up @@ -985,6 +1019,9 @@ func (l *EventListener) EnsureDefaults(logger Logger) {
l.BackgroundError = func(error) {}
}
}
if l.WALReplayed == nil {
l.WALReplayed = func(info WALReplayInfo) {}
}
if l.BlobFileCreated == nil {
l.BlobFileCreated = func(info BlobFileCreateInfo) {}
}
Expand Down Expand Up @@ -1082,6 +1119,9 @@ func MakeLoggingEventListener(logger Logger) EventListener {
BackgroundError: func(err error) {
logger.Errorf("background error: %s", err)
},
WALReplayed: func(info WALReplayInfo) {
logger.Infof("%s", info)
},
BlobFileCreated: func(info BlobFileCreateInfo) {
logger.Infof("%s", info)
},
Expand Down Expand Up @@ -1172,6 +1212,10 @@ func TeeEventListener(a, b EventListener) EventListener {
a.BackgroundError(err)
b.BackgroundError(err)
},
WALReplayed: func(info WALReplayInfo) {
a.WALReplayed(info)
b.WALReplayed(info)
},
BlobFileCreated: func(info BlobFileCreateInfo) {
a.BlobFileCreated(info)
b.BlobFileCreated(info)
Expand Down
16 changes: 11 additions & 5 deletions open.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
"github.com/cockroachdb/pebble/record"
"github.com/cockroachdb/pebble/vfs"
"github.com/cockroachdb/pebble/wal"
"github.com/cockroachdb/redact"
"github.com/prometheus/client_golang/prometheus"
)

Expand Down Expand Up @@ -413,10 +412,6 @@ func Open(dirname string, opts *Options) (db *DB, err error) {
if err != nil {
return nil, err
}
d.opts.Logger.Infof("Found %d WALs", redact.Safe(len(wals)))
for i := range wals {
d.opts.Logger.Infof(" - %s", wals[i])
}
walManager, err := wal.Init(walOpts, wals)
if err != nil {
return nil, err
Expand Down Expand Up @@ -546,6 +541,17 @@ func Open(dirname string, opts *Options) (db *DB, err error) {
d.mu.versions.logSeqNum.Store(maxSeqNum)
}
}
var info WALReplayInfo
for i := range wals {
for j := range wals[i].NumSegments() {
_, path := wals[i].SegmentLocation(j)
info.WALs = append(info.WALs, WALFileInfo{
LogicalNum: wals[i].Num,
Path: path,
})
}
}
opts.EventListener.WALReplayed(info)
if d.mu.mem.mutable == nil {
// Recreate the mutable memtable if replayWAL got rid of it.
var entry *flushableEntry
Expand Down
1 change: 1 addition & 0 deletions testdata/event_listener
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ sync: db
[JOB 1] MANIFEST created 000001
lock: wal/LOCK
open-dir: wal
Replayed WALs: none
create: wal/000002.log
sync: wal
[JOB 1] WAL created 000002
Expand Down