Skip to content

Commit 10f71d3

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 b0c3d6c commit 10f71d3

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
@@ -426,6 +426,20 @@ type CompactMetrics struct {
426426
// Duration records the cumulative duration of all compactions since the
427427
// database was opened.
428428
Duration time.Duration
429+
// BlobFileRewrite contains metrics for blob file rewrite compactions.
430+
BlobFileRewrite struct {
431+
// The total number of bytes read during blob file rewrite compactions.
432+
// This only counts blob value blocks (data blocks) that are read from
433+
// the input blob file. The index block is read but tracked as
434+
// blockkind.Metadata, not blockkind.BlobValue. As a result, BytesRead
435+
// can be smaller than BytesWritten.
436+
BytesRead int64
437+
// The total number of bytes written during blob file rewrite compactions.
438+
// This counts all bytes written to the output blob file, including blob
439+
// value blocks, index block, properties block, and footer. As a result,
440+
// BytesWritten can be larger than BytesRead.
441+
BytesWritten int64
442+
}
429443
}
430444

431445
// IngestMetrics contains metrics related to ingestions.
@@ -767,16 +781,21 @@ var (
767781
table.String("tot", 13, table.AlignRight, func(i cgoMemInfo) string { return i.memtablesTot }),
768782
)
769783
compactionInfoTableTopHeader = `COMPACTIONS`
784+
compactionInfoTableSubHeader = ` | blob rewrites`
770785
compactionInfoTable = table.Define[compactionMetricsInfo](
771-
table.String("estimated debt", 17, table.AlignRight, func(i compactionMetricsInfo) string { return i.estimatedDebt }),
786+
table.String("est. debt", 13, table.AlignRight, func(i compactionMetricsInfo) string { return i.estimatedDebt }),
787+
table.Div(),
788+
table.String("in progress", 13, table.AlignRight, func(i compactionMetricsInfo) string { return i.inProgress }),
789+
table.Div(),
790+
table.String("cancelled", 10, table.AlignRight, func(i compactionMetricsInfo) string { return i.cancelled }),
772791
table.Div(),
773-
table.String("in progress", 17, table.AlignRight, func(i compactionMetricsInfo) string { return i.inProgress }),
792+
table.String("failed", 8, table.AlignRight, func(i compactionMetricsInfo) string { return fmt.Sprint(i.failed) }),
774793
table.Div(),
775-
table.String("cancelled", 17, table.AlignRight, func(i compactionMetricsInfo) string { return i.cancelled }),
794+
table.String("problem spans", 16, table.AlignRight, func(i compactionMetricsInfo) string { return i.problemSpans }),
776795
table.Div(),
777-
table.String("failed", 17, table.AlignRight, func(i compactionMetricsInfo) string { return fmt.Sprint(i.failed) }),
796+
table.String("read", 10, table.AlignRight, func(i compactionMetricsInfo) string { return i.blobFileRewriteBytesRead }),
778797
table.Div(),
779-
table.String("problem spans", 18, table.AlignRight, func(i compactionMetricsInfo) string { return i.problemSpans }),
798+
table.String("written", 10, table.AlignRight, func(i compactionMetricsInfo) string { return i.blobFileRewriteBytesWritten }),
780799
)
781800
keysInfoTableTopHeader = `KEYS`
782801
keysInfoTable = table.Define[keysInfo](
@@ -902,11 +921,13 @@ type cgoMemInfo struct {
902921
}
903922

904923
type compactionMetricsInfo struct {
905-
estimatedDebt string
906-
inProgress string
907-
cancelled string
908-
failed int64
909-
problemSpans string
924+
estimatedDebt string
925+
inProgress string
926+
cancelled string
927+
failed int64
928+
problemSpans string
929+
blobFileRewriteBytesRead string
930+
blobFileRewriteBytesWritten string
910931
}
911932

912933
type keysInfo struct {
@@ -1119,10 +1140,13 @@ func (m *Metrics) String() string {
11191140
humanizeBytes(m.Compact.InProgressBytes)),
11201141
cancelled: fmt.Sprintf("%s (%s)", humanizeCount(m.Compact.CancelledCount),
11211142
humanizeBytes(m.Compact.CancelledBytes)),
1122-
failed: m.Compact.FailedCount,
1123-
problemSpans: fmt.Sprintf("%d%s", m.Compact.NumProblemSpans, ifNonZero(m.Compact.NumProblemSpans, "!!")),
1143+
failed: m.Compact.FailedCount,
1144+
problemSpans: fmt.Sprintf("%d%s", m.Compact.NumProblemSpans, ifNonZero(m.Compact.NumProblemSpans, "!!")),
1145+
blobFileRewriteBytesRead: humanizeBytes(m.Compact.BlobFileRewrite.BytesRead),
1146+
blobFileRewriteBytesWritten: humanizeBytes(m.Compact.BlobFileRewrite.BytesWritten),
11241147
}
11251148
cur = cur.WriteString(compactionInfoTableTopHeader).NewlineReturn()
1149+
cur = cur.WriteString(compactionInfoTableSubHeader).NewlineReturn()
11261150
cur = compactionInfoTable.Render(cur, table.RenderOptions{}, compactionMetricsInfoContents)
11271151
cur = cur.NewlineReturn()
11281152

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
@@ -216,9 +216,10 @@ CGO MEMORY | block cache | memtables
216216
0B | 0B | 0B | 0B | 0B | 0B
217217

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

223224
KEYS
224225
range keys | tombstones | missized tombstones | point dels | range dels
@@ -544,9 +545,10 @@ CGO MEMORY | block cache | memtables
544545
0B | 0B | 0B | 0B | 0B | 0B
545546

546547
COMPACTIONS
547-
estimated debt | in progress | cancelled | failed | problem spans
548-
------------------+-------------------+-------------------+-------------------+-------------------
549-
0B | 0 (0B) | 0 (0B) | 0 | 0
548+
| blob rewrites
549+
est. debt | in progress | cancelled | failed | problem spans | read | written
550+
--------------+---------------+------------+----------+------------------+------------+-----------
551+
0B | 0 (0B) | 0 (0B) | 0 | 0 | 83B | 150B
550552

551553
KEYS
552554
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
@@ -518,9 +519,10 @@ CGO MEMORY | block cache | memtables
518519
0B | 0B | 0B | 0B | 0B | 0B
519520

520521
COMPACTIONS
521-
estimated debt | in progress | cancelled | failed | problem spans
522-
------------------+-------------------+-------------------+-------------------+-------------------
523-
3.8KB | 0 (0B) | 0 (0B) | 0 | 0
522+
| blob rewrites
523+
est. debt | in progress | cancelled | failed | problem spans | read | written
524+
--------------+---------------+------------+----------+------------------+------------+-----------
525+
3.8KB | 0 (0B) | 0 (0B) | 0 | 0 | 0B | 0B
524526

525527
KEYS
526528
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)