Skip to content

Commit c8cfc93

Browse files
committed
db: use internal iterator stats to populate compaction bytes read
The LevelMetrics exposes two fields describing the volume of bytes read during compactions: one from sstables and one from blob files. Confusingly, these metrics weren't based on what a compaction actually read but computed based on the input of the sstable. Blocks that didn't needed to be loaded (eg, including blob value blocks when preserving existing blob references) were still recorded. This commit adapts these metrics to use the block bytes metric maintained by the internal iterator stack, reflecting the volume of bytes actually loaded by a compaction. This will make it easier to understand what portion of disk read volume is driven by compactions. Close #5021.
1 parent 1dd9cda commit c8cfc93

File tree

5 files changed

+49
-46
lines changed

5 files changed

+49
-46
lines changed

compaction.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"github.com/cockroachdb/pebble/sstable"
3535
"github.com/cockroachdb/pebble/sstable/blob"
3636
"github.com/cockroachdb/pebble/sstable/block"
37+
"github.com/cockroachdb/pebble/sstable/block/blockkind"
3738
"github.com/cockroachdb/pebble/vfs"
3839
"github.com/cockroachdb/redact"
3940
)
@@ -3447,17 +3448,21 @@ func (c *tableCompaction) makeVersionEdit(result compact.Result) (*manifest.Vers
34473448

34483449
outputMetrics := c.metrics.perLevel.level(c.outputLevel.level)
34493450
outputMetrics.TableBytesIn = startLevelBytes
3450-
// TODO(jackson): This BytesRead value does not include any blob files
3451-
// written. It either should, or we should add a separate metric.
3452-
outputMetrics.TableBytesRead = c.outputLevel.files.TableSizeSum()
3451+
for i := range c.metrics.internalIterStats.BlockReads {
3452+
switch blockkind.Kind(i) {
3453+
case blockkind.BlobValue:
3454+
outputMetrics.BlobBytesRead += c.metrics.internalIterStats.BlockReads[i].BlockBytes
3455+
default:
3456+
outputMetrics.TableBytesRead += c.metrics.internalIterStats.BlockReads[i].BlockBytes
3457+
}
3458+
}
34533459
outputMetrics.BlobBytesCompacted = result.Stats.CumulativeBlobFileSize
34543460
if c.flush.flushables != nil {
34553461
outputMetrics.BlobBytesFlushed = result.Stats.CumulativeBlobFileSize
34563462
}
34573463
if len(c.extraLevels) > 0 {
34583464
outputMetrics.TableBytesIn += c.extraLevels[0].files.TableSizeSum()
34593465
}
3460-
outputMetrics.TableBytesRead += outputMetrics.TableBytesIn
34613466

34623467
if len(c.flush.flushables) == 0 {
34633468
c.metrics.perLevel.level(c.startLevel.level)
@@ -3537,7 +3542,6 @@ func (c *tableCompaction) makeVersionEdit(result compact.Result) (*manifest.Vers
35373542
outputMetrics.TableBytesFlushed += fileMeta.Size
35383543
}
35393544
outputMetrics.EstimatedReferencesSize += fileMeta.EstimatedReferenceSize()
3540-
outputMetrics.BlobBytesReadEstimate += fileMeta.EstimatedReferenceSize()
35413545
outputMetrics.TablesSize += int64(fileMeta.Size)
35423546
outputMetrics.TablesCount++
35433547
outputMetrics.Additional.BytesWrittenDataBlocks += t.WriterMeta.Properties.DataSize

metrics.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,9 @@ type LevelMetrics struct {
103103
TablesDeleted uint64
104104
// The number of sstables excised in a level by a delete-only compaction.
105105
TablesExcised uint64
106-
// BlobBytesReadEstimate is an estimate of the physical bytes corresponding
107-
// to values referenced by sstables that were inputs into compactions
108-
// outputting into this level.
109-
BlobBytesReadEstimate uint64
106+
// BlobBytesRead is the volume of physical bytes read from blob files during
107+
// compactions outputting into this level.
108+
BlobBytesRead uint64
110109
// BlobBytesCompacted is the number of bytes written to blob files while
111110
// compacting sstables in this level.
112111
BlobBytesCompacted uint64
@@ -169,7 +168,7 @@ func (m *LevelMetrics) Add(u *LevelMetrics) {
169168
m.TablesMoved += u.TablesMoved
170169
m.BlobBytesCompacted += u.BlobBytesCompacted
171170
m.BlobBytesFlushed += u.BlobBytesFlushed
172-
m.BlobBytesReadEstimate += u.BlobBytesReadEstimate
171+
m.BlobBytesRead += u.BlobBytesRead
173172
m.MultiLevel.TableBytesInTop += u.MultiLevel.TableBytesInTop
174173
m.MultiLevel.TableBytesRead += u.MultiLevel.TableBytesRead
175174
m.MultiLevel.TableBytesIn += u.MultiLevel.TableBytesIn

testdata/compaction/value_separation

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ level | tables size val-bl vtables | score ff cff | in | tables size | ta
129129
3 | 0 0B 0B 0 | - 0 0 | 0B | 0 0B | 1 848B | 0 0B | 0B | 0 0 | 0B 0B
130130
4 | 0 0B 0B 0 | - 0 0 | 0B | 0 0B | 1 848B | 0 0B | 0B | 0 0 | 0B 0B
131131
5 | 0 0B 0B 0 | - 0 0 | 0B | 0 0B | 1 848B | 0 0B | 0B | 0 0 | 0B 0B
132-
6 | 1 899B 0B 0 | - 0.00 0.00 | 848B | 0 0B | 0 0B | 1 899B | 1.7KB | 1 1.19 | 112B 0B
133-
total | 1 899B 0B 0 | - - - | 41B | 0 0B | 5 4.1KB | 2 1.7KB | 1.7KB | 1 51.2 | 112B 0B
132+
6 | 1 899B 0B 0 | - 0.00 0.00 | 848B | 0 0B | 0 0B | 1 899B | 372B | 1 1.19 | 112B 0B
133+
total | 1 899B 0B 0 | - - - | 41B | 0 0B | 5 4.1KB | 2 1.7KB | 372B | 1 51.2 | 112B 0B
134134
--------------------------------------------------------------------------------------------------------------------------------------------
135135
WAL: 1 files (0B) in: 30B written: 41B (37% overhead)
136136
Flushes: 1
@@ -369,8 +369,8 @@ level | tables size val-bl vtables | score ff cff | in | tables size | ta
369369
3 | 0 0B 0B 0 | - 0 0 | 0B | 0 0B | 0 0B | 0 0B | 0B | 0 0 | 0B 0B
370370
4 | 0 0B 0B 0 | - 0 0 | 0B | 0 0B | 0 0B | 0 0B | 0B | 0 0 | 0B 0B
371371
5 | 0 0B 0B 0 | - 0 0 | 0B | 0 0B | 0 0B | 0 0B | 0B | 0 0 | 0B 0B
372-
6 | 1 900B 0B 0 | - 0.00 0.00 | 1.7KB | 0 0B | 0 0B | 1 900B | 1.7KB | 1 0.51 | 232B 0B
373-
total | 1 900B 0B 0 | - - - | 156B | 0 0B | 0 0B | 3 2.8KB | 1.7KB | 1 21.3 | 232B 0B
372+
6 | 1 900B 0B 0 | - 0.00 0.00 | 1.7KB | 0 0B | 0 0B | 1 900B | 310B | 1 0.51 | 232B 0B
373+
total | 1 900B 0B 0 | - - - | 156B | 0 0B | 0 0B | 3 2.8KB | 310B | 1 21.3 | 232B 0B
374374
--------------------------------------------------------------------------------------------------------------------------------------------
375375
WAL: 1 files (0B) in: 126B written: 156B (24% overhead)
376376
Flushes: 2

testdata/event_listener

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,8 @@ level | tables size val-bl vtables | score ff cff | in | tables size | ta
245245
3 | 0 0B 0B 0 | - 0 0 | 0B | 0 0B | 0 0B | 0 0B | 0B | 0 0 | 0B 0B
246246
4 | 0 0B 0B 0 | - 0 0 | 0B | 0 0B | 0 0B | 0 0B | 0B | 0 0 | 0B 0B
247247
5 | 0 0B 0B 0 | - 0 0 | 0B | 0 0B | 0 0B | 0 0B | 0B | 0 0 | 0B 0B
248-
6 | 1 755B 0B 0 | - 0.00 0.00 | 1.5KB | 0 0B | 0 0B | 1 755B | 1.5KB | 1 0.51 | 0B 0B
249-
total | 3 2.2KB 0B 0 | - - - | 852B | 1 755B | 0 0B | 4 3.8KB | 1.5KB | 3 4.52 | 0B 0B
248+
6 | 1 755B 0B 0 | - 0.00 0.00 | 1.5KB | 0 0B | 0 0B | 1 755B | 218B | 1 0.51 | 0B 0B
249+
total | 3 2.2KB 0B 0 | - - - | 852B | 1 755B | 0 0B | 4 3.8KB | 218B | 3 4.52 | 0B 0B
250250
--------------------------------------------------------------------------------------------------------------------------------------------
251251
WAL: 1 files (0B) in: 48B written: 97B (102% overhead)
252252
Flushes: 3
@@ -350,8 +350,8 @@ level | tables size val-bl vtables | score ff cff | in | tables size | ta
350350
3 | 0 0B 0B 0 | - 0 0 | 0B | 0 0B | 0 0B | 0 0B | 0B | 0 0 | 0B 0B
351351
4 | 0 0B 0B 0 | - 0 0 | 0B | 0 0B | 0 0B | 0 0B | 0B | 0 0 | 0B 0B
352352
5 | 0 0B 0B 0 | - 0 0 | 0B | 0 0B | 0 0B | 0 0B | 0B | 0 0 | 0B 0B
353-
6 | 2 1.5KB 0B 0 | - 0.00 0.00 | 1.5KB | 1 755B | 0 0B | 1 755B | 1.5KB | 1 0.51 | 0B 0B
354-
total | 6 4.4KB 0B 0 | - - - | 2.3KB | 3 2.2KB | 0 0B | 5 6.0KB | 1.5KB | 5 2.56 | 0B 0B
353+
6 | 2 1.5KB 0B 0 | - 0.00 0.00 | 1.5KB | 1 755B | 0 0B | 1 755B | 218B | 1 0.51 | 0B 0B
354+
total | 6 4.4KB 0B 0 | - - - | 2.3KB | 3 2.2KB | 0 0B | 5 6.0KB | 218B | 5 2.56 | 0B 0B
355355
--------------------------------------------------------------------------------------------------------------------------------------------
356356
WAL: 1 files (0B) in: 82B written: 132B (61% overhead)
357357
Flushes: 6

0 commit comments

Comments
 (0)