Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

db: add Metrics.Compact.Cancelled{Count,Bytes} #4132

Merged
merged 1 commit into from
Nov 4, 2024
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
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
Loading