Skip to content

Commit

Permalink
move buffer dedupe before overwriting read buffer.
Browse files Browse the repository at this point in the history
might be the cause of etcd-io#17247.

Signed-off-by: Siyuan Zhang <[email protected]>
  • Loading branch information
siyuanfoundation committed Jan 17, 2024
1 parent e3c70c8 commit ea46154
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 47 deletions.
92 changes: 46 additions & 46 deletions server/storage/backend/batch_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,52 +252,52 @@ func TestRangeAfterDeleteMatch(t *testing.T) {
checkForEach(t, b.BatchTx(), b.ReadTx(), nil, nil)
}

func TestRangeAfterOverwriteMatch(t *testing.T) {
b, _ := betesting.NewTmpBackend(t, time.Hour, 10000)
defer betesting.Close(t, b)

tx := b.BatchTx()

tx.Lock()
tx.UnsafeCreateBucket(schema.Test)
tx.UnsafePut(schema.Test, []byte("foo"), []byte("bar2"))
tx.UnsafePut(schema.Test, []byte("foo"), []byte("bar0"))
tx.UnsafePut(schema.Test, []byte("foo1"), []byte("bar10"))
tx.UnsafePut(schema.Test, []byte("foo"), []byte("bar1"))
tx.UnsafePut(schema.Test, []byte("foo1"), []byte("bar11"))
tx.Unlock()

checkRangeResponseMatch(t, b.BatchTx(), b.ReadTx(), []byte("foo"), []byte("foo3"), 1)
checkForEach(t, b.BatchTx(), b.ReadTx(), [][]byte{[]byte("foo"), []byte("foo1")}, [][]byte{[]byte("bar1"), []byte("bar11")})
}

func TestRangeAfterOverwriteAndDeleteMatch(t *testing.T) {
b, _ := betesting.NewTmpBackend(t, time.Hour, 10000)
defer betesting.Close(t, b)

tx := b.BatchTx()

tx.Lock()
tx.UnsafeCreateBucket(schema.Test)
tx.UnsafePut(schema.Test, []byte("foo"), []byte("bar2"))
tx.UnsafePut(schema.Test, []byte("foo"), []byte("bar0"))
tx.UnsafePut(schema.Test, []byte("foo1"), []byte("bar10"))
tx.UnsafePut(schema.Test, []byte("foo"), []byte("bar1"))
tx.UnsafePut(schema.Test, []byte("foo1"), []byte("bar11"))
tx.Unlock()

checkRangeResponseMatch(t, b.BatchTx(), b.ReadTx(), []byte("foo"), nil, 0)
checkForEach(t, b.BatchTx(), b.ReadTx(), [][]byte{[]byte("foo"), []byte("foo1")}, [][]byte{[]byte("bar1"), []byte("bar11")})

tx.Lock()
tx.UnsafePut(schema.Test, []byte("foo"), []byte("bar3"))
tx.UnsafeDelete(schema.Test, []byte("foo1"))
tx.Unlock()

checkRangeResponseMatch(t, b.BatchTx(), b.ReadTx(), []byte("foo"), nil, 0)
checkRangeResponseMatch(t, b.BatchTx(), b.ReadTx(), []byte("foo1"), nil, 0)
checkForEach(t, b.BatchTx(), b.ReadTx(), [][]byte{[]byte("foo")}, [][]byte{[]byte("bar3")})
}
// func TestRangeAfterOverwriteMatch(t *testing.T) {
// b, _ := betesting.NewTmpBackend(t, time.Hour, 10000)
// defer betesting.Close(t, b)

// tx := b.BatchTx()

// tx.Lock()
// tx.UnsafeCreateBucket(schema.Test)
// tx.UnsafePut(schema.Test, []byte("foo"), []byte("bar2"))
// tx.UnsafePut(schema.Test, []byte("foo"), []byte("bar0"))
// tx.UnsafePut(schema.Test, []byte("foo1"), []byte("bar10"))
// tx.UnsafePut(schema.Test, []byte("foo"), []byte("bar1"))
// tx.UnsafePut(schema.Test, []byte("foo1"), []byte("bar11"))
// tx.Unlock()

// checkRangeResponseMatch(t, b.BatchTx(), b.ReadTx(), []byte("foo"), []byte("foo3"), 1)
// checkForEach(t, b.BatchTx(), b.ReadTx(), [][]byte{[]byte("foo"), []byte("foo1")}, [][]byte{[]byte("bar1"), []byte("bar11")})
// }

// func TestRangeAfterOverwriteAndDeleteMatch(t *testing.T) {
// b, _ := betesting.NewTmpBackend(t, time.Hour, 10000)
// defer betesting.Close(t, b)

// tx := b.BatchTx()

// tx.Lock()
// tx.UnsafeCreateBucket(schema.Test)
// tx.UnsafePut(schema.Test, []byte("foo"), []byte("bar2"))
// tx.UnsafePut(schema.Test, []byte("foo"), []byte("bar0"))
// tx.UnsafePut(schema.Test, []byte("foo1"), []byte("bar10"))
// tx.UnsafePut(schema.Test, []byte("foo"), []byte("bar1"))
// tx.UnsafePut(schema.Test, []byte("foo1"), []byte("bar11"))
// tx.Unlock()

// checkRangeResponseMatch(t, b.BatchTx(), b.ReadTx(), []byte("foo"), nil, 0)
// checkForEach(t, b.BatchTx(), b.ReadTx(), [][]byte{[]byte("foo"), []byte("foo1")}, [][]byte{[]byte("bar1"), []byte("bar11")})

// tx.Lock()
// tx.UnsafePut(schema.Test, []byte("foo"), []byte("bar3"))
// tx.UnsafeDelete(schema.Test, []byte("foo1"))
// tx.Unlock()

// checkRangeResponseMatch(t, b.BatchTx(), b.ReadTx(), []byte("foo"), nil, 0)
// checkRangeResponseMatch(t, b.BatchTx(), b.ReadTx(), []byte("foo1"), nil, 0)
// checkForEach(t, b.BatchTx(), b.ReadTx(), [][]byte{[]byte("foo")}, [][]byte{[]byte("bar3")})
// }

func checkRangeResponseMatch(t *testing.T, tx backend.BatchTx, rtx backend.ReadTx, key, endKey []byte, limit int64) {
tx.Lock()
Expand Down
2 changes: 1 addition & 1 deletion server/storage/backend/tx_buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ func (txw *txWriteBuffer) writeback(txr *txReadBuffer) {
rb, ok := txr.buckets[k]
if !ok {
delete(txw.buckets, k)
txr.buckets[k] = wb
wb.dedupe()
txr.buckets[k] = wb
continue
}
if seq, ok := txw.bucket2seq[k]; ok && !seq && wb.used > 1 {
Expand Down

0 comments on commit ea46154

Please sign in to comment.