Skip to content

Commit 4b6872e

Browse files
author
Ibrahim Jarif
authored
feat(info): Show index and bloom filter size (#1543)
This PR depends upon hypermodeinc/ristretto#197 `badger info` now shows index size and bloom filter size
1 parent 5d1bab4 commit 4b6872e

File tree

5 files changed

+47
-30
lines changed

5 files changed

+47
-30
lines changed

badger/cmd/info.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,15 +244,23 @@ func tableInfo(dir, valueDir string, db *badger.DB) {
244244
tables := db.Tables(true)
245245
fmt.Println()
246246
fmt.Println("SSTable [Li, Id, Total Keys including internal keys] " +
247-
"[Left Key, Version -> Right Key, Version]" + "[Index Size]")
247+
"[Left Key, Version -> Right Key, Version] [Index Size] [BF Size]")
248+
totalIndex := uint64(0)
249+
totalBloomFilter := uint64(0)
248250
for _, t := range tables {
249251
lk, lt := y.ParseKey(t.Left), y.ParseTs(t.Left)
250252
rk, rt := y.ParseKey(t.Right), y.ParseTs(t.Right)
251253

252-
fmt.Printf("SSTable [L%d, %03d, %07d] [%20X, v%d -> %20X, v%d] [%s]\n",
253-
t.Level, t.ID, t.KeyCount, lk, lt, rk, rt, hbytes(int64(t.IndexSz)))
254+
totalIndex += uint64(t.IndexSz)
255+
totalBloomFilter += uint64(t.BloomFilterSize)
256+
fmt.Printf("SSTable [L%d, %03d, %07d] [%20X, v%d -> %20X, v%d] [%s] [%s] \n",
257+
t.Level, t.ID, t.KeyCount, lk, lt, rk, rt, hbytes(int64(t.IndexSz)),
258+
hbytes(int64(t.BloomFilterSize)))
254259
}
255260
fmt.Println()
261+
fmt.Printf("Total Index Size: %s\n", hbytes(int64(totalIndex)))
262+
fmt.Printf("Total BloomFilter Size: %s\n", hbytes(int64(totalIndex)))
263+
fmt.Println()
256264
}
257265

