Skip to content

Commit

Permalink
add IndexSz field to TableInfo, to show it through badger info tool
Browse files Browse the repository at this point in the history
This PR adds the table index size to badger info and adds a new field IndexSz to TableInfo struct. This field denotes the size of the table index
  • Loading branch information
NamanJain8 authored Aug 24, 2020
1 parent d38bef3 commit 6d3f4b1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
6 changes: 3 additions & 3 deletions badger/cmd/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,13 @@ func tableInfo(dir, valueDir string, db *badger.DB) {
tables := db.Tables(true)
fmt.Println()
fmt.Println("SSTable [Li, Id, Total Keys including internal keys] " +
"[Left Key, Version -> Right Key, Version]")
"[Left Key, Version -> Right Key, Version]" + "[Index Size]")
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("SSTable [L%d, %03d, %07d] [%20X, v%d -> %20X, v%d]\n",
t.Level, t.ID, t.KeyCount, lk, lt, rk, rt)
fmt.Printf("SSTable [L%d, %03d, %07d] [%20X, v%d -> %20X, v%d] [%s]\n",
t.Level, t.ID, t.KeyCount, lk, lt, rk, rt, hbytes(int64(t.IndexSz)))
}
fmt.Println()
}
Expand Down
2 changes: 2 additions & 0 deletions levels.go
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,7 @@ type TableInfo struct {
Right []byte
KeyCount uint64 // Number of keys in the table
EstimatedSz uint64
IndexSz int
}

func (s *levelsController) getTableInfo(withKeysCount bool) (result []TableInfo) {
Expand All @@ -1161,6 +1162,7 @@ func (s *levelsController) getTableInfo(withKeysCount bool) (result []TableInfo)
Right: t.Biggest(),
KeyCount: count,
EstimatedSz: t.EstimatedSize(),
IndexSz: t.IndexSize(),
}
result = append(result, info)
}
Expand Down
9 changes: 9 additions & 0 deletions table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,15 @@ func (t *Table) blockOffsetsCacheKey() []byte {
return buf
}

// IndexSize is the size of table index in bytes
func (t *Table) IndexSize() int {
indexSz := 0
for _, bi := range t.blockOffsets() {
indexSz += bi.Size()
}
return indexSz
}

// EstimatedSize returns the total size of key-values stored in this table (including the
// disk space occupied on the value log).
func (t *Table) EstimatedSize() uint64 { return t.estimatedSize }
Expand Down

0 comments on commit 6d3f4b1

Please sign in to comment.