Skip to content

Commit 0f5721c

Browse files
committed
db: add metric encapsulating blob file rewrite bytes read, written
Blob file rewrite compactions happen independent of LSM levels, and so don't contribute to the per-level 'compacted bytes' total. This patch adds separate metrics recording the bytes read and bytes written during these compactions. Fixes: #5444
1 parent 1df7d4a commit 0f5721c

File tree

9 files changed

+161
-100
lines changed

9 files changed

+161
-100
lines changed

blob_rewrite.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/cockroachdb/pebble/sstable"
2525
"github.com/cockroachdb/pebble/sstable/blob"
2626
"github.com/cockroachdb/pebble/sstable/block"
27+
"github.com/cockroachdb/pebble/sstable/block/blockkind"
2728
"github.com/cockroachdb/pebble/sstable/colblk"
2829
)
2930

@@ -242,8 +243,15 @@ func (c *blobFileRewriteCompaction) Execute(jobID JobID, d *DB) error {
242243
d.mu.versions.incrementCompactions(compactionKindBlobFileRewrite, nil, c.bytesWritten.Load(), err)
243244
d.mu.versions.incrementCompactionBytes(-c.bytesWritten.Load())
244245

245-
// Update the read state to publish the new version.
246246
if err == nil {
247+
// Record bytes read and written for blob file rewrite compactions.
248+
// These metrics are separate from per-level metrics since blob file
249+
// rewrites don't contribute to per-level compacted bytes.
250+
bytesRead := c.internalIteratorStats.BlockReads[blockkind.BlobValue].BlockBytes
251+
d.mu.versions.metrics.Compact.BlobFileRewrite.BytesRead += int64(bytesRead)
252+
d.mu.versions.metrics.Compact.BlobFileRewrite.BytesWritten += c.bytesWritten.Load()
253+
254+
// Update the read state to publish the new version.
247255
d.updateReadStateLocked(d.opts.DebugCheck)
248256
}
249257

metrics.go

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,20 @@ type CompactMetrics struct {
418418
// Duration records the cumulative duration of all compactions since the
419419
// database was opened.
420420
Duration time.Duration
421+
// BlobFileRewrite contains metrics for blob file rewrite compactions.
422+
BlobFileRewrite struct {
423+
// The total number of bytes read during blob file rewrite compactions.
424+
// This only counts blob value blocks (data blocks) that are read from
425+
// the input blob file. The index block is read but tracked as
426+
// blockkind.Metadata, not blockkind.BlobValue. As a result, BytesRead
427+
// can be smaller than BytesWritten.
428+
BytesRead int64
429+
// The total number of bytes written during blob file rewrite compactions.
430+
// This counts all bytes written to the output blob file, including blob
431+
// value blocks, index block, properties block, and footer. As a result,
432+
// BytesWritten can be larger than BytesRead.
433+
BytesWritten int64
434+
}
421435
}
422436

423437
// IngestMetrics contains metrics related to ingestions.
@@ -759,16 +773,21 @@ var (
759773
table.String("tot", 13, table.AlignRight, func(i cgoMemInfo) string { return i.memtablesTot }),
760774
)
761775
compactionInfoTableTopHeader = `COMPACTIONS`
776+
compactionInfoTableSubHeader = ` | blob rewrites`
762777
compactionInfoTable = table.Define[compactionMetricsInfo](
763-
table.String("estimated debt", 17, table.AlignRight, func(i compactionMetricsInfo) string { return i.estimatedDebt }),
778+
table.String("est. debt", 13, table.AlignRight, func(i compactionMetricsInfo) string { return i.estimatedDebt }),
779+
table.Div(),
780+
table.String("in progress", 13, table.AlignRight, func(i compactionMetricsInfo) string { return i.inProgress }),
781+
table.Div(),
782+
table.String("cancelled", 10, table.AlignRight, func(i compactionMetricsInfo) string { return i.cancelled }),
764783
table.Div(),
765-
table.String("in progress", 17, table.AlignRight, func(i compactionMetricsInfo) string { return i.inProgress }),
784+
table.String("failed", 8, table.AlignRight, func(i compactionMetricsInfo) string { return fmt.Sprint(i.failed) }),
766785
table.Div(),
767-
table.String("cancelled", 17, table.AlignRight, func(i compactionMetricsInfo) string { return i.cancelled }),
786+
table.String("problem spans", 16, table.AlignRight, func(i compactionMetricsInfo) string { return i.problemSpans }),
768787
table.Div(),
769-
table.String("failed", 17, table.AlignRight, func(i compactionMetricsInfo) string { return fmt.Sprint(i.failed) }),
788+
table.String("read", 10, table.AlignRight, func(i compactionMetricsInfo) string { return i.blobFileRewriteBytesRead }),
770789
table.Div(),
771-
table.String("problem spans", 18, table.AlignRight, func(i compactionMetricsInfo) string { return i.problemSpans }),
790+
table.String("written", 10, table.AlignRight, func(i compactionMetricsInfo) string { return i.blobFileRewriteBytesWritten }),
772791
)
773792
keysInfoTableTopHeader = `KEYS`
774793
keysInfoTable = table.Define[keysInfo](
@@ -883,11 +902,13 @@ type cgoMemInfo struct {
883902
}
884903

885904
type compactionMetricsInfo struct {
886-
estimatedDebt string
887-
inProgress string
888-
cancelled string
889-
failed int64
890-
problemSpans string
905+
estimatedDebt string
906+
inProgress string
907+
cancelled string
908+
failed int64
909+
problemSpans string
910+
blobFileRewriteBytesRead string
911+
blobFileRewriteBytesWritten string
891912
}
892913

893914
type keysInfo struct {
@@ -1072,10 +1093,13 @@ func (m *Metrics) String() string {
10721093
humanizeBytes(m.Compact.InProgressBytes)),
10731094
cancelled: fmt.Sprintf("%s (%s)", humanizeCount(m.Compact.CancelledCount),
10741095
humanizeBytes(m.Compact.CancelledBytes)),
1075-
failed: m.Compact.FailedCount,
1076-
problemSpans: fmt.Sprintf("%d%s", m.Compact.NumProblemSpans, ifNonZero(m.Compact.NumProblemSpans, "!!")),
1096+
failed: m.Compact.FailedCount,
1097+
problemSpans: fmt.Sprintf("%d%s", m.Compact.NumProblemSpans, ifNonZero(m.Compact.NumProblemSpans, "!!")),
1098+
blobFileRewriteBytesRead: humanizeBytes(m.Compact.BlobFileRewrite.BytesRead),
1099+
blobFileRewriteBytesWritten: humanizeBytes(m.Compact.BlobFileRewrite.BytesWritten),
10771100
}
10781101
cur = cur.WriteString(compactionInfoTableTopHeader).NewlineReturn()
1102+
cur = cur.WriteString(compactionInfoTableSubHeader).NewlineReturn()
10791103
cur = compactionInfoTable.Render(cur, table.RenderOptions{}, compactionMetricsInfoContents)
10801104
cur = cur.NewlineReturn()
10811105

testdata/compaction/l0_to_lbase_compaction

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,10 @@ CGO MEMORY | block cache | memtables
9898
0B | 0B | 0B | 0B | 0B | 0B
9999

100100
COMPACTIONS
101-
estimated debt | in progress | cancelled | failed | problem spans
102-
------------------+-------------------+-------------------+-------------------+-------------------
103-
0B | 0 (0B) | 0 (0B) | 0 | 0
101+
| blob rewrites
102+
est. debt | in progress | cancelled | failed | problem spans | read | written
103+
--------------+---------------+------------+----------+------------------+------------+-----------
104+
0B | 0 (0B) | 0 (0B) | 0 | 0 | 0B | 0B
104105

105106
KEYS
106107
range keys | tombstones | missized tombstones | point dels | range dels

testdata/compaction/value_separation

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,10 @@ CGO MEMORY | block cache | memtables
217217
0B | 0B | 0B | 0B | 0B | 0B
218218

219219
COMPACTIONS
220-
estimated debt | in progress | cancelled | failed | problem spans
221-
------------------+-------------------+-------------------+-------------------+-------------------
222-
0B | 0 (0B) | 0 (0B) | 0 | 0
220+
| blob rewrites
221+
est. debt | in progress | cancelled | failed | problem spans | read | written
222+
--------------+---------------+------------+----------+------------------+------------+-----------
223+
0B | 0 (0B) | 0 (0B) | 0 | 0 | 0B | 0B
223224

224225
KEYS
225226
range keys | tombstones | missized tombstones | point dels | range dels
@@ -539,9 +540,10 @@ CGO MEMORY | block cache | memtables
539540
0B | 0B | 0B | 0B | 0B | 0B
540541

541542
COMPACTIONS
542-
estimated debt | in progress | cancelled | failed | problem spans
543-
------------------+-------------------+-------------------+-------------------+-------------------
544-
0B | 0 (0B) | 0 (0B) | 0 | 0
543+
| blob rewrites
544+
est. debt | in progress | cancelled | failed | problem spans | read | written
545+
--------------+---------------+------------+----------+------------------+------------+-----------
546+
0B | 0 (0B) | 0 (0B) | 0 | 0 | 83B | 150B
545547

546548
KEYS
547549
range keys | tombstones | missized tombstones | point dels | range dels

testdata/compaction/virtual_rewrite

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,10 @@ CGO MEMORY | block cache | memtables
201201
0B | 0B | 0B | 0B | 0B | 0B
202202

203203
COMPACTIONS
204-
estimated debt | in progress | cancelled | failed | problem spans
205-
------------------+-------------------+-------------------+-------------------+-------------------
206-
0B | 0 (0B) | 0 (0B) | 0 | 0
204+
| blob rewrites
205+
est. debt | in progress | cancelled | failed | problem spans | read | written
206+
--------------+---------------+------------+----------+------------------+------------+-----------
207+
0B | 0 (0B) | 0 (0B) | 0 | 0 | 0B | 0B
207208

208209
KEYS
209210
range keys | tombstones | missized tombstones | point dels | range dels

testdata/event_listener

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,10 @@ CGO MEMORY | block cache | memtables
348348
0B | 0B | 0B | 0B | 0B | 0B
349349

350350
COMPACTIONS
351-
estimated debt | in progress | cancelled | failed | problem spans
352-
------------------+-------------------+-------------------+-------------------+-------------------
353-
1.9KB | 0 (0B) | 0 (0B) | 0 | 0
351+
| blob rewrites
352+
est. debt | in progress | cancelled | failed | problem spans | read | written
353+
--------------+---------------+------------+----------+------------------+------------+-----------
354+
1.9KB | 0 (0B) | 0 (0B) | 0 | 0 | 0B | 0B
354355

355356
KEYS
356357
range keys | tombstones | missized tombstones | point dels | range dels
@@ -512,9 +513,10 @@ CGO MEMORY | block cache | memtables
512513
0B | 0B | 0B | 0B | 0B | 0B
513514

514515
COMPACTIONS
515-
estimated debt | in progress | cancelled | failed | problem spans
516-
------------------+-------------------+-------------------+-------------------+-------------------
517-
3.8KB | 0 (0B) | 0 (0B) | 0 | 0
516+
| blob rewrites
517+
est. debt | in progress | cancelled | failed | problem spans | read | written
518+
--------------+---------------+------------+----------+------------------+------------+-----------
519+
3.8KB | 0 (0B) | 0 (0B) | 0 | 0 | 0B | 0B
518520

519521
KEYS
520522
range keys | tombstones | missized tombstones | point dels | range dels

testdata/ingest

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,10 @@ CGO MEMORY | block cache | memtables
9393
0B | 0B | 0B | 0B | 0B | 0B
9494

9595
COMPACTIONS
96-
estimated debt | in progress | cancelled | failed | problem spans
97-
------------------+-------------------+-------------------+-------------------+-------------------
98-
0B | 0 (0B) | 0 (0B) | 0 | 0
96+
| blob rewrites
97+
est. debt | in progress | cancelled | failed | problem spans | read | written
98+
--------------+---------------+------------+----------+------------------+------------+-----------
99+
0B | 0 (0B) | 0 (0B) | 0 | 0 | 0B | 0B
99100

100101
KEYS
101102
range keys | tombstones | missized tombstones | point dels | range dels

0 commit comments

Comments
 (0)