Skip to content

Commit

Permalink
Related to: #103744
Browse files Browse the repository at this point in the history
This change exposes a metric Ingest.Count on Pebble, which keeps track of the total number of ingestion operations performed.
  • Loading branch information
raggar committed May 29, 2023
1 parent ac69476 commit f235f56
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ingest.go
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,7 @@ func (d *DB) ingest(
if err != nil {
return IngestOperationStats{}, err
}

if len(meta) == 0 {
// All of the sstables to be ingested were empty. Nothing to do.
return IngestOperationStats{}, nil
Expand Down Expand Up @@ -1106,6 +1107,9 @@ func (d *DB) ingestApply(
}); err != nil {
return nil, err
}

d.mu.versions.metrics.Ingest.Count++

d.updateReadStateLocked(d.opts.DebugCheck)
d.updateTableStatsLocked(ve.NewFiles)
// The ingestion may have pushed a level over the threshold for compaction,
Expand Down
8 changes: 8 additions & 0 deletions metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ type Metrics struct {
Duration time.Duration
}

Ingest struct {
// The total number of ingestions
Count uint64
}

Flush struct {
// The total number of flushes.
Count int64
Expand Down Expand Up @@ -504,6 +509,9 @@ func (m *Metrics) SafeFormat(w redact.SafePrinter, _ rune) {
notApplicable,
notApplicable,
redact.Safe(hitRate(m.Filter.Hits, m.Filter.Misses)))
w.Printf(" ingest %9d\n",
redact.Safe(m.Ingest.Count),
)
}

func hitRate(hits, misses int64) float64 {
Expand Down
3 changes: 3 additions & 0 deletions metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func TestMetricsFormat(t *testing.T) {
m.WAL.Size = 24
m.WAL.BytesIn = 25
m.WAL.BytesWritten = 26
m.Ingest.Count = 27

for i := range m.Levels {
l := &m.Levels[i]
Expand Down Expand Up @@ -101,6 +102,7 @@ zmemtbl 14 13 B
snaps 4 - 1024 (score == earliest seq num)
titers 21
filter - - 47.4% (score == utility)
ingest 27
`
if s := "\n" + m.String(); expected != s {
t.Fatalf("expected%s\nbut found%s", expected, s)
Expand Down Expand Up @@ -296,6 +298,7 @@ zmemtbl 0 0 B
snaps 0 - 0 (score == earliest seq num)
titers 0
filter - - 0.0% (score == utility)
ingest 0
`

got := redact.Sprintf("%s", &Metrics{}).Redact()
Expand Down
2 changes: 2 additions & 0 deletions testdata/event_listener
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ zmemtbl 0 0 B
snaps 0 - 0 (score == earliest seq num)
titers 0
filter - - 0.0% (score == utility)
ingest 1

# Set up a scenario where the table to be ingested overlaps with the memtable.
# The table is ingested as a flushable. The flush metrics refect the flushed
Expand Down Expand Up @@ -377,6 +378,7 @@ zmemtbl 0 0 B
snaps 0 - 0 (score == earliest seq num)
titers 0
filter - - 0.0% (score == utility)
ingest 1

sstables
----
Expand Down
2 changes: 2 additions & 0 deletions testdata/ingest
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ zmemtbl 0 0 B
snaps 0 - 0 (score == earliest seq num)
titers 0
filter - - 0.0% (score == utility)
ingest 1


iter
seek-ge a
Expand Down
8 changes: 8 additions & 0 deletions testdata/metrics
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ zmemtbl 1 256 K
snaps 0 - 0 (score == earliest seq num)
titers 1
filter - - 0.0% (score == utility)
ingest 0

disk-usage
----
Expand Down Expand Up @@ -86,6 +87,7 @@ zmemtbl 2 512 K
snaps 0 - 0 (score == earliest seq num)
titers 2
filter - - 0.0% (score == utility)
ingest 0

disk-usage
----
Expand Down Expand Up @@ -119,6 +121,7 @@ zmemtbl 1 256 K
snaps 0 - 0 (score == earliest seq num)
titers 2
filter - - 0.0% (score == utility)
ingest 0

# Closing iter c will release one of the zombie sstables. The other
# zombie sstable is still referenced by iter b.
Expand Down Expand Up @@ -149,6 +152,7 @@ zmemtbl 1 256 K
snaps 0 - 0 (score == earliest seq num)
titers 1
filter - - 0.0% (score == utility)
ingest 0

disk-usage
----
Expand Down Expand Up @@ -182,6 +186,7 @@ zmemtbl 0 0 B
snaps 0 - 0 (score == earliest seq num)
titers 0
filter - - 0.0% (score == utility)
ingest 0

disk-usage
----
Expand Down Expand Up @@ -241,6 +246,7 @@ zmemtbl 0 0 B
snaps 0 - 0 (score == earliest seq num)
titers 0
filter - - 0.0% (score == utility)
ingest 0

additional-metrics
----
Expand Down Expand Up @@ -284,6 +290,7 @@ zmemtbl 0 0 B
snaps 0 - 0 (score == earliest seq num)
titers 0
filter - - 0.0% (score == utility)
ingest 0

additional-metrics
----
Expand Down Expand Up @@ -373,3 +380,4 @@ zmemtbl 0 0 B
snaps 0 - 0 (score == earliest seq num)
titers 0
filter - - 0.0% (score == utility)
ingest 0
1 change: 1 addition & 0 deletions tool/testdata/db_lsm
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ zmemtbl 0 0 B
snaps 0 - 0 (score == earliest seq num)
titers 0
filter - - 0.0% (score == utility)
ingest 0

0 comments on commit f235f56

Please sign in to comment.