Skip to content

Commit 8a142e5

Browse files
committed
db: log extreme values for deletion estimates
Check `PointDeletionsBytesEstimate` and `RangeDeletionsBytesEstimate` for extreme values and log them (at most once every 30s). This is to help identify the cause of very high level scores observed in a cluster.
1 parent 2e6bd92 commit 8a142e5

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

compaction.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -3259,7 +3259,7 @@ func (c *compaction) makeVersionEdit(result compact.Result) (*versionEdit, error
32593259
// If the file didn't contain any range deletions, we can fill its
32603260
// table stats now, avoiding unnecessarily loading the table later.
32613261
maybeSetStatsFromProperties(
3262-
fileMeta.PhysicalMeta(), &t.WriterMeta.Properties.CommonProperties,
3262+
fileMeta.PhysicalMeta(), &t.WriterMeta.Properties.CommonProperties, c.logger,
32633263
)
32643264

32653265
if t.WriterMeta.HasPointKeys {

ingest.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ func ingestLoad1(
357357
// disallowing removal of an open file. Under MemFS, if we don't populate
358358
// meta.Stats here, the file will be loaded into the file cache for
359359
// calculating stats before we can remove the original link.
360-
maybeSetStatsFromProperties(meta.PhysicalMeta(), &r.Properties.CommonProperties)
360+
maybeSetStatsFromProperties(meta.PhysicalMeta(), &r.Properties.CommonProperties, opts.Logger)
361361

362362
{
363363
iter, err := r.NewIter(sstable.NoTransforms, nil /* lower */, nil /* upper */, sstable.AssertNoBlobHandles)

table_stats.go

+28-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import (
88
"context"
99
"fmt"
1010
"math"
11+
"time"
1112

13+
"github.com/cockroachdb/crlib/crtime"
1214
"github.com/cockroachdb/errors"
1315
"github.com/cockroachdb/pebble/internal/base"
1416
"github.com/cockroachdb/pebble/internal/invariants"
@@ -17,6 +19,7 @@ import (
1719
"github.com/cockroachdb/pebble/internal/manifest"
1820
"github.com/cockroachdb/pebble/sstable"
1921
"github.com/cockroachdb/pebble/sstable/block"
22+
"github.com/cockroachdb/redact"
2023
)
2124

2225
// In-memory statistics about tables help inform compaction picking, but may
@@ -131,6 +134,7 @@ func (d *DB) collectTableStats() bool {
131134
for _, c := range collected {
132135
c.tableMetadata.Stats = c.TableStats
133136
maybeCompact = maybeCompact || fileCompensation(c.tableMetadata) > 0
137+
sanityCheckStats(c.tableMetadata, d.opts.Logger, "collected stats")
134138
c.tableMetadata.StatsMarkValid()
135139
}
136140

@@ -653,7 +657,29 @@ func (d *DB) estimateReclaimedSizeBeneath(
653657
return estimate, hintSeqNum, nil
654658
}
655659

656-
func maybeSetStatsFromProperties(meta *tableMetadata, props *sstable.CommonProperties) bool {
660+
var lastSanityCheckStatsLog crtime.AtomicMono
661+
662+
func sanityCheckStats(meta *tableMetadata, logger Logger, info string) {
663+
// Values for PointDeletionsBytesEstimate and RangeDeletionsBytesEstimate that
664+
// exceed this value are most likely indicative of a bug.
665+
const maxDeletionBytesEstimate = 16 << 30 // 16 GiB
666+
667+
if meta.Stats.PointDeletionsBytesEstimate > maxDeletionBytesEstimate ||
668+
meta.Stats.RangeDeletionsBytesEstimate > maxDeletionBytesEstimate {
669+
if v := lastSanityCheckStatsLog.Load(); v == 0 || v.Elapsed() > 30*time.Second {
670+
logger.Errorf("%s: table %s has extreme deletion bytes estimates: point=%d range=%d",
671+
info, meta.FileNum,
672+
redact.Safe(meta.Stats.PointDeletionsBytesEstimate),
673+
redact.Safe(meta.Stats.RangeDeletionsBytesEstimate),
674+
)
675+
lastSanityCheckStatsLog.Store(crtime.NowMono())
676+
}
677+
}
678+
}
679+
680+
func maybeSetStatsFromProperties(
681+
meta *tableMetadata, props *sstable.CommonProperties, logger Logger,
682+
) bool {
657683
// If a table contains range deletions or range key deletions, we defer the
658684
// stats collection. There are two main reasons for this:
659685
//
@@ -697,6 +723,7 @@ func maybeSetStatsFromProperties(meta *tableMetadata, props *sstable.CommonPrope
697723
meta.Stats.ValueBlocksSize = props.ValueBlocksSize
698724
meta.Stats.CompressionType = block.CompressionFromString(props.CompressionName)
699725
meta.StatsMarkValid()
726+
sanityCheckStats(meta, logger, "stats from properties")
700727
return true
701728
}
702729

0 commit comments

Comments
 (0)