From c3ae033f2581630fc91681f82e560dabefbbe06e Mon Sep 17 00:00:00 2001 From: Anthony Romano Date: Thu, 3 Aug 2017 21:37:06 -0700 Subject: [PATCH 1/2] integration: test Put with PrevKey=true Was missing in proxy. --- integration/v3_grpc_test.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/integration/v3_grpc_test.go b/integration/v3_grpc_test.go index 78fb21d20d2..13c2b875636 100644 --- a/integration/v3_grpc_test.go +++ b/integration/v3_grpc_test.go @@ -44,7 +44,7 @@ func TestV3PutOverwrite(t *testing.T) { kvc := toGRPC(clus.RandClient()).KV key := []byte("foo") - reqput := &pb.PutRequest{Key: key, Value: []byte("bar")} + reqput := &pb.PutRequest{Key: key, Value: []byte("bar"), PrevKv: true} respput, err := kvc.Put(context.TODO(), reqput) if err != nil { @@ -61,6 +61,9 @@ func TestV3PutOverwrite(t *testing.T) { t.Fatalf("expected newer revision on overwrite, got %v <= %v", respput2.Header.Revision, respput.Header.Revision) } + if pkv := respput2.PrevKv; pkv == nil || string(pkv.Value) != "bar" { + t.Fatalf("expected PrevKv=bar, got response %+v", respput2) + } reqrange := &pb.RangeRequest{Key: key} resprange, err := kvc.Range(context.TODO(), reqrange) From 6a4194c556d1dd985f419dc095b03a335aa5f940 Mon Sep 17 00:00:00 2001 From: Anthony Romano Date: Thu, 3 Aug 2017 21:38:20 -0700 Subject: [PATCH 2/2] grpcproxy: forward PrevKv flag in Put --- proxy/grpcproxy/kv.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/proxy/grpcproxy/kv.go b/proxy/grpcproxy/kv.go index 7799d817e33..4e6b0366173 100644 --- a/proxy/grpcproxy/kv.go +++ b/proxy/grpcproxy/kv.go @@ -196,6 +196,9 @@ func PutRequestToOp(r *pb.PutRequest) clientv3.Op { if r.IgnoreLease { opts = append(opts, clientv3.WithIgnoreLease()) } + if r.PrevKv { + opts = append(opts, clientv3.WithPrevKV()) + } return clientv3.OpPut(string(r.Key), string(r.Value), opts...) }