Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion blob_rewrite.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/cockroachdb/pebble/sstable"
"github.com/cockroachdb/pebble/sstable/blob"
"github.com/cockroachdb/pebble/sstable/block"
"github.com/cockroachdb/pebble/sstable/block/blockkind"
"github.com/cockroachdb/pebble/sstable/colblk"
)

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

// Update the read state to publish the new version.
if err == nil {
// Record bytes read and written for blob file rewrite compactions.
// These metrics are separate from per-level metrics since blob file
// rewrites don't contribute to per-level compacted bytes.
bytesRead := c.internalIteratorStats.BlockReads[blockkind.BlobValue].BlockBytes
d.mu.versions.metrics.Compact.BlobFileRewrite.BytesRead += int64(bytesRead)
d.mu.versions.metrics.Compact.BlobFileRewrite.BytesWritten += c.bytesWritten.Load()

// Update the read state to publish the new version.
d.updateReadStateLocked(d.opts.DebugCheck)
}

Expand Down
48 changes: 36 additions & 12 deletions metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,20 @@ type CompactMetrics struct {
// Duration records the cumulative duration of all compactions since the
// database was opened.
Duration time.Duration
// BlobFileRewrite contains metrics for blob file rewrite compactions.
BlobFileRewrite struct {
// The total number of bytes read during blob file rewrite compactions.
// This only counts blob value blocks (data blocks) that are read from
// the input blob file. The index block is read but tracked as
// blockkind.Metadata, not blockkind.BlobValue. As a result, BytesRead
// can be smaller than BytesWritten.
BytesRead int64
// The total number of bytes written during blob file rewrite compactions.
// This counts all bytes written to the output blob file, including blob
// value blocks, index block, properties block, and footer. As a result,
// BytesWritten can be larger than BytesRead.
BytesWritten int64
}
}

