Skip to content

Commit

Permalink
opt(restore): Sort the buffer before spinning the writeToDisk gorouti…
Browse files Browse the repository at this point in the history
…ne (#7984)

Sort the buffer beforehand instead of sorting it in the goroutine used for
writing the buffer to disk. The writeToDisk goroutines are throttled and
making it expensive causes other goroutines to block.

This change significantly improves the restore map phase.
  • Loading branch information
ahsanbarkati authored Aug 12, 2021
1 parent 3233a70 commit 1966245
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions worker/restore_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,6 @@ func (m *mapper) writeToDisk(buf *z.Buffer) error {
if buf.IsEmpty() {
return nil
}
buf.SortSlice(func(ls, rs []byte) bool {
lme := mapEntry(ls)
rme := mapEntry(rs)
return y.CompareKeys(lme.Key(), rme.Key()) < 0
})

f, err := m.newMapFile()
if err != nil {
Expand Down Expand Up @@ -239,6 +234,11 @@ func (mw *mapper) sendForWriting() error {
if mw.buf.IsEmpty() {
return nil
}
mw.buf.SortSlice(func(ls, rs []byte) bool {
lme := mapEntry(ls)
rme := mapEntry(rs)
return y.CompareKeys(lme.Key(), rme.Key()) < 0
})

if err := mw.thr.Do(); err != nil {
return err
Expand Down

0 comments on commit 1966245

Please sign in to comment.