Skip to content

Commit 366f538

Browse files
author
Anthony Romano
authored
Merge pull request #8366 from heyitsanthony/prevkey-proxy
grpcproxy: forward PrevKv flag in Put
2 parents faa4a62 + 6a4194c commit 366f538

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

integration/v3_grpc_test.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func TestV3PutOverwrite(t *testing.T) {
4444

4545
kvc := toGRPC(clus.RandClient()).KV
4646
key := []byte("foo")
47-
reqput := &pb.PutRequest{Key: key, Value: []byte("bar")}
47+
reqput := &pb.PutRequest{Key: key, Value: []byte("bar"), PrevKv: true}
4848

4949
respput, err := kvc.Put(context.TODO(), reqput)
5050
if err != nil {
@@ -61,6 +61,9 @@ func TestV3PutOverwrite(t *testing.T) {
6161
t.Fatalf("expected newer revision on overwrite, got %v <= %v",
6262
respput2.Header.Revision, respput.Header.Revision)
6363
}
64+
if pkv := respput2.PrevKv; pkv == nil || string(pkv.Value) != "bar" {
65+
t.Fatalf("expected PrevKv=bar, got response %+v", respput2)
66+
}
6467

6568
reqrange := &pb.RangeRequest{Key: key}
6669
resprange, err := kvc.Range(context.TODO(), reqrange)

proxy/grpcproxy/kv.go

+3
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ func PutRequestToOp(r *pb.PutRequest) clientv3.Op {
196196
if r.IgnoreLease {
197197
opts = append(opts, clientv3.WithIgnoreLease())
198198
}
199+
if r.PrevKv {
200+
opts = append(opts, clientv3.WithPrevKV())
201+
}
199202
return clientv3.OpPut(string(r.Key), string(r.Value), opts...)
200203
}
201204

0 commit comments

Comments
 (0)