Skip to content

Commit

Permalink
db: add Metrics.Compact.Cancelled{Count,Bytes}
Browse files Browse the repository at this point in the history
Add metrics for the count and bytes written by cancelled compactions.

Close #4097.
  • Loading branch information
jbowens committed Nov 4, 2024
1 parent af195dc commit 29fdaf9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions compaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -2257,6 +2257,9 @@ func (d *DB) compact1(c *compaction, errChannel chan error) (err error) {
// the manifest lock, we don't expect this bool to change its value
// as only the holder of the manifest lock will ever write to it.
if c.cancel.Load() {
d.mu.versions.metrics.Compact.CancelledCount++
d.mu.versions.metrics.Compact.CancelledBytes += c.bytesWritten

err = firstError(err, ErrCancelledCompaction)
// This is the first time we've seen a cancellation during the
// life of this compaction (or the original condition on err == nil
Expand Down Expand Up @@ -2289,6 +2292,10 @@ func (d *DB) compact1(c *compaction, errChannel chan error) (err error) {
// NB: clearing compacting state must occur before updating the read state;
// L0Sublevels initialization depends on it.
d.clearCompactingState(c, err != nil)
if err != nil && errors.Is(err, ErrCancelledCompaction) {
d.mu.versions.metrics.Compact.CancelledCount++
d.mu.versions.metrics.Compact.CancelledBytes += c.bytesWritten
}
d.mu.versions.incrementCompactions(c.kind, c.extraLevels, c.pickerMetrics)
d.mu.versions.incrementCompactionBytes(-c.bytesWritten)

Expand Down
5 changes: 5 additions & 0 deletions metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ type Metrics struct {
InProgressBytes int64
// Number of compactions that are in-progress.
NumInProgress int64
// Number of compactions that were cancelled.
CancelledCount int64
// CancelledBytes the number of bytes written by compactions that were
// cancelled.
CancelledBytes int64
// MarkedFiles is a count of files that are marked for
// compaction. Such files are compacted in a rewrite compaction
// when no other compactions are picked.
Expand Down

0 comments on commit 29fdaf9

Please sign in to comment.