diff --git a/pkg/storage/engine/pebble.go b/pkg/storage/engine/pebble.go index d4bced4c94b7..c6e073eb5146 100644 --- a/pkg/storage/engine/pebble.go +++ b/pkg/storage/engine/pebble.go @@ -17,6 +17,7 @@ import ( "io" "io/ioutil" "os" + "sort" "github.com/cockroachdb/cockroach/pkg/base" "github.com/cockroachdb/cockroach/pkg/roachpb" @@ -487,7 +488,10 @@ func (p *Pebble) Get(key MVCCKey) ([]byte, error) { // GetCompactionStats implements the Engine interface. func (p *Pebble) GetCompactionStats() string { - return p.db.Metrics().String() + // NB: The initial blank line matches the formatting used by RocksDB and + // ensures that compaction stats display will not contain the log prefix + // (this method is only used for logging purposes). + return "\n" + p.db.Metrics().String() } // GetTickersAndHistograms implements the Engine interface. @@ -879,6 +883,8 @@ func (p *Pebble) GetSSTables() (sstables SSTableInfos) { sstables = append(sstables, info) } } + + sort.Sort(sstables) return sstables } diff --git a/pkg/storage/engine/rocksdb.go b/pkg/storage/engine/rocksdb.go index fe3fceae3037..1360e7f70cc2 100644 --- a/pkg/storage/engine/rocksdb.go +++ b/pkg/storage/engine/rocksdb.go @@ -33,6 +33,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/util" "github.com/cockroachdb/cockroach/pkg/util/envutil" "github.com/cockroachdb/cockroach/pkg/util/hlc" + "github.com/cockroachdb/cockroach/pkg/util/humanizeutil" "github.com/cockroachdb/cockroach/pkg/util/log" "github.com/cockroachdb/cockroach/pkg/util/protoutil" "github.com/cockroachdb/cockroach/pkg/util/syncutil" @@ -1261,7 +1262,13 @@ func (r *RocksDB) GetTickersAndHistograms() (*enginepb.TickersAndHistograms, err // GetCompactionStats returns the internal RocksDB compaction stats. See // https://github.com/facebook/rocksdb/wiki/RocksDB-Tuning-Guide#rocksdb-statistics. func (r *RocksDB) GetCompactionStats() string { - return cStringToGoString(C.DBGetCompactionStats(r.rdb)) + s := cStringToGoString(C.DBGetCompactionStats(r.rdb)) + + "estimated_pending_compaction_bytes: " + stats, err := r.GetStats() + if err != nil { + return s + err.Error() + } + return s + humanizeutil.IBytes(stats.PendingCompactionBytesEstimate) } // GetEnvStats returns stats for the RocksDB env. This may include encryption stats. diff --git a/pkg/storage/store.go b/pkg/storage/store.go index 1cd6704c47b7..5399fba51785 100644 --- a/pkg/storage/store.go +++ b/pkg/storage/store.go @@ -53,7 +53,6 @@ import ( "github.com/cockroachdb/cockroach/pkg/util/contextutil" "github.com/cockroachdb/cockroach/pkg/util/envutil" "github.com/cockroachdb/cockroach/pkg/util/hlc" - "github.com/cockroachdb/cockroach/pkg/util/humanizeutil" "github.com/cockroachdb/cockroach/pkg/util/limit" "github.com/cockroachdb/cockroach/pkg/util/log" "github.com/cockroachdb/cockroach/pkg/util/metric" @@ -2354,8 +2353,7 @@ func (s *Store) ComputeMetrics(ctx context.Context, tick int) error { // stats. if tick%logSSTInfoTicks == 1 /* every 10m */ { log.Infof(ctx, "sstables (read amplification = %d):\n%s", readAmp, sstables) - log.Infof(ctx, "%sestimated_pending_compaction_bytes: %s", - s.engine.GetCompactionStats(), humanizeutil.IBytes(stats.PendingCompactionBytesEstimate)) + log.Infof(ctx, "%s", s.engine.GetCompactionStats()) } return nil }