Skip to content

Commit 7ad4823

Browse files
committed
db: add metric encapsulating blob file rewrite bytes read, written
Blob file rewrite compactions happen independent of the LSM, 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 951fae6 commit 7ad4823

File tree

9 files changed

+154
-100
lines changed

9 files changed

+154
-100
lines changed

blob_rewrite.go

Lines changed: 10 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,16 @@ 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+
// Count blob value blocks read from the blob file during the rewrite.
251+
bytesRead := c.internalIteratorStats.BlockReads[blockkind.BlobValue].BlockBytes
252+
d.mu.versions.metrics.Compact.BlobFileRewriteBytesRead += int64(bytesRead)
253+
d.mu.versions.metrics.Compact.BlobFileRewriteBytesWritten += c.bytesWritten.Load()
254+
255+
// Update the read state to publish the new version.
247256
d.updateReadStateLocked(d.opts.DebugCheck)
248257
}
249258

metrics.go

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,12 @@ type Metrics struct {
215215
MultiLevelCount int64
216216
BlobFileRewriteCount int64
217217
VirtualRewriteCount int64
218+
// BlobFileRewriteBytesRead is the total number of bytes read during
219+
// blob file rewrite compactions.
220+
BlobFileRewriteBytesRead int64
221+
// BlobFileRewriteBytesWritten is the total number of bytes written during
222+
// blob file rewrite compactions.
223+
BlobFileRewriteBytesWritten int64
218224
// An estimate of the number of bytes that need to be compacted for the LSM
219225
// to reach a stable state.
220226
EstimatedDebt uint64
@@ -761,16 +767,21 @@ var (
761767
table.String("tot", 13, table.AlignRight, func(i cgoMemInfo) string { return i.memtablesTot }),
762768
)
763769
compactionInfoTableTopHeader = `COMPACTIONS`
770+
compactionInfoTableSubHeader = ` | blob rewrites`
764771
compactionInfoTable = table.Define[compactionMetricsInfo](
765-
table.String("estimated debt", 17, table.AlignRight, func(i compactionMetricsInfo) string { return i.estimatedDebt }),
772+
table.String("est. debt", 13, table.AlignRight, func(i compactionMetricsInfo) string { return i.estimatedDebt }),
766773
table.Div(),
767-
table.String("in progress", 17, table.AlignRight, func(i compactionMetricsInfo) string { return i.inProgress }),
774+
table.String("in progress", 13, table.AlignRight, func(i compactionMetricsInfo) string { return i.inProgress }),
768775
table.Div(),
769-
table.String("cancelled", 17, table.AlignRight, func(i compactionMetricsInfo) string { return i.cancelled }),
776+
table.String("cancelled", 10, table.AlignRight, func(i compactionMetricsInfo) string { return i.cancelled }),
770777
table.Div(),
771-
table.String("failed", 17, table.AlignRight, func(i compactionMetricsInfo) string { return fmt.Sprint(i.failed) }),
778+
table.String("failed", 8, table.AlignRight, func(i compactionMetricsInfo) string { return fmt.Sprint(i.failed) }),
772779
table.Div(),
773-
table.String("problem spans", 18, table.AlignRight, func(i compactionMetricsInfo) string { return i.problemSpans }),
780+
table.String("problem spans", 16, table.AlignRight, func(i compactionMetricsInfo) string { return i.problemSpans }),
781+
table.Div(),
782+
table.String("read", 10, table.AlignRight, func(i compactionMetricsInfo) string { return i.blobFileRewriteBytesRead }),
783+
table.Div(),
784+
table.String("written", 10, table.AlignRight, func(i compactionMetricsInfo) string { return i.blobFileRewriteBytesWritten }),
774785
)
775786
keysInfoTableTopHeader = `KEYS`
776787
keysInfoTable = table.Define[keysInfo](
@@ -885,11 +896,13 @@ type cgoMemInfo struct {
885896
}
886897

887898
type compactionMetricsInfo struct {
888-
estimatedDebt string
889-
inProgress string
890-
cancelled string
891-
failed int64
892-
problemSpans string
899+
estimatedDebt string
900+
inProgress string
901+
cancelled string
902+
failed int64
903+
problemSpans string
904+
blobFileRewriteBytesRead string
905+
blobFileRewriteBytesWritten string
893906
}
894907

895908
type keysInfo struct {
@@ -1074,10 +1087,13 @@ func (m *Metrics) String() string {
10741087
humanizeBytes(m.Compact.InProgressBytes)),
10751088
cancelled: fmt.Sprintf("%s (%s)", humanizeCount(m.Compact.CancelledCount),
10761089
humanizeBytes(m.Compact.CancelledBytes)),
1077-
failed: m.Compact.FailedCount,
1078-
problemSpans: fmt.Sprintf("%d%s", m.Compact.NumProblemSpans, ifNonZero(m.Compact.NumProblemSpans, "!!")),
1090+
failed: m.Compact.FailedCount,
1091+
problemSpans: fmt.Sprintf("%d%s", m.Compact.NumProblemSpans, ifNonZero(m.Compact.NumProblemSpans, "!!")),
1092+
blobFileRewriteBytesRead: humanizeBytes(m.Compact.BlobFileRewriteBytesRead),
1093+
blobFileRewriteBytesWritten: humanizeBytes(m.Compact.BlobFileRewriteBytesWritten),
10791094
}
10801095
cur = cur.WriteString(compactionInfoTableTopHeader).NewlineReturn()
1096+
cur = cur.WriteString(compactionInfoTableSubHeader).NewlineReturn()
10811097
cur = compactionInfoTable.Render(cur, table.RenderOptions{}, compactionMetricsInfoContents)
10821098
cur = cur.NewlineReturn()
10831099

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)