From ed1c357994e193032df6134432beee4be178674b Mon Sep 17 00:00:00 2001 From: Manish R Jain Date: Thu, 7 Mar 2019 19:46:19 -0800 Subject: [PATCH] Fix the build breakage and improve the output so it is machine parseable. --- badger/cmd/info.go | 12 +++++------- histogram.go | 22 +++++++++++----------- histogram_test.go | 4 ++-- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/badger/cmd/info.go b/badger/cmd/info.go index b84fd6d03..55c8a5122 100644 --- a/badger/cmd/info.go +++ b/badger/cmd/info.go @@ -89,7 +89,7 @@ to the Dgraph team. } if opt.sizeHistogram { // use prefix as nil since we want to list all keys - db.ShowKeyValueSizeHistogram(nil) + db.PrintHistogram(nil) } }, } @@ -104,16 +104,14 @@ func dur(src, dst time.Time) string { func tableInfo(dir, valueDir string, db *badger.DB) error { tables := db.Tables() - fmt.Printf("\n%s SSTables %[1]s\n", strings.Repeat("=", 45)) - fmt.Printf("%-5s\t%-10s\t%-30s\t%-30s\t%-7s\n", "ID", "Level", - "Left-Key(in hex) (Time)", "Right-Key(in hex) (Time)", "Total Keys") - fmt.Printf("%s\n", strings.Repeat("=", 100)) + fmt.Println() + fmt.Println("SSTable [Li, Id, Total Keys including internal keys] [Left Key, Version -> Right Key, Version]") for _, t := range tables { lk, lt := y.ParseKey(t.Left), y.ParseTs(t.Left) rk, rt := y.ParseKey(t.Right), y.ParseTs(t.Right) - fmt.Printf("%-5d\tL%-9d\t%-30s\t%-30s\t%-7d\n", t.ID, t.Level, - fmt.Sprintf("%X (v%d)", lk, lt), fmt.Sprintf("%X (v%d)", rk, rt), t.KeyCount) + fmt.Printf("SSTable [L%d, %03d, %07d] [%20X, v%d -> %20X, v%d]\n", + t.Level, t.ID, t.KeyCount, lk, lt, rk, rt) } fmt.Println() return nil diff --git a/histogram.go b/histogram.go index 0d4643901..d8c94bb7a 100644 --- a/histogram.go +++ b/histogram.go @@ -21,15 +21,15 @@ import ( "math" ) -// PrintKeyValueHistogram builds and displays the key-value size histogram. +// PrintHistogram builds and displays the key-value size histogram. // When keyPrefix is set, only the keys that have prefix "keyPrefix" are // considered for creating the histogram -func (db *DB) PrintKeyValueHistogram(keyPrefix []byte) { +func (db *DB) PrintHistogram(keyPrefix []byte) { if db == nil { fmt.Println("\nCannot build histogram: DB is nil.") return } - histogram := db.buildKeyValueSizeHistogram(keyPrefix) + histogram := db.buildHistogram(keyPrefix) fmt.Printf("Histogram of key sizes (in bytes)\n") histogram.keySizeHistogram.printHistogram() fmt.Printf("Histogram of value sizes (in bytes)\n") @@ -46,18 +46,18 @@ type histogramData struct { sum int64 } -// keyValueSizeHistogram contains keySize histogram and valueSize histogram -type keyValueSizeHistogram struct { +// sizeHistogram contains keySize histogram and valueSize histogram +type sizeHistogram struct { keySizeHistogram, valueSizeHistogram histogramData } -// newKeyValueSizeHistogram returns a new instance of keyValueSizeHistogram with +// newSizeHistogram returns a new instance of keyValueSizeHistogram with // properly initialized fields. -func newKeyValueSizeHistogram() *keyValueSizeHistogram { +func newSizeHistogram() *sizeHistogram { // TODO(ibrahim): find appropriate bin size. keyBins := createHistogramBins(1, 16) valueBins := createHistogramBins(1, 30) - return &keyValueSizeHistogram{ + return &sizeHistogram{ keySizeHistogram: histogramData{ bins: keyBins, countPerBin: make([]int64, len(keyBins)+1), @@ -113,17 +113,17 @@ func (histogram *histogramData) Update(value int64) { } } -// buildKeyValueSizeHistogram builds the key-value size histogram. +// buildHistogram builds the key-value size histogram. // When keyPrefix is set, only the keys that have prefix "keyPrefix" are // considered for creating the histogram -func (db *DB) buildKeyValueSizeHistogram(keyPrefix []byte) *keyValueSizeHistogram { +func (db *DB) buildHistogram(keyPrefix []byte) *sizeHistogram { txn := db.NewTransaction(false) defer txn.Discard() itr := txn.NewIterator(DefaultIteratorOptions) defer itr.Close() - badgerHistogram := newKeyValueSizeHistogram() + badgerHistogram := newSizeHistogram() // Collect key and value sizes. for itr.Seek(keyPrefix); itr.ValidForPrefix(keyPrefix); itr.Next() { diff --git a/histogram_test.go b/histogram_test.go index 240fca621..bb73310c3 100644 --- a/histogram_test.go +++ b/histogram_test.go @@ -37,7 +37,7 @@ func TestBuildKeyValueSizeHistogram(t *testing.T) { }) require.NoError(t, err) - histogram := db.buildKeyValueSizeHistogram(nil) + histogram := db.buildHistogram(nil) keyHistogram := histogram.keySizeHistogram valueHistogram := histogram.valueSizeHistogram @@ -79,7 +79,7 @@ func TestBuildKeyValueSizeHistogram(t *testing.T) { }) require.NoError(t, err) - histogram := db.buildKeyValueSizeHistogram(nil) + histogram := db.buildHistogram(nil) keyHistogram := histogram.keySizeHistogram valueHistogram := histogram.valueSizeHistogram