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

storage/engine: small logging fixes #43240

Merged
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
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