mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
add key dedupe when a write buffer writeback to an empty read buffer bucket.
Signed-off-by: Siyuan Zhang <sizhang@google.com>
This commit is contained in:
parent
1901c85a8c
commit
4142d49eea
@ -80,6 +80,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
|
||||
}
|
||||
@ -201,10 +202,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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user