Skip to content

Commit

Permalink
sstable: reuse index block iterator in Layout
Browse files Browse the repository at this point in the history
  • Loading branch information
dt committed Jan 18, 2022
1 parent 628db89 commit 20f8dd0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion sstable/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -2478,6 +2478,7 @@ func (r *Reader) Layout() (*Layout, error) {
} else {
l.TopIndex = r.indexBH
topIter, _ := newBlockIter(r.Compare, indexH.Get())
iter := &blockIter{}
for key, value := topIter.First(); key != nil; key, value = topIter.Next() {
indexBH, err := decodeBlockHandleWithProperties(value)
if err != nil {
Expand All @@ -2490,7 +2491,9 @@ func (r *Reader) Layout() (*Layout, error) {
if err != nil {
return nil, err
}
iter, _ := newBlockIter(r.Compare, subIndex.Get())
if err := iter.init(r.Compare, subIndex.Get(), 0 /* globalSeqNum */); err != nil {
return nil, err
}
for key, value := iter.First(); key != nil; key, value = iter.Next() {
dataBH, err := decodeBlockHandleWithProperties(value)
if err != nil {
Expand All @@ -2499,6 +2502,7 @@ func (r *Reader) Layout() (*Layout, error) {
l.Data = append(l.Data, dataBH.BlockHandle)
}
subIndex.Release()
*iter = iter.resetForReuse()
}
}

Expand Down
10 changes: 10 additions & 0 deletions sstable/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1063,3 +1063,13 @@ func BenchmarkTableIterPrev(b *testing.B) {
})
}
}

func BenchmarkLayout(b *testing.B) {
r, _ := buildBenchmarkTable(b, WriterOptions{})
b.ResetTimer()
for i := 0; i < b.N; i++ {
r.Layout()
}
b.StopTimer()
r.Close()
}

0 comments on commit 20f8dd0

Please sign in to comment.