Skip to content

Commit

Permalink
add key dedupe when a write buffer writeback to an empty read buffer …
Browse files Browse the repository at this point in the history
…bucket.

Signed-off-by: Siyuan Zhang <sizhang@google.com>
  • Loading branch information
siyuanfoundation committed Jan 25, 2024
1 parent 8298c35 commit 9d4d3af
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions server/storage/backend/tx_buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func (txw *txWriteBuffer) writeback(txr *txReadBuffer) {
rb, ok := txr.buckets[k]
if !ok {
delete(txw.buckets, k)
wb.dedupe()
txr.buckets[k] = wb
continue
}
Expand Down Expand Up @@ -218,10 +219,15 @@ func (bb *bucketBuffer) merge(bbsrc *bucketBuffer) {
if bytes.Compare(bb.buf[(bb.used-bbsrc.used)-1].key, bbsrc.buf[0].key) < 0 {
return
}
bb.dedupe()
}

// dedupe removes duplicates, using only newest update
func (bb *bucketBuffer) dedupe() {
if bb.used <= 1 {
return
}
sort.Stable(bb)

// remove duplicates, using only newest update
widx := 0
for ridx := 1; ridx < bb.used; ridx++ {
if !bytes.Equal(bb.buf[ridx].key, bb.buf[widx].key) {
Expand Down

0 comments on commit 9d4d3af

Please sign in to comment.