Skip to content

Commit

Permalink
Reproduce readTxn breaks read commited on delete
Browse files Browse the repository at this point in the history
  • Loading branch information
serathius committed Dec 15, 2023
1 parent 902436e commit b8e26ae
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da
github.com/golang/protobuf v1.5.3
github.com/google/btree v1.1.2
github.com/google/go-cmp v0.6.0
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.1
Expand Down
37 changes: 37 additions & 0 deletions server/storage/backend/batch_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"testing"
"time"

"github.com/google/go-cmp/cmp"

bolt "go.etcd.io/bbolt"
"go.etcd.io/etcd/server/v3/storage/backend"
betesting "go.etcd.io/etcd/server/v3/storage/backend/testing"
Expand Down Expand Up @@ -205,3 +207,38 @@ func TestBatchTxBatchLimitCommit(t *testing.T) {
return nil
})
}

func TestBatchReadMatch(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("bar"))
tx.Unlock()
tx.Commit()

checkKeyValueMatch(t, b.BatchTx(), b.ReadTx(), []byte("foo"))

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

checkKeyValueMatch(t, b.BatchTx(), b.ReadTx(), []byte("foo"))
}

func checkKeyValueMatch(t *testing.T, tx backend.BatchTx, rtx backend.ReadTx, key []byte) {
tx.Lock()
ks1, _ := tx.UnsafeRange(schema.Test, key, nil, 0)
tx.Unlock()

rtx.RLock()
ks2, _ := rtx.UnsafeRange(schema.Test, key, nil, 0)
rtx.RUnlock()

if diff := cmp.Diff(ks1, ks2); diff != "" {
t.Errorf("response on read and batch transaction doesn't match, diff: %s", diff)
}
}

0 comments on commit b8e26ae

Please sign in to comment.