258266
func printInfo(dir, valueDir string) error {
@@ -403,13 +411,13 @@ func printInfo(dir, valueDir string) error {
403411
}
404412

405413
fmt.Print("\n[Summary]\n")
406-
totalIndexSize := int64(0)
414+
totalSSTSize := int64(0)
407415
for i, sz := range levelSizes {
408416
fmt.Printf("Level %d size: %12s\n", i, hbytes(sz))
409-
totalIndexSize += sz
417+
totalSSTSize += sz
410418
}
411419

412-
fmt.Printf("Total index size: %8s\n", hbytes(totalIndexSize))
420+
fmt.Printf("Total SST size: %8s\n", hbytes(totalSSTSize))
413421
fmt.Printf("Value log size: %10s\n", hbytes(valueLogSize))
414422
fmt.Println()
415423
totalExtra := numExtra + numValueDirExtra

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ go 1.12
55
require (
66
github.com/DataDog/zstd v1.4.1
77
github.com/cespare/xxhash v1.1.0
8-
github.com/dgraph-io/ristretto v0.0.4-0.20200906165740-41ebdbffecfd
8+
github.com/dgraph-io/ristretto v0.0.4-0.20200930150433-e1609c8d4ca6
99
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2
1010
github.com/dustin/go-humanize v1.0.0
1111
github.com/golang/protobuf v1.3.1
1212
github.com/golang/snappy v0.0.1
1313
github.com/kr/pretty v0.1.0 // indirect
14-
github.com/pkg/errors v0.8.1
14+
github.com/pkg/errors v0.9.1
1515
github.com/spaolacci/murmur3 v1.1.0 // indirect
1616
github.com/spf13/cobra v0.0.5
1717
github.com/stretchr/testify v1.4.0
1818
golang.org/x/net v0.0.0-20190620200207-3b0461eec859
19-
golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb
19+
golang.org/x/sys v0.0.0-20200918174421-af09f7315aff
2020
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
2121
)

go.sum

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwc
1313
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1414
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
1515
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
16-
github.com/dgraph-io/ristretto v0.0.4-0.20200906165740-41ebdbffecfd h1:KoJOtZf+6wpQaDTuOWGuo61GxcPBIfhwRxRTaTWGCTc=
17-
github.com/dgraph-io/ristretto v0.0.4-0.20200906165740-41ebdbffecfd/go.mod h1:YylP9MpCYGVZQrly/j/diqcdUetCRRePeBB0c2VGXsA=
16+
github.com/dgraph-io/ristretto v0.0.4-0.20200930150433-e1609c8d4ca6 h1:maqkH6zkcUx1PP+LpbLMef2IOSz2/mLYT3RqecFcdDI=
17+
github.com/dgraph-io/ristretto v0.0.4-0.20200930150433-e1609c8d4ca6/go.mod h1:bDI4cDaalvYSji3vBVDKrn9ouDZrwN974u8ZO/AhYXs=
1818
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 h1:tdlZCpZ/P9DhczCTSixgIKmwPv6+wP5DGjqLYw5SUiA=
1919
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
2020
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
@@ -36,8 +36,8 @@ github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czP
3636
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
3737
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
3838
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
39-
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
40-
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
39+
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
40+
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
4141
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4242
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
4343
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
@@ -64,8 +64,8 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwL
6464
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
6565
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
6666
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
67-
golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb h1:fgwFCsaw9buMuxNd6+DQfAuSFqbNiQZpcgJQAgJsK6k=
68-
golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
67+
golang.org/x/sys v0.0.0-20200918174421-af09f7315aff h1:1CPUrky56AcgSpxz/KfgzQWzfG09u5YOL8MvPYBlrL8=
68+
golang.org/x/sys v0.0.0-20200918174421-af09f7315aff/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
6969
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
7070
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
7171
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=

levels.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,13 +1128,14 @@ func (s *levelsController) appendIterators(
11281128

11291129
// TableInfo represents the information about a table.
11301130
type TableInfo struct {
1131-
ID uint64
1132-
Level int
1133-
Left []byte
1134-
Right []byte
1135-
KeyCount uint64 // Number of keys in the table
1136-
EstimatedSz uint64
1137-
IndexSz int
1131+
ID uint64
1132+
Level int
1133+
Left []byte
1134+
Right []byte
1135+
KeyCount uint64 // Number of keys in the table
1136+
EstimatedSz uint64
1137+
IndexSz int
1138+
BloomFilterSize int
11381139
}
11391140

11401141
func (s *levelsController) getTableInfo(withKeysCount bool) (result []TableInfo) {
@@ -1151,13 +1152,14 @@ func (s *levelsController) getTableInfo(withKeysCount bool) (result []TableInfo)
11511152
}
11521153

11531154
info := TableInfo{
1154-
ID: t.ID(),
1155-
Level: l.level,
1156-
Left: t.Smallest(),
1157-
Right: t.Biggest(),
1158-
KeyCount: count,
1159-
EstimatedSz: t.EstimatedSize(),
1160-
IndexSz: t.IndexSize(),
1155+
ID: t.ID(),
1156+
Level: l.level,
1157+
Left: t.Smallest(),
1158+
Right: t.Biggest(),
1159+
KeyCount: count,
1160+
EstimatedSz: t.EstimatedSize(),
1161+
IndexSz: t.IndexSize(),
1162+
BloomFilterSize: t.BloomFilterSize(),
11611163
}
11621164
result = append(result, info)
11631165
}

table/table.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,8 @@ func (t *Table) blockOffsetsCacheKey() uint64 {
669669
return t.id
670670
}
671671

672-
// IndexSize is the size of table index in bytes
672+
// IndexSize returns the size of table index in bytes stored in the memory. The
673+
// size of on-disk representation would be less than the in-memory representation.
673674
func (t *Table) IndexSize() int {
674675
indexSz := 0
675676
for _, bi := range t.blockOffsets() {
@@ -678,6 +679,12 @@ func (t *Table) IndexSize() int {
678679
return indexSz
679680
}
680681

682+
// BloomFilterSize returns the size of the bloom filter in bytes stored in memory. The
683+
// size of on-disk representation would be less than the in-memory representation.
684+
func (t *Table) BloomFilterSize() int {
685+
return t.bf.TotalSize()
686+
}
687+
681688
// EstimatedSize returns the total size of key-values stored in this table (including the
682689
// disk space occupied on the value log).
683690
func (t *Table) EstimatedSize() uint64 { return t.estimatedSize }

0 commit comments

Comments
 (0)