Skip to content
Merged
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
20 changes: 12 additions & 8 deletions bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -661,16 +661,20 @@ func (b *Bucket) Stats() BucketStats {
}
} else if p.IsBranchPage() {
s.BranchPageN++
lastElement := p.BranchPageElement(p.Count() - 1)

// used totals the used bytes for the page
// Add header and all element headers.
used := common.PageHeaderSize + (common.BranchPageElementSize * uintptr(p.Count()-1))
used := common.PageHeaderSize
if p.Count() != 0 {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: normally a branch page should always have at least 1 item, otherwise the page will be removed. But the change has no any harm.

lastElement := p.BranchPageElement(p.Count() - 1)

// Add all element headers.
used += common.BranchPageElementSize * uintptr(p.Count()-1)

// Add size of all keys and values.
// Again, use the fact that last element's position equals to
// the total of key, value sizes of all previous elements.
used += uintptr(lastElement.Pos() + lastElement.Ksize())
}

// Add size of all keys and values.
// Again, use the fact that last element's position equals to
// the total of key, value sizes of all previous elements.
used += uintptr(lastElement.Pos() + lastElement.Ksize())
s.BranchInuse += int(used)
s.BranchOverflowN += int(p.Overflow())
}
Expand Down