Skip to content
This repository has been archived by the owner on Aug 23, 2023. It is now read-only.

Commit

Permalink
more efficient buffer flushing
Browse files Browse the repository at this point in the history
  • Loading branch information
replay committed Jul 4, 2017
1 parent 6371869 commit a02edb9
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions mdata/write_buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,22 +107,19 @@ func (wb *WriteBuffer) flushIfReady() {
return
}

// seek the entry up to which we'll want to flush
flushEnd := wb.last
for cnt := uint32(0); cnt < wb.reorderWindow; flushEnd = flushEnd.prev {
cnt++
}

for i := wb.first; ; i = i.next {
wb.flush(i.ts, i.val)
bufPool.Put(i)
if i == flushEnd {
break
}
// we want to flush until the length is equal to the reorder window
flushCount := wb.len - wb.reorderWindow

nextEntry := wb.first
for i := uint32(0); i < flushCount; i++ {
flushEntry := nextEntry
nextEntry = flushEntry.next
wb.flush(flushEntry.ts, flushEntry.val)
bufPool.Put(flushEntry)
}

wb.len = wb.reorderWindow
wb.first = flushEnd.next
wb.first = nextEntry
wb.first.prev = nil
wb.lastFlush = wb.first.ts
}
Expand Down

0 comments on commit a02edb9

Please sign in to comment.