Skip to content

Commit

Permalink
storage/engine: small logging fixes
Browse files Browse the repository at this point in the history
Change `Pebble.GetCompactionStats` to be prefixed with a newline to
match the formatting of RocksDB. This ensures that the compaction stats
display will not contain the log prefix which was misaligning the table
header.

Adding a missing sort to `Pebble.GetSSTables`. This was causing the
sstable summary log message to be much busier than for RocksDB because
`SSTableInfos.String` expects the infos to be sorted.

Move the formatting of `estimated_pending_compaction_bytes: x` into
`RocksDB.GetCompactionStats`. The Pebble compaction stats already
included this and it is useful to see the estimated pending compaction
bytes whenever the compaction stats are output.

Release note: None
  • Loading branch information
petermattis committed Dec 17, 2019
1 parent fe04d3f commit b6e6cde
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
8 changes: 7 additions & 1 deletion pkg/storage/engine/pebble.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"io"
"io/ioutil"
"os"
"sort"

"github.com/cockroachdb/cockroach/pkg/base"
"github.com/cockroachdb/cockroach/pkg/roachpb"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -879,6 +883,8 @@ func (p *Pebble) GetSSTables() (sstables SSTableInfos) {
sstables = append(sstables, info)
}
}

sort.Sort(sstables)
return sstables
}

Expand Down
9 changes: 8 additions & 1 deletion pkg/storage/engine/rocksdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 1 addition & 3 deletions pkg/storage/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit b6e6cde

Please sign in to comment.