// IngestMetrics contains metrics related to ingestions.
Expand Down Expand Up @@ -767,16 +781,21 @@ var (
table.String("tot", 13, table.AlignRight, func(i cgoMemInfo) string { return i.memtablesTot }),
)
compactionInfoTableTopHeader = `COMPACTIONS`
compactionInfoTableSubHeader = ` | blob rewrites`
compactionInfoTable = table.Define[compactionMetricsInfo](
table.String("estimated debt", 17, table.AlignRight, func(i compactionMetricsInfo) string { return i.estimatedDebt }),
table.String("est. debt", 13, table.AlignRight, func(i compactionMetricsInfo) string { return i.estimatedDebt }),
table.Div(),
table.String("in progress", 13, table.AlignRight, func(i compactionMetricsInfo) string { return i.inProgress }),
table.Div(),
table.String("cancelled", 10, table.AlignRight, func(i compactionMetricsInfo) string { return i.cancelled }),
table.Div(),
table.String("in progress", 17, table.AlignRight, func(i compactionMetricsInfo) string { return i.inProgress }),
table.String("failed", 8, table.AlignRight, func(i compactionMetricsInfo) string { return fmt.Sprint(i.failed) }),
table.Div(),
table.String("cancelled", 17, table.AlignRight, func(i compactionMetricsInfo) string { return i.cancelled }),
table.String("problem spans", 16, table.AlignRight, func(i compactionMetricsInfo) string { return i.problemSpans }),
table.Div(),
table.String("failed", 17, table.AlignRight, func(i compactionMetricsInfo) string { return fmt.Sprint(i.failed) }),
table.String("read", 10, table.AlignRight, func(i compactionMetricsInfo) string { return i.blobFileRewriteBytesRead }),
table.Div(),
table.String("problem spans", 18, table.AlignRight, func(i compactionMetricsInfo) string { return i.problemSpans }),
table.String("written", 10, table.AlignRight, func(i compactionMetricsInfo) string { return i.blobFileRewriteBytesWritten }),
)
keysInfoTableTopHeader = `KEYS`
keysInfoTable = table.Define[keysInfo](
Expand Down Expand Up @@ -902,11 +921,13 @@ type cgoMemInfo struct {
}

type compactionMetricsInfo struct {
estimatedDebt string
inProgress string
cancelled string
failed int64
problemSpans string
estimatedDebt string
inProgress string
cancelled string
failed int64
problemSpans string
blobFileRewriteBytesRead string
blobFileRewriteBytesWritten string
}

type keysInfo struct {
Expand Down Expand Up @@ -1119,10 +1140,13 @@ func (m *Metrics) String() string {
humanizeBytes(m.Compact.InProgressBytes)),
cancelled: fmt.Sprintf("%s (%s)", humanizeCount(m.Compact.CancelledCount),
humanizeBytes(m.Compact.CancelledBytes)),
failed: m.Compact.FailedCount,
problemSpans: fmt.Sprintf("%d%s", m.Compact.NumProblemSpans, ifNonZero(m.Compact.NumProblemSpans, "!!")),
failed: m.Compact.FailedCount,
problemSpans: fmt.Sprintf("%d%s", m.Compact.NumProblemSpans, ifNonZero(m.Compact.NumProblemSpans, "!!")),
blobFileRewriteBytesRead: humanizeBytes(m.Compact.BlobFileRewrite.BytesRead),
blobFileRewriteBytesWritten: humanizeBytes(m.Compact.BlobFileRewrite.BytesWritten),
}
cur = cur.WriteString(compactionInfoTableTopHeader).NewlineReturn()
cur = cur.WriteString(compactionInfoTableSubHeader).NewlineReturn()
cur = compactionInfoTable.Render(cur, table.RenderOptions{}, compactionMetricsInfoContents)
cur = cur.NewlineReturn()

Expand Down
7 changes: 4 additions & 3 deletions testdata/compaction/l0_to_lbase_compaction
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,10 @@ CGO MEMORY | block cache | memtables
0B | 0B | 0B | 0B | 0B | 0B

COMPACTIONS
estimated debt | in progress | cancelled | failed | problem spans
------------------+-------------------+-------------------+-------------------+-------------------
0B | 0 (0B) | 0 (0B) | 0 | 0
| blob rewrites
est. debt | in progress | cancelled | failed | problem spans | read | written
--------------+---------------+------------+----------+------------------+------------+-----------
0B | 0 (0B) | 0 (0B) | 0 | 0 | 0B | 0B

KEYS
range keys | tombstones | missized tombstones | point dels | range dels
Expand Down
14 changes: 8 additions & 6 deletions testdata/compaction/value_separation
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,10 @@ CGO MEMORY | block cache | memtables
0B | 0B | 0B | 0B | 0B | 0B

COMPACTIONS
estimated debt | in progress | cancelled | failed | problem spans
------------------+-------------------+-------------------+-------------------+-------------------
0B | 0 (0B) | 0 (0B) | 0 | 0
| blob rewrites
est. debt | in progress | cancelled | failed | problem spans | read | written
--------------+---------------+------------+----------+------------------+------------+-----------
0B | 0 (0B) | 0 (0B) | 0 | 0 | 0B | 0B

KEYS
range keys | tombstones | missized tombstones | point dels | range dels
Expand Down Expand Up @@ -544,9 +545,10 @@ CGO MEMORY | block cache | memtables
0B | 0B | 0B | 0B | 0B | 0B

COMPACTIONS
estimated debt | in progress | cancelled | failed | problem spans
------------------+-------------------+-------------------+-------------------+-------------------
0B | 0 (0B) | 0 (0B) | 0 | 0
| blob rewrites
est. debt | in progress | cancelled | failed | problem spans | read | written
--------------+---------------+------------+----------+------------------+------------+-----------
0B | 0 (0B) | 0 (0B) | 0 | 0 | 83B | 150B

KEYS
range keys | tombstones | missized tombstones | point dels | range dels
Expand Down
7 changes: 4 additions & 3 deletions testdata/compaction/virtual_rewrite
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,10 @@ CGO MEMORY | block cache | memtables
0B | 0B | 0B | 0B | 0B | 0B

COMPACTIONS
estimated debt | in progress | cancelled | failed | problem spans
------------------+-------------------+-------------------+-------------------+-------------------
0B | 0 (0B) | 0 (0B) | 0 | 0
| blob rewrites
est. debt | in progress | cancelled | failed | problem spans | read | written
--------------+---------------+------------+----------+------------------+------------+-----------
0B | 0 (0B) | 0 (0B) | 0 | 0 | 0B | 0B

KEYS
range keys | tombstones | missized tombstones | point dels | range dels
Expand Down
14 changes: 8 additions & 6 deletions testdata/event_listener
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,10 @@ CGO MEMORY | block cache | memtables
0B | 0B | 0B | 0B | 0B | 0B

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

KEYS
range keys | tombstones | missized tombstones | point dels | range dels
Expand Down Expand Up @@ -518,9 +519,10 @@ CGO MEMORY | block cache | memtables
0B | 0B | 0B | 0B | 0B | 0B

COMPACTIONS
estimated debt | in progress | cancelled | failed | problem spans
------------------+-------------------+-------------------+-------------------+-------------------
3.8KB | 0 (0B) | 0 (0B) | 0 | 0
| blob rewrites
est. debt | in progress | cancelled | failed | problem spans | read | written
--------------+---------------+------------+----------+------------------+------------+-----------
3.8KB | 0 (0B) | 0 (0B) | 0 | 0 | 0B | 0B

KEYS
range keys | tombstones | missized tombstones | point dels | range dels
Expand Down
7 changes: 4 additions & 3 deletions testdata/ingest
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ CGO MEMORY | block cache | memtables
0B | 0B | 0B | 0B | 0B | 0B

COMPACTIONS
estimated debt | in progress | cancelled | failed | problem spans
------------------+-------------------+-------------------+-------------------+-------------------
0B | 0 (0B) | 0 (0B) | 0 | 0
| blob rewrites
est. debt | in progress | cancelled | failed | problem spans | read | written
--------------+---------------+------------+----------+------------------+------------+-----------
0B | 0 (0B) | 0 (0B) | 0 | 0 | 0B | 0B

KEYS
range keys | tombstones | missized tombstones | point dels | range dels
Expand Down
Loading